Search in sources :

Example 16 with AttributeIfc

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

the class ModuleMXBeanEntryPluginTest method testThreadsJavaPlugin.

@Test
public void testThreadsJavaPlugin() {
    Map<String, ModuleMXBeanEntry> /* identity local name */
    namesToMBEs = loadThreadsJava();
    {
        // check threadfactory-naming
        ModuleMXBeanEntry threadFactoryNaming = namesToMBEs.get(THREADFACTORY_NAMING_MXB_NAME);
        Collection<RuntimeBeanEntry> runtimeBeans = threadFactoryNaming.getRuntimeBeans();
        assertThat(runtimeBeans.size(), is(4));
        // first one should be root
        {
            RuntimeBeanEntry rootRB = findFirstByYangName(runtimeBeans, THREADFACTORY_NAMING_MXB_NAME);
            assertThat(rootRB.isRoot(), is(true));
            assertThat(rootRB.getAttributes().size(), is(1));
            JavaAttribute attribute = (JavaAttribute) rootRB.getAttributes().iterator().next();
            assertThat(attribute.getAttributeYangName(), is("created-sessions"));
            assertThat(rootRB.getYangName(), is(THREADFACTORY_NAMING_MXB_NAME));
            Map<String, FtlTemplate> ftlMap = TemplateFactory.getTOAndMXInterfaceFtlFiles(rootRB);
            assertThat(ftlMap.size(), is(1));
            GeneralInterfaceTemplate rootGeneratorInterface = (GeneralInterfaceTemplate) ftlMap.get("NamingThreadFactoryRuntimeMXBean.java");
            assertNotNull(rootGeneratorInterface);
            assertThat(rootGeneratorInterface.getPackageName(), is(PACKAGE_NAME));
            assertThat(rootGeneratorInterface.getFullyQualifiedName(), is(PACKAGE_NAME + ".NamingThreadFactoryRuntimeMXBean"));
            assertThat(rootGeneratorInterface.getTypeDeclaration().getExtended(), is(Arrays.asList("org.opendaylight.controller.config.api.runtime.RuntimeBean")));
            assertThat(rootGeneratorInterface.getMethods().size(), is(1));
            Method getCreatedSessions = findFirstMethodByName(rootGeneratorInterface.getMethods(), "getCreatedSessions");
            assertThat(getCreatedSessions.getName(), is("getCreatedSessions"));
            assertThat(getCreatedSessions.getParameters().isEmpty(), is(true));
            assertThat(getCreatedSessions.getReturnType(), is(Long.class.getName()));
        }
    }
    {
        ModuleMXBeanEntry threadFactoryNaming = namesToMBEs.get(THREADFACTORY_NAMING_MXB_NAME);
        Collection<RuntimeBeanEntry> runtimeBeans = threadFactoryNaming.getRuntimeBeans();
        assertThat(runtimeBeans.size(), is(4));
        {
            RuntimeBeanEntry streamRB = findFirstByNamePrefix(runtimeBeans, "ThreadStream");
            assertNotNull(streamRB);
            assertFalse(streamRB.getKeyYangName().isPresent());
            assertFalse(streamRB.getKeyJavaName().isPresent());
            Map<String, AttributeIfc> attributeMap = streamRB.getYangPropertiesToTypesMap();
            assertEquals(4, attributeMap.size());
            TOAttribute toAttr = (TOAttribute) attributeMap.get("peer");
            assertNotNull(toAttr);
            JavaAttribute timestampAttr = (JavaAttribute) attributeMap.get("timestamp");
            assertNotNull(timestampAttr);
            JavaAttribute stateAttr = (JavaAttribute) attributeMap.get("state");
            assertNotNull(stateAttr);
            ListAttribute innerStreamList = (ListAttribute) attributeMap.get("inner-stream-list");
            assertNotNull(innerStreamList);
            Map<String, FtlTemplate> ftlMap = TemplateFactory.getTOAndMXInterfaceFtlFiles(streamRB);
            assertThat(ftlMap.size(), is(3));
            GeneralInterfaceTemplate streamGeneralInterface = (GeneralInterfaceTemplate) ftlMap.get("ThreadStreamRuntimeMXBean.java");
            assertThat(streamGeneralInterface.getMethods().size(), is(4));
            Method getPeer = findFirstMethodByName(streamGeneralInterface.getMethods(), "getPeer");
            assertNotNull(getPeer);
            assertThat(getPeer.getReturnType(), is(PACKAGE_NAME + ".Peer"));
            // test TO
            GeneralClassTemplate peerTO = (GeneralClassTemplate) ftlMap.get("pack2.Peer");
            assertThat(peerTO.getPackageName(), is(PACKAGE_NAME));
            assertThat(peerTO.getTypeDeclaration().getExtended().isEmpty(), is(true));
            assertThat(peerTO.getFullyQualifiedName(), is(PACKAGE_NAME + ".Peer"));
            assertThat(peerTO.getMethods().size(), is(5 + 2));
            Method getPort = findFirstMethodByName(peerTO.getMethods(), "getPort");
            assertNotNull(getPort);
            Method setPort = findFirstMethodByName(peerTO.getMethods(), "setPort");
            assertNotNull(setPort);
            Method getCoreSize = findFirstMethodByName(peerTO.getMethods(), "getCoreSize");
            Method setCoreSize = findFirstMethodByName(peerTO.getMethods(), "setCoreSize");
            assertNotNull(setCoreSize);
            assertNotNull(getCoreSize);
        }
    }
}
Also used : GeneralInterfaceTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralInterfaceTemplate) RuntimeBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry) GeneralClassTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralClassTemplate) Method(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method) TOAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute) ModuleMXBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry) Collection(java.util.Collection) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) FtlTemplate(org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute) ListAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute) Test(org.junit.Test) ModuleMXBeanEntryTest(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntryTest)

