Refactoring NETCONF client to consolidate active and passive components into the same jar and app.

Simplifying names and consolidating dependencies on other apps.

Change-Id: Ifd7f9253732839a083930ebc5f04116daf090e06
diff --git a/apps/netconf/client/BUCK b/apps/netconf/client/BUCK
new file mode 100644
index 0000000..804a67f
--- /dev/null
+++ b/apps/netconf/client/BUCK
@@ -0,0 +1,27 @@
+APPS = [
+  'org.onosproject.yang',
+  'org.onosproject.config',
+  'org.onosproject.netconf',
+]
+
+COMPILE_DEPS = [
+  '//lib:CORE_DEPS',
+  '//lib:onos-yang-model',
+  '//lib:onos-yang-runtime',
+  '//apps/config:onos-apps-config',
+  '//protocols/netconf/api:onos-protocols-netconf-api',
+  '//utils/osgi:onlab-osgi',
+]
+
+osgi_jar_with_tests(
+  deps = COMPILE_DEPS,
+)
+
+onos_app(
+  app_name = 'org.onosproject.netconfsb',
+  title = 'NETCONF Device Configuration',
+  category = 'Protocols',
+  url = 'http://onosproject.org',
+  description = 'Extension to allow ONOS to configure NETCONF devices.',
+  required_apps = APPS,
+)
diff --git a/apps/netconfsb/client/src/main/java/org/onosproject/netconf/client/NetconfTranslator.java b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/NetconfTranslator.java
similarity index 100%
rename from apps/netconfsb/client/src/main/java/org/onosproject/netconf/client/NetconfTranslator.java
rename to apps/netconf/client/src/main/java/org/onosproject/netconf/client/NetconfTranslator.java
diff --git a/apps/netconfsb/storeadapter/src/main/java/org/onosproject/netconf/storeadapter/NetconfActiveComponent.java b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java
similarity index 86%
rename from apps/netconfsb/storeadapter/src/main/java/org/onosproject/netconf/storeadapter/NetconfActiveComponent.java
rename to apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java
index 8d824f7..287f871 100644
--- a/apps/netconfsb/storeadapter/src/main/java/org/onosproject/netconf/storeadapter/NetconfActiveComponent.java
+++ b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfActiveComponent.java
@@ -14,12 +14,11 @@
  * limitations under the License.
  */
 
-package org.onosproject.netconf.storeadapter;
+package org.onosproject.netconf.client.impl;
 
 import com.google.common.annotations.Beta;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
-
 import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
@@ -29,13 +28,10 @@
 import org.onosproject.config.Filter;
 import org.onosproject.mastership.MastershipService;
 import org.onosproject.net.DeviceId;
-import org.onosproject.net.resource.Resource;
+import org.onosproject.netconf.NetconfController;
+import org.onosproject.netconf.NetconfException;
 import org.onosproject.netconf.client.NetconfTranslator;
 import org.onosproject.netconf.client.NetconfTranslator.OperationType;
-import org.onosproject.netconf.NetconfException;
-import org.onosproject.netconf.NetconfController;
-import java.net.URI;
-import java.net.URISyntaxException;
 import org.onosproject.yang.model.DataNode;
 import org.onosproject.yang.model.LeafNode;
 import org.onosproject.yang.model.ResourceId;
@@ -44,6 +40,8 @@
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 
 
 @Beta
@@ -65,8 +63,9 @@
     protected NetconfController controller;
 
     private ResourceId resId = new ResourceId.Builder()
-            .addBranchPointSchema("device", DEVNMSPACE )
+            .addBranchPointSchema("device", DEVNMSPACE)
             .build();
