Search in sources :

Example 1 with AttributeConfigElement

use of org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement in project controller by opendaylight.

the class InstanceRuntimeRpc method resolveConfiguration.

private void resolveConfiguration(final Map<String, AttributeConfigElement> mappedConfig) {
    // TODO make field, resolvingStrategies can be instantiated only once
    Map<String, AttributeResolvingStrategy<?, ? extends OpenType<?>>> resolvingStrategies = new ObjectResolver(null).prepareResolving(yangToAttrConfig, enumResolver);
    // TODO make constructor for object resolver without service tracker
    for (Entry<String, AttributeConfigElement> configDefEntry : mappedConfig.entrySet()) {
        try {
            AttributeResolvingStrategy<?, ? extends OpenType<?>> attributeResolvingStrategy = resolvingStrategies.get(configDefEntry.getKey());
            configDefEntry.getValue().resolveValue(attributeResolvingStrategy, configDefEntry.getKey());
            configDefEntry.getValue().setJmxName(yangToAttrConfig.get(configDefEntry.getKey()).getUpperCaseCammelCase());
        } catch (final DocumentedException e) {
            throw new IllegalStateException("Unable to resolve value " + configDefEntry.getValue() + " to attribute " + configDefEntry.getKey(), 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 2 with AttributeConfigElement

use of org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement in project controller by opendaylight.

the class RpcFacade method fromXml.

public OperationExecution fromXml(final XmlElement xml) throws DocumentedException {
    final String namespace;
    namespace = xml.getNamespace();
    final XmlElement contextInstanceElement = xml.getOnlyChildElement(CONTEXT_INSTANCE);
    final String operationName = xml.getName();
    final RuntimeRpcElementResolved id = RuntimeRpcElementResolved.fromXpath(contextInstanceElement.getTextContent(), operationName, namespace);
    final Rpcs rpcs = mapRpcs();
    final ModuleRpcs rpcMapping = rpcs.getRpcMapping(id);
    final InstanceRuntimeRpc instanceRuntimeRpc = rpcMapping.getRpc(id.getRuntimeBeanName(), operationName);
    // TODO move to Rpcs after xpath attribute is redesigned
    final ObjectName on = id.getObjectName(rpcMapping);
    Map<String, AttributeConfigElement> attributes = instanceRuntimeRpc.fromXml(xml);
    attributes = sortAttributes(attributes, xml);
    return new OperationExecution(on, instanceRuntimeRpc.getName(), attributes, instanceRuntimeRpc.getReturnType(), namespace);
}
Also used : AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) RuntimeRpcElementResolved(org.opendaylight.controller.config.facade.xml.rpc.RuntimeRpcElementResolved) Rpcs(org.opendaylight.controller.config.facade.xml.rpc.Rpcs) ModuleRpcs(org.opendaylight.controller.config.facade.xml.rpc.ModuleRpcs) InstanceRuntimeRpc(org.opendaylight.controller.config.facade.xml.rpc.InstanceRuntimeRpc) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) ModuleRpcs(org.opendaylight.controller.config.facade.xml.rpc.ModuleRpcs) ObjectName(javax.management.ObjectName)

Example 3 with AttributeConfigElement

use of org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement in project controller by opendaylight.

the class RpcFacade method sortAttributes.

private Map<String, AttributeConfigElement> sortAttributes(final Map<String, AttributeConfigElement> attributes, final XmlElement xml) {
    final Map<String, AttributeConfigElement> sorted = new LinkedHashMap<>();
    for (XmlElement xmlElement : xml.getChildElements()) {
        final String name = xmlElement.getName();
        if (!CONTEXT_INSTANCE.equals(name)) {
            // skip context
            // instance child node
            // because it
            // specifies
            // ObjectName
            final AttributeConfigElement value = attributes.get(name);
            if (value == null) {
                throw new IllegalArgumentException("Cannot find yang mapping for node " + xmlElement);
            }
            sorted.put(name, value);
        }
    }
    return sorted;
}
Also used : AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) XmlElement(org.opendaylight.controller.config.util.xml.XmlElement) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with AttributeConfigElement

use of org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement in project controller by opendaylight.

the class RpcFacade method executeOperation.

public Object executeOperation(final OperationExecution execution) {
    final Object[] params = new Object[execution.attributes.size()];
    final String[] signature = new String[execution.attributes.size()];
    int index = 0;
    for (final AttributeConfigElement attribute : execution.attributes.values()) {
        final Optional<?> resolvedValueOpt = attribute.getResolvedValue();
        params[index] = resolvedValueOpt.isPresent() ? resolvedValueOpt.get() : attribute.getResolvedDefaultValue();
        signature[index] = resolvedValueOpt.isPresent() ? resolvedValueOpt.get().getClass().getName() : attribute.getResolvedDefaultValue().getClass().getName();
        index++;
    }
    return configRegistryClient.invokeMethod(execution.on, execution.operationName, params, signature);
}
Also used : AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement)

