Remove yang-test
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / strategy / ReplaceEditConfigStrategy.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 java.util.Map.Entry;
13 import javax.management.Attribute;
14 import javax.management.ObjectName;
15 import org.opendaylight.controller.config.facade.xml.exception.ConfigHandlingException;
16 import org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement;
17 import org.opendaylight.controller.config.facade.xml.mapping.config.ServiceRegistryWrapper;
18 import org.opendaylight.controller.config.util.ConfigTransactionClient;
19 import org.opendaylight.controller.config.util.xml.DocumentedException;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class ReplaceEditConfigStrategy extends AbstractEditConfigStrategy {
24
25     private static final Logger LOG = LoggerFactory.getLogger(ReplaceEditConfigStrategy.class);
26
27     @Override
28     void handleMissingInstance(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
29             String module, String instance, ServiceRegistryWrapper services) throws ConfigHandlingException {
30         throw new ConfigHandlingException(String.format(
31                 "Unable to handle missing instance, no missing instances should appear"
32                 + " at this point, missing: %s : %s ",
33                 module, instance), DocumentedException.ErrorType.APPLICATION,
34                 DocumentedException.ErrorTag.OPERATION_FAILED, DocumentedException.ErrorSeverity.ERROR);
35     }
36
37     @Override
38     @SuppressWarnings("IllegalCatch")
39     void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on,
40             ServiceRegistryWrapper services) throws ConfigHandlingException {
41         for (Entry<String, AttributeConfigElement> configAttributeEntry : configuration.entrySet()) {
42             try {
43                 AttributeConfigElement ace = configAttributeEntry.getValue();
44
45                 if (!ace.getResolvedValue().isPresent()) {
46                     Object value = ace.getResolvedDefaultValue();
47                     ta.setAttribute(on, ace.getJmxName(), new Attribute(ace.getJmxName(), value));
48                     LOG.debug("Attribute {} set to default value {} for {}", configAttributeEntry.getKey(), value, on);
49                 } else {
50                     Object value = ace.getResolvedValue().get();
51                     ta.setAttribute(on, ace.getJmxName(), new Attribute(ace.getJmxName(), value));
52                     LOG.debug("Attribute {} set to value {} for {}", configAttributeEntry.getKey(), value, on);
53                 }
54             } catch (RuntimeException e) {
55                 throw new IllegalStateException("Unable to set attributes for " + on + ", Error with attribute "
56                         + configAttributeEntry.getKey() + ":" + configAttributeEntry.getValue(), e);
57             }
58         }
59     }
60 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.