Search in sources :

Example 1 with RevisionSourceIdentifier

use of org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier in project netconf by opendaylight.

the class SchemaExportContentYangBodyWriter method writeTo.

@Override
public void writeTo(final SchemaExportContext context, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException {
    final RevisionSourceIdentifier sourceId = RevisionSourceIdentifier.create(context.getModule().getName(), context.getModule().getQNameModule().getRevision());
    final YangTextSchemaSource yangTextSchemaSource;
    try {
        yangTextSchemaSource = context.getSourceProvider().getSource(sourceId).get();
    } catch (InterruptedException | ExecutionException e) {
        throw new WebApplicationException("Unable to retrieve source from SourceProvider.", e);
    }
    yangTextSchemaSource.copyTo(entityStream);
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) WebApplicationException(javax.ws.rs.WebApplicationException) ExecutionException(java.util.concurrent.ExecutionException) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier)

Example 2 with RevisionSourceIdentifier

use of org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier in project netconf by opendaylight.

the class SchemaSourceCache method initializeCachedSchemas.

/**
 * Restore cache state using input set of modules. Cached schemas are filled with dependencies of input modules too.
 *
 * @param moduleList Set of modules information.
 */
private void initializeCachedSchemas(final Set<YangModuleInfo> moduleList) {
    // searching for all dependencies
    final Set<YangModuleInfo> allModulesInfo = new HashSet<>(moduleList);
    allModulesInfo.addAll(moduleList.stream().flatMap(yangModuleInfo -> collectYangModuleInfoDependencies(yangModuleInfo, moduleList).stream()).collect(Collectors.toSet()));
    // creation of source identifiers for all yang module info
    cachedSchemas = allModulesInfo.stream().map(yangModuleInfo -> {
        final RevisionSourceIdentifier revisionSourceIdentifier = RevisionSourceIdentifier.create(yangModuleInfo.getName().getLocalName(), yangModuleInfo.getName().getRevision());
        return new AbstractMap.SimpleEntry<>(revisionSourceIdentifier, yangModuleInfo);
    }).collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
    cachedSchemas.keySet().forEach(this::register);
}
Also used : YangModuleInfo(org.opendaylight.yangtools.yang.binding.YangModuleInfo) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) HashSet(java.util.HashSet)

Example 3 with RevisionSourceIdentifier

use of org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier in project yangtools by opendaylight.

the class TextToIRTransformer method transformText.

@NonNull
public static IRSchemaSource transformText(final YangTextSchemaSource text) throws YangSyntaxErrorException, IOException {
    final IRStatement rootStatement = AntlrSupport.createStatement(YangStatementStreamSource.parseYangSource(text));
    final String name = YangModelDependencyInfo.safeStringArgument(text.getIdentifier(), rootStatement, "name");
    final String latestRevision = YangModelDependencyInfo.getLatestRevision(rootStatement, text.getIdentifier());
    final RevisionSourceIdentifier sourceId = latestRevision == null ? RevisionSourceIdentifier.create(name) : RevisionSourceIdentifier.create(name, Revision.of(latestRevision));
    return new IRSchemaSource(sourceId, rootStatement, text.getSymbolicName().orElse(null));
}
Also used : IRStatement(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRStatement) IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 4 with RevisionSourceIdentifier

use of org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier in project yangtools by opendaylight.

the class YangTextSchemaContextResolverTest method testYangTextSchemaContextResolver.

