ONOS-6078 Netconf active component and integration with store

Change-Id: Ia80f0123f58a8e872de6ef7bf90bdde24f99d00c
diff --git a/apps/netconf/BUCK b/apps/netconf/BUCK
index c619118..f4cc35c 100644
--- a/apps/netconf/BUCK
+++ b/apps/netconf/BUCK
@@ -1,5 +1,6 @@
 BUNDLES = [
   '//apps/netconf/client:onos-apps-netconf-client',
+  '//apps/netconf/storeadapter:onos-apps-netconf-storeadapter',
 ]
 
 onos_app (
diff --git a/apps/netconf/storeadapter/BUCK b/apps/netconf/storeadapter/BUCK
new file mode 100644
index 0000000..b58c1d8
--- /dev/null
+++ b/apps/netconf/storeadapter/BUCK
@@ -0,0 +1,26 @@
+COMPILE_DEPS = [
+    '//lib:CORE_DEPS',
+    '//lib:onos-yang-model',
+    '//lib:onos-yang-runtime',
+    '//apps/config:onos-apps-config',
+]
+
+osgi_jar_with_tests (
+  deps = COMPILE_DEPS,
+)
+
+BUNDLES = [
+  '//apps/netconf/client:onos-apps-netconf-client',
+  '//apps/netconf/storeadapter:onos-apps-netconf-storeadapter',
+]
+
+onos_app (
+  app_name = 'org.onosproject.netconf',
+  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/netconf/storeadapter/src/main/java/org/onosproject/netconf/storeadapter/NetConfListener.java b/apps/netconf/storeadapter/src/main/java/org/onosproject/netconf/storeadapter/NetConfListener.java
new file mode 100644
index 0000000..a268c35
--- /dev/null
+++ b/apps/netconf/storeadapter/src/main/java/org/onosproject/netconf/storeadapter/NetConfListener.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.netconf.storeadapter;
+
+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;
+import org.onosproject.config.DynamicConfigEvent;
+import org.onosproject.config.DynamicConfigListener;
+import org.onosproject.config.DynamicConfigService;
+import org.onosproject.config.Filter;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Beta
+@Component(immediate = true)
+public class NetConfListener implements DynamicConfigListener {
+
+    private static final Logger log = LoggerFactory.getLogger(NetConfListener.class);
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DynamicConfigService cfgServcie;
+    public static final String DEVNMSPACE = "namespace1";
+
+    private ResourceId resId = new ResourceId.Builder()
+            .addBranchPointSchema("device", DEVNMSPACE )
+            .build();
+    @Activate
+    protected void activate() {
+        cfgServcie.addListener(this);
+        log.info("NetConfListener Started");
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        cfgServcie.removeListener(this);
+        log.info("NetConfListener Stopped");
+    }
+
+    public boolean isRelevant(DynamicConfigEvent event) {
+        if (event.subject().equals(resId)) {
+            log.info("isRelevant {} = {}", resId, event.subject());
+                return true;
+            } else {
+            log.info("isRelevant {} != {}", resId, event.subject());
+            return false;
+        }
+    }
+
+    public void event(DynamicConfigEvent event) {
+        if (!isRelevant(event)) {
+            log.info("event is not relevanyt!!!! {} != {}", resId, event.subject());
+            return;
+        }
+        switch (event.type()) {
+            case NODE_ADDED:
+                log.info("NetConfListener: RXD NODE_ADDED event");
+                Filter filt = new Filter();
+                DataNode node = cfgServcie.readNode(event.subject(), filt);
+                //call netconf passive
+                break;
+            case NODE_UPDATED:
+                log.info("NetConfListener: RXD NODE_UPDATED event");
+                break;
+            case NODE_REPLACED:
+                log.info("NetConfListener: RXD NODE_REPLACED event");
+                break;
+            case NODE_DELETED:
+                log.info("NetConfListener: RXD NODE_DELETED event");
+                break;
+            case UNKNOWN_OPRN:
+            default:
+                log.warn("NetConfListener: unknown event: {}", event.type());
+                break;
+        }
+    }
+}
\ No newline at end of file