import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
public static final Function<QName, SourceIdentifier> QNAME_TO_SOURCE_ID_FUNCTION = new Function<QName, SourceIdentifier>() {
@Override
public SourceIdentifier apply(final QName input) {
- return new SourceIdentifier(input.getLocalName(), Optional.fromNullable(input.getFormattedRevision()));
+ return RevisionSourceIdentifier
+ .create(input.getLocalName(), Optional.fromNullable(input.getFormattedRevision()));
}
};
// Message transformer is constructed once the schemas are available
private MessageTransformer<NetconfMessage> messageTransformer;
- public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final RemoteDeviceId id, final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
- final ExecutorService globalProcessingExecutor) {
- this(schemaResourcesDTO, id, salFacade, globalProcessingExecutor, false);
- }
-
/**
* Create rpc implementation capable of handling RPC for monitoring and notifications even before the schemas of remote device are downloaded
*/
return new NetconfDeviceRpc(baseSchema.getSchemaContext(), listener, new NetconfMessageTransformer(baseSchema.getSchemaContext(), false, baseSchema));
}
-
- // FIXME reduce parameters
- public NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final RemoteDeviceId id, final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
+ protected NetconfDevice(final SchemaResourcesDTO schemaResourcesDTO, final RemoteDeviceId id, final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
final ExecutorService globalProcessingExecutor, final boolean reconnectOnSchemasChange) {
this.id = id;
this.reconnectOnSchemasChange = reconnectOnSchemasChange;
return;
} catch (Throwable t) {
if (t instanceof MissingSchemaSourceException){
- // In case source missing, try without it
- final SourceIdentifier missingSource = ((MissingSchemaSourceException) t).getSourceId();
- LOG.warn("{}: Unable to build schema context, missing source {}, will reattempt without it", id, missingSource);
- LOG.debug("{}: Unable to build schema context, missing source {}, will reattempt without it", t);
- final Collection<QName> qNameOfMissingSource = getQNameFromSourceIdentifiers(Sets.newHashSet(missingSource));
- if (!qNameOfMissingSource.isEmpty()) {
- capabilities.addUnresolvedCapabilities(qNameOfMissingSource, UnavailableCapability.FailureReason.MissingSource);
- }
- requiredSources = stripMissingSource(requiredSources, missingSource);
+ requiredSources = handleMissingSchemaSourceException(requiredSources, (MissingSchemaSourceException) t);
} else if (t instanceof SchemaResolutionException) {
- // In case resolution error, try only with resolved sources
- SchemaResolutionException resolutionException = (SchemaResolutionException) t;
- final Set<SourceIdentifier> unresolvedSources = resolutionException.getUnsatisfiedImports().keySet();
- capabilities.addUnresolvedCapabilities(getQNameFromSourceIdentifiers(unresolvedSources), UnavailableCapability.FailureReason.UnableToResolve);
- LOG.warn("{}: Unable to build schema context, unsatisfied imports {}, will reattempt with resolved only", id, resolutionException.getUnsatisfiedImports());
- LOG.debug("{}: Unable to build schema context, unsatisfied imports {}, will reattempt with resolved only", resolutionException);
- requiredSources = resolutionException.getResolvedSources();
+ // schemaBuilderFuture.checkedGet() throws only SchemaResolutionException
+ // that might be wrapping a MissingSchemaSourceException so we need to look
+ // at the cause of the exception to make sure we don't misinterpret it.
+ if (t.getCause() instanceof MissingSchemaSourceException) {
+ requiredSources = handleMissingSchemaSourceException(requiredSources, (MissingSchemaSourceException) t.getCause());
+ continue;
+ }
+ requiredSources = handleSchemaResolutionException(requiredSources, (SchemaResolutionException) t);
} else {
// unknown error, fail
handleSalInitializationFailure(t, listener);
salFacade.onDeviceFailed(cause);
}
+ private Collection<SourceIdentifier> handleMissingSchemaSourceException(Collection<SourceIdentifier> requiredSources, final MissingSchemaSourceException t) {
+ // In case source missing, try without it
+ final SourceIdentifier missingSource = t.getSourceId();
+ LOG.warn("{}: Unable to build schema context, missing source {}, will reattempt without it", id, missingSource);
+ LOG.debug("{}: Unable to build schema context, missing source {}, will reattempt without it", t);
+ final Collection<QName> qNameOfMissingSource = getQNameFromSourceIdentifiers(Sets.newHashSet(missingSource));
+ if (!qNameOfMissingSource.isEmpty()) {
+ capabilities.addUnresolvedCapabilities(qNameOfMissingSource, UnavailableCapability.FailureReason.MissingSource);
+ }
+ return stripMissingSource(requiredSources, missingSource);
+ }
+
+ private Collection<SourceIdentifier> handleSchemaResolutionException(Collection<SourceIdentifier> requiredSources, final SchemaResolutionException resolutionException) {
+ // In case resolution error, try only with resolved sources
+ final Set<SourceIdentifier> unresolvedSources = resolutionException.getUnsatisfiedImports().keySet();
+ capabilities.addUnresolvedCapabilities(getQNameFromSourceIdentifiers(unresolvedSources), UnavailableCapability.FailureReason.UnableToResolve);
+ LOG.warn("{}: Unable to build schema context, unsatisfied imports {}, will reattempt with resolved only", id, resolutionException.getUnsatisfiedImports());
+ LOG.debug("{}: Unable to build schema context, unsatisfied imports {}, will reattempt with resolved only", resolutionException);
+ return resolutionException.getResolvedSources();
+ }
protected NetconfDeviceRpc getDeviceSpecificRpc(final SchemaContext result) {
return new NetconfDeviceRpc(result, listener, new NetconfMessageTransformer(result, true));