Merge changes Ic434bf4a,I05a3fb18,I47a3783d,I8234bbfd
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / operations / editconfig / DeleteEditConfigStrategy.java
1 /*
2  * Copyright (c) 2013 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.netconf.confignetconfconnector.operations.editconfig;
10
11 import java.util.Map;
12 import javax.management.InstanceNotFoundException;
13 import javax.management.ObjectName;
14 import org.opendaylight.controller.config.util.ConfigTransactionClient;
15 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
16 import org.opendaylight.controller.netconf.confignetconfconnector.exception.NetconfConfigHandlingException;
17 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
18 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper;
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 NetconfConfigHandlingException {
30         throw new NetconfConfigHandlingException(String.format("Unable to delete %s : %s , ServiceInstance not found", module ,instance),
31                 NetconfDocumentedException.ErrorType.application,
32                 NetconfDocumentedException.ErrorTag.operation_failed,
33                 NetconfDocumentedException.ErrorSeverity.error);
34     }
35
36     @Override
37     void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) throws NetconfConfigHandlingException {
38         try {
39             ta.destroyModule(on);
40             LOG.debug("ServiceInstance {} deleted successfully", on);
41         } catch (InstanceNotFoundException e) {
42             throw new NetconfConfigHandlingException(
43                     String.format("Unable to delete %s because of exception %s" + on, e.getMessage()),
44                     NetconfDocumentedException.ErrorType.application,
45                     NetconfDocumentedException.ErrorTag.operation_failed,
46                     NetconfDocumentedException.ErrorSeverity.error);
47         }
48     }
49 }