* 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.test.tool;
import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Optional;
import com.google.common.collect.Collections2;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.channels.AsynchronousChannelGroup;
-import java.nio.file.Files;
-import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import org.apache.sshd.common.keyprovider.KeyPairProvider;
-import org.apache.sshd.common.util.security.SecurityUtils;
import org.apache.sshd.common.util.threads.ThreadUtils;
import org.opendaylight.netconf.api.capability.BasicCapability;
import org.opendaylight.netconf.api.capability.Capability;
import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl;
import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory;
+import org.opendaylight.netconf.impl.ServerChannelInitializer;
import org.opendaylight.netconf.impl.SessionIdProvider;
import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory;
import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
-import org.opendaylight.netconf.monitoring.osgi.NetconfMonitoringActivator;
-import org.opendaylight.netconf.monitoring.osgi.NetconfMonitoringOperationService;
import org.opendaylight.netconf.ssh.SshProxyServer;
import org.opendaylight.netconf.ssh.SshProxyServerConfiguration;
import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder;
import org.opendaylight.netconf.test.tool.config.Configuration;
import org.opendaylight.netconf.test.tool.customrpc.SettableOperationProvider;
+import org.opendaylight.netconf.test.tool.monitoring.NetconfMonitoringOperationService;
+import org.opendaylight.netconf.test.tool.monitoring.NetconfMonitoringOperationServiceFactory;
import org.opendaylight.netconf.test.tool.operations.DefaultOperationsCreator;
import org.opendaylight.netconf.test.tool.operations.OperationsProvider;
import org.opendaylight.netconf.test.tool.rpchandler.SettableOperationRpcProvider;
import org.opendaylight.netconf.test.tool.schemacache.SchemaSourceCache;
import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
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;
private final NioEventLoopGroup nettyThreadgroup;
private final HashedWheelTimer hashedWheelTimer;
- private final List<Channel> devicesChannels = Lists.newArrayList();
- private final List<SshProxyServer> sshWrappers = Lists.newArrayList();
+ private final List<Channel> devicesChannels = new ArrayList<>();
+ private final List<SshProxyServer> sshWrappers = new ArrayList<>();
private final ScheduledExecutorService minaTimerExecutor;
private final ExecutorService nioExecutor;
private final Configuration configuration;
- private SchemaContext schemaContext;
+ private EffectiveModelContext schemaContext;
private boolean sendFakeSchema = false;
private NetconfServerDispatcherImpl createDispatcher(final Set<Capability> capabilities,
final SchemaSourceProvider<YangTextSchemaSource> sourceProvider) {
- final Set<Capability> transformedCapabilities = Sets.newHashSet(Collections2.transform(capabilities, input -> {
+ final Set<Capability> transformedCapabilities = new HashSet<>(Collections2.transform(capabilities, input -> {
if (sendFakeSchema) {
sendFakeSchema = false;
return new FakeCapability((YangModuleCapability) input);
configuration.getGenerateConfigsTimeout(),
monitoringService1, serverCapabilities);
- final NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer =
- new NetconfServerDispatcherImpl.ServerChannelInitializer(serverNegotiatorFactory);
+ final ServerChannelInitializer serverChannelInitializer =
+ new ServerChannelInitializer(serverNegotiatorFactory);
return new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
}
} else if (configuration.isXmlConfigurationProvided()) {
LOG.info("using SimulatedOperationProvider.");
operationProvider = new SimulatedOperationProvider(idProvider, transformedCapabilities,
- Optional.fromNullable(configuration.getNotificationFile()),
- Optional.fromNullable(configuration.getInitialConfigXMLFile()));
+ Optional.ofNullable(configuration.getNotificationFile()),
+ Optional.ofNullable(configuration.getInitialConfigXMLFile()));
} else {
LOG.info("using OperationsProvider.");
operationProvider = new OperationsProvider(idProvider, transformedCapabilities,
}
- final NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory monitoringService =
- new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(
+ final NetconfMonitoringOperationServiceFactory monitoringService =
+ new NetconfMonitoringOperationServiceFactory(
new NetconfMonitoringOperationService(monitoringService1));
aggregatedNetconfOperationServiceFactory.onAddNetconfOperationServiceFactory(operationProvider);
aggregatedNetconfOperationServiceFactory.onAddNetconfOperationServiceFactory(monitoringService);
int currentPort = configuration.getStartingPort();
- final List<Integer> openDevices = Lists.newArrayList();
+ final List<Integer> openDevices = new ArrayList<>();
// Generate key to temp folder
- final KeyPairProvider keyPairProvider = getPemGeneratorHostKeyProvider();
+ final KeyPairProvider keyPairProvider = new VirtualKeyPairProvider();
final AsynchronousChannelGroup group;
try {
group = AsynchronousChannelGroup.withThreadPool(nioExecutor);
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new IllegalStateException("Failed to create group", e);
}
continue;
}
- LOG.debug("Simulated TCP device started on {}", address);
+ LOG.debug("Simulated TCP device started on {}", server.channel().localAddress());
}
devicesChannels.add(server.channel());
.createSshProxyServerConfiguration();
}
- private static KeyPairProvider getPemGeneratorHostKeyProvider() {
- try {
- final Path tempFile = Files.createTempFile("tempKeyNetconfTest", "suffix");
- return SecurityUtils.createGeneratorHostKeyProvider(tempFile.toAbsolutePath());
- } catch (final IOException e) {
- LOG.error("Unable to generate PEM key", e);
- throw new RuntimeException(e);
- }
- }
-
private Set<Capability> parseSchemasToModuleCapabilities(final SharedSchemaRepository consumer) {
- final Set<SourceIdentifier> loadedSources = Sets.newHashSet();
+ final Set<SourceIdentifier> loadedSources = new HashSet<>();
consumer.registerSchemaSourceListener(TextToASTTransformer.create(consumer, consumer));
consumer.registerSchemaSourceListener(new SchemaSourceListener() {
@Override
- public void schemaSourceEncountered(final SchemaSourceRepresentation schemaSourceRepresentation) {}
+ public void schemaSourceEncountered(final SchemaSourceRepresentation schemaSourceRepresentation) {
+
+ }
@Override
public void schemaSourceRegistered(final Iterable<PotentialSchemaSource<?>> potentialSchemaSources) {
}
@Override
- public void schemaSourceUnregistered(final PotentialSchemaSource<?> potentialSchemaSource) {}
+ public void schemaSourceUnregistered(final PotentialSchemaSource<?> potentialSchemaSource) {
+
+ }
});
if (configuration.getSchemasDir() != null) {
}
configuration.getDefaultYangResources().forEach(r -> {
- SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create(r.getModuleName(),
+ final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create(r.getModuleName(),
Revision.ofNullable(r.getRevision()));
registerSource(consumer, r.getResourcePath(), sourceIdentifier);
});
try {
//necessary for creating mdsal data stores and operations
- this.schemaContext = consumer.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT)
- .createSchemaContext(loadedSources).get();
+ this.schemaContext = consumer.createEffectiveModelContextFactory()
+ .createEffectiveModelContext(loadedSources).get();
} catch (final InterruptedException | ExecutionException e) {
throw new RuntimeException("Cannot parse schema context", e);
}
- final Set<Capability> capabilities = Sets.newHashSet();
+ final Set<Capability> capabilities = new HashSet<>();
for (final Module module : schemaContext.getModules()) {
for (final Module subModule : module.getSubmodules()) {
consumer.getSchemaSource(moduleSourceIdentifier, YangTextSchemaSource.class).get().read());
capabilities.add(new YangModuleCapability(module, moduleContent));
//IOException would be thrown in creating SchemaContext already
- } catch (ExecutionException | InterruptedException | IOException e) {
+ } catch (final ExecutionException | InterruptedException | IOException e) {
throw new RuntimeException("Cannot retrieve schema source for module "
+ moduleSourceIdentifier.toString() + " from schema repository", e);
}
for (final SshProxyServer sshWrapper : sshWrappers) {
try {
sshWrapper.close();
- } catch (IOException e) {
+ } catch (final IOException e) {
LOG.debug("Wrapper {} failed to close", sshWrapper, e);
}
}