2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.config.facade.xml.strategy;
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;
23 public class ReplaceEditConfigStrategy extends AbstractEditConfigStrategy {
25 private static final Logger LOG = LoggerFactory.getLogger(ReplaceEditConfigStrategy.class);
28 void handleMissingInstance(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta,
29 String module, String instance, ServiceRegistryWrapper services) throws
30 ConfigHandlingException {
31 throw new ConfigHandlingException(
32 String.format("Unable to handle missing instance, no missing instances should appear at this point, missing: %s : %s ",
35 DocumentedException.ErrorType.application,
36 DocumentedException.ErrorTag.operation_failed,
37 DocumentedException.ErrorSeverity.error);
41 void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) throws
42 ConfigHandlingException {
43 for (Entry<String, AttributeConfigElement> configAttributeEntry : configuration.entrySet()) {
45 AttributeConfigElement ace = configAttributeEntry.getValue();
47 if (!ace.getResolvedValue().isPresent()) {
48 Object value = ace.getResolvedDefaultValue();
49 ta.setAttribute(on, ace.getJmxName(), new Attribute(ace.getJmxName(), value));
50 LOG.debug("Attribute {} set to default value {} for {}", configAttributeEntry.getKey(), value,
53 Object value = ace.getResolvedValue().get();
54 ta.setAttribute(on, ace.getJmxName(), new Attribute(ace.getJmxName(), value));
55 LOG.debug("Attribute {} set to value {} for {}", configAttributeEntry.getKey(), value, on);
58 } catch (Exception e) {
59 throw new IllegalStateException("Unable to set attributes for " + on + ", Error with attribute "
60 + configAttributeEntry.getKey() + ":" + configAttributeEntry.getValue(), e);