*/
package org.opendaylight.netconf.sal.connect.netconf;
-import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
-import org.opendaylight.yangtools.yang.parser.util.ASTSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(NetconfDevice.class);
- public static final Function<QName, SourceIdentifier> QNAME_TO_SOURCE_ID_FUNCTION =
- input -> RevisionSourceIdentifier.create(input.getLocalName(),
- Optional.fromNullable(input.getFormattedRevision()));
-
protected final RemoteDeviceId id;
private final boolean reconnectOnSchemasChange;
private final NetconfDeviceSchemasResolver stateSchemasResolver;
private final NotificationHandler notificationHandler;
protected final List<SchemaSourceRegistration<? extends SchemaSourceRepresentation>> sourceRegistrations =
- Lists.newArrayList();
+ new ArrayList<>();
@GuardedBy("this")
private boolean connected = false;
}
};
- Futures.addCallback(sourceResolverFuture, resolvedSourceCallback);
+ Futures.addCallback(sourceResolverFuture, resolvedSourceCallback, MoreExecutors.directExecutor());
}
private void registerToBaseNetconfStream(final NetconfDeviceRpc deviceRpc,
LOG.warn("Unable to subscribe to base notification stream. Schemas will not be reloaded on the fly",
throwable);
}
- });
+ }, MoreExecutors.directExecutor());
}
private boolean shouldListenOnSchemaChange(final NetconfSessionPreferences remoteSessionCapabilities) {
}
public Collection<SourceIdentifier> getRequiredSources() {
- return Collections2.transform(requiredSources, QNAME_TO_SOURCE_ID_FUNCTION);
+ return Collections2.transform(requiredSources, DeviceSources::toSourceId);
}
public Collection<SourceIdentifier> getProvidedSources() {
- return Collections2.transform(providedSources, QNAME_TO_SOURCE_ID_FUNCTION);
+ return Collections2.transform(providedSources, DeviceSources::toSourceId);
}
public SchemaSourceProvider<YangTextSchemaSource> getSourceProvider() {
return sourceProvider;
}
+
+ private static SourceIdentifier toSourceId(final QName input) {
+ return RevisionSourceIdentifier.create(input.getLocalName(), input.getRevision());
+ }
}
/**
}
private Collection<SourceIdentifier> filterMissingSources(final Collection<SourceIdentifier> requiredSources) {
-
return requiredSources.parallelStream().filter(sourceIdentifier -> {
- boolean remove = false;
try {
- schemaRepository.getSchemaSource(sourceIdentifier, ASTSchemaSource.class).checkedGet();
- } catch (SchemaSourceException e) {
- remove = true;
+ schemaRepository.getSchemaSource(sourceIdentifier, ASTSchemaSource.class).get();
+ return false;
+ } catch (InterruptedException | ExecutionException e) {
+ return true;
}
- return remove;
}).collect(Collectors.toList());
}
while (!requiredSources.isEmpty()) {
LOG.trace("{}: Trying to build schema context from {}", id, requiredSources);
try {
- final CheckedFuture<SchemaContext, SchemaResolutionException> schemaBuilderFuture =
- schemaContextFactory.createSchemaContext(requiredSources);
- final SchemaContext result = schemaBuilderFuture.checkedGet();
+ final ListenableFuture<SchemaContext> schemaBuilderFuture = schemaContextFactory
+ .createSchemaContext(requiredSources);
+ final SchemaContext result = schemaBuilderFuture.get();
LOG.debug("{}: Schema context built successfully from {}", id, requiredSources);
final Collection<QName> filteredQNames = Sets.difference(deviceSources.getRequiredSourcesQName(),
capabilities.getUnresolvedCapabilites().keySet());
capabilities.addNonModuleBasedCapabilities(remoteSessionCapabilities
.getNonModuleCaps().stream().map(entry -> new AvailableCapabilityBuilder()
- .setCapability(entry).setCapabilityOrigin(
+ .setCapability(entry).setCapabilityOrigin(
remoteSessionCapabilities.getNonModuleBasedCapsOrigin().get(entry)).build())
.collect(Collectors.toList()));
handleSalInitializationSuccess(result, remoteSessionCapabilities, getDeviceSpecificRpc(result));
return;
- } catch (final Throwable t) {
- if (t instanceof MissingSchemaSourceException) {
- requiredSources =
- handleMissingSchemaSourceException(requiredSources, (MissingSchemaSourceException) t);
- } else if (t instanceof SchemaResolutionException) {
- // 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);
+ } catch (final ExecutionException e) {
+ // 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.
+ final Throwable cause = e.getCause();
+
+ if (cause instanceof MissingSchemaSourceException) {
+ requiredSources = handleMissingSchemaSourceException(
+ requiredSources, (MissingSchemaSourceException) e.getCause());
+ continue;
+ }
+ if (cause instanceof SchemaResolutionException) {
+ requiredSources = handleSchemaResolutionException(requiredSources,
+ (SchemaResolutionException) cause);
} else {
- // unknown error, fail
- handleSalInitializationFailure(t, listener);
+ handleSalInitializationFailure(e, listener);
return;
}
+ } catch (final Exception e) {
+ // unknown error, fail
+ handleSalInitializationFailure(e, listener);
+ return;
}
}
// No more sources, fail
continue;
}
- final String rev = getNullableRev(identifier);
- if (rev == null) {
- if (qname.getRevision() == null) {
- return qname;
- }
- } else if (qname.getFormattedRevision().equals(rev)) {
+ if (identifier.getRevision().equals(qname.getRevision())) {
return qname;
}
}
// this capability will be removed from required sources and not reported as unresolved-capability
return null;
}
-
- private String getNullableRev(final SourceIdentifier identifier) {
- final String rev = identifier.getRevision();
- return rev == null || SourceIdentifier.NOT_PRESENT_FORMATTED_REVISION.equals(rev) ? null : rev;
- }
}
}