use of org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException in project yangtools by opendaylight.
the class FilesystemSchemaSourceCache method getSource.
@Override
public synchronized FluentFuture<? extends T> getSource(final SourceIdentifier sourceIdentifier) {
final File file = sourceIdToFile(sourceIdentifier, storageDirectory);
if (file.exists() && file.canRead()) {
LOG.trace("Source {} found in cache as {}", sourceIdentifier, file);
final SchemaSourceRepresentation restored = STORAGE_ADAPTERS.get(representation).restore(sourceIdentifier, file);
return immediateFluentFuture(representation.cast(restored));
}
LOG.debug("Source {} not found in cache as {}", sourceIdentifier, file);
return immediateFailedFluentFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier));
}
use of org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException in project yangtools by opendaylight.
the class SoftSchemaSourceCache method getSource.
@Override
public ListenableFuture<? extends T> getSource(final SourceIdentifier sourceIdentifier) {
final var ref = references.get(sourceIdentifier);
if (ref != null) {
final var src = ref.get();
if (src != null) {
// We have a hit
return Futures.immediateFuture(src);
}
// Expired entry: remove it
references.remove(sourceIdentifier, ref);
}
return Futures.immediateFailedFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier));
}
use of org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException in project yangtools by opendaylight.
the class AbstractSchemaRepository method getSchemaSource.
@Override
public <T extends SchemaSourceRepresentation> ListenableFuture<T> getSchemaSource(final SourceIdentifier id, final Class<T> representation) {
final ArrayList<AbstractSchemaSourceRegistration<?>> sortedSchemaSourceRegistrations;
synchronized (this) {
final ListMultimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> srcs = sources.get(id);
if (srcs == null) {
return immediateFailedFluentFuture(new MissingSchemaSourceException("No providers registered for source " + id, id));
}
sortedSchemaSourceRegistrations = Lists.newArrayList(srcs.get(representation));
}
// TODO, remove and make sources keep sorted multimap (e.g. ArrayListMultimap with SortedLists)
sortedSchemaSourceRegistrations.sort(SchemaProviderCostComparator.INSTANCE);
final Iterator<AbstractSchemaSourceRegistration<?>> regs = sortedSchemaSourceRegistrations.iterator();
if (!regs.hasNext()) {
return immediateFailedFluentFuture(new MissingSchemaSourceException("No providers for source " + id + " representation " + representation + " available", id));
}
final ListenableFuture<T> fetchSourceFuture = fetchSource(id, regs);
// Add callback to notify cache listeners about encountered schema
Futures.addCallback(fetchSourceFuture, new FutureCallback<T>() {
@Override
public void onSuccess(final T result) {
for (final SchemaListenerRegistration listener : listeners) {
listener.getInstance().schemaSourceEncountered(result);
}
}
@Override
@SuppressWarnings("checkstyle:parameterName")
public void onFailure(final Throwable t) {
LOG.trace("Skipping notification for encountered source {}, fetching source failed", id, t);
}
}, MoreExecutors.directExecutor());
return fetchSourceFuture;
}
use of org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException in project netconf by opendaylight.
the class NetconfDeviceTest method testNetconfDeviceMissingSource.
@Test
public void testNetconfDeviceMissingSource() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = getListener();
final EffectiveModelContextFactory schemaFactory = getSchemaFactory();
final SchemaRepository schemaRepository = getSchemaRepository();
// Make fallback attempt to fail due to empty resolved sources
final MissingSchemaSourceException schemaResolutionException = new MissingSchemaSourceException("fail first", TEST_SID);
doReturn(Futures.immediateFailedFuture(schemaResolutionException)).when(schemaRepository).getSchemaSource(eq(TEST_SID), eq(YangTextSchemaSource.class));
doAnswer(invocation -> {
if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
return Futures.immediateFailedFuture(schemaResolutionException);
} else {
return Futures.immediateFuture(SCHEMA_CONTEXT);
}
}).when(schemaFactory).createEffectiveModelContext(anyCollection());
final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id, schemaContext) -> {
final Module first = Iterables.getFirst(SCHEMA_CONTEXT.getModules(), null);
final QName qName = QName.create(first.getQNameModule(), first.getName());
final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName);
final NetconfStateSchemas.RemoteYangSchema source2 = new NetconfStateSchemas.RemoteYangSchema(QName.create(first.getQNameModule(), "test-module2"));
return new NetconfStateSchemas(Sets.newHashSet(source1, source2));
};
final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), schemaRepository, schemaFactory, stateSchemasResolver);
final NetconfDevice device = new NetconfDeviceBuilder().setReconnectOnSchemasChange(true).setSchemaResourcesDTO(schemaResourcesDTO).setGlobalProcessingExecutor(getExecutor()).setBaseSchemas(BASE_SCHEMAS).setId(getId()).setSalFacade(facade).build();
// Monitoring supported
final NetconfSessionPreferences sessionCaps = getSessionCaps(true, Lists.newArrayList(TEST_CAPABILITY, TEST_CAPABILITY2));
device.onRemoteSessionUp(sessionCaps, listener);
verify(facade, timeout(5000)).onDeviceConnected(any(MountPointContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull());
verify(schemaFactory, times(1)).createEffectiveModelContext(anyCollection());
}
use of org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException in project yangtools by opendaylight.
the class YangTextSchemaContextResolver method getSource.
@Override
@NonNull
public synchronized FluentFuture<YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
final Collection<YangTextSchemaSource> ret = texts.get(sourceIdentifier);
LOG.debug("Lookup {} result {}", sourceIdentifier, ret);
if (ret.isEmpty()) {
return immediateFailedFluentFuture(new MissingSchemaSourceException("URL for " + sourceIdentifier + " not registered", sourceIdentifier));
}
return immediateFluentFuture(ret.iterator().next());
}
Aggregations