Search in sources :

Example 1 with SchemaSourceException

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

the class RemoteSchemaProviderTest method getNonExistingSchemaSource.

@Test(expected = SchemaSourceException.class)
public void getNonExistingSchemaSource() throws Exception {
    Futures.failed(new Exception("halo"));
    Mockito.when(mockedRemoteSchemaRepository.getYangTextSchemaSource(ID)).thenReturn(Futures.failed(new SchemaSourceException("Source not provided")));
    CheckedFuture<?, ?> sourceFuture = remoteSchemaProvider.getSource(ID);
    assertTrue(sourceFuture.isDone());
    sourceFuture.checkedGet();
}
Also used : SchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException) IOException(java.io.IOException) SchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException) Test(org.junit.Test)

Example 2 with SchemaSourceException

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

the class ModuleInfoSnapshotResolver method registerModuleInfo.

/*
     * Perform registration of a YangModuleInfo.
     */
@Holding("this")
private RegisteredModuleInfo registerModuleInfo(@NonNull final YangModuleInfo info) {
    // First search for an existing explicit registration
    final SourceIdentifier sourceId = sourceIdentifierFrom(info);
    for (RegisteredModuleInfo reg : sourceToInfoReg.get(sourceId)) {
        if (info.equals(reg.info)) {
            reg.incRef();
            LOG.debug("Reusing registration {}", reg);
            return reg;
        }
    }
    // Create an explicit registration
    final Registration reg;
    try {
        reg = ctxResolver.registerSource(toYangTextSource(sourceId, info));
    } catch (YangSyntaxErrorException | SchemaSourceException | IOException e) {
        throw new IllegalStateException("Failed to register info " + info, e);
    }
    final RegisteredModuleInfo regInfo = new RegisteredModuleInfo(info, reg, info.getClass().getClassLoader());
    LOG.debug("Created new registration {}", regInfo);
    sourceToInfoReg.put(sourceId, regInfo);
    return regInfo;
}
Also used : YangSyntaxErrorException(org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException) ObjectRegistration(org.opendaylight.yangtools.concepts.ObjectRegistration) AbstractObjectRegistration(org.opendaylight.yangtools.concepts.AbstractObjectRegistration) Registration(org.opendaylight.yangtools.concepts.Registration) SchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) IOException(java.io.IOException) Holding(org.checkerframework.checker.lock.qual.Holding)

Example 3 with SchemaSourceException

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

the class YangLibrarySchemaYangSourceProvider method getSource.

@Override
public ListenableFuture<? extends YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
    final URL url = availableSources.get(requireNonNull(sourceIdentifier));
    checkArgument(url != null);
    try (InputStream in = url.openStream()) {
        final byte[] schemaContent = in.readAllBytes();
        final NetconfYangTextSchemaSource yangSource = new NetconfYangTextSchemaSource(id, sourceIdentifier, url.toString(), schemaContent);
        LOG.debug("Source {} downloaded from a yang library's url {}", sourceIdentifier, url);
        return Futures.immediateFuture(yangSource);
    } catch (IOException e) {
        LOG.warn("Unable to download source {} from a yang library's url {}", sourceIdentifier, url, e);
        return Futures.immediateFailedFuture(new SchemaSourceException("Unable to download remote schema for " + sourceIdentifier + " from " + url, e));
    }
}
Also used : InputStream(java.io.InputStream) SchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException) IOException(java.io.IOException) NetconfYangTextSchemaSource(org.opendaylight.netconf.sal.connect.netconf.schema.NetconfRemoteSchemaYangSourceProvider.NetconfYangTextSchemaSource) URL(java.net.URL)

Aggregations

IOException (java.io.IOException)3 SchemaSourceException (org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException)3 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Holding (org.checkerframework.checker.lock.qual.Holding)1 Test (org.junit.Test)1 NetconfYangTextSchemaSource (org.opendaylight.netconf.sal.connect.netconf.schema.NetconfRemoteSchemaYangSourceProvider.NetconfYangTextSchemaSource)1 AbstractObjectRegistration (org.opendaylight.yangtools.concepts.AbstractObjectRegistration)1 ObjectRegistration (org.opendaylight.yangtools.concepts.ObjectRegistration)1 Registration (org.opendaylight.yangtools.concepts.Registration)1 RevisionSourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier)1 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)1 YangSyntaxErrorException (org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException)1