+
     @Activate
     protected void activate() {
         cfgService.addListener(this);
@@ -81,19 +80,11 @@
 
     @Override
     public boolean isRelevant(DynamicConfigEvent event) {
-        if (event.subject().equals(resId)) {
-            return true;
-        } else {
-            return false;
-        }
+        return event.subject().equals(resId);
     }
 
     public boolean isMaster(DeviceId deviceId) {
-        if (mastershipService.isLocalMaster(deviceId)) {
-            return true;
-        } else {
-            return false;
-        }
+        return mastershipService.isLocalMaster(deviceId);
     }
 
     @Override
@@ -124,8 +115,9 @@
 
     /**
      * Performs the delete operation corresponding to the passed event.
-     * @param node a relevant dataNode
-     * @param deviceId the deviceId of the device to be updated
+     *
+     * @param node       a relevant dataNode
+     * @param deviceId   the deviceId of the device to be updated
      * @param resourceId the resourceId of the root of the subtree to be edited
      * @return true if the update succeeds false otherwise
      */
@@ -135,8 +127,9 @@
 
     /**
      * Performs the update operation corresponding to the passed event.
-     * @param node a relevant dataNode
-     * @param deviceId the deviceId of the device to be updated
+     *
+     * @param node       a relevant dataNode
+     * @param deviceId   the deviceId of the device to be updated
      * @param resourceId the resourceId of the root of the subtree to be edited
      * @return true if the update succeeds false otherwise
      */
@@ -147,10 +140,11 @@
     /**
      * Parses the incoming event and pushes configuration to the effected
      * device.
-     * @param node the dataNode effecting a particular device of which this node
-     *              is master
-     * @param deviceId the deviceId of the device to be modified
-     * @param resourceId the resourceId of the root of the subtree to be edited
+     *
+     * @param node          the dataNode effecting a particular device of which this node
+     *                      is master
+     * @param deviceId      the deviceId of the device to be modified
+     * @param resourceId    the resourceId of the root of the subtree to be edited
      * @param operationType the type of editing to be performed
      * @return true if the operation succeeds, false otherwise
      */
@@ -206,11 +200,11 @@
         if (controller.getNetconfDevice(deviceId) == null) {
             try {
                 //if (this.isReachable(deviceId)) {
-                    this.controller.connectDevice(deviceId);
+                this.controller.connectDevice(deviceId);
                 //}
             } catch (Exception ex) {
-                throw new RuntimeException(new NetconfException("Can\'t " +
-                        "connect to NETCONF device on " + deviceId + ":" + deviceId, ex));
+                throw new RuntimeException(new NetconfException("Unable to connect to NETCONF device on " +
+                                                                        deviceId, ex));
             }
         }
     }
diff --git a/apps/netconfsb/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java
similarity index 99%
rename from apps/netconfsb/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java
rename to apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java
index c74ea54..500d1eb 100644
--- a/apps/netconfsb/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java
+++ b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/NetconfTranslatorImpl.java
@@ -16,6 +16,7 @@
 
 package org.onosproject.netconf.client.impl;
 
+import org.apache.felix.scr.annotations.Service;
 import org.onosproject.cluster.NodeId;
 import org.onosproject.net.DeviceId;
 import org.onosproject.netconf.client.NetconfTranslator;
@@ -89,6 +90,7 @@
  * will be no session available.
  */
 @Beta
