[ONOS-5465][TE Tunnel SB Provider] Interaction with ONOS core TE subsystems for TE tunnel updates

Change-Id: I2cb7ed7731192228a5f6ef4c4b6c3a14a7175732
diff --git a/providers/ietfte/topology/app.xml b/providers/ietfte/topology/app.xml
deleted file mode 100644
index d38fac4..0000000
--- a/providers/ietfte/topology/app.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  ~ 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.
-  -->
-<app name="org.onosproject.teprovider.topology" origin="HUAWEI" version="${project.version}"
-     category="Provider" title="RESTCONF TE Topology Provider"
-     featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
-     features="${project.artifactId}">
-    <description>${project.description}</description>
-    <artifact>mvn:${project.groupId}/${project.artifactId}/${project.version}</artifact>
-    <artifact>mvn:${project.groupId}/onos-app-tenbi-yangmodel/${project.version}</artifact>    
-</app>
diff --git a/providers/ietfte/topology/features.xml b/providers/ietfte/topology/features.xml
deleted file mode 100644
index 3207bac..0000000
--- a/providers/ietfte/topology/features.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<!--
-  ~ 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.
-  -->
-<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
-    <repository>mvn:${project.groupId}/onos-app-tenbi-yangmodel/${project.version}/xml/features</repository>
-    <feature name="${project.artifactId}" version="${project.version}"
-             description="${project.description}">
-        <feature>onos-api</feature>
-        <feature>onos-app-tenbi-yangmodel</feature>
-        <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
-        <bundle>mvn:${project.groupId}/onos-restconf-client-api/${project.version}</bundle>
-        <bundle>mvn:${project.groupId}/onos-restconf-client-ctl/${project.version}</bundle>
-        <bundle>mvn:org.glassfish.jersey.core/jersey-client/2.22.2</bundle>
-        <bundle>mvn:commons-io/commons-io/2.4</bundle>
-        <bundle>mvn:org.apache.httpcomponents/httpclient-osgi/4.5.1</bundle>
-        <bundle>mvn:org.apache.httpcomponents/httpcore-osgi/4.4.4</bundle>
-        <bundle>mvn:${project.groupId}/onos-app-tetopology/${project.version}</bundle>
-        <bundle>mvn:${project.groupId}/onos-app-yms-api/${project.version}</bundle>
-        <bundle>mvn:${project.groupId}/onos-app-tenbi-utils/${project.version}</bundle>
-    </feature>
-</features>
-
diff --git a/providers/ietfte/topology/pom.xml b/providers/ietfte/topology/pom.xml
index 04243e4..ddee4af 100644
--- a/providers/ietfte/topology/pom.xml
+++ b/providers/ietfte/topology/pom.xml
@@ -30,6 +30,18 @@
     <packaging>bundle</packaging>
 
     <description>IETF TE topology southbound provider</description>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 
     <dependencies>
         <dependency>
@@ -67,6 +79,11 @@
             <artifactId>onos-restconf-server-utils</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-ietfte-provider-utils</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 
 </project>
diff --git a/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/JsonYdtCodec.java b/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/JsonYdtCodec.java
deleted file mode 100644
index f53bac8..0000000
--- a/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/JsonYdtCodec.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright 2016 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.provider.te.topology;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.apache.commons.io.IOUtils;
-import org.onosproject.protocol.restconf.server.utils.parser.json.ParserUtils;
-import org.onosproject.yms.ych.YangCompositeEncoding;
-import org.onosproject.yms.ych.YangDataTreeCodec;
-import org.onosproject.yms.ydt.YdtBuilder;
-import org.onosproject.yms.ydt.YmsOperationType;
-import org.onosproject.yms.ymsm.YmsService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import static org.onosproject.yms.ydt.YdtContextOperationType.NONE;
-
-
-/**
- * JSON/YDT Codec implementation.
- */
-public class JsonYdtCodec implements YangDataTreeCodec {
-    private static final String RESTCONF_ROOT = "restconf/data";
-
-    protected final YmsService ymsService;
-
-    private final Logger log = LoggerFactory.getLogger(getClass());
-
-    public JsonYdtCodec(YmsService service) {
-        ymsService = service;
-    }
-
-    @Override
-    public String encodeYdtToProtocolFormat(YdtBuilder ydtBuilder) {
-        String json = ParserUtils.convertYdtToJson(ydtBuilder.getRootNode().getName(),
-                                                   ydtBuilder.getRootNode(),
-                                                   ymsService.getYdtWalker())
-                .textValue();
-        return json;
-    }
-
-    @Override
-    public YangCompositeEncoding encodeYdtToCompositeProtocolFormat(YdtBuilder ydtBuilder) {
-        // Mainly for POST/PUT operation.
-        // YdtBuilder/YdtContext has YdtContextType NONE for URI,
-        // YdtContextType CREATE/MERGE/REPLACE for Resource data.
-
-        // TODO: Implement this method in Release Ibis for TE Tunnel.
-
-        return null;
-    }
-
-    @Override
-    public YdtBuilder decodeProtocolDataToYdt(String protocolData,
-                                              Object schemaRegistryForYdt,
-                                              YmsOperationType opType) {
-        // Get a new builder
-        YdtBuilder builder = ymsService.getYdtBuilder(RESTCONF_ROOT,
-                                                      null,
-                                                      opType,
-                                                      schemaRegistryForYdt);
-        ParserUtils.convertJsonToYdt(getObjectNode(protocolData), builder);
-        return builder;
-    }
-
-    @Override
-    public YdtBuilder decodeCompositeProtocolDataToYdt(YangCompositeEncoding protocolData,
-                                                       Object schemaRegistryForYdt,
-                                                       YmsOperationType opType) {
-        // opType should be QUERY_REPLY
-        // Get a new builder
-        YdtBuilder builder = ymsService.getYdtBuilder(RESTCONF_ROOT,
-                                                      null,
-                                                      opType,
-                                                      schemaRegistryForYdt);
-        // Convert the URI to ydtBuilder
-
-        // YdtContextOperationType should be NONE for URI in QUERY_RESPONSE.
-        ParserUtils.convertUriToYdt(protocolData.getResourceIdentifier(), builder, NONE);
-        // Set default operation type for the payload node, is this for resource data?
-        // NULL/EMPTY for Resource data
-        builder.setDefaultEditOperationType(null);
-
-        // Convert the payload json body to ydt
-        ParserUtils.convertJsonToYdt(getObjectNode(protocolData.getResourceInformation()), builder);
-        return builder;
-    }
-
-    // Returns an ObjectNode from s JSON string.
-    private ObjectNode getObjectNode(String json) {
-        InputStream stream = IOUtils.toInputStream(json);
-
-        ObjectNode rootNode;
-        ObjectMapper mapper = new ObjectMapper();
-        try {
-            rootNode = (ObjectNode) mapper.readTree(stream);
-        } catch (IOException e) {
-            log.error("Can't read stream as a JSON ObjectNode: {}", e);
-            return null;
-        }
-        return rootNode;
-    }
-
-}
diff --git a/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/TeTopologyRestconfProvider.java b/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/TeTopologyRestconfProvider.java
index 2fd6aec..8fdf49c 100644
--- a/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/TeTopologyRestconfProvider.java
+++ b/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/TeTopologyRestconfProvider.java
@@ -36,6 +36,8 @@
 import org.onosproject.protocol.rest.RestSBDevice;
 import org.onosproject.protocol.restconf.RestConfNotificationEventListener;
 import org.onosproject.protocol.restconf.RestConfSBController;
