X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-ssh%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fssh%2Fosgi%2FNetconfSSHActivator.java;h=5b8803001ca9a33f71d2cacab990f03891a6891e;hp=112bf67f69b48d869fede643308dca962c317819;hb=84248dac9ed8aa37e996e39429c8aa8ece473eaf;hpb=721b580748cb93b3dac952ff1f111d0ab0da0c79 diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/osgi/NetconfSSHActivator.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/osgi/NetconfSSHActivator.java index 112bf67f69..5b8803001c 100644 --- a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/osgi/NetconfSSHActivator.java +++ b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/osgi/NetconfSSHActivator.java @@ -45,7 +45,7 @@ public class NetconfSSHActivator implements BundleActivator{ private IUserManager iUserManager; private BundleContext context = null; - ServiceTrackerCustomizer customizer = new ServiceTrackerCustomizer(){ + private ServiceTrackerCustomizer customizer = new ServiceTrackerCustomizer(){ @Override public IUserManager addingService(ServiceReference reference) { logger.trace("Service {} added, let there be SSH bridge.", reference); @@ -72,19 +72,19 @@ public class NetconfSSHActivator implements BundleActivator{ @Override - public void start(BundleContext context) throws Exception { + public void start(BundleContext context) { this.context = context; listenForManagerService(); } @Override - public void stop(BundleContext context) throws Exception { + public void stop(BundleContext context) throws IOException { if (server != null){ server.stop(); logger.trace("Netconf SSH bridge is down ..."); } } - private void startSSHServer() throws Exception { + private void startSSHServer() throws IllegalStateException, IOException { logger.trace("Starting netconf SSH bridge."); Optional sshSocketAddressOptional = NetconfConfigUtil.extractSSHNetconfAddress(context, EXCEPTION_MESSAGE); InetSocketAddress tcpSocketAddress = NetconfConfigUtil.extractTCPNetconfAddress(context, @@ -94,14 +94,18 @@ public class NetconfSSHActivator implements BundleActivator{ String path = NetconfConfigUtil.getPrivateKeyPath(context); path = path.replace("\\", "/"); // FIXME: shouldn't this convert lines to system dependent path separator? if (path.equals("")){ - throw new Exception("Missing netconf.ssh.pk.path key in configuration file."); + throw new IllegalStateException("Missing netconf.ssh.pk.path key in configuration file."); } File privateKeyFile = new File(path); - String privateKeyPEMString; + String privateKeyPEMString = null; if (privateKeyFile.exists() == false) { // generate & save to file - privateKeyPEMString = PEMGenerator.generateTo(privateKeyFile); + try { + privateKeyPEMString = PEMGenerator.generateTo(privateKeyFile); + } catch (Exception e) { + logger.error("Exception occured while generating PEM string {}",e); + } } else { // read from file try (FileInputStream fis = new FileInputStream(path)) { @@ -111,7 +115,12 @@ public class NetconfSSHActivator implements BundleActivator{ throw new IllegalStateException("Error reading RSA key from file " + path); } } - AuthProvider authProvider = new AuthProvider(iUserManager, privateKeyPEMString); + AuthProvider authProvider = null; + try { + authProvider = new AuthProvider(iUserManager, privateKeyPEMString); + } catch (Exception e) { + logger.error("Error instantiating AuthProvider {}",e); + } this.server = NetconfSSHServer.start(sshSocketAddressOptional.get().getPort(),tcpSocketAddress,authProvider); Thread serverThread = new Thread(server,"netconf SSH server thread"); @@ -120,10 +129,10 @@ public class NetconfSSHActivator implements BundleActivator{ logger.trace("Netconf SSH bridge up and running."); } else { logger.trace("No valid connection configuration for SSH bridge found."); - throw new Exception("No valid connection configuration for SSH bridge found."); + throw new IllegalStateException("No valid connection configuration for SSH bridge found."); } } - private void onUserManagerFound(IUserManager userManager) throws Exception{ + private void onUserManagerFound(IUserManager userManager) throws IOException { if (server!=null && server.isUp()){ server.addUserManagerService(userManager); } else {