Search in sources :

Example 6 with AttributeIfc

use of org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc in project controller by opendaylight.

the class TemplateFactory method getTOAndMXInterfaceFtlFiles.

/**
 * Get map of file name as key, FtlFile instance representing runtime mx
 * bean as value that should be persisted from this instance.
 */
public static Map<String, FtlTemplate> getTOAndMXInterfaceFtlFiles(final RuntimeBeanEntry entry) {
    final Map<String, FtlTemplate> result = new HashMap<>();
    {
        // create GeneralInterfaceFtlFile for runtime MXBean. Attributes will
        // be transformed to getter methods
        final String mxBeanTypeName = entry.getJavaNameOfRuntimeMXBean();
        final List<String> extendedInterfaces = Collections.singletonList(RuntimeBean.class.getCanonicalName());
        final List<MethodDeclaration> methods = new ArrayList<>();
        // convert attributes to getters
        for (final AttributeIfc attributeIfc : entry.getAttributes()) {
            String returnType;
            returnType = getReturnType(attributeIfc);
            final String getterName = "get" + attributeIfc.getUpperCaseCammelCase();
            final MethodDeclaration getter = new MethodDeclaration(returnType, getterName, Collections.<Field>emptyList());
            methods.add(getter);
        }
        // add rpc methods
        for (final Rpc rpc : entry.getRpcs()) {
            // convert JavaAttribute parameters into fields
            final List<Field> fields = new ArrayList<>();
            for (final JavaAttribute ja : rpc.getParameters()) {
                final Field field = new Field(Collections.emptyList(), ja.getType().getFullyQualifiedName(), ja.getLowerCaseCammelCase(), ja.getNullableDefaultWrappedForCode());
                fields.add(field);
            }
            final MethodDeclaration operation = new MethodDeclaration(getReturnType(rpc.getReturnType()), rpc.getName(), fields);
            methods.add(operation);
        }
        // FIXME header
        final GeneralInterfaceTemplate runtimeMxBeanIfc = new GeneralInterfaceTemplate(null, entry.getPackageName(), mxBeanTypeName, extendedInterfaces, methods);
        result.put(runtimeMxBeanIfc.getTypeDeclaration().getName() + ".java", runtimeMxBeanIfc);
    }
    result.putAll(TemplateFactory.tOsFromRbe(entry));
    return result;
}
Also used : ModuleField(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.ModuleField) Field(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field) IdentityRefModuleField(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.IdentityRefModuleField) Rpc(org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc) HashMap(java.util.HashMap) MethodDeclaration(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDeclaration) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) ArrayList(java.util.ArrayList) List(java.util.List) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)

Example 7 with AttributeIfc

use of org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc in project controller by opendaylight.

the class ObjectXmlWriter method caseListAttribute.

@Override
protected AttributeWritingStrategy caseListAttribute(final ArrayType<?> openType) {
    Preconditions.checkState(getLastAttribute() instanceof ListAttribute);
    AttributeIfc innerAttribute = ((ListAttribute) getLastAttribute()).getInnerAttribute();
    AttributeWritingStrategy innerStrategy = prepareWritingStrategy(key, innerAttribute, document);
    return new ArrayAttributeWritingStrategy(innerStrategy);
}
Also used : AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) ListAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute)

Example 8 with AttributeIfc

use of org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc in project controller by opendaylight.

the class InstanceConfig method getMappedConfiguration.

@SuppressWarnings("IllegalCatch")
private Map<String, Object> getMappedConfiguration(final ObjectName on, final EnumResolver enumResolver) {
    // TODO make field, mappingStrategies can be instantiated only once
    Map<String, AttributeMappingStrategy<?, ? extends OpenType<?>>> mappingStrategies = new ObjectMapper().prepareMapping(jmxToAttrConfig, enumResolver);
    Map<String, Object> toXml = Maps.newHashMap();
    for (Entry<String, AttributeIfc> configDefEntry : jmxToAttrConfig.entrySet()) {
        // Skip children runtime beans as they are mapped by InstanceRuntime
        if (configDefEntry.getValue() instanceof RuntimeBeanEntry) {
            continue;
        }
        Object value = configRegistryClient.getAttributeCurrentValue(on, configDefEntry.getKey());
        try {
            AttributeMappingStrategy<?, ? extends OpenType<?>> attributeMappingStrategy = mappingStrategies.get(configDefEntry.getKey());
            Optional<?> attribute = attributeMappingStrategy.mapAttribute(value);
            if (!attribute.isPresent()) {
                continue;
            }
            toXml.put(configDefEntry.getValue().getAttributeYangName(), attribute.get());
        } catch (final RuntimeException e) {
            throw new IllegalStateException("Unable to map value " + value + " to attribute " + configDefEntry.getKey(), e);
        }
    }
    return toXml;
}
Also used : OpenType(javax.management.openmbean.OpenType) RuntimeBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry) AttributeMappingStrategy(org.opendaylight.controller.config.facade.xml.mapping.attributes.mapping.AttributeMappingStrategy) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) ObjectMapper(org.opendaylight.controller.config.facade.xml.mapping.attributes.mapping.ObjectMapper)

Example 9 with AttributeIfc

use of org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc in project controller by opendaylight.

the class ObjectResolver method caseListAttribute.

@Override
protected AttributeResolvingStrategy<?, ? extends OpenType<?>> caseListAttribute(final ArrayType<?> openType) {
    Preconditions.checkState(getLastAttribute() instanceof ListAttribute);
    AttributeIfc innerAttribute = ((ListAttribute) getLastAttribute()).getInnerAttribute();
    return new ArrayAttributeResolvingStrategy(prepareStrategy(innerAttribute), openType);
}
Also used : AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) ListAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute)

Example 10 with AttributeIfc

use of org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc in project controller by opendaylight.

the class ObjectXmlReader method caseListAttribute.

@Override
protected AttributeReadingStrategy caseListAttribute(final ArrayType<?> openType) {
    AttributeIfc lastAttribute = getLastAttribute();
    Preconditions.checkState(lastAttribute instanceof ListAttribute);
    AttributeReadingStrategy innerStrategy = prepareReadingStrategy(key, ((ListAttribute) lastAttribute).getInnerAttribute());
    return new ArrayAttributeReadingStrategy(lastAttribute.getNullableDefault(), innerStrategy);
}
Also used : AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) ListAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute)

Aggregations

AttributeIfc (org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc)18 ListAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute)7 JavaAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute)6 TOAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute)6 HashMap (java.util.HashMap)4 QName (org.opendaylight.yangtools.yang.common.QName)4 OpenType (javax.management.openmbean.OpenType)3 Test (org.junit.Test)3 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 SimpleType (javax.management.openmbean.SimpleType)2 ModuleMXBeanEntry (org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry)2 RuntimeBeanEntry (org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry)2 Rpc (org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc)2 DependencyAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute)2 ListDependenciesAttribute (org.opendaylight.controller.config.yangjmxgenerator.attribute.ListDependenciesAttribute)2 IdentitySchemaNode (org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode)2