+@Service
 @Component(immediate = true)
 public class NetconfTranslatorImpl implements NetconfTranslator {
 
diff --git a/apps/netconfsb/client/src/main/java/org/onosproject/netconf/client/impl/package-info.java b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/package-info.java
similarity index 100%
rename from apps/netconfsb/client/src/main/java/org/onosproject/netconf/client/impl/package-info.java
rename to apps/netconf/client/src/main/java/org/onosproject/netconf/client/impl/package-info.java
diff --git a/apps/netconfsb/client/src/main/java/org/onosproject/netconf/client/package-info.java b/apps/netconf/client/src/main/java/org/onosproject/netconf/client/package-info.java
similarity index 100%
rename from apps/netconfsb/client/src/main/java/org/onosproject/netconf/client/package-info.java
rename to apps/netconf/client/src/main/java/org/onosproject/netconf/client/package-info.java
diff --git a/apps/netconfsb/client/src/test/java/org/onosproject/netconf/client/NetconfTranslatorImplTest.java b/apps/netconf/client/src/test/java/org/onosproject/netconf/client/NetconfTranslatorImplTest.java
similarity index 100%
rename from apps/netconfsb/client/src/test/java/org/onosproject/netconf/client/NetconfTranslatorImplTest.java
rename to apps/netconf/client/src/test/java/org/onosproject/netconf/client/NetconfTranslatorImplTest.java
diff --git a/apps/netconfsb/BUCK b/apps/netconfsb/BUCK
deleted file mode 100644
index 907e4be..0000000
--- a/apps/netconfsb/BUCK
+++ /dev/null
@@ -1,15 +0,0 @@
-BUNDLES = [
-  '//apps/netconfsb/client:onos-apps-netconfsb-client',
-  '//apps/netconfsb/storeadapter:onos-apps-netconfsb-storeadapter',
-]
-
-onos_app (
-  app_name = 'org.onosproject.netconfsb',
-  title = 'NETCONF Application Module',
-  category = 'Utility',
-  url = 'http://onosproject.org',
-  description = """This application provides an interface for monitoring and modifying datastores
-                   of NETCONF devices using Yang data. It uses the YangRuntime to serialize outbound
-                   messages from Yang into NETCONF and deserialize received messages.""",
-  included_bundles = BUNDLES,
-)
diff --git a/apps/netconfsb/client/BUCK b/apps/netconfsb/client/BUCK
deleted file mode 100644
index 49070d1..0000000
--- a/apps/netconfsb/client/BUCK
+++ /dev/null
@@ -1,23 +0,0 @@
-APPS = [
-  'org.onosproject.yang',
-]
-
-COMPILE_DEPS = [
-  '//lib:CORE_DEPS',
-  '//lib:onos-yang-model',
-  '//lib:onos-yang-runtime',
-  '//protocols/netconf/api:onos-protocols-netconf-api',
-  '//utils/osgi:onlab-osgi',
-]
-
-osgi_jar_with_tests (
-  deps = COMPILE_DEPS,
-)
-
-onos_app (
-  title = 'Dynamic Config Netconf App',
-  category = 'Utility',
-  url = 'http://onosproject.org',
-  description = 'Netconf support for Dynamic configuration service.',
-  required_apps = APPS,
-)
\ No newline at end of file
diff --git a/apps/netconfsb/storeadapter/BUCK b/apps/netconfsb/storeadapter/BUCK
deleted file mode 100644
index 6444a6c..0000000
--- a/apps/netconfsb/storeadapter/BUCK
+++ /dev/null
@@ -1,30 +0,0 @@
-COMPILE_DEPS = [
-    '//lib:CORE_DEPS',
-    '//lib:onos-yang-model',
-    '//lib:onos-yang-runtime',
-    '//apps/config:onos-apps-config',
-    '//protocols/netconf/api:onos-protocols-netconf-api',
-    '//apps/netconfsb/client:onos-apps-netconfsb-client'
-
-
-]
-
-osgi_jar_with_tests (
-  deps = COMPILE_DEPS,
-)
-
-BUNDLES = [
-  '//apps/netconfsb/client:onos-apps-netconfsb-client',
-  '//apps/netconfsb/storeadapter:onos-apps-netconfsb-storeadapter',
-]
-
-onos_app (
-  app_name = 'org.onosproject.netconfsb',
-  title = 'NETCONF Application Module',
-  category = 'Utility',
-  url = 'http://onosproject.org',
-  description = """This application provides an interface for monitoring and modifying datastores
-                   of NETCONF devices using Yang data. It uses the YangRuntime to serialize outbound
-                   messages from Yang into NETCONF and deserialize received messages.""",
-  included_bundles = BUNDLES,
-)
diff --git a/modules.defs b/modules.defs
index 3c55a8d..05beed6 100644
--- a/modules.defs
+++ b/modules.defs
@@ -178,7 +178,7 @@
     '//apps/ofagent:onos-apps-ofagent-oar',
     '//apps/mappingmanagement:onos-apps-mappingmanagement-oar',
     '//apps/config:onos-apps-config-oar',
-    '//apps/netconfsb:onos-apps-netconfsb-oar',
+    '//apps/netconf/client:onos-apps-netconf-client-oar',
     '//apps/tetopology:onos-apps-tetopology-oar',
     '//apps/tetunnel:onos-apps-tetunnel-oar',
 #    '//apps/tenbi/yangmodel:onos-apps-tenbi-yangmodel-feature',
@@ -210,3 +210,4 @@
 ]
 
 APPS = ONOS_DRIVERS + ONOS_PROVIDERS + ONOS_APPS
+