DynamicConfig netconf rpc update

- use new NETCONF RPC API
- Cleaned up debug logs

Change-Id: Ibc365bb144466d4815f02e0ecfe2f9f7bc207310
diff --git a/.gitignore b/.gitignore
index 5190347..08fd82f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,7 @@
 bucklets/plugins/
 .watchmanconfig
 .vscode
+*.fxs
 
 /bin/
 lib/yang
diff --git a/apps/config/src/main/java/org/onosproject/config/impl/DistributedDynamicConfigStore.java b/apps/config/src/main/java/org/onosproject/config/impl/DistributedDynamicConfigStore.java
index 1af7b34..b7ae330 100644
--- a/apps/config/src/main/java/org/onosproject/config/impl/DistributedDynamicConfigStore.java
+++ b/apps/config/src/main/java/org/onosproject/config/impl/DistributedDynamicConfigStore.java
@@ -63,7 +63,6 @@
 import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
-
 import static org.onosproject.config.DynamicConfigEvent.Type.NODE_ADDED;
 import static org.onosproject.config.DynamicConfigEvent.Type.NODE_DELETED;
 import static org.onosproject.config.DynamicConfigEvent.Type.NODE_UPDATED;
@@ -228,13 +227,12 @@
         log.trace("dpath={}", dpath);
         // FIXME Not atomic, should probably use create or replace
         if (completeVersioned(keystore.get(dpath)) != null) {
+            log.trace(" keystore.set({}, {})", dpath, type);
             completeVersioned(keystore.set(dpath, type));
-            log.trace("true");
             return true;
         }
         log.trace(" keystore.create({}, {})", dpath, type);
         Boolean result = complete(keystore.create(dpath, type));
-        log.trace("{}", result);
         return result;
     }
 
@@ -298,6 +296,8 @@
                 DocumentPath.from(spath));
         Map<String, Versioned<DataNode.Type>> entries = null;
         entries = complete(ret);
+        log.trace(" keystore.getChildren({})", spath);
+        log.trace("  entries keys:{}", entries.keySet());
         if ((entries != null) && (!entries.isEmpty())) {
             entries.forEach((k, v) -> {
                 String[] names = k.split(ResourceIdParser.NM_CHK);
@@ -429,10 +429,12 @@
                 }
             });
         }
+        log.trace(" keystore.removeNode({})", spath);
         keystore.removeNode(DocumentPath.from(spath));
     }
 
     private void removeLeaf(String path) {
+        log.trace(" keystore.removeNode({})", path);
         keystore.removeNode(DocumentPath.from(path));
         objectStore.remove(path);
     }
diff --git a/apps/configsync-netconf/src/main/java/org/onosproject/d/config/sync/impl/netconf/NetconfDeviceConfigSynchronizerProvider.java b/apps/configsync-netconf/src/main/java/org/onosproject/d/config/sync/impl/netconf/NetconfDeviceConfigSynchronizerProvider.java
index 876cceb..148cc8f 100644
--- a/apps/configsync-netconf/src/main/java/org/onosproject/d/config/sync/impl/netconf/NetconfDeviceConfigSynchronizerProvider.java
+++ b/apps/configsync-netconf/src/main/java/org/onosproject/d/config/sync/impl/netconf/NetconfDeviceConfigSynchronizerProvider.java
@@ -23,8 +23,6 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.atomic.AtomicInteger;
-
 import org.onlab.util.XmlString;
 import org.onosproject.d.config.ResourceIds;
 import org.onosproject.d.config.sync.DeviceConfigSynchronizationProvider;
@@ -47,6 +45,7 @@
 import org.onosproject.yang.model.ResourceId;
 import org.onosproject.yang.runtime.AnnotatedNodeInfo;
 import org.onosproject.yang.runtime.Annotation;
+import org.onosproject.yang.runtime.CompositeData;
 import org.onosproject.yang.runtime.CompositeStream;
 import org.onosproject.yang.runtime.DefaultAnnotatedNodeInfo;
 import org.onosproject.yang.runtime.DefaultAnnotation;
