Search in sources :

Example 11 with Module

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

the class ConfigSubsystemFacadeFactory method getCurrentCapabilities.

public Set<Capability> getCurrentCapabilities() {
    Set<Module> modules = yangStoreService.getModules();
    final Set<Capability> capabilities = Sets.newHashSet();
    for (Module module : modules) {
        capabilities.add(new YangModuleCapability(module, yangStoreService.getModuleSource(RevisionSourceIdentifier.create(module.getName(), module.getRevision()))));
    }
    return capabilities;
}
Also used : Capability(org.opendaylight.controller.config.util.capability.Capability) YangModuleCapability(org.opendaylight.controller.config.util.capability.YangModuleCapability) Module(org.opendaylight.yangtools.yang.model.api.Module) YangModuleCapability(org.opendaylight.controller.config.util.capability.YangModuleCapability)

Example 12 with Module

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

the class JMXGenerator method generateSources.

@Override
public Collection<File> generateSources(final SchemaContext context, final File outputBaseDir, final Set<Module> currentModules, final Function<Module, Optional<String>> moduleResourcePathResolver) {
    Preconditions.checkArgument(context != null, "Null context received");
    Preconditions.checkArgument(outputBaseDir != null, "Null outputBaseDir received");
    Preconditions.checkArgument(this.namespaceToPackageMapping != null && !this.namespaceToPackageMapping.isEmpty(), "No namespace to package mapping provided in additionalConfiguration");
    final PackageTranslator packageTranslator = new PackageTranslator(this.namespaceToPackageMapping);
    if (!outputBaseDir.exists()) {
        outputBaseDir.mkdirs();
    }
    final GeneratedFilesTracker generatedFiles = new GeneratedFilesTracker();
    // create SIE structure qNamesToSIEs
    final Map<QName, ServiceInterfaceEntry> qNamesToSIEs = new HashMap<>();
    final Map<IdentitySchemaNode, ServiceInterfaceEntry> knownSEITracker = new HashMap<>();
    for (final Module module : context.getModules()) {
        final String packageName = packageTranslator.getPackageName(module);
        final Map<QName, ServiceInterfaceEntry> namesToSIEntries = ServiceInterfaceEntry.create(module, packageName, knownSEITracker);
        for (final Entry<QName, ServiceInterfaceEntry> sieEntry : namesToSIEntries.entrySet()) {
            // merge value into qNamesToSIEs
            if (qNamesToSIEs.put(sieEntry.getKey(), sieEntry.getValue()) != null) {
                throw new IllegalStateException("Cannot add two SIE with same qname " + sieEntry.getValue());
            }
        }
        if (currentModules.contains(module)) {
            // write this sie to disk
            for (final ServiceInterfaceEntry sie : namesToSIEntries.values()) {
                try {
                    generatedFiles.addFile(this.codeWriter.writeSie(sie, outputBaseDir));
                } catch (final Exception e) {
                    throw new RuntimeException("Error occurred during SIE source generate phase", e);
                }
            }
        }
    }
    final File mainBaseDir = concatFolders(this.projectBaseDir, "src", "main", "java");
    Preconditions.checkNotNull(this.resourceBaseDir, "resource base dir attribute was null");
    final StringBuilder fullyQualifiedNamesOfFactories = new StringBuilder();
    // create MBEs
    for (final Module module : currentModules) {
        final String packageName = packageTranslator.getPackageName(module);
        final Map<String, ModuleMXBeanEntry> /* MB identity local name */
        namesToMBEs = ModuleMXBeanEntry.create(module, qNamesToSIEs, context, new TypeProviderWrapper(new TypeProviderImpl(context)), packageName);
        for (final Entry<String, ModuleMXBeanEntry> mbeEntry : namesToMBEs.entrySet()) {
            final ModuleMXBeanEntry mbe = mbeEntry.getValue();
            try {
                final List<File> files1 = this.codeWriter.writeMbe(mbe, outputBaseDir, mainBaseDir);
                generatedFiles.addFile(files1);
            } catch (final Exception e) {
                throw new RuntimeException("Error occurred during MBE source generate phase", e);
            }
            fullyQualifiedNamesOfFactories.append(mbe.getFullyQualifiedName(mbe.getStubFactoryName()));
            fullyQualifiedNamesOfFactories.append("\n");
        }
    }
    // create ModuleFactory file if needed
    if (fullyQualifiedNamesOfFactories.length() > 0 && this.generateModuleFactoryFile) {
        final File serviceLoaderFile = JMXGenerator.concatFolders(this.resourceBaseDir, "META-INF", "services", ModuleFactory.class.getName());
        // if this file does not exist, create empty file
        serviceLoaderFile.getParentFile().mkdirs();
        try {
            serviceLoaderFile.createNewFile();
            Files.asCharSink(serviceLoaderFile, StandardCharsets.UTF_8).write(fullyQualifiedNamesOfFactories.toString());
        } catch (final IOException e) {
            final String message = "Cannot write to " + serviceLoaderFile;
            LOG.error(message, e);
            throw new RuntimeException(message, e);
        }
    }
    return generatedFiles.getFiles();
}
Also used : HashMap(java.util.HashMap) QName(org.opendaylight.yangtools.yang.common.QName) ServiceInterfaceEntry(org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry) IOException(java.io.IOException) IdentitySchemaNode(org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode) IOException(java.io.IOException) PackageTranslator(org.opendaylight.controller.config.yangjmxgenerator.PackageTranslator) ModuleFactory(org.opendaylight.controller.config.spi.ModuleFactory) ModuleMXBeanEntry(org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry) Module(org.opendaylight.yangtools.yang.model.api.Module) TypeProviderImpl(org.opendaylight.mdsal.binding.yang.types.TypeProviderImpl) File(java.io.File) TypeProviderWrapper(org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper)

