Fix sonar warnings in config-util.
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / strategy / ReCreateEditConfigStrategy.java
1 /*
2  * Copyright (c) 2016 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.config.facade.xml.strategy;
9
10 import java.util.Map;
11 import javax.management.InstanceNotFoundException;
12 import javax.management.ObjectName;
13 import org.opendaylight.controller.config.facade.xml.exception.ConfigHandlingException;
14 import org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement;
15 import org.opendaylight.controller.config.facade.xml.mapping.config.ServiceRegistryWrapper;
16 import org.opendaylight.controller.config.util.ConfigTransactionClient;
17 import org.opendaylight.controller.config.util.xml.DocumentedException;
18
19 /**
20  * Edit strategy that forces re-creation of a module instance even if the config didn't change.
21  *
22  * @author Thomas Pantelis
23  */
24 public class ReCreateEditConfigStrategy extends AbstractEditConfigStrategy {
25
26     @Override
27     void handleMissingInstance(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
28             String module, String instance, ServiceRegistryWrapper services) throws ConfigHandlingException {
29         throw new ConfigHandlingException(
30                 String.format("Unable to recreate %s : %s, Existing module instance not found", module, instance),
31                 DocumentedException.ErrorType.APPLICATION,
32                 DocumentedException.ErrorTag.OPERATION_FAILED,
33                 DocumentedException.ErrorSeverity.ERROR);
34     }
35
36     @Override
37     void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
38             ObjectName objectName, ServiceRegistryWrapper services) throws ConfigHandlingException {
39         try {
40             ta.reCreateModule(objectName);
41         } catch(InstanceNotFoundException e) {
42             throw new ConfigHandlingException(String.format("Unable to recreate instance for %s", objectName),
43                     DocumentedException.ErrorType.APPLICATION,
44                     DocumentedException.ErrorTag.OPERATION_FAILED,
45                     DocumentedException.ErrorSeverity.ERROR);
46         }
47     }
48 }