Mark netconf related factory as functional interface

- deprecate/remove redundant factory implementations

Change-Id: I29ba9f3397c37c02b37d07dff16a4203186c5fcd
diff --git a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfController.java b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfController.java
index a78be6d..ce50558 100644
--- a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfController.java
+++ b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfController.java
@@ -33,7 +33,7 @@
     private Map<DeviceId, NetconfDevice> devicesMap;
 
     public MockNetconfController() {
-        devicesMap = new HashMap<DeviceId, NetconfDevice>();
+        devicesMap = new HashMap<>();
     }
 
     @Override
@@ -56,13 +56,9 @@
         IpAddress ipAddress = Ip4Address.valueOf(nameParts[1]);
         int port = Integer.parseInt(nameParts[2]);
         NetconfDeviceInfo ncdi = new NetconfDeviceInfo("mock", "mock", ipAddress, port);
-        try {
-            mockNetconfDevice = (new MockNetconfDeviceFactory()).createNetconfDevice(ncdi);
-            devicesMap.put(deviceId, mockNetconfDevice);
-        } catch (NetconfException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
+
+        mockNetconfDevice = new MockNetconfDevice(ncdi);
+        devicesMap.put(deviceId, mockNetconfDevice);
 
         return mockNetconfDevice;
     }
diff --git a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfDeviceFactory.java b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfDeviceFactory.java
index 349237d..085e649 100644
--- a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfDeviceFactory.java
+++ b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockNetconfDeviceFactory.java
@@ -20,6 +20,10 @@
 import org.onosproject.netconf.NetconfDeviceInfo;
 import org.onosproject.netconf.NetconfException;
 
+/**
+ * @deprecated in 1.14.0
+ */
+@Deprecated
 public class MockNetconfDeviceFactory implements NetconfDeviceFactory {
 
     @Override
diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfDeviceFactory.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfDeviceFactory.java
index 484d809..312c7c3 100644
--- a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfDeviceFactory.java
+++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfDeviceFactory.java
@@ -19,6 +19,7 @@
 /**
  * Abstract interface for the creation of a NETCONF device.
  */
+@FunctionalInterface
 public interface NetconfDeviceFactory {
 
     /**
diff --git a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSessionFactory.java b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSessionFactory.java
index 0e5e9be..806eccb 100644
--- a/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSessionFactory.java
+++ b/protocols/netconf/api/src/main/java/org/onosproject/netconf/NetconfSessionFactory.java
@@ -19,6 +19,7 @@
 /**
  * Abstract interface for the creation of a NETCONF session.
  */
+@FunctionalInterface
 public interface NetconfSessionFactory {
 
     /**
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/DefaultNetconfDevice.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/DefaultNetconfDevice.java
index f700768..c952027 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/DefaultNetconfDevice.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/DefaultNetconfDevice.java
@@ -49,7 +49,7 @@
     public DefaultNetconfDevice(NetconfDeviceInfo deviceInfo)
             throws NetconfException {
         netconfDeviceInfo = deviceInfo;
-        sessionFactory = new NetconfSessionMinaImpl.MinaSshNetconfSessionFactory();
+        sessionFactory = (ncDevInfo) -> new NetconfSessionMinaImpl(ncDevInfo);
         try {
             netconfSession = sessionFactory.createNetconfSession(deviceInfo);
         } catch (NetconfException e) {
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfControllerImpl.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfControllerImpl.java
index ab0189d..e0959cd 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfControllerImpl.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfControllerImpl.java
@@ -118,7 +118,7 @@
     private final NetconfDeviceOutputEventListener downListener = new DeviceDownEventListener();
 
     protected Set<NetconfDeviceListener> netconfDeviceListeners = new CopyOnWriteArraySet<>();
-    protected NetconfDeviceFactory deviceFactory = new DefaultNetconfDeviceFactory();
+    protected NetconfDeviceFactory deviceFactory = (deviceInfo) -> new DefaultNetconfDevice(deviceInfo);
 
     protected final ExecutorService executor =
             Executors.newCachedThreadPool(groupedThreads("onos/netconfdevicecontroller",
@@ -343,14 +343,17 @@
     }
 
 
-    //Device factory for the specific NetconfDeviceImpl
+    /**
+     * Device factory for the specific NetconfDeviceImpl.
+     *
+     * @deprecated in 1.14.0
+     */
+    @Deprecated
     private class DefaultNetconfDeviceFactory implements NetconfDeviceFactory {
 
         @Override
         public NetconfDevice createNetconfDevice(NetconfDeviceInfo netconfDeviceInfo)
                 throws NetconfException {
-            log.info("Creating NETCONF session to {} with {}",
-                    netconfDeviceInfo.getDeviceId(), NetconfSshClientLib.APACHE_MINA);
             return new DefaultNetconfDevice(netconfDeviceInfo);
         }
     }
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImpl.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImpl.java
index 31ec0ac..846ec26 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImpl.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImpl.java
@@ -199,6 +199,9 @@
     }
 
     private void startClient() throws IOException {
+        log.info("Creating NETCONF session to {}",
+                 deviceInfo.getDeviceId());
+
         client = SshClient.setUpDefaultClient();
         client.getProperties().putIfAbsent(FactoryManager.IDLE_TIMEOUT,
                 TimeUnit.SECONDS.toMillis(idleTimeout));
@@ -1019,6 +1022,10 @@
         }
     }
 
+    /**
+     * @deprecated in 1.14.0
+     */
+    @Deprecated
     public static class MinaSshNetconfSessionFactory implements NetconfSessionFactory {
 
         @Override
diff --git a/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfControllerImplTest.java b/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfControllerImplTest.java
index b350688..459559c 100644
--- a/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfControllerImplTest.java
+++ b/protocols/netconf/ctl/src/test/java/org/onosproject/netconf/ctl/impl/NetconfControllerImplTest.java
@@ -17,6 +17,7 @@
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
+
 import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Before;
@@ -35,7 +36,6 @@
 import org.onosproject.net.device.DeviceService;
 import org.onosproject.net.key.DeviceKeyService;
 import org.onosproject.netconf.NetconfDevice;
-import org.onosproject.netconf.NetconfDeviceFactory;
 import org.onosproject.netconf.NetconfDeviceInfo;
 import org.onosproject.netconf.NetconfDeviceListener;
 import org.onosproject.netconf.NetconfDeviceOutputEvent;
@@ -120,7 +120,7 @@
     @Before
     public void setUp() throws Exception {
         ctrl = new NetconfControllerImpl();
-        ctrl.deviceFactory = new TestNetconfDeviceFactory();
+        ctrl.deviceFactory = (ncDevInfo) -> new TestNetconfDevice(ncDevInfo);
         ctrl.cfgService = cfgService;
         ctrl.deviceService = deviceService;
         ctrl.deviceKeyService = deviceKeyService;
@@ -398,17 +398,6 @@
     }
 
     /**
-     * Mock NetconfDeviceFactory class.
-     */
-    private class TestNetconfDeviceFactory implements NetconfDeviceFactory {
-
-        @Override
-        public NetconfDevice createNetconfDevice(NetconfDeviceInfo netconfDeviceInfo) throws NetconfException {
-            return new TestNetconfDevice(netconfDeviceInfo);
-        }
-    }
-
-    /**
      * Mock NetconfDeviceImpl class, used for creating test devices.
      */
     protected class TestNetconfDevice implements NetconfDevice {