Example 17 with AttributeIfc

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

the class ModuleMXBeanEntryTest method testThreadsJava.

@Test
public void testThreadsJava() {
    final Map<String, ModuleMXBeanEntry> /* identity local name */
    namesToMBEs = loadThreadsJava();
    {
        // check threadpool-dynamic
        final ModuleMXBeanEntry dynamicThreadPool = namesToMBEs.get(THREADPOOL_DYNAMIC_MXB_NAME);
        final Map<String, AttributeIfc> attributes = dynamicThreadPool.getAttributes();
        // core-size, keepalive, maximum-size
        // threadfactory
        final Set<String> longAttribs = Sets.newHashSet("core-size", "maximum-size");
        for (final String longAttrib : longAttribs) {
            final TypedAttribute attribute = (TypedAttribute) attributes.get(longAttrib);
            assertThat("Failed to check " + longAttrib, attribute.getType(), is((Type) Types.typeForClass(Long.class)));
        }
        // check dependency on thread factory
        final QName threadfactoryQName = QName.create(THREADS_NAMESPACE, THREADS_REVISION_DATE, "threadfactory");
        final ServiceInterfaceEntry threadFactorySIEntry = this.modulesToSIEs.get(threadfactoryQName);
        assertNotNull(threadFactorySIEntry);
        final boolean expectedMandatory = true;
        final TypedAttribute actualThreadFactory = (TypedAttribute) attributes.get("threadfactory");
        final DataSchemaNode mockedDataSchemaNode = mock(DataSchemaNode.class);
        doReturn(Collections.emptyList()).when(mockedDataSchemaNode).getUnknownSchemaNodes();
        doReturn(threadfactoryQName).when(mockedDataSchemaNode).getQName();
        final AttributeIfc expectedDependencyAttribute = new DependencyAttribute(mockedDataSchemaNode, threadFactorySIEntry, expectedMandatory, "threadfactory description");
        assertThat(actualThreadFactory, is(expectedDependencyAttribute));
        assertThat(dynamicThreadPool.getFullyQualifiedName("DynamicThreadPoolModuleMXBean"), is(PACKAGE_NAME + ".DynamicThreadPoolModuleMXBean"));
        assertThat(dynamicThreadPool.getNullableDescription(), is("threadpool-dynamic description"));
        assertThat(dynamicThreadPool.getYangModuleName(), is("config-threads-java"));
        assertThat(dynamicThreadPool.getYangModuleLocalname(), is(THREADPOOL_DYNAMIC_MXB_NAME));
        // check root runtime bean
        final Collection<RuntimeBeanEntry> runtimeBeans = dynamicThreadPool.getRuntimeBeans();
        assertThat(runtimeBeans.size(), is(1));
        final RuntimeBeanEntry rootRB = findFirstByYangName(runtimeBeans, THREADPOOL_DYNAMIC_MXB_NAME);
        assertThat(rootRB.isRoot(), is(true));
        assertThat(rootRB.getAttributes().size(), is(1));
        final JavaAttribute attribute = (JavaAttribute) rootRB.getAttributes().iterator().next();
        assertThat(attribute.getAttributeYangName(), is("created-sessions"));
        assertThat(rootRB.getYangName(), is(THREADPOOL_DYNAMIC_MXB_NAME));
        assertThat(attribute.getType().getFullyQualifiedName(), is(Long.class.getName()));
    }
    {
        // check threadfactory-naming
        final ModuleMXBeanEntry threadFactoryNaming = namesToMBEs.get(THREADFACTORY_NAMING_MXB_NAME);
        final Collection<RuntimeBeanEntry> runtimeBeans = threadFactoryNaming.getRuntimeBeans();
        assertThat(runtimeBeans.size(), is(4));
        {
            final RuntimeBeanEntry threadRB = findFirstByYangName(runtimeBeans, "thread");
            assertNotNull(threadRB);
            assertFalse(threadRB.isRoot());
            assertEquals("name", threadRB.getKeyYangName().get());
            assertEquals("Name", threadRB.getKeyJavaName().get());
            assertThat(threadRB.getAttributes().size(), is(1));
            final AttributeIfc threadNameAttr = threadRB.getAttributes().iterator().next();
            assertThat(threadNameAttr.getAttributeYangName(), is("name"));
            assertTrue(threadNameAttr instanceof JavaAttribute);
            assertThat(((JavaAttribute) threadNameAttr).getType().getFullyQualifiedName(), is(String.class.getName()));
            assertThat(threadRB.getRpcs().size(), is(2));
        }
        {
            final RuntimeBeanEntry streamRB = findFirstByNamePrefix(runtimeBeans, "ThreadStream");
            assertNotNull(streamRB);
            assertFalse(streamRB.getKeyYangName().isPresent());
            assertFalse(streamRB.getKeyJavaName().isPresent());
            final Map<String, AttributeIfc> attributeMap = streamRB.getYangPropertiesToTypesMap();
            assertEquals(4, attributeMap.size());
            final TOAttribute toAttr = (TOAttribute) attributeMap.get("peer");
            assertNotNull(toAttr);
            assertThat(toAttr.getAttributeYangName(), is("peer"));
            assertThat(toAttr.getLowerCaseCammelCase(), is("peer"));
            assertThat(toAttr.getUpperCaseCammelCase(), is("Peer"));
            assertThat(toAttr.getOpenType(), isA(CompositeType.class));
            Set<String> propsExpected = new HashSet<>(2);
            propsExpected.add("port");
            propsExpected.add("core-size");
            assertThat(toAttr.getYangPropertiesToTypesMap().keySet(), is(propsExpected));
            propsExpected = new HashSet<>(2);
            propsExpected.add("Port");
            propsExpected.add("CoreSize");
            assertThat(toAttr.getCapitalizedPropertiesToTypesMap().keySet(), is(propsExpected));
            propsExpected = new HashSet<>(2);
            propsExpected.add("port");
            propsExpected.add("coreSize");
            assertThat(toAttr.getJmxPropertiesToTypesMap().keySet(), is(propsExpected));
            final JavaAttribute timestampAttr = (JavaAttribute) attributeMap.get("timestamp");
            assertNotNull(timestampAttr);
            final JavaAttribute stateAttr = (JavaAttribute) attributeMap.get("state");
            assertNotNull(stateAttr);
            final ListAttribute innerStream = (ListAttribute) attributeMap.get("inner-stream-list");
            assertNotNull(innerStream);
            assertThat(innerStream.getAttributeYangName(), is("inner-stream-list"));
            assertThat(innerStream.getLowerCaseCammelCase(), is("innerStreamList"));
            assertThat(innerStream.getUpperCaseCammelCase(), is("InnerStreamList"));
            assertThat(innerStream.getOpenType(), isA(ArrayType.class));
        }
    }
    {
        // test multiple dependencies
        final ModuleMXBeanEntry threadPoolRegistry = namesToMBEs.get(THREADPOOL_REGISTRY_IMPL_NAME);
        final Map<String, AttributeIfc> attributes = threadPoolRegistry.getAttributes();
        assertEquals(1, attributes.size());
        final AttributeIfc threadpoolsAttr = attributes.get("threadpools");
        assertNotNull(threadpoolsAttr);
        assertTrue(threadpoolsAttr instanceof ListDependenciesAttribute);
        final ListDependenciesAttribute threadpools = (ListDependenciesAttribute) threadpoolsAttr;
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TypedAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.TypedAttribute) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) ListDependenciesAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.ListDependenciesAttribute) TOAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.TOAttribute) ArrayType(javax.management.openmbean.ArrayType) DependencyAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) JavaAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.JavaAttribute) ListAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.ListAttribute) CompositeType(javax.management.openmbean.CompositeType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with AttributeIfc

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

the class ModuleMXBeanEntryTest method test_jmxImplModule.

@Test
public void test_jmxImplModule() {
    final Map<IdentitySchemaNode, ServiceInterfaceEntry> identitiesToSIs = new HashMap<>();
    final Map<QName, ServiceInterfaceEntry> modulesToSIEs = ServiceInterfaceEntry.create(this.threadsModule, PACKAGE_NAME, identitiesToSIs);
    modulesToSIEs.putAll(ServiceInterfaceEntry.create(this.jmxModule, PACKAGE_NAME, identitiesToSIs));
    final Map<String, ModuleMXBeanEntry> /* identity local name */
    namesToMBEs = ModuleMXBeanEntry.create(this.jmxImplModule, modulesToSIEs, this.context, new TypeProviderWrapper(new TypeProviderImpl(this.context)), PACKAGE_NAME);
    final Map<String, AttributeIfc> attributes = namesToMBEs.get("impl-netconf").getAttributes();
    assertCorrectAttributesSize(namesToMBEs, attributes);
    // 
    final DependencyAttribute threadFactoryAttribute = (DependencyAttribute) attributes.get("thread-factory");
    assertNotNull(threadFactoryAttribute);
    assertFalse(threadFactoryAttribute.getDependency().isMandatory());
    assertThat(threadFactoryAttribute.getDependency().getSie().getTypeName(), is("ThreadFactoryServiceInterface"));
    assertThat(threadFactoryAttribute.getAttributeYangName(), is("thread-factory"));
    assertThat(threadFactoryAttribute.getLowerCaseCammelCase(), is("threadFactory"));
    assertThat(threadFactoryAttribute.getUpperCaseCammelCase(), is("ThreadFactory"));
    assertThat(threadFactoryAttribute.getOpenType(), isA(SimpleType.class));
    assertNull(threadFactoryAttribute.getNullableDefault());
    assertNull(threadFactoryAttribute.getNullableDescription());
    assertThat(threadFactoryAttribute.getType().getName(), is("ObjectName"));
}
Also used : HashMap(java.util.HashMap) QName(org.opendaylight.yangtools.yang.common.QName) IdentitySchemaNode(org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode) DependencyAttribute(org.opendaylight.controller.config.yangjmxgenerator.attribute.DependencyAttribute) SimpleType(javax.management.openmbean.SimpleType) AttributeIfc(org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc) TypeProviderImpl(org.opendaylight.mdsal.binding.yang.types.TypeProviderImpl) Test(org.junit.Test)

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