use of org.opendaylight.controller.config.yangjmxgenerator.attribute.TypedAttribute in project controller by opendaylight.
the class TemplateFactory method getReturnType.
private static String getReturnType(final AttributeIfc attributeIfc) {
String returnType;
if (attributeIfc instanceof TypedAttribute) {
final Type type = ((TypedAttribute) attributeIfc).getType();
returnType = serializeType(type);
} else if (attributeIfc == VoidAttribute.getInstance()) {
return "void";
} else {
throw new UnsupportedOperationException("Attribute not supported: " + attributeIfc.getClass());
}
return returnType;
}
use of org.opendaylight.controller.config.yangjmxgenerator.attribute.TypedAttribute 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;
}
}
Aggregations