Example 5 with AttributeConfigElement

use of org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement in project controller by opendaylight.

the class InstanceConfig method fromXml.

public InstanceConfigElementResolved fromXml(XmlElement moduleElement, final ServiceRegistryWrapper services, final String moduleNamespace, final EditStrategyType defaultStrategy, final Map<String, Map<Optional<Revision>, IdentityMapping>> identityMap, final EnumResolver enumResolver) throws DocumentedException {
    Map<String, AttributeConfigElement> retVal = Maps.newHashMap();
    Map<String, AttributeReadingStrategy> strats = new ObjectXmlReader().prepareReading(yangToAttrConfig, identityMap);
    List<XmlElement> recognisedChildren = Lists.newArrayList();
    XmlElement typeElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlMappingConstants.TYPE_KEY);
    XmlElement nameElement = moduleElement.getOnlyChildElementWithSameNamespace(XmlMappingConstants.NAME_KEY);
    List<XmlElement> typeAndNameElements = Lists.newArrayList(typeElement, nameElement);
    // if dummy container was defined in yang, set moduleElement to its content
    if (nullableDummyContainerName != null) {
        int size = moduleElement.getChildElements().size();
        int expectedChildNodes = 1 + typeAndNameElements.size();
        if (size > expectedChildNodes) {
            throw new DocumentedException("Error reading module " + typeElement.getTextContent() + " : " + nameElement.getTextContent() + " - Expected " + expectedChildNodes + " child nodes, " + "one of them with name " + nullableDummyContainerName + ", got " + size + " elements.");
        }
        if (size == expectedChildNodes) {
            try {
                moduleElement = moduleElement.getOnlyChildElement(nullableDummyContainerName, moduleNamespace);
            } catch (final DocumentedException e) {
                throw new DocumentedException("Error reading module " + typeElement.getTextContent() + " : " + nameElement.getTextContent() + " - Expected child node with name " + nullableDummyContainerName + "." + e.getMessage(), e);
            }
        }
    // else 2 elements, no need to descend
    }
    for (Entry<String, AttributeReadingStrategy> readStratEntry : strats.entrySet()) {
        List<XmlElement> configNodes = getConfigNodes(moduleElement, moduleNamespace, readStratEntry.getKey(), recognisedChildren, typeAndNameElements);
        AttributeConfigElement readElement = readStratEntry.getValue().readElement(configNodes);
        retVal.put(readStratEntry.getKey(), readElement);
    }
    recognisedChildren.addAll(typeAndNameElements);
    try {
        moduleElement.checkUnrecognisedElements(recognisedChildren);
    } catch (final DocumentedException e) {
        throw new DocumentedException("Error reading module " + typeElement.getTextContent() + " : " + nameElement.getTextContent() + " - " + e.getMessage(), e, e.getErrorType(), e.getErrorTag(), e.getErrorSeverity(), e.getErrorInfo());
    }
    // TODO: add check for conflicts between global and local edit strategy
    String perInstanceEditStrategy = moduleElement.getAttribute(XmlMappingConstants.OPERATION_ATTR_KEY, XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
    InstanceConfigElementResolved instanceConfigElementResolved = perInstanceEditStrategy.equals("") ? new InstanceConfigElementResolved(retVal, defaultStrategy) : new InstanceConfigElementResolved(perInstanceEditStrategy, retVal, defaultStrategy);
    resolveConfiguration(instanceConfigElementResolved, services, enumResolver);
    return instanceConfigElementResolved;
}
Also used : AttributeReadingStrategy(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeReadingStrategy) AttributeConfigElement(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.AttributeConfigElement) ObjectXmlReader(org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.ObjectXmlReader) DocumentedException(org.opendaylight.controller.config.util.xml.DocumentedException) 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