Merge "BUG 652 leafref CCE & BUG 720 colons problem"
[controller.git] / opendaylight / netconf / netconf-ssh / src / main / java / org / opendaylight / controller / netconf / ssh / osgi / NetconfSSHActivator.java
index 112bf67f69b48d869fede643308dca962c317819..5b8803001ca9a33f71d2cacab990f03891a6891e 100644 (file)
@@ -45,7 +45,7 @@ public class NetconfSSHActivator implements BundleActivator{
     private IUserManager iUserManager;
     private BundleContext context = null;
 
-    ServiceTrackerCustomizer<IUserManager, IUserManager> customizer = new ServiceTrackerCustomizer<IUserManager, IUserManager>(){
+    private ServiceTrackerCustomizer<IUserManager, IUserManager> customizer = new ServiceTrackerCustomizer<IUserManager, IUserManager>(){
         @Override
         public IUserManager addingService(ServiceReference<IUserManager> 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<InetSocketAddress> 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 {