@@ -93,9 +92,6 @@
 
     private NetconfContext context;
 
-    // FIXME remove and let netconf southbound deal with message-id generation
-    private final AtomicInteger messageId = new AtomicInteger(1);
-
     protected NetconfDeviceConfigSynchronizerProvider(ProviderId id,
                                                       NetconfContext context) {
         super(id);
@@ -115,8 +111,8 @@
         StringBuilder rpc = new StringBuilder();
 
         // - Add NETCONF envelope
-        rpc.append("<rpc xmlns=\"").append(NETCONF_1_0_BASE_NAMESPACE).append("\" ")
-            .append("message-id=\"").append(messageId.getAndIncrement()).append("\">");
+        rpc.append("<rpc xmlns=\"").append(NETCONF_1_0_BASE_NAMESPACE).append('"')
+            .append(">");
 
         rpc.append("<edit-config>");
         rpc.append("<target>");
@@ -134,6 +130,7 @@
 
         // Convert change(s) into a DataNode tree
         for (Change change : request.changes()) {
+            log.trace("change={}", change);
 
             // TODO switch statement can probably be removed
             switch (change.op()) {
@@ -157,7 +154,9 @@
                                            .setDataFormat(DATAFORMAT_XML)
                                            .addAnnotation(XMLNS_XC_ANNOTATION)
                                            .build();
-                CompositeStream xml = context.yangRuntime().encode(compositeData.build(),
+                CompositeData cdata = compositeData.build();
+                log.trace("CompositeData:{}", cdata);
+                CompositeStream xml = context.yangRuntime().encode(cdata,
                                                                    yrtContext);
                 try {
                     CharStreams.copy(new InputStreamReader(xml.resourceData(), UTF_8), rpc);
@@ -191,11 +190,12 @@
         try {
             // FIXME Netconf async API is currently screwed up, need to fix
             // NetconfSession, etc.
-            CompletableFuture<String> response = session.request(rpc.toString());
-            log.info("TRACE: request:\n{}", XmlString.prettifyXml(rpc));
+            CompletableFuture<String> response = session.rpc(rpc.toString());
+            log.trace("raw request:\n{}", rpc);
+            log.trace("prettified request:\n{}", XmlString.prettifyXml(rpc));
             return response.handle((resp, err) -> {
                 if (err == null) {
-                    log.info("TRACE: reply:\n{}", XmlString.prettifyXml(resp));
+                    log.trace("reply:\n{}", XmlString.prettifyXml(resp));
                     // FIXME check response properly
                     return SetResponse.ok(request);
                 } else {
diff --git a/apps/configsync/src/main/java/org/onosproject/d/config/sync/impl/DynamicDeviceConfigSynchronizer.java b/apps/configsync/src/main/java/org/onosproject/d/config/sync/impl/DynamicDeviceConfigSynchronizer.java
index f9fdfb7..344c6d0 100644
--- a/apps/configsync/src/main/java/org/onosproject/d/config/sync/impl/DynamicDeviceConfigSynchronizer.java
+++ b/apps/configsync/src/main/java/org/onosproject/d/config/sync/impl/DynamicDeviceConfigSynchronizer.java
@@ -165,6 +165,7 @@
     void processEventNonBatch(DynamicConfigEvent event) {
         ResourceId path = event.subject();
         if (isUnderDeviceRootNode(path)) {
+            log.trace("processing event:{}", event);
 
             DeviceId deviceId = DeviceResourceIds.toDeviceId(path);
             ResourceId deviceRootPath = DeviceResourceIds.toResourceId(deviceId);
@@ -207,6 +208,8 @@
                     log.error("Request to {} failed {}", deviceId, response, e);
                 }
             });
+        } else {
+            log.warn("Ignored event's ResourceId: {}", event.subject());
         }
     }