Search in sources :

Example 1 with Module

use of org.opendaylight.yangtools.yang.model.api.Module in project controller by opendaylight.

the class ModuleMXBeanEntryBuilder method findSIE.

private static ServiceInterfaceEntry findSIE(final String prefixAndIdentityLocalName, final Module currentModule, final Map<QName, ServiceInterfaceEntry> qNamesToSIEs, final SchemaContext schemaContext) {
    Matcher m = PREFIX_COLON_LOCAL_NAME.matcher(prefixAndIdentityLocalName);
    Module foundModule;
    String localSIName;
    if (m.matches()) {
        // if there is a prefix, look for ModuleImport with this prefix. Get
        // Module from SchemaContext
        String prefix = m.group(1);
        ModuleImport moduleImport = findModuleImport(currentModule, prefix);
        foundModule = schemaContext.findModule(moduleImport.getModuleName(), moduleImport.getRevision()).orElse(null);
        checkNotNull(foundModule, format("Module not found in SchemaContext by %s", moduleImport));
        localSIName = m.group(2);
    } else {
        // no prefix => SIE is in currentModule
        foundModule = currentModule;
        localSIName = prefixAndIdentityLocalName;
    }
    QName siQName = QName.create(foundModule.getNamespace(), foundModule.getRevision(), localSIName);
    ServiceInterfaceEntry sie = qNamesToSIEs.get(siQName);
    checkState(sie != null, "Cannot find referenced Service Interface by " + prefixAndIdentityLocalName);
    return sie;
}
Also used : Matcher(java.util.regex.Matcher) QName(org.opendaylight.yangtools.yang.common.QName) ConfigConstants.createConfigQName(org.opendaylight.controller.config.yangjmxgenerator.ConfigConstants.createConfigQName) ModuleImport(org.opendaylight.yangtools.yang.model.api.ModuleImport) Module(org.opendaylight.yangtools.yang.model.api.Module)

Example 2 with Module

use of org.opendaylight.yangtools.yang.model.api.Module 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;
}
Also used : LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) UnknownSchemaNode(org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) QName(org.opendaylight.yangtools.yang.common.QName) Module(org.opendaylight.yangtools.yang.model.api.Module) UnknownSchemaNode(org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode) UsesNode(org.opendaylight.yangtools.yang.model.api.UsesNode)

Example 3 with Module

use of org.opendaylight.yangtools.yang.model.api.Module in project controller by opendaylight.

the class YangModelSearchUtils method mapModulesByNames.

public static Map<String, Module> mapModulesByNames(Collection<Module> modules) {
    Map<String, Module> result = new HashMap<>();
    for (Module m : modules) {
        String moduleName = m.getName();
        Preconditions.checkArgument(result.containsKey(moduleName) == false, "Two modules have same name " + moduleName);
        result.put(moduleName, m);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Module(org.opendaylight.yangtools.yang.model.api.Module)

Example 4 with Module

use of org.opendaylight.yangtools.yang.model.api.Module in project controller by opendaylight.

the class PackageTranslatorTest method test.

@Test
public void test() throws Exception {
    Map<String, String> map = Maps.newHashMap();
    map.put(ConfigConstants.CONFIG_NAMESPACE, EXPECTED_PACKAGE_PREFIX);
    PackageTranslator tested = new PackageTranslator(map);
    Module module = mock(Module.class);
    doReturn(new URI(ConfigConstants.CONFIG_NAMESPACE + ":threads:api")).when(module).getNamespace();
    assertEquals(EXPECTED_PACKAGE_PREFIX + ".threads.api", tested.getPackageName(module));
}
Also used : Module(org.opendaylight.yangtools.yang.model.api.Module) URI(java.net.URI) Test(org.junit.Test)

Example 5 with Module

use of org.opendaylight.yangtools.yang.model.api.Module in project controller by opendaylight.

the class DataStoreAppConfigDefaultXMLReader method createDefaultInstance.

@SuppressWarnings("unchecked")
public T createDefaultInstance(final FallbackConfigProvider fallback) throws ConfigXMLReaderException, URISyntaxException, ParserConfigurationException, XMLStreamException, SAXException, IOException {
    YangInstanceIdentifier yangPath = bindingSerializer.toYangInstanceIdentifier(bindingContext.appConfigPath);
    LOG.debug("{}: Creating app config instance from path {}, Qname: {}", logName, yangPath, bindingContext.bindingQName);
    checkNotNull(schemaService, "%s: Could not obtain the SchemaService OSGi service", logName);
    SchemaContext schemaContext = schemaService.getGlobalContext();
    Module module = schemaContext.findModule(bindingContext.bindingQName.getModule()).orElse(null);
    checkNotNull(module, "%s: Could not obtain the module schema for namespace %s, revision %s", logName, bindingContext.bindingQName.getNamespace(), bindingContext.bindingQName.getRevision());
    DataSchemaNode dataSchema = module.getDataChildByName(bindingContext.bindingQName);
    checkNotNull(dataSchema, "%s: Could not obtain the schema for %s", logName, bindingContext.bindingQName);
    checkCondition(bindingContext.schemaType.isAssignableFrom(dataSchema.getClass()), "%s: Expected schema type %s for %s but actual type is %s", logName, bindingContext.schemaType, bindingContext.bindingQName, dataSchema.getClass());
    NormalizedNode<?, ?> dataNode = parsePossibleDefaultAppConfigXMLFile(schemaContext, dataSchema);
    if (dataNode == null) {
        dataNode = fallback.get(schemaService.getGlobalContext(), dataSchema);
    }
    DataObject appConfig = bindingSerializer.fromNormalizedNode(yangPath, dataNode).getValue();
    // This shouldn't happen but need to handle it in case...
    checkNotNull(appConfig, "%s: Could not create instance for app config binding %s", logName, bindingContext.appConfigBindingClass);
    return (T) appConfig;
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Aggregations

Module (org.opendaylight.yangtools.yang.model.api.Module)18 QName (org.opendaylight.yangtools.yang.common.QName)5 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)5 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)4 HashMap (java.util.HashMap)3 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)3 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Capability (org.opendaylight.controller.config.util.capability.Capability)2 YangModuleCapability (org.opendaylight.controller.config.util.capability.YangModuleCapability)2 TypeProviderImpl (org.opendaylight.mdsal.binding.yang.types.TypeProviderImpl)2 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)2 IdentitySchemaNode (org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode)2 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)2 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)2 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)2 SchemaNode (org.opendaylight.yangtools.yang.model.api.SchemaNode)2 SchemaPath (org.opendaylight.yangtools.yang.model.api.SchemaPath)2