e88863c685ace15c486c9b5c263345a81ace9a44
[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 com.google.common.collect.HashMultimap;
12 import com.google.common.collect.Multimap;
13 import org.opendaylight.controller.config.util.ConfigTransactionClient;
14 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
15 import org.opendaylight.controller.netconf.confignetconfconnector.exception.NetconfConfigHandlingException;
16 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.AttributeConfigElement;
17 import org.opendaylight.controller.netconf.confignetconfconnector.mapping.config.ServiceRegistryWrapper;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 import javax.management.InstanceNotFoundException;
22 import javax.management.ObjectName;
23 import java.util.Map;
24
25 public class DeleteEditConfigStrategy extends AbstractEditConfigStrategy {
26
27     private static final Logger logger = LoggerFactory.getLogger(DeleteEditConfigStrategy.class);
28
29     private final Multimap<String, String> providedServices;
30
31     public DeleteEditConfigStrategy() {
32         this.providedServices = HashMultimap.create();
33     }
34
35     public DeleteEditConfigStrategy(Multimap<String, String> providedServices) {
36         this.providedServices = providedServices;
37     }
38
39     @Override
40     void handleMissingInstance(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
41                                String module, String instance, ServiceRegistryWrapper services) throws NetconfConfigHandlingException {
42         throw new NetconfConfigHandlingException(String.format("Unable to delete %s : %s , ServiceInstance not found", module ,instance),
43                 NetconfDocumentedException.ErrorType.application,
44                 NetconfDocumentedException.ErrorTag.operation_failed,
45                 NetconfDocumentedException.ErrorSeverity.error);
46     }
47
48     @Override
49     void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) throws NetconfConfigHandlingException {
50         try {
51             ta.destroyModule(on);
52             logger.debug("ServiceInstance {} deleted successfully", on);
53         } catch (InstanceNotFoundException e) {
54             throw new NetconfConfigHandlingException(
55                     String.format("Unable to delete %s because of exception %s" + on, e.getMessage()),
56                     NetconfDocumentedException.ErrorType.application,
57                     NetconfDocumentedException.ErrorTag.operation_failed,
58                     NetconfDocumentedException.ErrorSeverity.error);
59         }
60     }
61 }