Search in sources :

Example 1 with ModulesStateBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.ModulesStateBuilder in project netconf by opendaylight.

the class YangLibraryNotificationProducerTest method testOnDataTreeChanged.

@Test
public void testOnDataTreeChanged() {
    final String moduleSetId = "1";
    ModulesState modulesStateAfter = new ModulesStateBuilder().setModuleSetId(moduleSetId).build();
    final DataTreeModification<ModulesState> treeChange = mock(DataTreeModification.class);
    final DataObjectModification<Capabilities> objectChange = mock(DataObjectModification.class);
    doReturn(objectChange).when(treeChange).getRootNode();
    doReturn(modulesStateAfter).when(objectChange).getDataAfter();
    YangLibraryChange yangLibraryChange = new YangLibraryChangeBuilder().setModuleSetId(moduleSetId).build();
    yangLibraryNotificationProducer.onDataTreeChanged(Collections.singleton(treeChange));
    verify(yangLibraryPublisherRegistration).onYangLibraryChange(yangLibraryChange);
}
Also used : ModulesState(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesState) ModulesStateBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesStateBuilder) Capabilities(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities) YangLibraryChange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryChange) YangLibraryChangeBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryChangeBuilder) Test(org.junit.Test)

Example 2 with ModulesStateBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.ModulesStateBuilder in project netconf by opendaylight.

the class YangLibProvider method schemaSourceRegistered.

@Override
public void schemaSourceRegistered(final Iterable<PotentialSchemaSource<?>> sources) {
    final Map<ModuleKey, Module> newModules = new HashMap<>();
    for (PotentialSchemaSource<?> potentialYangSource : Iterables.filter(sources, YANG_SCHEMA_SOURCE)) {
        final YangIdentifier moduleName = new YangIdentifier(potentialYangSource.getSourceIdentifier().getName());
        final Module newModule = new ModuleBuilder().setName(moduleName).setRevision(RevisionUtils.fromYangCommon(potentialYangSource.getSourceIdentifier().getRevision())).setSchema(getUrlForModule(potentialYangSource.getSourceIdentifier())).build();
        newModules.put(newModule.key(), newModule);
    }
    if (newModules.isEmpty()) {
        // If no new yang modules then do nothing
        return;
    }
    WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
    tx.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(ModulesState.class), new ModulesStateBuilder().setModule(newModules).build());
    tx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Modules state successfully populated with new modules");
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.warn("Unable to update modules state", 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.rev160621.ModulesState) ModulesStateBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.ModulesStateBuilder) HashMap(java.util.HashMap) ModuleBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.ModuleBuilder) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) Module(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.Module) ModuleKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.ModuleKey) YangIdentifier(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier)

Example 3 with ModulesStateBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.ModulesStateBuilder in project netconf by opendaylight.

the class YangLibProviderTest method testSchemaSourceRegistered.

@Test
public void testSchemaSourceRegistered() {
    yangLibProvider.init();
    when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
    doNothing().when(writeTransaction).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(InstanceIdentifier.create(ModulesState.class)), any());
    List<PotentialSchemaSource<?>> list = new ArrayList<>();
    list.add(PotentialSchemaSource.create(RevisionSourceIdentifier.create("no-revision"), YangTextSchemaSource.class, PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
    list.add(PotentialSchemaSource.create(RevisionSourceIdentifier.create("with-revision", org.opendaylight.yangtools.yang.common.Revision.of("2016-04-28")), YangTextSchemaSource.class, PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
    doReturn(emptyFluentFuture()).when(writeTransaction).commit();
    yangLibProvider.schemaSourceRegistered(list);
    Map<ModuleKey, Module> newModulesList = new HashMap<>();
    Module newModule = new ModuleBuilder().setName(new YangIdentifier("no-revision")).setRevision(RevisionUtils.emptyRevision()).setSchema(new Uri("http://www.fake.com:300/yanglib/schemas/no-revision/")).build();
    newModulesList.put(newModule.key(), newModule);
    newModule = new ModuleBuilder().setName(new YangIdentifier("with-revision")).setRevision(new Revision(new RevisionIdentifier("2016-04-28"))).setSchema(new Uri("http://www.fake.com:300/yanglib/schemas/with-revision/2016-04-28")).build();
    newModulesList.put(newModule.key(), newModule);
    verify(dataBroker).newWriteOnlyTransaction();
    verify(writeTransaction).merge(eq(LogicalDatastoreType.OPERATIONAL), eq(InstanceIdentifier.create(ModulesState.class)), eq(new ModulesStateBuilder().setModule(newModulesList).build()));
    verify(writeTransaction).commit();
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) ModulesStateBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.ModulesStateBuilder) HashMap(java.util.HashMap) ModuleBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.ModuleBuilder) ArrayList(java.util.ArrayList) PotentialSchemaSource(org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) Revision(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.CommonLeafs.Revision) RevisionIdentifier(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.RevisionIdentifier) Module(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.Module) ModuleKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.ModuleKey) YangIdentifier(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ModulesStateBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.ModulesStateBuilder)2 Module (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.Module)2 ModuleBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.ModuleBuilder)2 ModuleKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.ModuleKey)2 YangIdentifier (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier)2 ArrayList (java.util.ArrayList)1 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)1 CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)1 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)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.rev160621.ModulesState)1 RevisionIdentifier (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.RevisionIdentifier)1 Revision (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.CommonLeafs.Revision)1 ModulesState (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesState)1 ModulesStateBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.ModulesStateBuilder)1 YangLibraryChange (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryChange)1 YangLibraryChangeBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibraryChangeBuilder)1 YangTextSchemaSource (org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource)1