Search in sources :

Example 1 with NetconfYangTextSchemaSource

use of org.opendaylight.netconf.sal.connect.netconf.schema.NetconfRemoteSchemaYangSourceProvider.NetconfYangTextSchemaSource 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)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 NetconfYangTextSchemaSource (org.opendaylight.netconf.sal.connect.netconf.schema.NetconfRemoteSchemaYangSourceProvider.NetconfYangTextSchemaSource)1 SchemaSourceException (org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException)1