use of org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement in project controller by opendaylight.
the class InstanceConfig method resolveConfiguration.
private void resolveConfiguration(final InstanceConfigElementResolved mappedConfig, final ServiceRegistryWrapper depTracker, final EnumResolver enumResolver) {
// TODO make field, resolvingStrategies can be instantiated only once
Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> resolvingStrategies = new ObjectResolver(depTracker).prepareResolving(yangToAttrConfig, enumResolver);
for (Entry<String, AttributeConfigElement> configDefEntry : mappedConfig.getConfiguration().entrySet()) {
AttributeConfigElement value = configDefEntry.getValue();
String attributeName = configDefEntry.getKey();
try {
AttributeResolvingStrategy<?, ? extends OpenType<?>> attributeResolvingStrategy = resolvingStrategies.get(attributeName);
LOG.trace("Trying to set value {} of attribute {} with {}", value, attributeName, attributeResolvingStrategy);
value.resolveValue(attributeResolvingStrategy, attributeName);
value.setJmxName(yangToAttrConfig.get(attributeName).getUpperCaseCammelCase());
} catch (final DocumentedException e) {
throw new IllegalStateException("Unable to resolve value " + value + " to attribute " + attributeName, e);
}
}
}
use of org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement in project controller by opendaylight.
the class MergeEditConfigStrategy method executeStrategy.
@Override
@SuppressWarnings("IllegalCatch")
void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) throws ConfigHandlingException {
for (Entry<String, AttributeConfigElement> configAttributeEntry : configuration.entrySet()) {
try {
AttributeConfigElement ace = configAttributeEntry.getValue();
if (!ace.getResolvedValue().isPresent()) {
LOG.debug("Skipping attribute {} for {}", configAttributeEntry.getKey(), on);
continue;
}
Object toBeMergedIn = ace.getResolvedValue().get();
// Get the existing values so we can merge the new values with them.
Attribute currentAttribute = ta.getAttribute(on, ace.getJmxName());
Object oldValue = currentAttribute != null ? currentAttribute.getValue() : null;
// Merge value with currentValue
toBeMergedIn = merge(oldValue, toBeMergedIn);
ta.setAttribute(on, ace.getJmxName(), new Attribute(ace.getJmxName(), toBeMergedIn));
LOG.debug("Attribute {} set to {} for {}", configAttributeEntry.getKey(), toBeMergedIn, on);
} catch (RuntimeException e) {
LOG.error("Error while merging object names of {}", on, e);
throw new ConfigHandlingException(String.format("Unable to set attributes for %s, " + "Error with attribute %s : %s ", on, configAttributeEntry.getKey(), configAttributeEntry.getValue()), e, DocumentedException.ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, DocumentedException.ErrorSeverity.ERROR);
}
}
}
use of org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement in project controller by opendaylight.
the class ReplaceEditConfigStrategy method executeStrategy.
@Override
@SuppressWarnings("IllegalCatch")
void executeStrategy(Map<String, AttributeConfigElement> configuration, ConfigTransactionClient ta, ObjectName on, ServiceRegistryWrapper services) throws ConfigHandlingException {
for (Entry<String, AttributeConfigElement> configAttributeEntry : configuration.entrySet()) {
try {
AttributeConfigElement ace = configAttributeEntry.getValue();
if (!ace.getResolvedValue().isPresent()) {
Object value = ace.getResolvedDefaultValue();
ta.setAttribute(on, ace.getJmxName(), new Attribute(ace.getJmxName(), value));
LOG.debug("Attribute {} set to default value {} for {}", configAttributeEntry.getKey(), value, on);
} else {
Object value = ace.getResolvedValue().get();
ta.setAttribute(on, ace.getJmxName(), new Attribute(ace.getJmxName(), value));
LOG.debug("Attribute {} set to value {} for {}", configAttributeEntry.getKey(), value, on);
}
} catch (RuntimeException e) {
throw new IllegalStateException("Unable to set attributes for " + on + ", Error with attribute " + configAttributeEntry.getKey() + ":" + configAttributeEntry.getValue(), e);
}
}
}
use of org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement in project controller by opendaylight.
the class InstanceRuntimeRpc method fromXml.
public Map<String, AttributeConfigElement> fromXml(final XmlElement configRootNode) throws DocumentedException {
Map<String, AttributeConfigElement> retVal = Maps.newHashMap();
// FIXME add identity map to runtime data
Map<String, AttributeReadingStrategy> strats = new ObjectXmlReader().prepareReading(yangToAttrConfig, Collections.<String, Map<Optional<Revision>, IdentityMapping>>emptyMap());
for (Entry<String, AttributeReadingStrategy> readStratEntry : strats.entrySet()) {
List<XmlElement> configNodes = configRootNode.getChildElements(readStratEntry.getKey());
AttributeConfigElement readElement = readStratEntry.getValue().readElement(configNodes);
retVal.put(readStratEntry.getKey(), readElement);
}
resolveConfiguration(retVal);
return retVal;
}
Aggregations