ONOS-5718 Dynamic Config APIs with RPC and Notification support

Change-Id: I670890efee83c86c7a3b242783c0a62879059849
diff --git a/apps/config/src/main/java/org/onosproject/config/model/DataNode.java b/apps/config/src/main/java/org/onosproject/config/model/DataNode.java
new file mode 100755
index 0000000..5c43304
--- /dev/null
+++ b/apps/config/src/main/java/org/onosproject/config/model/DataNode.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2016-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.config.model;
+
+import java.util.LinkedHashMap;
+
+/**
+ * Hollow definition of DataNode for ConfigService APIs.
+ */
+public interface DataNode {
+    //will remove this when the corresponding changes in onos-yang-tools become available
+
+    /**
+     * Builder for DataNode.
+     */
+    interface Builder<V> {
+        /**
+         * clones a base Data node obj to a new one.
+         *
+         * @param base base DataNode obj to be cloned
+         * @return a DataNode builder
+         */
+        Builder addBaseObj(DataNode base);
+        /**
+         * Adds the value of the instance node.
+         *
+         * @param key of the node
+         * @return a DataNode builder
+         */
+        Builder addKey(NodeKey key);
+        /**
+         * Adds the value of the instance node.
+         *
+         * @param type of the node
+         * @return a DataNode builder
+         */
+        Builder addType(DataNode.Type type);
+        /**
+         * Adds the value of the leaf node.
+         *
+         * @param value at the node
+         * @return a DataNode builder
+         */
+        Builder addValue(String value);
+
+        /**
+         * Adds children to the children field.
+         *
+         * @param children to be added
+         * @return a DataNode builder
+         */
+        //Builder addChildren(LinkedHashMap<NodeKey, DataNode> children);
+
+        /**
+         * Builds an immutable DataNode entity.
+         *
+         * @return DataNode
+         */
+        DataNode build();
+    }
+
+    /**
+     * Returns the children if DataNode contains an inner node.
+     *
+     * @return LinkedHashMap of children for an inner node, null for a leaf node
+     */
+    LinkedHashMap<NodeKey, DataNode> children();
+
+    /**
+     * Returns the value at the leaf node as a string.
+     *
+     * @return value at the leaf node as a string, null if it is an innernode
+     */
+    String value();
+
+    /**
+     * Returns the node schema identifier.
+     *
+     * @return node schema identifier
+     */
+    SchemaIdentifier identifier();
+
+    /**
+     * Returns the type of node.
+     *
+     * @return node type
+     */
+    Type type();
+
+    /**
+     * Returns the key to identify a branching node.
+     *
+     * @return key to identify a branching node
+     */
+    NodeKey key();
+
+    /**
+     * Represents type of node in data store.
+     */
+    enum Type {
+
+        /**
+         * Single instance node.
+         */
+        SINGLE_INSTANCE_NODE,
+
+        /**
+         * Multi instance node.
+         */
+        MULTI_INSTANCE_NODE,
+
+        /**
+         * Single instance leaf node.
+         */
+        SINGLE_INSTANCE_LEAF_VALUE_NODE,
+
+        /**
+         * Multi instance leaf node.
+         */
+        MULTI_INSTANCE_LEAF_VALUE_NODE
+    }
+}
diff --git a/apps/config/src/main/java/org/onosproject/config/model/DefaultDataNode.java b/apps/config/src/main/java/org/onosproject/config/model/DefaultDataNode.java
new file mode 100755
index 0000000..44b8c1e
--- /dev/null
+++ b/apps/config/src/main/java/org/onosproject/config/model/DefaultDataNode.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2016-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.config.model;
+
+import java.util.LinkedHashMap;
+
+/**
+ * Representation of an instance node in the Dynamic config store.
+ */
+public final class DefaultDataNode implements DataNode {
+    DataNode.Type type;
+    NodeKey key;
+    //Object value;
+    String value;
+    LinkedHashMap<NodeKey, DataNode> children;
+
+    /**
+     * Creates a new DefaultDataNode.
+     *
+     * @param key node key
+     * @param type of the node
+     * @param value of leaf node
+     * @param children of the inner node
+     */
+    private DefaultDataNode(NodeKey key, DataNode.Type type,
+                            String value, LinkedHashMap<NodeKey, DataNode> children) {
+        this.type = type;
+        this.key = key;
+        this.value = value;
+        this.children = children;
+    }
+    /**
+     *
+     */
+    /**
+     * Creates a new DefaultDataNode.
+     *
+     * @param node to be cloned
+     * @param value of leaf node
+     */
+    private DefaultDataNode(DataNode node, String value) {
+        this.type = node.type();
+        this.key = node.key();
+        this.value = value;
+        this.children = null;
+    }
+    /**
+     * Creates a new DefaultDataNode.
+     *
+     * @param node to be cloned
+     * @param children to be added
+     */
+    private DefaultDataNode(DataNode node, LinkedHashMap<NodeKey, DataNode> children) {
+        this.type = node.type();
+        this.key = node.key();
+        this.value = null;
+        this.children = children;
+    }
+
+    @Override
+    public LinkedHashMap<NodeKey, DataNode> children() {
+        return this.children;
+    }
+
+    @Override
+    public  String value() {
+        return value;
+        //return value.toString();
+    }
+
+
+    /**
+     * Creates and returns a new builder instance.
+     *
+     * @return new builder
+     */
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public static final class Builder<V> implements DataNode.Builder {
+
+        private DataNode.Type type;
+        private NodeKey key;
+        //Object value;
+        private String value;
+        private LinkedHashMap<NodeKey, DataNode> children;
+
+        private Builder() {
+            this.type = null;
+            this.key = null;
+            this.value = null;
+            this.children = null;
+        }
+
+        @Override
+        public Builder addBaseObj(DataNode base) {
+            this.key = base.key();
+            this.type = base.type();
+            this.value = base.value();
+            this.children = base.children();
+            return this;
+        }
+
+        @Override
+        public Builder addKey(NodeKey key) {
+            this.key = key;
+            return this;
+        }
+
+        @Override
+        public Builder addType(DataNode.Type type) {
+            this.type = type;
+            return this;
+        }
+
+        @Override
+        public Builder addValue(String value) {
+            this.value = value;
+            return this;
+        }
+
+        //@Override
+        public Builder addChildren(LinkedHashMap<NodeKey, DataNode> children) {
+            this.children = children;
+            return this;
+        }
+
+        @Override
+        public DataNode build() {
+            return new DefaultDataNode(this.key, this.type, this.value, this.children);
+        }
+    }
+
+
+    @Override
+    public SchemaIdentifier identifier() {
+        return this.key.schemaId;
+    }
+
+    @Override
+    public Type type() {
+        return this.type;
+    }
+
+    @Override
+    public NodeKey key() {
+        return this.key;
+    }
+}
\ No newline at end of file
diff --git a/apps/config/src/main/java/org/onosproject/config/model/DefaultResourceIdentifier.java b/apps/config/src/main/java/org/onosproject/config/model/DefaultResourceIdentifier.java
new file mode 100755
index 0000000..63aba40
--- /dev/null
+++ b/apps/config/src/main/java/org/onosproject/config/model/DefaultResourceIdentifier.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2016-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.config.model;
+
+/**
+ * Created by sdn on 12/15/16.
+ */
+public class DefaultResourceIdentifier<V> implements ResourceIdentifier     {
+    NodeKey key;
+    ResourceIdentifier next;
+
+    public DefaultResourceIdentifier(String nm, String nmspc) {
+        this.key = new NodeKey(nm, nmspc);
+        this.next = null;
+    }
+
+    public DefaultResourceIdentifier(ResourceIdentifier parent, NodeKey ckey) {
+        this.key = parent.nodeKey();
+        //new NodeKey(parent.nodeKey().schemaId.name, parent.nodeKey().schemaId.nameSpace);
+        this.next = new DefaultResourceIdentifier(ckey);
+    }
+
+    public DefaultResourceIdentifier(ResourceIdentifier parent, ResourceIdentifier child) {
+        this.key = parent.nodeKey();
+        this.next = child;
+    }
+
+    public DefaultResourceIdentifier(NodeKey nkey) {
+        this.key = nkey;
+        this.next = null;
+    }
+
+    /*public void setChild(NodeKey ckey) {
+        this.next = new DefaultResourceIdentifier(ckey);
+    }*/
+
+    @Override
+    public NodeKey nodeKey() {
+        return this.key;
+    }
+
+    @Override
+    public ResourceIdentifier descendentIdentifier() {
+        return this.next;
+    }
+
+    @Override
+    public String getBase() {
+        return this.key.schemaId.name.concat("#").concat(this.key.schemaId.nameSpace);
+    }
+
+    @Override
+    public String asString() {
+        String base = getBase();
+        ResourceIdentifier desc = next;
+        while (desc != null) {
+            base.concat(".").concat(desc.getBase());
+            desc = desc.descendentIdentifier();
+        }
+        return base;
+    }
+}
\ No newline at end of file
diff --git a/apps/config/src/main/java/org/onosproject/config/model/NodeKey.java b/apps/config/src/main/java/org/onosproject/config/model/NodeKey.java
new file mode 100755
index 0000000..9b462a0
--- /dev/null
+++ b/apps/config/src/main/java/org/onosproject/config/model/NodeKey.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2016-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.config.model;
+
+/**
+ * Created by sdn on 12/15/16.
+ */
+public class NodeKey {
+    SchemaIdentifier schemaId;
+
+    public NodeKey(String nm, String nmspc) {
+        this.schemaId = new SchemaIdentifier(nm, nmspc);
+    }
+}
diff --git a/apps/config/src/main/java/org/onosproject/config/model/ResourceIdentifier.java b/apps/config/src/main/java/org/onosproject/config/model/ResourceIdentifier.java
new file mode 100755
index 0000000..4862fb2
--- /dev/null
+++ b/apps/config/src/main/java/org/onosproject/config/model/ResourceIdentifier.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016-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.config.model;
+
+/**
+ * Hollow definition of ResourceIdentifier for ConfigService APIs.
+ */
+public interface ResourceIdentifier {
+    //will remove this when the corresponding changes in onos-yang-tools become available
+
+    /**
+     * Returns the node key used to uniquely identify the branch in the
+     * logical tree.
+     *
+     * @return node key uniquely identifying the branch
+     */
+    NodeKey nodeKey();
+
+    /**
+     * Returns the descendent resource identifier.
+     *
+     * @return descendent resource identifier
+     */
+    ResourceIdentifier descendentIdentifier();
+
+    String getBase();
+    String asString();
+    //DefaultResourceIdentifier asResId(NodeKey nkey);
+}
diff --git a/apps/config/src/main/java/org/onosproject/config/model/SchemaIdentifier.java b/apps/config/src/main/java/org/onosproject/config/model/SchemaIdentifier.java
new file mode 100755
index 0000000..20ce4cb
--- /dev/null
+++ b/apps/config/src/main/java/org/onosproject/config/model/SchemaIdentifier.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2016-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.config.model;
+
+/**
+ * Created by sdn on 12/15/16.
+ */
+public class SchemaIdentifier {
+    String name;
+    String nameSpace;
+    SchemaIdentifier(String nm, String nmspc) {
+        this.name = nm;
+        this.nameSpace = nmspc;
+    }
+}
diff --git a/apps/config/src/main/java/org/onosproject/config/model/package-info.java b/apps/config/src/main/java/org/onosproject/config/model/package-info.java
new file mode 100755
index 0000000..c6e61b3
--- /dev/null
+++ b/apps/config/src/main/java/org/onosproject/config/model/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2016-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.
+ */
+
+/**
+ * Dynamic config data model, hollow definitions for APIs.
+ * Will be REMOVED when the yang/model/* are available.
+ */
+package org.onosproject.config.model;
\ No newline at end of file