Revert "Bump apache mina to 1.2.0"
[netconf.git] / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / netconf / test / tool / NetconfDeviceSimulator.java
index ea3aae54f15caa87853076f98104ca4450b4aec8..165decc6d4d6a8a41a05722026753ee375a696ea 100644 (file)
@@ -38,9 +38,8 @@ 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.SecurityUtils;
-import org.apache.sshd.common.util.threads.ThreadUtils;
+import org.apache.sshd.common.util.ThreadUtils;
+import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider;
 import org.opendaylight.controller.config.util.capability.BasicCapability;
 import org.opendaylight.controller.config.util.capability.Capability;
 import org.opendaylight.controller.config.util.capability.YangModuleCapability;
@@ -167,7 +166,7 @@ public class NetconfDeviceSimulator implements Closeable {
         final List<Integer> openDevices = Lists.newArrayList();
 
         // Generate key to temp folder
-        final KeyPairProvider keyPairProvider = getPemGeneratorHostKeyProvider();
+        final PEMGeneratorHostKeyProvider keyPairProvider = getPemGeneratorHostKeyProvider();
 
         for (int i = 0; i < params.deviceCount; i++) {
             if (currentPort > 65535) {
@@ -243,8 +242,7 @@ public class NetconfDeviceSimulator implements Closeable {
         return openDevices;
     }
 
-    private static SshProxyServerConfiguration getSshConfiguration(final InetSocketAddress bindingAddress,
-            final LocalAddress tcpLocalAddress, final KeyPairProvider keyPairProvider) {
+    private SshProxyServerConfiguration getSshConfiguration(final InetSocketAddress bindingAddress, final LocalAddress tcpLocalAddress, final PEMGeneratorHostKeyProvider keyPairProvider) throws IOException {
         return new SshProxyServerConfigurationBuilder()
                 .setBindingAddress(bindingAddress)
                 .setLocalAddress(tcpLocalAddress)
@@ -259,13 +257,13 @@ public class NetconfDeviceSimulator implements Closeable {
                 .createSshProxyServerConfiguration();
     }
 
-    private static KeyPairProvider getPemGeneratorHostKeyProvider() {
+    private PEMGeneratorHostKeyProvider getPemGeneratorHostKeyProvider() {
         try {
             final Path tempFile = Files.createTempFile("tempKeyNetconfTest", "suffix");
-            return SecurityUtils.createGeneratorHostKeyProvider(tempFile.toAbsolutePath());
+            return new PEMGeneratorHostKeyProvider(tempFile.toAbsolutePath().toString());
         } catch (final IOException e) {
             LOG.error("Unable to generate PEM key", e);
-            throw new RuntimeException("Unable to generate PEM key", e);
+            throw new RuntimeException(e);
         }
     }
 
@@ -316,8 +314,7 @@ public class NetconfDeviceSimulator implements Closeable {
         return capabilities;
     }
 
-    private static void addModuleCapability(final SharedSchemaRepository consumer, final Set<Capability> capabilities,
-            final Module module) {
+    private void addModuleCapability(final SharedSchemaRepository consumer, final Set<Capability> capabilities, final Module module) {
         final SourceIdentifier moduleSourceIdentifier = SourceIdentifier.create(module.getName(),
                 (SimpleDateFormatUtil.DEFAULT_DATE_REV == module.getRevision() ? Optional.<String>absent() :
                         Optional.of(SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision()))));
@@ -331,7 +328,7 @@ public class NetconfDeviceSimulator implements Closeable {
         }
     }
 
-    private static void addDefaultSchemas(final SharedSchemaRepository consumer) {
+    private void addDefaultSchemas(final SharedSchemaRepository consumer) {
         SourceIdentifier sId = RevisionSourceIdentifier.create("ietf-netconf-monitoring", "2010-10-04");
         registerSource(consumer, "/META-INF/yang/ietf-netconf-monitoring.yang", sId);
 
@@ -345,8 +342,7 @@ public class NetconfDeviceSimulator implements Closeable {
         registerSource(consumer, "/META-INF/yang/ietf-inet-types@2013-07-15.yang", sId);
     }
 
-    private static void registerSource(final SharedSchemaRepository consumer, final String resource,
-            final SourceIdentifier sourceId) {
+    private void registerSource(final SharedSchemaRepository consumer, final String resource, final SourceIdentifier sourceId) {
         consumer.registerSchemaSource(new SchemaSourceProvider<SchemaSourceRepresentation>() {
             @Override
             public CheckedFuture<? extends SchemaSourceRepresentation, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) {
@@ -376,11 +372,7 @@ public class NetconfDeviceSimulator implements Closeable {
     @Override
     public void close() {
         for (final SshProxyServer sshWrapper : sshWrappers) {
-            try {
-                sshWrapper.close();
-            } catch (IOException e) {
-                LOG.error("Failed to close wrapper {}", sshWrapper, e);
-            }
+            sshWrapper.close();
         }
         for (final Channel deviceCh : devicesChannels) {
             deviceCh.close();