Fix sonar warnings in config-util.
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / strategy / DeleteEditConfigStrategy.java
1 /*
2  * Copyright (c) 2015 Cisco 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
9 package org.opendaylight.controller.config.facade.xml.strategy;
10
11 import java.util.Map;
12 import javax.management.InstanceNotFoundException;
13 import javax.management.ObjectName;
14 import org.opendaylight.controller.config.facade.xml.exception.ConfigHandlingException;
15 import org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement;
16 import org.opendaylight.controller.config.facade.xml.mapping.config.ServiceRegistryWrapper;
17 import org.opendaylight.controller.config.util.ConfigTransactionClient;
18 import org.opendaylight.controller.config.util.xml.DocumentedException;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 public class DeleteEditConfigStrategy extends AbstractEditConfigStrategy {
23
24     private static final Logger LOG = LoggerFactory.getLogger(DeleteEditConfigStrategy.class);
25
26
27     @Override
28     void handleMissingInstance(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
29                                String module, String instance, ServiceRegistryWrapper services) throws
30         ConfigHandlingException {
31         throw new ConfigHandlingException(String.format("Unable to delete %s : %s , ServiceInstance not found", module, instance),
32                 DocumentedException.ErrorType.APPLICATION,
33                 DocumentedException.ErrorTag.OPERATION_FAILED,
34                 DocumentedException.ErrorSeverity.ERROR);
35     }
36
37     @Override
38     void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) throws
39         ConfigHandlingException {
40         try {
41             ta.destroyModule(on);
42             LOG.debug("ServiceInstance {} deleted successfully", on);
43         } catch (InstanceNotFoundException e) {
44             throw new ConfigHandlingException(
45                     String.format("Unable to delete %s because of exception %s" + on, e.getMessage()),
46                     DocumentedException.ErrorType.APPLICATION,
47                     DocumentedException.ErrorTag.OPERATION_FAILED,
48                     DocumentedException.ErrorSeverity.ERROR);
49         }
50     }
51 }