Search in sources :

Example 1 with MissingSchemaSourceException

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));
}
Also used : MissingSchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException) File(java.io.File) SchemaSourceRepresentation(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation)

Example 2 with MissingSchemaSourceException

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));
}
Also used : MissingSchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException)

Example 3 with MissingSchemaSourceException

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;
}
Also used : SchemaSourceRepresentation(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation) MissingSchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException)

Example 4 with MissingSchemaSourceException

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());
}
Also used : Arrays(java.util.Arrays) SchemaSourceRegistration(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) SettableFuture(com.google.common.util.concurrent.SettableFuture) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) HashMultimap(com.google.common.collect.HashMultimap) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) Mockito.after(org.mockito.Mockito.after) Mockito.doReturn(org.mockito.Mockito.doReturn) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) RemoteDeviceHandler(org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler) DOMActionService(org.opendaylight.mdsal.dom.api.DOMActionService) XmlUtil(org.opendaylight.netconf.api.xml.XmlUtil) Module(org.opendaylight.yangtools.yang.model.api.Module) Collection(java.util.Collection) RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) Set(java.util.Set) Mockito.doNothing(org.mockito.Mockito.doNothing) InetSocketAddress(java.net.InetSocketAddress) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) NetconfDeviceCommunicator(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator) SchemaSourceRepresentation(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation) List(java.util.List) Revision(org.opendaylight.yangtools.yang.common.Revision) MissingSchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException) Assert.assertFalse(org.junit.Assert.assertFalse) PotentialSchemaSource(org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource) SAXException(org.xml.sax.SAXException) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) Mockito.mock(org.mockito.Mockito.mock) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) Iterables(com.google.common.collect.Iterables) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) Mockito.timeout(org.mockito.Mockito.timeout) SchemaSourceRegistry(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry) Lists(com.google.common.collect.Lists) ArgumentCaptor(org.mockito.ArgumentCaptor) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) XmlNetconfConstants(org.opendaylight.netconf.api.xml.XmlNetconfConstants) NetconfDeviceRpc(org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) SchemaRepository(org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) NetconfMessageTransformUtil(org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) QName(org.opendaylight.yangtools.yang.common.QName) Mockito.verify(org.mockito.Mockito.verify) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) Futures(com.google.common.util.concurrent.Futures) NetconfDeviceSchemasResolver(org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemasResolver) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) SchemaResolutionException(org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException) AvailableCapability(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability) Collections(java.util.Collections) NetconfDeviceCapabilities(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities) Assert.assertEquals(org.junit.Assert.assertEquals) MessageTransformer(org.opendaylight.netconf.sal.connect.api.MessageTransformer) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) NetconfDeviceRpc(org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc) NetconfDeviceCommunicator(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator) YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) QName(org.opendaylight.yangtools.yang.common.QName) EffectiveModelContextFactory(org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext) MissingSchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException) Module(org.opendaylight.yangtools.yang.model.api.Module) NetconfDeviceSchemasResolver(org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemasResolver) SchemaRepository(org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository) Test(org.junit.Test)

Example 5 with MissingSchemaSourceException

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());
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) MissingSchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException) Objects.requireNonNull(java.util.Objects.requireNonNull) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

MissingSchemaSourceException (org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException)7 SchemaSourceRepresentation (org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation)3 YangTextSchemaSource (org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource)3 Test (org.junit.Test)2 HashMultimap (com.google.common.collect.HashMultimap)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Futures (com.google.common.util.concurrent.Futures)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 File (java.io.File)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1