Search in sources :

Example 1 with YangLibrary

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.schema.storage.YangLibrary in project netconf by opendaylight.

the class YangLibraryWriter method updateYangLibrary.

private synchronized void updateYangLibrary(final EffectiveModelContext context) {
    if (reg == null) {
        // Already shut down, do not do anything
        return;
    }
    final long currentSetId = moduleSetId++;
    final YangLibrary newYangLibrary = createYangLibraryFromContext(context.getModules(), currentSetId);
    final ModulesState newModuleState = createModuleStateFromModules(context.getModules(), currentSetId);
    LOG.debug("Trying to write new yang-library: {}", newYangLibrary);
    LOG.debug("Trying to write new module-state: {}", newModuleState);
    final WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.OPERATIONAL, YANG_LIBRARY_INSTANCE_IDENTIFIER, newYangLibrary);
    tx.put(LogicalDatastoreType.OPERATIONAL, MODULES_STATE_INSTANCE_IDENTIFIER, newModuleState);
    tx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Yang library updated successfully");
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.warn("Failed to update yang library", throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) ModulesState(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesState) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) YangLibrary(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary)

Example 2 with YangLibrary

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.schema.storage.YangLibrary in project netconf by opendaylight.

the class YangLibraryTest method createTestModuleSet.

private static YangLibrary createTestModuleSet() {
    Submodule sub = new SubmoduleBuilder().setName(new YangIdentifier("test-submodule")).setRevision(ImportOnlyModuleRevisionBuilder.emptyRevision().getRevisionIdentifier()).build();
    Module modules = new ModuleBuilder().setName(new YangIdentifier("test-module_2013-07-22")).setNamespace(new Uri("test:namespace")).setRevision(new RevisionIdentifier("2013-07-22")).setSubmodule(ImmutableMap.of(sub.key(), sub)).build();
    Module yangLibrary = new ModuleBuilder().setName(new YangIdentifier("ietf-yang-library_2019-01-04")).setNamespace(new Uri("urn:ietf:params:xml:ns:yang:ietf-yang-library")).setRevision(new RevisionIdentifier("2019-01-04")).build();
    ModuleSet modulesSet = new ModuleSetBuilder().setName("state-modules").setModule(ImmutableMap.of(modules.key(), modules, yangLibrary.key(), yangLibrary)).build();
    Schema schema = new SchemaBuilder().setName("state-schema").setModuleSet(Collections.singletonList(modulesSet.getName())).build();
    Datastore datastore = new DatastoreBuilder().setName(Operational.class).setSchema(schema.getName()).build();
    return new YangLibraryBuilder().setModuleSet(BindingMap.of(modulesSet)).setSchema(BindingMap.of(schema)).setDatastore(BindingMap.of(datastore)).setContentId("0").build();
}
Also used : ModuleBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.ModuleBuilder) Schema(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.Schema) Submodule(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.module.Submodule) SubmoduleBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.module.SubmoduleBuilder) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) ModuleSetBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.ModuleSetBuilder) YangLibraryBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryBuilder) Datastore(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.Datastore) SchemaBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.SchemaBuilder) ModuleSet(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.ModuleSet) RevisionIdentifier(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.RevisionIdentifier) Module(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.Module) YangIdentifier(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier) DatastoreBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.DatastoreBuilder)

Example 3 with YangLibrary

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.schema.storage.YangLibrary in project netconf by opendaylight.

the class AbstractNetconfTopology method registerDeviceSchemaSources.

