591595eaa5ed019731b352a724d2c6ab49ed10a5
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / strategy / MissingInstanceHandlingStrategy.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.InstanceAlreadyExistsException;
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 MissingInstanceHandlingStrategy extends AbstractEditConfigStrategy {
23
24     private static final Logger LOG = LoggerFactory.getLogger(MissingInstanceHandlingStrategy.class);
25
26     @Override
27     void handleMissingInstance(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
28             String module, String instance, ServiceRegistryWrapper services) throws ConfigHandlingException {
29         try {
30             ObjectName on = ta.createModule(module, instance);
31             LOG.trace("New instance for {} {} created under name {}", module, instance, on);
32         } catch (InstanceAlreadyExistsException e1) {
33             throw new ConfigHandlingException(String.format("Unable to create instance for %s : %s.", module, instance),
34                     DocumentedException.ErrorType.APPLICATION,
35                     DocumentedException.ErrorTag.OPERATION_FAILED,
36                     DocumentedException.ErrorSeverity.ERROR);
37         }
38     }
39
40     @Override
41     void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
42             ObjectName objectName, ServiceRegistryWrapper services) {
43     }
44 }