Search in sources :

Example 1 with YangIdentifier

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier in project mdsal by opendaylight.

the class MountPointContextFactoryImpl method fillSource.

private static void fillSource(final List<SourceReference> sources, final YangIdentifier sourceName, final Optional<Revision> revision, final Set<Uri> uris) {
    final var sourceId = RevisionSourceIdentifier.create(sourceName.getValue(), revision);
    final SourceReference sourceRef;
    if (uris != null && uris.isEmpty()) {
        final var locations = new ArrayList<URL>();
        for (Uri uri : uris) {
            try {
                locations.add(new URL(uri.getValue()));
            } catch (MalformedURLException e) {
                LOG.debug("Ignoring invalid schema location {}", uri, e);
            }
        }
        sourceRef = SourceReference.of(sourceId, locations);
    } else {
        sourceRef = SourceReference.of(sourceId);
    }
    sources.add(sourceRef);
}
Also used : MalformedURLException(java.net.MalformedURLException) SourceReference(org.opendaylight.mdsal.yanglib.api.SourceReference) ArrayList(java.util.ArrayList) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) URL(java.net.URL)

Example 2 with YangIdentifier

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier 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));
}
Also used : RevisionIdentifier(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev131019.RevisionIdentifier) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) YangIdentifier(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier) Test(org.junit.Test)

Example 3 with YangIdentifier

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier 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 4 with YangIdentifier

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier 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 5 with YangIdentifier

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier 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());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) 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)

Aggregations

YangIdentifier (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.YangIdentifier)6 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)4 ModuleKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.ModuleKey)4 Test (org.junit.Test)3 Module (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.Module)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)2 CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)2 ModulesState (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.ModulesState)2 ModulesStateBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.ModulesStateBuilder)2 RevisionIdentifier (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.RevisionIdentifier)2 Revision (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.CommonLeafs.Revision)2 ModuleBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev160621.module.list.ModuleBuilder)2 YangTextSchemaSource (org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 SourceReference (org.opendaylight.mdsal.yanglib.api.SourceReference)1 RevisionIdentifier (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev131019.RevisionIdentifier)1 RevisionIdentifier (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.RevisionIdentifier)1