use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.ModuleKey in project netconf by opendaylight.
the class ModuleBuilderTest method testModuleBuilder.
@Test
public void testModuleBuilder() {
final ModuleBuilder moduleBuilder = new ModuleBuilder();
final Module.Revision revision = new Module.Revision(new RevisionIdentifier("2016-10-11"));
final YangIdentifier yangIdentifierOne = new YangIdentifier("YangIdentifier1");
final YangIdentifier yangIdentifierTwo = new YangIdentifier("YangIdentifier2");
final Uri namespace = new Uri("namespace");
final List<YangIdentifier> yangIdentifierList = ImmutableList.of(yangIdentifierOne, yangIdentifierTwo);
final ModuleKey moduleKeyOne = new ModuleKey(yangIdentifierOne, revision);
final ModuleKey moduleKeyTwo = new ModuleKey(moduleKeyOne);
moduleBuilder.setRevision(revision);
moduleBuilder.setDeviation(yangIdentifierList);
moduleBuilder.setFeature(yangIdentifierList);
moduleBuilder.setName(yangIdentifierOne);
moduleBuilder.setNamespace(namespace);
moduleBuilder.withKey(moduleKeyOne);
final Module moduleOne = moduleBuilder.build();
final Module moduleTwo = new ModuleBuilder(moduleOne).build();
assertNotNull(moduleBuilder);
assertNotNull(revision);
assertNotNull(yangIdentifierOne);
assertNotNull(yangIdentifierTwo);
assertNotNull(namespace);
assertNotNull(yangIdentifierList);
assertNotNull(moduleKeyOne);
assertNotNull(moduleKeyOne.hashCode());
assertNotNull(moduleKeyOne.toString());
assertNotNull(moduleBuilder.toString());
assertNotNull(moduleBuilder.hashCode());
assertEquals(moduleKeyOne, moduleKeyTwo);
assertEquals(revision, moduleKeyOne.getRevision());
assertEquals(yangIdentifierOne, moduleKeyOne.getName());
assertEquals(revision, moduleBuilder.getRevision());
assertEquals(yangIdentifierList, moduleBuilder.getDeviation());
assertEquals(yangIdentifierList, moduleBuilder.getFeature());
assertEquals(yangIdentifierOne, moduleBuilder.getName());
assertEquals(namespace, moduleBuilder.getNamespace());
assertEquals(moduleKeyOne, moduleBuilder.key());
assertEquals(moduleOne.toString(), moduleTwo.toString());
assertEquals(moduleKeyOne.toString(), moduleKeyTwo.toString());
assertTrue(moduleOne.equals(moduleTwo));
assertTrue(moduleKeyOne.equals(moduleKeyTwo));
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.ModuleKey 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());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.ModuleKey in project netconf by opendaylight.
the class YangLibProvider method schemaSourceUnregistered.
@Override
public void schemaSourceUnregistered(final PotentialSchemaSource<?> source) {
if (!YANG_SCHEMA_SOURCE.apply(source)) {
// we do not want to delete this module entry from module list
return;
}
WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
tx.delete(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(ModulesState.class).child(Module.class, new ModuleKey(new YangIdentifier(source.getSourceIdentifier().getName()), RevisionUtils.fromYangCommon(source.getSourceIdentifier().getRevision()))));
tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.debug("Modules state successfully updated.");
}
@Override
public void onFailure(final Throwable throwable) {
LOG.warn("Unable to update modules state", throwable);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.ModuleKey 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();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.ModuleKey in project netconf by opendaylight.
the class YangLibProviderTest method testSchemaSourceUnregistered.
@Test
public void testSchemaSourceUnregistered() {
yangLibProvider.init();
when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
doNothing().when(writeTransaction).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
doReturn(emptyFluentFuture()).when(writeTransaction).commit();
PotentialSchemaSource<YangTextSchemaSource> yangUnregistererSource = PotentialSchemaSource.create(RevisionSourceIdentifier.create("unregistered-yang-schema-without-revision"), YangTextSchemaSource.class, PotentialSchemaSource.Costs.LOCAL_IO.getValue());
yangLibProvider.schemaSourceUnregistered(yangUnregistererSource);
verify(dataBroker).newWriteOnlyTransaction();
verify(writeTransaction).delete(eq(LogicalDatastoreType.OPERATIONAL), eq(InstanceIdentifier.create(ModulesState.class).child(Module.class, new ModuleKey(new YangIdentifier("unregistered-yang-schema-without-revision"), RevisionUtils.emptyRevision()))));
verify(writeTransaction).commit();
yangUnregistererSource = PotentialSchemaSource.create(RevisionSourceIdentifier.create("unregistered-yang-with-revision", org.opendaylight.yangtools.yang.common.Revision.of("2016-04-28")), YangTextSchemaSource.class, PotentialSchemaSource.Costs.LOCAL_IO.getValue());
yangLibProvider.schemaSourceUnregistered(yangUnregistererSource);
verify(dataBroker, times(2)).newWriteOnlyTransaction();
verify(writeTransaction).delete(eq(LogicalDatastoreType.OPERATIONAL), eq(InstanceIdentifier.create(ModulesState.class).child(Module.class, new ModuleKey(new YangIdentifier("unregistered-yang-with-revision"), new Revision(new RevisionIdentifier("2016-04-28"))))));
verify(writeTransaction, times(2)).commit();
}
Aggregations