Search in sources :

Example 36 with EffectiveModelContext

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");
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) ExecutionException(java.util.concurrent.ExecutionException) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 37 with EffectiveModelContext

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());
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 38 with EffectiveModelContext

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);
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 39 with EffectiveModelContext

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;
}
Also used : SchemaResolutionException(org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) ExecutionException(java.util.concurrent.ExecutionException) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 40 with EffectiveModelContext

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);
}
Also used : IRSchemaSource(org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Aggregations

EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)182 Test (org.junit.Test)99 Module (org.opendaylight.yangtools.yang.model.api.Module)37 QName (org.opendaylight.yangtools.yang.common.QName)29 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)28 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)26 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)24 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)24 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)21 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)18 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)16 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)16 NormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter)16 IRSchemaSource (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource)14 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)13 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)13 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)13 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)11 IOException (java.io.IOException)9 Collection (java.util.Collection)9