@Test
public void testYangTextSchemaContextResolver() throws SchemaSourceException, IOException, YangSyntaxErrorException, InterruptedException, ExecutionException {
    final YangTextSchemaContextResolver yangTextSchemaContextResolver = YangTextSchemaContextResolver.create("test-bundle");
    assertNotNull(yangTextSchemaContextResolver);
    final URL yangFile1 = getClass().getResource("/yang-text-schema-context-resolver-test/foo.yang");
    assertNotNull(yangFile1);
    final URL yangFile2 = getClass().getResource("/yang-text-schema-context-resolver-test/bar.yang");
    assertNotNull(yangFile2);
    final URL yangFile3 = getClass().getResource("/yang-text-schema-context-resolver-test/baz.yang");
    assertNotNull(yangFile2);
    final YangTextSchemaSourceRegistration registration1 = yangTextSchemaContextResolver.registerSource(yangFile1);
    assertNotNull(registration1);
    final YangTextSchemaSourceRegistration registration2 = yangTextSchemaContextResolver.registerSource(yangFile2);
    assertNotNull(registration2);
    final YangTextSchemaSourceRegistration registration3 = yangTextSchemaContextResolver.registerSource(yangFile3);
    assertNotNull(registration3);
    assertEquals(3, yangTextSchemaContextResolver.getAvailableSources().size());
    final SourceIdentifier fooModuleId = RevisionSourceIdentifier.create("foo", Revision.of("2016-09-26"));
    final ListenableFuture<YangTextSchemaSource> foo = yangTextSchemaContextResolver.getSource(fooModuleId);
    assertTrue(foo.isDone());
    assertEquals(fooModuleId, foo.get().getIdentifier());
    final SourceIdentifier barModuleId = RevisionSourceIdentifier.create("bar", Revision.of("2016-09-26"));
    final ListenableFuture<YangTextSchemaSource> bar = yangTextSchemaContextResolver.getSource(barModuleId);
    assertTrue(bar.isDone());
    assertEquals(barModuleId, bar.get().getIdentifier());
    final SourceIdentifier bazModuleId = RevisionSourceIdentifier.create("baz", Revision.of("2016-09-26"));
    final ListenableFuture<YangTextSchemaSource> baz = yangTextSchemaContextResolver.getSource(bazModuleId);
    assertTrue(baz.isDone());
    assertEquals(bazModuleId, baz.get().getIdentifier());
    final SourceIdentifier foobarModuleId = RevisionSourceIdentifier.create("foobar", Revision.of("2016-09-26"));
    final ListenableFuture<YangTextSchemaSource> foobar = yangTextSchemaContextResolver.getSource(foobarModuleId);
    assertTrue(foobar.isDone());
    try {
        foobar.get();
        fail("A MissingSchemaSourceException should have been thrown.");
    } catch (ExecutionException e) {
        assertEquals("URL for RevisionSourceIdentifier [name=foobar@2016-09-26] not registered", e.getCause().getMessage());
    }
    Optional<? extends SchemaContext> schemaContextOptional = yangTextSchemaContextResolver.getEffectiveModelContext();
    assertTrue(schemaContextOptional.isPresent());
    SchemaContext schemaContext = schemaContextOptional.get();
    assertEquals(3, schemaContext.getModules().size());
    registration1.close();
    registration2.close();
    registration3.close();
    assertEquals(0, yangTextSchemaContextResolver.getAvailableSources().size());
    schemaContextOptional = yangTextSchemaContextResolver.getEffectiveModelContext();
    assertTrue(schemaContextOptional.isPresent());
    schemaContext = schemaContextOptional.get();
    assertEquals(0, schemaContext.getModules().size());
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL) Test(org.junit.Test)

Example 5 with RevisionSourceIdentifier

use of org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier in project yangtools by opendaylight.

the class SharedEffectiveModelContextFactoryTest method testTransientFailureWhilreRetrievingSchemaSource.

@Test
public void testTransientFailureWhilreRetrievingSchemaSource() throws Exception {
    final RevisionSourceIdentifier s3 = RevisionSourceIdentifier.create("network-topology", Revision.of("2013-10-21"));
    repository.registerSchemaSource(new TransientFailureProvider(YangTextSchemaSource.forResource("/ietf/network-topology@2013-10-21.yang")), PotentialSchemaSource.create(s3, YangTextSchemaSource.class, 1));
    final SharedEffectiveModelContextFactory sharedSchemaContextFactory = new SharedEffectiveModelContextFactory(repository, config);
    ListenableFuture<EffectiveModelContext> schemaContext = sharedSchemaContextFactory.createEffectiveModelContext(s1, s3);
    final ExecutionException exception = assertThrows(ExecutionException.class, schemaContext::get);
    assertThat(exception.getCause(), instanceOf(MissingSchemaSourceException.class));
    // check if future is invalidated and resolution of source is retried after failure
    schemaContext = sharedSchemaContextFactory.createEffectiveModelContext(s1, s3);
    assertNotNull(schemaContext.get());
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) MissingSchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException) ExecutionException(java.util.concurrent.ExecutionException) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Aggregations

RevisionSourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier)6 ExecutionException (java.util.concurrent.ExecutionException)4 YangTextSchemaSource (org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource)4 WebApplicationException (javax.ws.rs.WebApplicationException)2 Test (org.junit.Test)2 URL (java.net.URL)1 HashSet (java.util.HashSet)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 YangModuleInfo (org.opendaylight.yangtools.yang.binding.YangModuleInfo)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)1 MissingSchemaSourceException (org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException)1 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)1 IRSchemaSource (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource)1 IRStatement (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRStatement)1