use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.
the class SharedSchemaRepositoryTest method testFailedSchemaContext.
@Test
public void testFailedSchemaContext() throws Exception {
final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
final SettableSchemaProvider<IRSchemaSource> remoteInetTypesYang = getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
remoteInetTypesYang.register(sharedSchemaRepository);
final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
// Make source appear
final Throwable ex = new IllegalStateException("failed schema");
remoteInetTypesYang.setException(ex);
final ListenableFuture<EffectiveModelContext> schemaContextFuture = fact.createEffectiveModelContext(remoteInetTypesYang.getId());
try {
schemaContextFuture.get();
} catch (final ExecutionException e) {
assertNotNull(e.getCause());
assertNotNull(e.getCause().getCause());
assertSame(ex, e.getCause().getCause());
return;
}
fail("Schema context creation should have failed");
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.
the class SharedSchemaRepositoryTest method testSimpleSchemaContext.
@Test
public void testSimpleSchemaContext() throws Exception {
final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
final SettableSchemaProvider<IRSchemaSource> remoteInetTypesYang = getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
remoteInetTypesYang.register(sharedSchemaRepository);
final ListenableFuture<IRSchemaSource> registeredSourceFuture = sharedSchemaRepository.getSchemaSource(remoteInetTypesYang.getId(), IRSchemaSource.class);
assertFalse(registeredSourceFuture.isDone());
final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
final ListenableFuture<EffectiveModelContext> schemaContextFuture = fact.createEffectiveModelContext(remoteInetTypesYang.getId());
assertFalse(schemaContextFuture.isDone());
// Make source appear
remoteInetTypesYang.setResult();
assertEquals(remoteInetTypesYang.getSchemaSourceRepresentation(), registeredSourceFuture.get());
// Verify schema created successfully
assertTrue(schemaContextFuture.isDone());
final SchemaContext firstSchemaContext = schemaContextFuture.get();
assertSchemaContext(firstSchemaContext, 1);
// Try same schema second time
final ListenableFuture<EffectiveModelContext> secondSchemaFuture = sharedSchemaRepository.createEffectiveModelContextFactory().createEffectiveModelContext(remoteInetTypesYang.getId());
// Verify second schema created successfully immediately
assertTrue(secondSchemaFuture.isDone());
// Assert same context instance is returned from first and second attempt
assertSame(firstSchemaContext, secondSchemaFuture.get());
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.
the class SharedSchemaRepositoryTest method testTwoSchemaContextsSharingSource.
@Test
public void testTwoSchemaContextsSharingSource() throws Exception {
final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
final SettableSchemaProvider<IRSchemaSource> remoteInetTypesYang = getImmediateYangSourceProviderFromResource("/ietf/ietf-inet-types@2010-09-24.yang");
remoteInetTypesYang.register(sharedSchemaRepository);
remoteInetTypesYang.setResult();
final SettableSchemaProvider<IRSchemaSource> remoteTopologyYang = getImmediateYangSourceProviderFromResource("/ietf/network-topology@2013-10-21.yang");
remoteTopologyYang.register(sharedSchemaRepository);
remoteTopologyYang.setResult();
final SettableSchemaProvider<IRSchemaSource> remoteModuleNoRevYang = getImmediateYangSourceProviderFromResource("/no-revision/module-without-revision.yang");
remoteModuleNoRevYang.register(sharedSchemaRepository);
final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
final ListenableFuture<EffectiveModelContext> inetAndTopologySchemaContextFuture = fact.createEffectiveModelContext(remoteInetTypesYang.getId(), remoteTopologyYang.getId());
assertTrue(inetAndTopologySchemaContextFuture.isDone());
assertSchemaContext(inetAndTopologySchemaContextFuture.get(), 2);
final ListenableFuture<EffectiveModelContext> inetAndNoRevSchemaContextFuture = fact.createEffectiveModelContext(remoteInetTypesYang.getId(), remoteModuleNoRevYang.getId());
assertFalse(inetAndNoRevSchemaContextFuture.isDone());
remoteModuleNoRevYang.setResult();
assertTrue(inetAndNoRevSchemaContextFuture.isDone());
assertSchemaContext(inetAndNoRevSchemaContextFuture.get(), 2);
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.
the class YangTextSchemaContextResolver method getEffectiveModelContext.
/**
* Try to parse all currently available yang files and build new schema context depending on specified parsing mode.
*
* @param statementParserMode mode of statement parser
* @return new schema context iif there is at least 1 yang file registered and
* new schema context was successfully built.
*/
public Optional<? extends EffectiveModelContext> getEffectiveModelContext(final StatementParserMode statementParserMode) {
final EffectiveModelContextFactory factory = repository.createEffectiveModelContextFactory(config(statementParserMode));
Optional<EffectiveModelContext> sc;
Object ver;
do {
// Spin get stable context version
Object cv;
do {
cv = contextVersion;
sc = currentSchemaContext.get();
if (version == cv) {
return sc;
}
} while (cv != contextVersion);
// Version has been updated
Collection<SourceIdentifier> sources;
do {
ver = version;
sources = ImmutableSet.copyOf(requiredSources);
} while (ver != version);
while (true) {
final ListenableFuture<EffectiveModelContext> f = factory.createEffectiveModelContext(sources);
try {
sc = Optional.of(f.get());
break;
} catch (final InterruptedException e) {
throw new IllegalStateException("Interrupted while assembling schema context", e);
} catch (final ExecutionException e) {
LOG.info("Failed to fully assemble schema context for {}", sources, e);
final Throwable cause = e.getCause();
Verify.verify(cause instanceof SchemaResolutionException);
sources = ((SchemaResolutionException) cause).getResolvedSources();
}
}
LOG.debug("Resolved schema context for {}", sources);
synchronized (this) {
if (contextVersion == cv) {
currentSchemaContext.set(sc);
contextVersion = ver;
}
}
} while (version == ver);
return sc;
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.
the class OpenconfigVerSharedSchemaRepositoryTest method testSharedSchemaRepository.
@Test
public void testSharedSchemaRepository() throws Exception {
final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("shared-schema-repo-test");
final SettableSchemaProvider<IRSchemaSource> bar = getImmediateYangSourceProviderFromResource("/openconfig-version/shared-schema-repository/bar@2016-01-01.yang");
bar.register(sharedSchemaRepository);
bar.setResult();
final SettableSchemaProvider<IRSchemaSource> foo = getImmediateYangSourceProviderFromResource("/openconfig-version/shared-schema-repository/foo.yang");
foo.register(sharedSchemaRepository);
foo.setResult();
final SettableSchemaProvider<IRSchemaSource> semVer = getImmediateYangSourceProviderFromResource("/openconfig-version/shared-schema-repository/openconfig-extensions.yang");
semVer.register(sharedSchemaRepository);
semVer.setResult();
final EffectiveModelContextFactory fact = sharedSchemaRepository.createEffectiveModelContextFactory();
final ListenableFuture<EffectiveModelContext> inetAndTopologySchemaContextFuture = fact.createEffectiveModelContext(bar.getId(), foo.getId(), semVer.getId());
assertTrue(inetAndTopologySchemaContextFuture.isDone());
assertSchemaContext(inetAndTopologySchemaContextFuture.get(), 3);
final ListenableFuture<EffectiveModelContext> barSchemaContextFuture = fact.createEffectiveModelContext(bar.getId(), semVer.getId());
assertTrue(barSchemaContextFuture.isDone());
assertSchemaContext(barSchemaContextFuture.get(), 2);
}
Aggregations