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