use of org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode in project controller by opendaylight.
the class ModuleMXBeanEntryBuilder method getIdentityMap.
private Map<String, IdentitySchemaNode> getIdentityMap() {
Map<String, IdentitySchemaNode> moduleIdentities = Maps.newHashMap();
for (IdentitySchemaNode id : currentModule.getIdentities()) {
if (!id.getBaseIdentities().isEmpty() && ConfigConstants.MODULE_TYPE_Q_NAME.equals(id.getBaseIdentities().iterator().next().getQName())) {
String identityLocalName = id.getQName().getLocalName();
if (moduleIdentities.containsKey(identityLocalName)) {
throw new IllegalStateException("Module name already defined in this currentModule: " + identityLocalName);
} else {
moduleIdentities.put(identityLocalName, id);
LOG.debug("Found identity {}", identityLocalName);
}
// validation check on unknown schema nodes
boolean providedServiceWasSet = false;
for (UnknownSchemaNode unknownNode : id.getUnknownSchemaNodes()) {
// TODO: test this
boolean unknownNodeIsProvidedServiceExtension = ConfigConstants.PROVIDED_SERVICE_EXTENSION_QNAME.equals(unknownNode.getNodeType());
if (ConfigConstants.JAVA_NAME_PREFIX_EXTENSION_QNAME.equals(unknownNode.getNodeType())) {
// 0..1 allowed
checkState(providedServiceWasSet == false, format("More than one language extension %s is not allowed here: %s", ConfigConstants.JAVA_NAME_PREFIX_EXTENSION_QNAME, id));
providedServiceWasSet = true;
} else if (unknownNodeIsProvidedServiceExtension == false) {
throw new IllegalStateException("Unexpected language extension " + unknownNode.getNodeType());
}
}
}
}
return moduleIdentities;
}
use of org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode in project controller by opendaylight.
the class RuntimeBeanEntry method extractSubtree.
/**
* Get direct descendants of this subtree, together with attributes defined
* in subtree.
*/
private static AttributesRpcsAndRuntimeBeans extractSubtree(final String packageName, final DataNodeContainer subtree, final TypeProviderWrapper typeProviderWrapper, final Module currentModule, final SchemaContext ctx) {
Multimap<QName, RpcDefinition> identitiesToRpcs = getIdentitiesToRpcs(ctx);
List<AttributeIfc> attributes = Lists.newArrayList();
List<RuntimeBeanEntry> runtimeBeanEntries = new ArrayList<>();
for (DataSchemaNode child : subtree.getChildNodes()) {
// runtime beans
if (child instanceof LeafSchemaNode) {
// just save the attribute
LeafSchemaNode leaf = (LeafSchemaNode) child;
attributes.add(new JavaAttribute(leaf, typeProviderWrapper));
} else if (child instanceof ContainerSchemaNode) {
ContainerSchemaNode container = (ContainerSchemaNode) child;
// this can be either TO or hierarchical RB
TOAttribute toAttribute = TOAttribute.create(container, typeProviderWrapper, packageName);
attributes.add(toAttribute);
} else if (child instanceof ListSchemaNode) {
if (isInnerStateBean(child)) {
ListSchemaNode listSchemaNode = (ListSchemaNode) child;
RuntimeBeanEntry hierarchicalChild = createHierarchical(packageName, listSchemaNode, typeProviderWrapper, currentModule, ctx);
runtimeBeanEntries.add(hierarchicalChild);
} else /* ordinary list attribute */
{
ListAttribute listAttribute = ListAttribute.create((ListSchemaNode) child, typeProviderWrapper, packageName);
attributes.add(listAttribute);
}
} else if (child instanceof LeafListSchemaNode) {
ListAttribute listAttribute = ListAttribute.create((LeafListSchemaNode) child, typeProviderWrapper);
attributes.add(listAttribute);
} else {
throw new IllegalStateException("Unexpected running-data node " + child);
}
}
Set<Rpc> rpcs = new HashSet<>();
SchemaNode subtreeSchemaNode = (SchemaNode) subtree;
for (UnknownSchemaNode unknownSchemaNode : subtreeSchemaNode.getUnknownSchemaNodes()) {
if (ConfigConstants.RPC_CONTEXT_INSTANCE_EXTENSION_QNAME.equals(unknownSchemaNode.getNodeType())) {
String localIdentityName = unknownSchemaNode.getNodeParameter();
QName identityQName = unknownSchemaNode.isAddedByUses() ? findQNameFromGrouping(subtree, ctx, unknownSchemaNode, localIdentityName) : QName.create(currentModule.getNamespace(), currentModule.getRevision(), localIdentityName);
// convert RpcDefinition to Rpc
for (RpcDefinition rpcDefinition : identitiesToRpcs.get(identityQName)) {
String name = TypeProviderWrapper.findJavaParameter(rpcDefinition);
AttributeIfc returnType;
if (rpcDefinition.getOutput() == null || rpcDefinition.getOutput().getChildNodes().isEmpty()) {
returnType = VoidAttribute.getInstance();
} else if (rpcDefinition.getOutput().getChildNodes().size() == 1) {
DataSchemaNode returnDSN = rpcDefinition.getOutput().getChildNodes().iterator().next();
returnType = getReturnTypeAttribute(returnDSN, typeProviderWrapper, packageName);
} else {
throw new IllegalArgumentException("More than one child node in rpc output is not supported. " + "Error occured in " + rpcDefinition);
}
List<JavaAttribute> parameters = new ArrayList<>();
for (DataSchemaNode childNode : sortAttributes(rpcDefinition.getInput().getChildNodes())) {
if (childNode.isAddedByUses() == false) {
// skip
// refined
// context-instance
checkArgument(childNode instanceof LeafSchemaNode, "Unexpected type of rpc input type. " + "Currently only leafs and empty output nodes are supported, got " + childNode);
JavaAttribute javaAttribute = new JavaAttribute((LeafSchemaNode) childNode, typeProviderWrapper);
parameters.add(javaAttribute);
}
}
Rpc newRpc = new Rpc(returnType, name, rpcDefinition.getQName().getLocalName(), parameters);
rpcs.add(newRpc);
}
}
}
return new AttributesRpcsAndRuntimeBeans(runtimeBeanEntries, attributes, rpcs);
}
use of org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode in project controller by opendaylight.
the class RuntimeBeanEntry method getIdentitiesToRpcs.
private static Multimap<QName, /* of identity */
RpcDefinition> getIdentitiesToRpcs(final SchemaContext schemaCtx) {
Multimap<QName, RpcDefinition> result = HashMultimap.create();
for (Module currentModule : schemaCtx.getModules()) {
// Find all identities in current module for later identity->rpc mapping
Set<QName> allIdentitiesInModule = Sets.newHashSet(Collections2.transform(currentModule.getIdentities(), SchemaNode::getQName));
for (RpcDefinition rpc : currentModule.getRpcs()) {
ContainerSchemaNode input = rpc.getInput();
if (input != null) {
for (UsesNode uses : input.getUses()) {
// Check if the rpc is config rpc by looking for input argument rpc-context-ref
Iterator<QName> pathFromRoot = uses.getGroupingPath().getPathFromRoot().iterator();
if (!pathFromRoot.hasNext() || !pathFromRoot.next().equals(ConfigConstants.RPC_CONTEXT_REF_GROUPING_QNAME)) {
continue;
}
for (SchemaNode refinedNode : uses.getRefines().values()) {
for (UnknownSchemaNode unknownSchemaNode : refinedNode.getUnknownSchemaNodes()) {
if (ConfigConstants.RPC_CONTEXT_INSTANCE_EXTENSION_QNAME.equals(unknownSchemaNode.getNodeType())) {
String localIdentityName = unknownSchemaNode.getNodeParameter();
QName identityQName = QName.create(currentModule.getNamespace(), currentModule.getRevision(), localIdentityName);
Preconditions.checkArgument(allIdentitiesInModule.contains(identityQName), "Identity referenced by rpc not found. Identity: %s, rpc: %s", localIdentityName, rpc);
result.put(identityQName, rpc);
}
}
}
}
}
}
}
return result;
}
use of org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode in project controller by opendaylight.
the class SchemaContextTest method testReadingIdentities_threadsModule.
@Test
public void testReadingIdentities_threadsModule() {
IdentitySchemaNode serviceType = findIdentityByQName(configModule, SERVICE_TYPE_Q_NAME);
Map<String, Optional<QName>> /* identity name */
expectedIdentitiesToBases = ImmutableMap.of("eventbus", Optional.<QName>absent(), "threadfactory", Optional.<QName>absent(), "threadpool", Optional.<QName>absent(), "scheduled-threadpool", Optional.<QName>absent());
assertThat(threadsModule.getIdentities().size(), is(expectedIdentitiesToBases.size()));
assertAllIdentitiesAreExpected(threadsModule, expectedIdentitiesToBases);
IdentitySchemaNode eventBusSchemaNode = null;
for (IdentitySchemaNode id : threadsModule.getIdentities()) {
String localName = id.getQName().getLocalName();
if (localName.equals("eventbus")) {
eventBusSchemaNode = id;
}
// serviceType
if (localName.equals("scheduled-threadpool") == false) {
assertEquals(serviceType, id.getBaseIdentities().iterator().next());
}
}
assertNotNull(eventBusSchemaNode);
// check unknown schma nodes
List<UnknownSchemaNode> unknownSchemaNodes = eventBusSchemaNode.getUnknownSchemaNodes();
assertEquals(1, unknownSchemaNodes.size());
UnknownSchemaNode usn = unknownSchemaNodes.get(0);
assertEquals("com.google.common.eventbus.EventBus", usn.getQName().getLocalName());
assertEquals(ConfigConstants.JAVA_CLASS_EXTENSION_QNAME, usn.getNodeType());
}
use of org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode in project controller by opendaylight.
the class RuntimeBeanEntryTest method createRuntimeBean.
@Test
public void createRuntimeBean() {
final CaseSchemaNode caseNode = Mockito.mock(CaseSchemaNode.class);
doReturn(new HashSet<LeafSchemaNode>()).when(caseNode).getChildNodes();
doReturn(new ArrayList<UnknownSchemaNode>()).when(caseNode).getUnknownSchemaNodes();
final Map<String, RuntimeBeanEntry> runtimeBeans = RuntimeBeanEntry.extractClassNameToRuntimeBeanMap(PACKAGE_NAME, caseNode, "test-name", new TypeProviderWrapper(new TypeProviderImpl(this.context)), "test", this.jmxImplModule, this.context);
assertEquals(1, runtimeBeans.size());
final RuntimeBeanEntry runtimeMXBean = runtimeBeans.get("testRuntimeMXBean");
assertTrue(runtimeMXBean.isRoot());
assertEquals("test-name", runtimeMXBean.getYangName());
}
Aggregations