Example 13 with Module

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

the class BindingToNormalizedNodeCodec method getRpcMethodToSchema.

public ImmutableBiMap<Method, RpcDefinition> getRpcMethodToSchema(final Class<? extends RpcService> key) {
    final Module module = getModuleBlocking(key);
    final ImmutableBiMap.Builder<Method, RpcDefinition> ret = ImmutableBiMap.builder();
    try {
        for (final RpcDefinition rpcDef : module.getRpcs()) {
            final Method method = findRpcMethod(key, rpcDef);
            ret.put(method, rpcDef);
        }
    } catch (final NoSuchMethodException e) {
        throw new IllegalStateException("Rpc defined in model does not have representation in generated class.", e);
    }
    return ret.build();
}
Also used : ImmutableBiMap(com.google.common.collect.ImmutableBiMap) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) Method(java.lang.reflect.Method) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module)

Example 14 with Module

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

the class BindingToNormalizedNodeCodec method getRpcMethodToSchemaPath.

// FIXME: This should be probably part of Binding Runtime context
public ImmutableBiMap<Method, SchemaPath> getRpcMethodToSchemaPath(final Class<? extends RpcService> key) {
    final Module module = getModuleBlocking(key);
    final ImmutableBiMap.Builder<Method, SchemaPath> ret = ImmutableBiMap.<Method, SchemaPath>builder();
    try {
        for (final RpcDefinition rpcDef : module.getRpcs()) {
            final Method method = findRpcMethod(key, rpcDef);
            ret.put(method, rpcDef.getPath());
        }
    } catch (final NoSuchMethodException e) {
        throw new IllegalStateException("Rpc defined in model does not have representation in generated class.", e);
    }
    return ret.build();
}
Also used : ImmutableBiMap(com.google.common.collect.ImmutableBiMap) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) Method(java.lang.reflect.Method) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module)

Example 15 with Module

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

the class ModuleMXBeanEntryNameConflictTest method loadYangs.

private Module loadYangs(final String testedModule, final String moduleName) {
    final List<String> yangs = new ArrayList<>();
    yangs.add("/ietf-inet-types.yang");
    yangs.add("/duplicates/" + testedModule + YangConstants.RFC6020_YANG_FILE_EXTENSION);
    yangs.addAll(getConfigApiYangs());
    this.context = YangParserTestUtils.parseYangResources(ModuleMXBeanEntryNameConflictTest.class, yangs);
    this.namesToModules = YangModelSearchUtils.mapModulesByNames(this.context.getModules());
    this.configModule = this.namesToModules.get(ConfigConstants.CONFIG_MODULE);
    final Module module = this.namesToModules.get(moduleName);
    Preconditions.checkNotNull(module, "Cannot get module %s from %s", moduleName, this.namesToModules.keySet());
    return module;
}
Also used : ArrayList(java.util.ArrayList) Module(org.opendaylight.yangtools.yang.model.api.Module)

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