+import org.onosproject.provider.te.utils.DefaultJsonCodec;
+import org.onosproject.provider.te.utils.YangCompositeEncodingImpl;
 import org.onosproject.tetopology.management.api.TeTopologyProvider;
 import org.onosproject.tetopology.management.api.TeTopologyProviderRegistry;
 import org.onosproject.tetopology.management.api.TeTopologyProviderService;
@@ -155,7 +157,7 @@
         codecHandler.addDeviceSchema(IetfNetworkTopology.class);
         codecHandler.addDeviceSchema(IetfTeTopology.class);
         // Register JSON CODEC functions
-        codecHandler.registerOverriddenCodec(new JsonYdtCodec(ymsService),
+        codecHandler.registerOverriddenCodec(new DefaultJsonCodec(ymsService),
                                              YangProtocolEncodingFormat.JSON);
 
         appId = coreService.registerApplication(APP_NAME);
diff --git a/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/YangCompositeEncodingImpl.java b/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/YangCompositeEncodingImpl.java
deleted file mode 100644
index 2f025e8..0000000
--- a/providers/ietfte/topology/src/main/java/org/onosproject/provider/te/topology/YangCompositeEncodingImpl.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package org.onosproject.provider.te.topology;
-
-import org.onosproject.yms.ych.YangCompositeEncoding;
-import org.onosproject.yms.ych.YangResourceIdentifierType;
-
-/**
- * Represents implementation of YangCompositeEncoding interfaces.
- */
-public class YangCompositeEncodingImpl implements YangCompositeEncoding {
-
-    /**
-     * Resource identifier for composite encoding.
-     */
-    private String resourceIdentifier;
-
-    /**
-     * Resource information for composite encoding.
-     */
-    private String resourceInformation;
-
-    /**
-     * Resource identifier type.
-     */
-    public YangResourceIdentifierType resourceIdentifierType;
-
-    /**
-     * Creates an instance of YangCompositeEncodingImpl.
-     *
-     * @param resourceIdentifierType is URI
-     * @param resourceIdentifier is the URI string
-     * @param resourceInformation is the JSON body string
-     */
-    public YangCompositeEncodingImpl(YangResourceIdentifierType resourceIdentifierType,
-                                     String resourceIdentifier,
-                                     String resourceInformation) {
-        this.resourceIdentifierType = resourceIdentifierType;
-        this.resourceIdentifier = resourceIdentifier;
-        this.resourceInformation = resourceInformation;
-    }
-
-    @Override
-    public String getResourceIdentifier() {
-        return resourceIdentifier;
-    }
-
-    @Override
-    public YangResourceIdentifierType getResourceIdentifierType() {
-        return resourceIdentifierType;
-    }
-
-    @Override
-    public String getResourceInformation() {
-        return resourceInformation;
-    }
-
-    @Override
-    public void setResourceIdentifier(String resourceId) {
-        resourceIdentifier = resourceId;
-    }
-
-    @Override
-    public void setResourceInformation(String resourceInfo) {
-        resourceInformation = resourceInfo;
-    }
-
-    @Override
-    public void setResourceIdentifierType(YangResourceIdentifierType idType) {
-        resourceIdentifierType = idType;
-    }
-}
-