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());
}
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();
}
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();
}
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);
}
}
}
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);
}
Aggregations