final var registry = resources.registry();
for (var entry : schemas.getAvailableModels().entrySet()) {
registrations.add(registry.registerSchemaSource(new LibrarySchemaSourceProvider(
- remoteDeviceId, schemas.getAvailableModels()),
+ schemas.getAvailableModels()),
PotentialSchemaSource.create(entry.getKey(), YangTextSource.class,
PotentialSchemaSource.Costs.REMOTE_IO.getValue())));
}
+++ /dev/null
-/*
- * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netconf.client.mdsal;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.base.MoreObjects;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
-import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
-import org.opendaylight.yangtools.yang.model.spi.source.StringYangTextSource;
-
-/**
- * A {@link YangTextSource} cached from a remote service.
- */
-@NonNullByDefault
-public final class CachedYangTextSource extends StringYangTextSource {
- private final RemoteDeviceId deviceId;
-
- public CachedYangTextSource(final RemoteDeviceId deviceId, final SourceIdentifier sourceId, final String content,
- final @Nullable String symbolicName) {
- super(sourceId, content, symbolicName);
- this.deviceId = requireNonNull(deviceId);
- }
-
- public RemoteDeviceId deviceId() {
- return deviceId;
- }
-
- @Override
- protected MoreObjects.ToStringHelper addToStringAttributes(final MoreObjects.ToStringHelper toStringHelper) {
- return super.addToStringAttributes(toStringHelper.add("deviceId", deviceId));
- }
-}
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Map;
-import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
+import org.opendaylight.yangtools.yang.model.spi.source.StringYangTextSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(LibrarySchemaSourceProvider.class);
private final ImmutableMap<SourceIdentifier, URL> availableSources;
- private final RemoteDeviceId id;
- public LibrarySchemaSourceProvider(final RemoteDeviceId id, final Map<SourceIdentifier, URL> availableSources) {
- this.id = requireNonNull(id);
+ public LibrarySchemaSourceProvider(final Map<SourceIdentifier, URL> availableSources) {
this.availableSources = ImmutableMap.copyOf(availableSources);
}
"Unable to download remote schema for " + sourceIdentifier + " from " + url, e));
}
- final var yangSource = new CachedYangTextSource(id, sourceIdentifier,
+ final var yangSource = new StringYangTextSource(sourceIdentifier,
new String(schemaContent, StandardCharsets.UTF_8), url.toString());
LOG.debug("Source {} downloaded from a yang library's url {}", sourceIdentifier, url);
return Futures.immediateFuture(yangSource);
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
+import org.opendaylight.yangtools.yang.model.spi.source.StringYangTextSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
id + ": Unexpected response to get-schema, schema not present in message for: "
+ sourceIdentifier));
LOG.debug("{}: YANG Schema successfully retrieved for {}:{}", id, moduleName, revision);
- return new CachedYangTextSource(id, sourceIdentifier, schemaString, null);
+ return new StringYangTextSource(sourceIdentifier, schemaString);
}
LOG.warn("{}: YANG schema was not successfully retrieved for {}. Errors: {}", id, sourceIdentifier,
// FIXME: this instanceof check is quite bad
final var sourceProvider = availableSchemas instanceof LibraryModulesSchemas libraryModule
- ? new LibrarySchemaSourceProvider(deviceId, libraryModule.getAvailableModels())
+ ? new LibrarySchemaSourceProvider(libraryModule.getAvailableModels())
: new MonitoringSchemaSourceProvider(deviceId, deviceRpc);
return new DeviceSources(requiredSources, providedSources, sourceProvider);
}, MoreExecutors.directExecutor());
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import org.junit.jupiter.api.Test;
-import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
public class LibrarySchemaYangSourceProviderTest {
private final SourceIdentifier workingSid = new SourceIdentifier("abc");
private final LibrarySchemaSourceProvider yangLibrarySchemaYangSourceProvider = new LibrarySchemaSourceProvider(
- new RemoteDeviceId("id", new InetSocketAddress("localhost", 22)),
Map.of(workingSid, LibrarySchemaYangSourceProviderTest.class.getResource("/schemas/config-test-rpc.yang")));
@Test
void testGetSourceFailure() throws InterruptedException, MalformedURLException {
final var sourceIdentifierURLMap = Map.of(workingSid, new URL("http://non-existing-entity.yang"));
final var failingYangLibrarySchemaYangSourceProvider = new LibrarySchemaSourceProvider(
- new RemoteDeviceId("id", new InetSocketAddress("localhost", 22)), sourceIdentifierURLMap);
+ sourceIdentifierURLMap);
final var future = failingYangLibrarySchemaYangSourceProvider.getSource(workingSid);
final var ex = assertThrows(ExecutionException.class, () -> future.get());