private List<SchemaSourceRegistration<?>> registerDeviceSchemaSources(final RemoteDeviceId remoteDeviceId, final NetconfNode node, final SchemaResourcesDTO resources) {
    final YangLibrary yangLibrary = node.getYangLibrary();
    if (yangLibrary != null) {
        final Uri uri = yangLibrary.getYangLibraryUrl();
        if (uri != null) {
            final List<SchemaSourceRegistration<?>> registrations = new ArrayList<>();
            final String yangLibURL = uri.getValue();
            final SchemaSourceRegistry schemaRegistry = resources.getSchemaRegistry();
            // pre register yang library sources as fallback schemas to schema registry
            final LibraryModulesSchemas schemas;
            final String yangLibUsername = yangLibrary.getUsername();
            final String yangLigPassword = yangLibrary.getPassword();
            if (yangLibUsername != null && yangLigPassword != null) {
                schemas = LibraryModulesSchemas.create(yangLibURL, yangLibUsername, yangLigPassword);
            } else {
                schemas = LibraryModulesSchemas.create(yangLibURL);
            }
            for (final Map.Entry<SourceIdentifier, URL> entry : schemas.getAvailableModels().entrySet()) {
                registrations.add(schemaRegistry.registerSchemaSource(new YangLibrarySchemaYangSourceProvider(remoteDeviceId, schemas.getAvailableModels()), PotentialSchemaSource.create(entry.getKey(), YangTextSchemaSource.class, PotentialSchemaSource.Costs.REMOTE_IO.getValue())));
            }
            return List.copyOf(registrations);
        }
    }
    return List.of();
}
Also used : YangLibrarySchemaYangSourceProvider(org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider) ArrayList(java.util.ArrayList) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) YangLibrary(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.schema.storage.YangLibrary) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) URL(java.net.URL) LibraryModulesSchemas(org.opendaylight.netconf.sal.connect.netconf.LibraryModulesSchemas) SchemaSourceRegistration(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration) SchemaSourceRegistry(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with YangLibrary

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.schema.storage.YangLibrary in project netconf by opendaylight.

the class YangLibraryNotificationProducerRFC8525 method onDataTreeChanged.

@Override
public void onDataTreeChanged(@NonNull Collection<DataTreeModification<YangLibrary>> changes) {
    for (DataTreeModification<YangLibrary> change : changes) {
        final DataObjectModification<YangLibrary> rootNode = change.getRootNode();
        final YangLibrary dataAfter = rootNode.getDataAfter();
        if (dataAfter != null) {
            final YangLibraryUpdate yangLibraryUpdate = new YangLibraryUpdateBuilder().setContentId(dataAfter.getContentId()).build();
            yangLibraryPublisherRegistration.onYangLibraryUpdate(yangLibraryUpdate);
        }
    }
}
Also used : YangLibraryUpdateBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdateBuilder) YangLibraryUpdate(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdate) YangLibrary(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary)

Example 5 with YangLibrary

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.schema.storage.YangLibrary in project netconf by opendaylight.

the class YangLibraryNotificationProducerTestRFC8525 method testOnDataTreeChanged.

@Test
public void testOnDataTreeChanged() {
    final String contentId = "1";
    YangLibrary yangLibraryAfter = new YangLibraryBuilder().setContentId(contentId).build();
    final DataTreeModification<YangLibrary> treeChange = mock(DataTreeModification.class);
    final DataObjectModification<Capabilities> objectChange = mock(DataObjectModification.class);
    doReturn(objectChange).when(treeChange).getRootNode();
    doReturn(yangLibraryAfter).when(objectChange).getDataAfter();
    YangLibraryUpdate yangLibraryUpdate = new YangLibraryUpdateBuilder().setContentId(contentId).build();
    yangLibraryNotificationProducer.onDataTreeChanged(Collections.singleton(treeChange));
    verify(yangLibraryPublisherRegistration).onYangLibraryUpdate(yangLibraryUpdate);
}
Also used : YangLibraryBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryBuilder) YangLibraryUpdateBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdateBuilder) Capabilities(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities) YangLibraryUpdate(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdate) YangLibrary(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary) Test(org.junit.Test)

Aggregations

YangLibrary (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary)4 Test (org.junit.Test)2 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)2 YangLibraryBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryBuilder)2 YangLibraryUpdate (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdate)2 YangLibraryUpdateBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryUpdateBuilder)2 ModuleSet (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.yang.library.parameters.ModuleSet)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)1 CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)1 LibraryModulesSchemas (org.opendaylight.netconf.sal.connect.netconf.LibraryModulesSchemas)1 YangLibrarySchemaYangSourceProvider (org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider)1 Capabilities (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities)1 ModulesState (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesState)1 RevisionIdentifier (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.RevisionIdentifier)1 Module (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.Module)1 ModuleBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.module.set.parameters.ModuleBuilder)1