Fix checkstyle reported by odlparent-3.0.0
[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, 2017 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     @Override
27     void handleMissingInstance(final Map<String, AttributeConfigElement> configuration,
28             final ConfigTransactionClient ta, final String module, final String instance,
29             final ServiceRegistryWrapper services)
30                     throws ConfigHandlingException {
31         throw new ConfigHandlingException(
32                 String.format("Unable to delete %s : %s , ServiceInstance not found", module, instance),
33                 DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED,
34                 DocumentedException.ErrorSeverity.ERROR);
35     }
36
37     @Override
38     void executeStrategy(final Map<String, AttributeConfigElement> configuration, final ConfigTransactionClient ta,
39             final ObjectName on, final ServiceRegistryWrapper services) throws 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()), e,
46                     DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED,
47                     DocumentedException.ErrorSeverity.ERROR);
48         }
49     }
50 }