Search in sources :

Example 6 with AttributeConfigElement

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);
        }
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) AttributeResolvingStrategy(org.opendaylight.controller.config.facade.xml.mapping.attributes.resolving.AttributeResolvingStrategy) AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException) ObjectResolver(org.opendaylight.controller.config.facade.xml.mapping.attributes.resolving.ObjectResolver)

Example 7 with AttributeConfigElement

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);
        }
    }
}
Also used : ConfigHandlingException(org.opendaylight.controller.config.facade.xml.exception.ConfigHandlingException) AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) Attribute(javax.management.Attribute)

Example 8 with AttributeConfigElement

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);
        }
    }
}
Also used : AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) Attribute(javax.management.Attribute)

Example 9 with AttributeConfigElement

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;
}
Also used : IdentityMapping(org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping) AttributeReadingStrategy(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeReadingStrategy) Optional(com.google.common.base.Optional) AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) ObjectXmlReader(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.ObjectXmlReader) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement)

Aggregations

AttributeConfigElement (org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement)9 XmlElement (org.opendaylight.controller.config.util.xml.XmlElement)4 DocumentedException (org.opendaylight.controller.config.util.xml.DocumentedException)3 Attribute (javax.management.Attribute)2 OpenType (javax.management.openmbean.OpenType)2 AttributeReadingStrategy (org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeReadingStrategy)2 ObjectXmlReader (org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.ObjectXmlReader)2 AttributeResolvingStrategy (org.opendaylight.controller.config.facade.xml.mapping.attributes.resolving.AttributeResolvingStrategy)2 ObjectResolver (org.opendaylight.controller.config.facade.xml.mapping.attributes.resolving.ObjectResolver)2 Optional (com.google.common.base.Optional)1 LinkedHashMap (java.util.LinkedHashMap)1 ObjectName (javax.management.ObjectName)1 ConfigHandlingException (org.opendaylight.controller.config.facade.xml.exception.ConfigHandlingException)1 IdentityMapping (org.opendaylight.controller.config.facade.xml.mapping.IdentityMapping)1 InstanceRuntimeRpc (org.opendaylight.controller.config.facade.xml.rpc.InstanceRuntimeRpc)1 ModuleRpcs (org.opendaylight.controller.config.facade.xml.rpc.ModuleRpcs)1 Rpcs (org.opendaylight.controller.config.facade.xml.rpc.Rpcs)1 RuntimeRpcElementResolved (org.opendaylight.controller.config.facade.xml.rpc.RuntimeRpcElementResolved)1