summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorruilin cai <ruilin.cai@huawei.com>2023-05-23 13:00:31 -0400
committerRuilin Cai <ruilin.cai@huawei.com>2023-06-20 18:02:08 +0000
commit31512b50bcba5b865fa0107f4efd8f678ac9d430 (patch)
tree93a44f5e8776ba407281466a287f892d4d7e7383
parentfaecd518922d9a28eb8add2779b3c73d0165331e (diff)
[actn-interface-tools] Added files in global-api module and yang-utils module. Amend files in actn-client module.
Added files including several interfaces and abstract class in global-api module. Added filed with function of converting between yang pojo and json. Deleted some unnessessary files in actn-client module and added copyright to each files. Issue-ID: INT-2213 Change-Id: I9958b6950fa96bd3a1566190d976ddbec4543982 Signed-off-by: ruilin cai <ruilin.cai@huawei.com>
-rw-r--r--actn-interface-tools/actn-client/pom.xml31
-rw-r--r--actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/OssMessage.java60
-rw-r--r--actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/PncSession.java38
-rw-r--r--actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/SessionId.java24
-rw-r--r--actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/YangValue.java32
-rw-r--r--actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/impl/ActnClientServiceImpl.java60
-rw-r--r--actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/impl/PncClientInstance.java188
-rw-r--r--actn-interface-tools/global-control/api/pom.xml72
-rw-r--r--actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/ActnClientService.java (renamed from actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/Transcoder.java)13
-rw-r--r--actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/ActnDataConverter.java (renamed from actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/ActnDataConverter.java)12
-rw-r--r--actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/CustomerEthService.java (renamed from actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/CustomerEthService.java)2
-rw-r--r--actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/CustomerOtnTopology.java (renamed from actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/CustomerOtnTopology.java)4
-rw-r--r--actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/CustomerOtnTunnel.java (renamed from actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/CustomerOtnTunnel.java)2
-rw-r--r--actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/CustomerTopology.java (renamed from actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/CustomerTopology.java)2
-rw-r--r--actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/GlobalService.java49
-rw-r--r--actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/PncClient.java (renamed from actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/PncClient.java)21
-rw-r--r--actn-interface-tools/global-control/pom.xml45
-rw-r--r--actn-interface-tools/pom.xml2
-rw-r--r--actn-interface-tools/yang-utils/pom.xml104
-rw-r--r--actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/Base64CodeUtils.java87
-rw-r--r--actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/CodecConverter.java256
-rw-r--r--actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/ResourceIdUtil.java1035
-rw-r--r--actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/YangToolsUtil.java560
-rw-r--r--actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/package-info.java (renamed from actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/RequestId.java)12
24 files changed, 2516 insertions, 195 deletions
diff --git a/actn-interface-tools/actn-client/pom.xml b/actn-interface-tools/actn-client/pom.xml
index 9450159..f787e4b 100644
--- a/actn-interface-tools/actn-client/pom.xml
+++ b/actn-interface-tools/actn-client/pom.xml
@@ -31,6 +31,7 @@
<groupId>org.onap.integration.ietf-actn-tools</groupId>
<artifactId>actn-client</artifactId>
+ <packaging>jar</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
@@ -40,6 +41,7 @@
<guava.version>22.0</guava.version>
</properties>
<dependencies>
+
<dependency>
<groupId>org.onap.integration.ietf-actn-tools</groupId>
<artifactId>actn-model</artifactId>
@@ -80,7 +82,11 @@
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
-
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.8.8</version>
+ </dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
@@ -101,6 +107,29 @@
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
+ <dependency>
+ <groupId>com.google.auto.service</groupId>
+ <artifactId>auto-service</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
+ <artifactId>restconf-client-ctl</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
+ <artifactId>globalapi</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
+ <artifactId>yang-utils</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
</project> \ No newline at end of file
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/OssMessage.java b/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/OssMessage.java
deleted file mode 100644
index 84e13d0..0000000
--- a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/OssMessage.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Actn Interface Tools
- * ================================================================================
- * Copyright (C) 2022 Huawei Canada Limited.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.integration.actninterfacetools.actnclient.api;
-
-/**
- * Base class for OSS internal message
- */
-public class OssMessage {
- protected int xid;
-
- public OssMessage() {
-
- }
-
- public int getXid() {
- return xid;
- }
-
- public OssMessage setXid(int xid) {
- this.xid = xid;
- return this;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof OssMessage)) {
- return false;
- }
- OssMessage other = (OssMessage) obj;
-
- if (xid != other.xid) {
- return false;
- }
- return true;
- }
-} \ No newline at end of file
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/PncSession.java b/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/PncSession.java
deleted file mode 100644
index fa72cc6..0000000
--- a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/PncSession.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Actn Interface Tools
- * ================================================================================
- * Copyright (C) 2022 Huawei Canada Limited.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.integration.actninterfacetools.actnclient.api;
-
-import java.net.Inet4Address;
-import java.util.UUID;
-
-public interface PncSession {
- UUID pncId();
-
- Inet4Address ipAddress();
-
- int providerId();
-
- int clientId();
-
- int topologyId();
-
- MdscController getMdscController();
-}
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/SessionId.java b/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/SessionId.java
deleted file mode 100644
index 199a042..0000000
--- a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/SessionId.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Actn Interface Tools
- * ================================================================================
- * Copyright (C) 2022 Huawei Canada Limited.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.integration.actninterfacetools.actnclient.api;
-
-public class SessionId {
-}
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/YangValue.java b/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/YangValue.java
deleted file mode 100644
index 966eeb5..0000000
--- a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/YangValue.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Actn Interface Tools
- * ================================================================================
- * Copyright (C) 2022 Huawei Canada Limited.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.integration.actninterfacetools.actnclient.api;
-
-public class YangValue<T> {
- private final long version;
- private final T value;
-
- public YangValue(long v, T val) {
- super();
- version = v;
- value = val;
- }
-}
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/impl/ActnClientServiceImpl.java b/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/impl/ActnClientServiceImpl.java
new file mode 100644
index 0000000..647536b
--- /dev/null
+++ b/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/impl/ActnClientServiceImpl.java
@@ -0,0 +1,60 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Actn Interface Tools
+ * ================================================================================
+ * Copyright (C) 2023 Huawei Canada Limited.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.integration.actninterfacetools.actnclient.impl;
+
+import com.google.auto.service.AutoService;
+import org.onap.integration.actninterfacetools.globalapi.ActnClientService;
+import org.onap.integration.actninterfacetools.globalapi.ActnDataConverter;
+import org.onap.integration.actninterfacetools.globalapi.PncClient;
+import org.onap.integration.actninterfacetools.protocol.restconf.PncInstance;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+@AutoService(ActnClientService.class)
+public class ActnClientServiceImpl implements ActnClientService {
+ private ActnDataConverter actnDataConverter;
+
+ private Map<PncInstance, PncClientInstance> pncClientMap = new ConcurrentHashMap();
+
+
+ public ActnClientServiceImpl() {
+ }
+ public ActnClientServiceImpl(ActnDataConverter actnDataConverter) {
+ this.actnDataConverter = actnDataConverter;
+ }
+
+
+ @Override
+ public void registerDataConverter(ActnDataConverter converter) {
+ this.actnDataConverter = converter;
+ }
+
+ @Override
+ public PncClient getPncClient(PncInstance pncInstance) {
+ if(pncClientMap.get(pncInstance)!=null){
+ return pncClientMap.get(pncInstance);
+ }else{
+ PncClientInstance pncClientInstance = new PncClientInstance(pncInstance, actnDataConverter);
+ this.pncClientMap.put(pncInstance, pncClientInstance);
+ return pncClientInstance;
+ }
+
+ }
+}
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/impl/PncClientInstance.java b/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/impl/PncClientInstance.java
new file mode 100644
index 0000000..fccf1c8
--- /dev/null
+++ b/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/impl/PncClientInstance.java
@@ -0,0 +1,188 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Actn Interface Tools
+ * ================================================================================
+ * Copyright (C) 2023 Huawei Canada Limited.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.integration.actninterfacetools.actnclient.impl;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.auto.service.AutoService;
+import org.onap.integration.actninterfacetools.globalapi.*;
+import org.onap.integration.actninterfacetools.protocol.restconf.PncInstance;
+import org.onap.integration.actninterfacetools.protocol.restconf.RestConfSBController;
+import org.onap.integration.actninterfacetools.protocol.restconf.ctl.RestConfSBControllerImpl;
+import org.onap.integration.actninterfacetools.yangutils.CodecConverter;
+import org.onap.integration.actninterfacetools.yangutils.YangToolsUtil;
+import org.onosproject.yang.gen.v11.ietfethtranservice.rev20210111.ietfethtranservice.DefaultEthtSvc;
+import org.onosproject.yang.gen.v11.ietfethtranservice.rev20210111.ietfethtranservice.ethtsvc.DefaultEthtSvcInstances;
+import org.onosproject.yang.gen.v11.ietfethtranservice.rev20210111.ietfethtranservice.ethtsvc.EthtSvcInstances;
+import org.onosproject.yang.gen.v11.ietfnetwork.rev20180226.ietfnetwork.DefaultNetworks;
+import org.onosproject.yang.gen.v11.ietfnetwork.rev20180226.ietfnetwork.NetworkId;
+import org.onosproject.yang.gen.v11.ietfnetwork.rev20180226.ietfnetwork.networks.Network;
+import org.onosproject.yang.gen.v11.ietfte.rev20210220.ietfte.tunnelsgrouping.tunnels.DefaultTunnel;
+import org.onosproject.yang.model.DataNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+import static org.onap.integration.actninterfacetools.yangutils.YangToolsUtil.*;
+@AutoService(PncClient.class)
+public class PncClientInstance implements PncClient {
+ private static final Logger log = LoggerFactory.getLogger(PncClientInstance.class);
+
+ private PncInstance pncInstance;
+ private ActnDataConverter actnDataConverter;
+ private RestConfSBController restConfSBController;
+
+ public PncClientInstance(PncInstance pncInstance, ActnDataConverter actnDataConverter) {
+ this.pncInstance = pncInstance;
+ this.actnDataConverter = actnDataConverter;
+ this.restConfSBController = RestConfSBControllerImpl.getRestConfClient();
+ this.restConfSBController.addPncInstance(this.pncInstance);
+ }
+
+
+
+ public CustomerOtnTopology getNetworkTopology(String topologyId) throws Exception {
+
+ ObjectNode json = restConfSBController.get(pncInstance.pncId(), "ietf-network:networks", "json");
+ String s = json.toString();
+ String s1 = s.replaceAll("classify-c-vlan", "ietf-eth-tran-types:classify-c-vlan");
+ String s2 = s1.replaceAll("classify-s-vlan", "ietf-eth-tran-types:classify-s-vlan");
+ ObjectNode jsonNode = new ObjectMapper().readTree(s2).deepCopy();
+
+ DefaultNetworks yangNetworks = YangToolsUtil.convertJsonToYangObj("/", jsonNode, DefaultNetworks.class);
+
+ NetworkId networkId = NetworkId.fromString(topologyId);
+ List<Network> networkList = yangNetworks.network();
+
+ Network networkSelected = null;
+ if(networkList!=null && !networkList.isEmpty()){
+ for(Network network : networkList){
+ if(network.networkId().equals(networkId)){
+ networkSelected = network;
+ break;
+ }
+ }
+ }
+ CustomerOtnTopology ct = actnDataConverter.convertActnOtnTopology(networkSelected);
+ return ct;
+
+ }
+ public void createOtnTunnel(CustomerOtnTunnel customerOtnTunnel) throws Exception {
+ DefaultTunnel actnOtnTunnel = actnDataConverter.convertActnOtnTunnel(customerOtnTunnel);
+ ObjectNode jsonNodes = convertYangTeTunnel2Json(actnOtnTunnel);
+ String s = jsonNodes.toString();
+ String s1 = s.replaceAll("gfp-n", "ietf-otn-tunnel:gfp-n");
+ String s2 = s1.replaceAll("odu-type", "ietf-otn-tunnel:odu-type");
+ ObjectNode jsonNode = new ObjectMapper().readTree(s2).deepCopy();
+ boolean result = restConfSBController.post(pncInstance.pncId(), "ietf-te:te/tunnels", jsonNode, "json");
+ if(!result){
+ log.warn("Failed to create otn tunnel");
+ }else{
+ log.info("Create otn tunnel successfully");
+ }
+
+ }
+
+ public void updateOtnTunnel(CustomerOtnTunnel customerOtnTunnel, String otnName) throws Exception {
+ DefaultTunnel actnOtnTunnel = actnDataConverter.convertActnOtnTunnel(customerOtnTunnel);
+ ObjectNode jsonNodes = convertYangTeTunnel2Json(actnOtnTunnel);
+ boolean result = restConfSBController.patch(pncInstance.pncId(), "ietf-te:te/tunnels/tunnel="+otnName, jsonNodes, "json");
+ if(!result){
+ log.warn("Failed to update otn tunnel");
+ }else{
+ log.info("Update otn tunnel successfully");
+ }
+
+ }
+ public CustomerOtnTunnel getOtnTunnel(String actnOtnTunnelId) throws Exception {
+ ObjectNode jsonNode = restConfSBController.get(pncInstance.pncId(), "ietf-te:te/tunnels/tunnel="+actnOtnTunnelId, "json");
+ DefaultTunnel actnOtnTunnel = YangToolsUtil.convertJsonToYangObj("ietf-te:te/tunnels", jsonNode, DefaultTunnel.class);
+ CustomerOtnTunnel customerOtnTunnel = actnDataConverter.convertActnOtnTunnel(actnOtnTunnel);
+ return customerOtnTunnel;
+ }
+
+
+
+
+ public void createEthService(CustomerEthService customerEthService) throws Exception {
+ DefaultEthtSvc actnEthService = actnDataConverter.convertActnEthService(customerEthService);
+ ObjectNode jsonNodes = convertYangEthSvc2Json(actnEthService);
+ boolean result = restConfSBController.patch(pncInstance.pncId(), "ietf-eth-tran-service:etht-svc/etht-svc-instances", jsonNodes, "json");
+ if(!result){
+ log.warn("Failed to create ethernet service");
+ }else{
+ log.info("Create ethernet service successfully");
+ }
+
+ }
+ public void updateEthService(CustomerEthService customerEthService) throws Exception {
+ DefaultEthtSvc actnEthService = actnDataConverter.convertActnEthService(customerEthService);
+ ObjectNode jsonNodes = convertYangEthSvc2Json(actnEthService);
+ boolean result = restConfSBController.patch(pncInstance.pncId(), "ietf-eth-tran-service:etht-svc/etht-svc-instances", jsonNodes, "json");
+ if(!result){
+ log.warn("Failed to update ethernet service");
+ }else{
+ log.info("Update ethernet service successfully");
+ }
+
+ }
+
+
+ public CustomerEthService getEthService(String actnEthServiceId) throws Exception {
+ ObjectNode jsonNode = restConfSBController.get(pncInstance.pncId(), "ietf-eth-tran-service:etht-svc/etht-svc-instances="+actnEthServiceId, "json");
+ DefaultEthtSvcInstances actnEthSvcInstance = YangToolsUtil.convertJsonToYangObj("ietf-eth-tran-service:etht-svc", jsonNode, DefaultEthtSvcInstances.class);
+ DefaultEthtSvc actnEthSvc = new DefaultEthtSvc();
+ actnEthSvc.addToEthtSvcInstances(actnEthSvcInstance);
+
+ return actnDataConverter.convertActnEthService(actnEthSvc);
+ }
+ public void deleteOtnTunnel(String actnOtnTunnelId) throws Exception{
+ boolean result = restConfSBController.delete(pncInstance.pncId(), "ietf-te:te/tunnels/tunnel=" + actnOtnTunnelId, "json");
+ if(!result){
+ log.warn("Failed to delete otn tunnel");
+ }else{
+ log.info("Delete otn tunnel successfully");
+ }
+ }
+ public void deleteEthService(String actnEthServiceId) throws Exception{
+ boolean result = restConfSBController.delete(pncInstance.pncId(), "ietf-eth-tran-service:etht-svc/etht-svc-instances=" + actnEthServiceId, "json");
+ if(!result){
+ log.warn("Failed to delete ethernet service");
+ }else{
+ log.info("Delete ethernet service successfully");
+ }
+ }
+ public static ObjectNode convertYangTeTunnel2Json(DefaultTunnel yangTeTunnel){
+ String tunnelName = yangTeTunnel.name();
+
+ DataNode dataNode = yangPojo2DataNode(getModIdForTeTunnels(), yangTeTunnel);
+
+ return CodecConverter.dataNodeToObjectNode(getRidForTeTunnel(tunnelName), dataNode);
+ }
+ public static ObjectNode convertYangEthSvc2Json(DefaultEthtSvc yangEthSvc){
+ EthtSvcInstances ethtSvcInstances = yangEthSvc.ethtSvcInstances().get(0);
+ String ethSvcName = ethtSvcInstances.ethtSvcName();
+
+ DataNode dataNode = yangPojo2DataNode(getModIdForEthSvc(), (DefaultEthtSvcInstances)ethtSvcInstances);
+
+ return CodecConverter.dataNodeToObjectNode(getRIdForEthSvcInstances(ethSvcName), dataNode);
+ }
+}
diff --git a/actn-interface-tools/global-control/api/pom.xml b/actn-interface-tools/global-control/api/pom.xml
new file mode 100644
index 0000000..868f443
--- /dev/null
+++ b/actn-interface-tools/global-control/api/pom.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ ============LICENSE_START=======================================================
+ ~ Actn Interface Tools
+ ~ ================================================================================
+ ~ Copyright (C) 2023 Huawei Canada Limited.
+ ~ ================================================================================
+ ~ 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.
+ ~ ============LICENSE_END=========================================================
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
+ <artifactId>global-control</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
+ <artifactId>globalapi</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <properties>
+ <jackson.version>2.11.0</jackson.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
+ <artifactId>actn-model</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-yang-runtime</artifactId>
+ <version>2.6.1</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+
+ <!-- jackson-core -->
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <!-- jackson-annotations -->
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
+ <artifactId>restconf-client-api</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/Transcoder.java b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/ActnClientService.java
index d110dde..89a2586 100644
--- a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/Transcoder.java
+++ b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/ActnClientService.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Actn Interface Tools
* ================================================================================
- * Copyright (C) 2022 Huawei Canada Limited.
+ * Copyright (C) 2023 Huawei Canada Limited.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,11 +17,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+package org.onap.integration.actninterfacetools.globalapi;
-package org.onap.integration.actninterfacetools.actnclient.api;
+import org.onap.integration.actninterfacetools.protocol.restconf.PncInstance;
-public interface Transcoder<T> {
- T decode(byte[] d);
-
- byte[] encode(T o);
+public interface ActnClientService {
+ void registerDataConverter(ActnDataConverter converter);
+ PncClient getPncClient(PncInstance pncInstance);
}
+
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/ActnDataConverter.java b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/ActnDataConverter.java
index e6eb42d..c64732f 100644
--- a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/ActnDataConverter.java
+++ b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/ActnDataConverter.java
@@ -17,26 +17,26 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.integration.actninterfacetools.actnclient.api;
+package org.onap.integration.actninterfacetools.globalapi;
import org.onosproject.yang.gen.v11.ietfethtranservice.rev20210111.ietfethtranservice.DefaultEthtSvc;
import org.onosproject.yang.gen.v11.ietfnetwork.rev20180226.ietfnetwork.networks.Network;
import org.onosproject.yang.gen.v11.ietfte.rev20210220.ietfte.tunnelsgrouping.tunnels.DefaultTunnel;
public abstract class ActnDataConverter {
- CustomerOtnTopology convertActnOtnTopology(Network actnOtnTopology) throws Exception {
+ public CustomerOtnTopology convertActnOtnTopology(Network actnOtnTopology) throws Exception {
throw new Exception("unsupported method");
}
- CustomerOtnTunnel convertActnOtnTunnel(DefaultTunnel actnOtnTunnel) throws Exception {
+ public CustomerOtnTunnel convertActnOtnTunnel(DefaultTunnel actnOtnTunnel) throws Exception {
throw new Exception("unsupported method");
}
- DefaultTunnel convertActnOtnTunnel(CustomerOtnTunnel customerOtnTunnel) throws Exception {
+ public DefaultTunnel convertActnOtnTunnel(CustomerOtnTunnel customerOtnTunnel) throws Exception {
throw new Exception("unsupported method");
}
- CustomerEthService convertActnEthService(DefaultEthtSvc actnEthService) throws Exception {
+ public CustomerEthService convertActnEthService(DefaultEthtSvc actnEthService) throws Exception {
throw new Exception("unsupported method");
}
- DefaultEthtSvc convertActnEthService(CustomerEthService customerEthService) throws Exception {
+ public DefaultEthtSvc convertActnEthService(CustomerEthService customerEthService) throws Exception {
throw new Exception("unsupported method");
}
}
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/CustomerEthService.java b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/CustomerEthService.java
index 9c4aede..959b57d 100644
--- a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/CustomerEthService.java
+++ b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/CustomerEthService.java
@@ -17,7 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.integration.actninterfacetools.actnclient.api;
+package org.onap.integration.actninterfacetools.globalapi;
public abstract class CustomerEthService {
}
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/CustomerOtnTopology.java b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/CustomerOtnTopology.java
index d57c0f7..d0f4d79 100644
--- a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/CustomerOtnTopology.java
+++ b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/CustomerOtnTopology.java
@@ -17,7 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.integration.actninterfacetools.actnclient.api;
+package org.onap.integration.actninterfacetools.globalapi;
-public abstract class CustomerOtnTopology extends CustomerTopology{
+public abstract class CustomerOtnTopology extends CustomerTopology {
}
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/CustomerOtnTunnel.java b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/CustomerOtnTunnel.java
index 4390c57..8b6cb39 100644
--- a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/CustomerOtnTunnel.java
+++ b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/CustomerOtnTunnel.java
@@ -17,7 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.integration.actninterfacetools.actnclient.api;
+package org.onap.integration.actninterfacetools.globalapi;
public abstract class CustomerOtnTunnel {
}
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/CustomerTopology.java b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/CustomerTopology.java
index a9cd142..0e25650 100644
--- a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/CustomerTopology.java
+++ b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/CustomerTopology.java
@@ -17,7 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.integration.actninterfacetools.actnclient.api;
+package org.onap.integration.actninterfacetools.globalapi;
public abstract class CustomerTopology {
}
diff --git a/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/GlobalService.java b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/GlobalService.java
new file mode 100644
index 0000000..47829d4
--- /dev/null
+++ b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/GlobalService.java
@@ -0,0 +1,49 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Actn Interface Tools
+ * ================================================================================
+ * Copyright (C) 2023 Huawei Canada Limited.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.integration.actninterfacetools.globalapi;
+
+
+import org.onosproject.yang.runtime.impl.DefaultModelConverter;
+import org.onosproject.yang.runtime.impl.DefaultYangModelRegistry;
+import org.onosproject.yang.runtime.impl.DefaultYangRuntimeHandler;
+import org.onosproject.yang.runtime.impl.DefaultYangSerializerRegistry;
+import org.onosproject.yang.runtime.impl.DefaultSchemaContextProvider;
+import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+public interface GlobalService {
+ String getServiceName();
+ void initialize() throws URISyntaxException;
+ ActnClientService getActnClientService(ActnDataConverter actnDataConverter) throws URISyntaxException;
+ DefaultYangModelRegistry getModelRegistry();
+ DefaultYangSerializerRegistry getSerializerRegistry();
+ DefaultYangRuntimeHandler getRuntimeService();
+ DefaultModelConverter getModelConverter();
+ DefaultSchemaContextProvider getSchemaContextProvider();
+
+ Map<String, ClassLoader> getClassLoaders();
+ static ActnClientService getActnClientSvc(ActnDataConverter actnDataConverter) throws URISyntaxException {
+ ServiceLoader<GlobalService> serviceLoader = ServiceLoader.load(GlobalService.class);
+ GlobalService globalService = serviceLoader.iterator().next();
+ return globalService.getActnClientService(actnDataConverter);
+ }
+
+}
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/PncClient.java b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/PncClient.java
index 3361ce4..c4d6551 100644
--- a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/PncClient.java
+++ b/actn-interface-tools/global-control/api/src/main/java/org/onap/integration/actninterfacetools/globalapi/PncClient.java
@@ -18,17 +18,16 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.integration.actninterfacetools.actnclient.api;
-
-import java.util.concurrent.Future;
+package org.onap.integration.actninterfacetools.globalapi;
public interface PncClient {
-
- <T> Future<YangValue<T>> asyncGets(String key, Transcoder<T> tc);
-
- Future<YangValue<Object>> asyncGets(String key);
-
- <T> Future<Boolean> put(String key, T o, Transcoder<T> tc);
-
- Future<Boolean> put(String key, Object o);
+ CustomerOtnTopology getNetworkTopology(String topologyId) throws Exception;
+ void createOtnTunnel(CustomerOtnTunnel customerOtnTunnel) throws Exception;
+ void updateOtnTunnel(CustomerOtnTunnel customerOtnTunnel, String otnName) throws Exception;
+ CustomerOtnTunnel getOtnTunnel(String actnOtnTunnelId) throws Exception;
+ void createEthService(CustomerEthService customerEthService) throws Exception;
+ void updateEthService(CustomerEthService customerEthService) throws Exception;
+ CustomerEthService getEthService(String actnEthServiceId) throws Exception;
+ void deleteOtnTunnel(String actnOtnTunnelId) throws Exception;
+ void deleteEthService(String actnEthServiceId) throws Exception;
}
diff --git a/actn-interface-tools/global-control/pom.xml b/actn-interface-tools/global-control/pom.xml
index 1c01ad8..be13013 100644
--- a/actn-interface-tools/global-control/pom.xml
+++ b/actn-interface-tools/global-control/pom.xml
@@ -3,7 +3,7 @@
~ ============LICENSE_START=======================================================
~ Actn Interface Tools
~ ================================================================================
- ~ Copyright (C) 2022 Huawei Canada Limited.
+ ~ Copyright (C) 2023 Huawei Canada Limited.
~ ================================================================================
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
@@ -26,6 +26,47 @@
<artifactId>actn-interface-tools</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
+ <packaging>pom</packaging>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
+ <version>1.0-SNAPSHOT</version>
<artifactId>global-control</artifactId>
+ <properties>
+ <jackson.version>2.11.0</jackson.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
+ <artifactId>actn-model</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-yang-runtime</artifactId>
+ <version>2.6.1</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <!-- jackson-core -->
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <!-- jackson-annotations -->
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>${jackson.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
+ <artifactId>restconf-client-api</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
</project>
-
diff --git a/actn-interface-tools/pom.xml b/actn-interface-tools/pom.xml
index b92341b..b8af25c 100644
--- a/actn-interface-tools/pom.xml
+++ b/actn-interface-tools/pom.xml
@@ -34,6 +34,8 @@
<module>global-control</module>
<module>yang-utils</module>
<module>restconf-client</module>
+ <module>global-control/api</module>
+ <module>global-control/app</module>
</modules>
<properties>
<maven.compiler.source>11</maven.compiler.source>
diff --git a/actn-interface-tools/yang-utils/pom.xml b/actn-interface-tools/yang-utils/pom.xml
index 6fc3a7c..12e0971 100644
--- a/actn-interface-tools/yang-utils/pom.xml
+++ b/actn-interface-tools/yang-utils/pom.xml
@@ -3,7 +3,7 @@
~ ============LICENSE_START=======================================================
~ Actn Interface Tools
~ ================================================================================
- ~ Copyright (C) 2022 Huawei Canada Limited.
+ ~ Copyright (C) 2023 Huawei Canada Limited.
~ ================================================================================
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
@@ -18,13 +18,109 @@
~ limitations under the License.
~ ============LICENSE_END=========================================================
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+
+ <!-- <parent>-->
+ <!-- <groupId>org.onosproject</groupId>-->
+ <!-- <artifactId>onos-apps</artifactId>-->
+ <!-- <version>1.11.0-SNAPSHOT</version>-->
+ <!-- <relativePath>../pom.xml</relativePath>-->
+ <!-- </parent>-->
<parent>
- <groupId>org.onap.integration.ietf-actn-tools</groupId>
<artifactId>actn-interface-tools</artifactId>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
+ <version>1.0-SNAPSHOT</version>
<artifactId>yang-utils</artifactId>
+ <packaging>jar</packaging>
+
+ <description>IETF TE NBI Utilities</description>
+
+ <properties>
+ <yang-tool-version>2.6.1</yang-tool-version>
+ <onos.app.name>yang-utils</onos.app.name>
+ <onos.app.origin>HUAWEI</onos.app.origin>
+ </properties>
+
+ <dependencies>
+ <!-- https://mvnrepository.com/artifact/org.onosproject/onos-yang-utils-generator -->
+ <dependency>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
+ <artifactId>actn-model</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-yang-utils-generator</artifactId>
+ <version>1.11</version>
+ </dependency>
+ <!-- https://mvnrepository.com/artifact/org.dom4j/dom4j -->
+ <dependency>
+ <groupId>org.dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>2.0.3</version>
+ </dependency>
+ <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-collections4</artifactId>
+ <version>4.4</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.8.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-yang-model</artifactId>
+ <version>${yang-tool-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-yang-runtime</artifactId>
+ <version>${yang-tool-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava-testlib</artifactId>
+ <version>22.0</version>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ <version>3.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-yang-serializers-utils</artifactId>
+ <version>2.6.1</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ <scope>provided</scope>
+ <version>1.9.12</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.integration.ietf-actn-tools</groupId>
+ <artifactId>globalapi</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+
+ </dependencies>
</project>
diff --git a/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/Base64CodeUtils.java b/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/Base64CodeUtils.java
new file mode 100644
index 0000000..d16a6db
--- /dev/null
+++ b/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/Base64CodeUtils.java
@@ -0,0 +1,87 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Actn Interface Tools
+ * ================================================================================
+ * Copyright (C) 2023 Huawei Canada Limited.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.integration.actninterfacetools.yangutils;
+
+import java.io.IOException;
+
+import java.util.Base64;
+/**
+ * Created by sdn on 8/2/17.
+ */
+public class Base64CodeUtils {
+ @Deprecated
+ public static String EnCode(String str) {
+ if (str == null) {
+ return null;
+ }
+ byte[] bytes = str.getBytes();
+ String result = null;
+ try {
+ result = Base64.getEncoder().encodeToString(bytes);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+
+ @Deprecated
+ public static String decode(String str) {
+ if (str == null) {
+ return null;
+ }
+ byte[] bytes = null;
+ try {
+ bytes = Base64.getDecoder().decode(str);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ String result = String.valueOf(bytes);
+ return result;
+ }
+
+ @Deprecated
+ public static byte[] numsCovertToBytes(long num) {
+ String NumString = String.valueOf(num);
+ String EncodeString = "";
+ for (int i = 0; i < NumString.length(); i++) {
+ EncodeString += EnCode(String.valueOf(NumString.charAt(i)));
+ }
+ return EncodeString.getBytes();
+ }
+
+ //convert from TE long to Yang binary
+ public static byte[] longToBytes(long x) {
+ //TODO: HENRY: need to convert 'x' into a string format, e.g., "MTEwMTE=".
+ //should just return unprocessed byte[].
+ byte[] src = String.valueOf(x).getBytes();
+
+ return src;
+ }
+
+ //convert from Yang binary to TE long
+ public static long bytesToLong(byte[] bytes) {
+ /*
+ * the input bytes are already decoded by YangTools.
+ */
+ String s = new String(bytes);
+ return Long.valueOf(s);
+ }
+}
diff --git a/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/CodecConverter.java b/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/CodecConverter.java
new file mode 100644
index 0000000..f1d27d6
--- /dev/null
+++ b/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/CodecConverter.java
@@ -0,0 +1,256 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Actn Interface Tools
+ * ================================================================================
+ * Copyright (C) 2023 Huawei Canada Limited.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.integration.actninterfacetools.yangutils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.commons.io.IOUtils;
+import org.onap.integration.actninterfacetools.globalapi.GlobalService;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.DefaultResourceData;
+import org.onosproject.yang.model.InnerNode;
+import org.onosproject.yang.model.NodeKey;
+import org.onosproject.yang.model.ResourceData;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.CompositeData;
+import org.onosproject.yang.runtime.CompositeStream;
+import org.onosproject.yang.runtime.DefaultCompositeData;
+import org.onosproject.yang.runtime.DefaultCompositeStream;
+import org.onosproject.yang.runtime.DefaultRuntimeContext;
+import org.onosproject.yang.runtime.RuntimeContext;
+import org.onosproject.yang.runtime.YangRuntimeService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utilities used by the RESTCONF app.
+ */
+public final class CodecConverter {
+ /**
+ * Data format required by YangRuntime Service.
+ */
+ private static final String JSON_FORMAT = "JSON";
+ private static final String SLASH = "/";
+ private static YangRuntimeService YANG_RUNTIME = null ;
+ private static final Logger log = LoggerFactory.getLogger(CodecConverter.class);
+
+ public static void active(){
+ ServiceLoader<GlobalService> serviceLoader = ServiceLoader.load(GlobalService.class);
+ for (GlobalService service : serviceLoader) {
+ YANG_RUNTIME = service.getRuntimeService();
+ }
+ }
+
+ /**
+ * No instantiation.
+ */
+ private CodecConverter() {
+ }
+
+ /**
+ * Converts an input stream to JSON objectNode.
+ *
+ * @param inputStream the InputStream from Resource Data
+ * @return JSON representation of the data resource
+ */
+ public static ObjectNode convertInputStreamToObjectNode(InputStream inputStream) {
+ if (inputStream == null) {
+ return null;
+ }
+
+ ObjectNode rootNode = null;
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ rootNode = (ObjectNode) mapper.readTree(inputStream);
+ } catch (IOException e) {
+ log.error("ERROR: convertInputStreamToObjectNode: ", e);
+ }
+ return rootNode;
+ }
+
+ public static JsonNode convertInputStreamToJsonNode(InputStream inputStream) {
+ if (inputStream == null) {
+ return null;
+ }
+
+ JsonNode rootNode = null;
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ rootNode = mapper.readTree(inputStream);
+ } catch (IOException e) {
+ log.error("ERROR: convertInputStreamToObjectNode: ", e);
+ }
+ return rootNode;
+ }
+
+ /**
+ * Convert ObjectNode to InputStream.
+ *
+ * @param rootNode JSON representation of the data resource
+ * @return the InputStream from Resource Data
+ */
+ public static InputStream convertObjectNodeToInputStream(ObjectNode rootNode) {
+ if (rootNode == null) {
+ return null;
+ }
+
+ String json = rootNode.toString();
+ InputStream inputStream = null;
+ try {
+ inputStream = IOUtils.toInputStream(json);
+ } catch (Exception e) {
+ log.error("ERROR: convertObjectNodeToInputStream: ", e);
+ }
+ return inputStream;
+ }
+
+ public static InputStream convertJsonNodeToInputStream(JsonNode rootNode) {
+ if (rootNode == null) {
+ return null;
+ }
+
+ String json = rootNode.toString();
+ InputStream inputStream = null;
+ try {
+ inputStream = IOUtils.toInputStream(json);
+ } catch (Exception e) {
+ log.error("ERROR: convertObjectNodeToInputStream: ", e);
+ }
+ return inputStream;
+ }
+
+ public static ResourceId uriToRid(URI uri) {
+ ResourceData resourceData = objectNodeToResourceData(uri, null);
+ return resourceData.resourceId();
+ }
+
+
+ public static DataNode objectNodeToDataNode(URI uri, ObjectNode jsonNode) {
+ URI parentUri = ResourceIdUtil.rmLastPathSegment(uri);
+ ResourceData resourceData = objectNodeToResourceData(parentUri, jsonNode);
+ return resourceData.dataNodes().get(0);
+ }
+
+ public static DataNode objectNodeToDataNode(String uriStr, ObjectNode jsonNode) {
+ String parentUriStr = ResourceIdUtil.rmLastPathSegmentStr(uriStr);
+ return objectNodeToDataNodeWithParentUriStr(parentUriStr, jsonNode);
+ }
+
+ public static DataNode objectNodeToDataNodeWithParentUriStr(String parentUriStr, ObjectNode jsonNode) {
+ ResourceData resourceData = objectNodeToResourceData(parentUriStr, jsonNode);
+ return resourceData.dataNodes().get(0);
+ }
+
+ public static DataNode objectNodeToDataNodeWithParentRid(ResourceId parentRid, ObjectNode jsonNode) {
+ String parentUriStr = ResourceIdUtil.convertRidToUriStr(parentRid);
+ ResourceData resourceData = objectNodeToResourceData(parentUriStr, jsonNode);
+ return resourceData.dataNodes().get(0);
+ }
+
+ public static DataNode objectNodeToDataNode(ResourceId rId, ObjectNode jsonNode) {
+ ResourceId parentRid = ResourceIdUtil.parentOf(rId);
+ return objectNodeToDataNodeWithParentRid(parentRid, jsonNode);
+ }
+
+ public static ResourceData objectNodeToResourceData(URI parentUri, ObjectNode rootNode) {
+ return objectNodeToResourceData(ResourceIdUtil.getRawUriPath(parentUri), rootNode);
+ }
+
+ public static DataNode removeRootFromDataNode(DataNode dataNode) {
+ if (dataNode instanceof InnerNode && dataNode.key().schemaId().name().equals("/")) {
+ Map.Entry<NodeKey, DataNode> entry = ((InnerNode) dataNode).childNodes().entrySet().iterator().next();
+ dataNode = entry.getValue();
+ }
+ return dataNode;
+ }
+
+ public static ResourceData objectNodeToResourceData(String parentUriStr, ObjectNode jsonNode) {
+
+ RuntimeContext.Builder runtimeContextBuilder = new DefaultRuntimeContext.Builder();
+ runtimeContextBuilder.setDataFormat(JSON_FORMAT);
+ RuntimeContext context = runtimeContextBuilder.build();
+ ResourceData resourceData = null;
+ InputStream jsonData = null;
+ try {
+ if (jsonNode != null) {
+ jsonData = convertObjectNodeToInputStream(jsonNode);
+ }
+ CompositeStream compositeStream = new DefaultCompositeStream(parentUriStr, jsonData);
+ // CompositeStream --- YangRuntimeService ---> CompositeData.
+ CompositeData compositeData = YANG_RUNTIME.decode(compositeStream, context);
+ resourceData = compositeData.resourceData();
+ } catch (Exception ex) {
+ log.error("convertJsonToDataNode failure: ", ex);
+ }
+ return resourceData;
+ }
+
+
+ /**
+ * Convert Resource Id and Data Node to Json ObjectNode.
+ *
+ * @param rid resource identifier
+ * @param dataNode represents type of node in data store
+ * @return JSON representation of the data resource
+ */
+ public static ObjectNode dataNodeToObjectNode(ResourceId rid, DataNode dataNode) {
+ return convertInputStreamToObjectNode(dataNodeToStream(rid, dataNode));
+ }
+
+ public static InputStream dataNodeToStream(ResourceId rid, DataNode dataNode) {
+ RuntimeContext.Builder runtimeContextBuilder = DefaultRuntimeContext.builder();
+ runtimeContextBuilder.setDataFormat(JSON_FORMAT);
+ RuntimeContext context = runtimeContextBuilder.build();
+ DefaultResourceData.Builder resourceDataBuilder = DefaultResourceData.builder();
+ resourceDataBuilder.addDataNode(dataNode);
+ resourceDataBuilder.resourceId(rid);
+ ResourceData resourceData = resourceDataBuilder.build();
+ DefaultCompositeData.Builder compositeDataBuilder = DefaultCompositeData.builder();
+ compositeDataBuilder.resourceData(resourceData);
+ CompositeData compositeData = compositeDataBuilder.build();
+ InputStream inputStream = null;
+ try {
+ // CompositeData --- YangRuntimeService ---> CompositeStream.
+ CompositeStream compositeStream = YANG_RUNTIME.encode(compositeData, context);
+ inputStream = compositeStream.resourceData();
+ } catch (Exception ex) {
+ log.error("convertInputStreamToObjectNode failure: ", ex);
+ }
+
+ return inputStream;
+ }
+
+ public static DataNode removeTopDataNode(DataNode dataNode) {
+ if (dataNode instanceof InnerNode && dataNode.key().schemaId().name().equals("/")) {
+ Map.Entry<NodeKey, DataNode> entry = ((InnerNode) dataNode).childNodes().entrySet().iterator().next();
+ dataNode = entry.getValue();
+ }
+ return dataNode;
+ }
+}
diff --git a/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/ResourceIdUtil.java b/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/ResourceIdUtil.java
new file mode 100644
index 0000000..f70ee51
--- /dev/null
+++ b/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/ResourceIdUtil.java
@@ -0,0 +1,1035 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Actn Interface Tools
+ * ================================================================================
+ * Copyright (C) 2023 Huawei Canada Limited.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.integration.actninterfacetools.yangutils;
+
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
+import org.apache.commons.collections4.CollectionUtils;
+import org.dom4j.Attribute;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.onosproject.yang.compiler.datamodel.YangSchemaNode;
+import org.onosproject.yang.model.KeyLeaf;
+import org.onosproject.yang.model.LeafListKey;
+import org.onosproject.yang.model.ListKey;
+import org.onosproject.yang.model.NodeKey;
+import org.onosproject.yang.model.ResourceData;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.runtime.AnnotatedNodeInfo;
+import org.onosproject.yang.runtime.Annotation;
+import org.onosproject.yang.runtime.DefaultAnnotatedNodeInfo;
+import org.onosproject.yang.runtime.DefaultAnnotation;
+import org.onosproject.yang.runtime.DefaultRuntimeContext;
+import org.onosproject.yang.runtime.DefaultYangSerializerContext;
+import org.onosproject.yang.runtime.RuntimeContext;
+import org.onosproject.yang.runtime.SerializerHelper;
+import org.onosproject.yang.runtime.YangSerializerContext;
+import org.onosproject.yang.runtime.impl.DefaultYangModelRegistry;
+import org.onosproject.yang.serializers.utils.SerializerUtilException;
+import org.slf4j.Logger;
+
+import javax.ws.rs.core.UriBuilder;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * The class services as a placeholder for utilities related to
+ * generic ResourceId operations.
+ */
+public final class ResourceIdUtil {
+ public static final String ROOT_NAME = "/";
+ public static final String ROOT_NS = null;
+ public static final ResourceId ROOT_ID = ResourceId.builder().addBranchPointSchema(ROOT_NAME, ROOT_NS).build();
+
+ private static final Logger log = getLogger(ResourceIdUtil.class);
+ private static final String JSON_FORMAT = "JSON";
+ private static final Splitter SLASH_SPLITTER = Splitter.on('/');
+ private static final Splitter COMMA_SPLITTER = Splitter.on(',');
+ private static final String QUOTES = "\"";
+ private static final String ROOT_ELEMENT_START = "<root ";
+ private static final String ROOT_ELEMENT_END = "</root>";
+ private static final String URI_ENCODING_CHAR_SET = "ISO-8859-1";
+ private static final String UTF8_ENCODING = "utf-8";
+ private static final String ERROR_LIST_MSG = "List/Leaf-list node should be " +
+ "in format \"nodeName=key\"or \"nodeName=instance-value\"";
+ private static final String EQUAL = "=";
+ private static final String COMMA = ",";
+ private static final String COLON = ":";
+ private static final String SLASH = "/";
+ private static final String URI_ENCODED_SLASH = "%2F";
+ private static final String URI_ENCODED_COLON = "%3A";
+
+
+ // no instantiation
+ private ResourceIdUtil() {
+ }
+
+ /**
+ * Converts XML atrtibutes into annotated node info.
+ *
+ * @param element XML element
+ * @param id resource id of an element
+ * @return annotated node info
+ */
+ public static AnnotatedNodeInfo convertXmlAttributesToAnnotations(Element element,
+ ResourceId id) {
+ Iterator iter = element.attributeIterator();
+ if (!iter.hasNext()) {
+ // element does not have any attributes
+ return null;
+ }
+ AnnotatedNodeInfo.Builder builder = DefaultAnnotatedNodeInfo.builder();
+ builder = builder.resourceId(id);
+ while (iter.hasNext()) {
+ Attribute attr = (Attribute) iter.next();
+ DefaultAnnotation annotation = new DefaultAnnotation(
+ attr.getQualifiedName(), attr.getValue());
+ builder = builder.addAnnotation(annotation);
+ }
+ return builder.build();
+ }
+
+
+ /**
+ * Appends the XML data with root element.
+ *
+ * @param inputStream XML data
+ * @param protocolAnnotation list of annoations for root element
+ * @return XML with root element
+ * @throws DocumentException if root element cannot be created
+ * @throws IOException if input data cannot be read
+ */
+ public static String addRootElementWithAnnotation(InputStream inputStream,
+ List<Annotation>
+ protocolAnnotation)
+ throws DocumentException, IOException {
+ BufferedReader br;
+ StringBuilder sb = new StringBuilder();
+ String xmlData;
+ // Parse composite stream resourceData
+ br = new BufferedReader(new InputStreamReader(inputStream));
+ while ((xmlData = br.readLine()) != null) {
+ sb.append(xmlData);
+ }
+
+ StringBuilder rootElement = new StringBuilder(ROOT_ELEMENT_START);
+ if (protocolAnnotation != null) {
+ for (Annotation annotation : protocolAnnotation) {
+ rootElement.append(annotation.name()).append(EQUAL)
+ .append(QUOTES).append(annotation.value()).append(QUOTES);
+ }
+ }
+ rootElement.append(">").append(sb.toString()).append(ROOT_ELEMENT_END);
+ return rootElement.toString();
+ }
+
+ public static ResourceId convertUriToRid(URI uri) {
+ if (uri == null) {
+ return null;
+ }
+
+ return convertUriStrToRid(getRawUriPath(uri));
+ }
+
+ public static ResourceId convertUriStrToRid(String uriStr) {
+ if (uriStr == null || uriStr.isEmpty()) {
+ return null;
+ }
+
+ ResourceData resourceData = CodecConverter.objectNodeToResourceData(uriStr, null);
+ return resourceData.resourceId();
+ }
+
+ /**
+ * Converts a URI string to resource identifier.
+ *
+ * @param uriString given URI
+ * @param context YANG schema context information
+ * @return resource ID
+ */
+ @Deprecated
+ public static ResourceId.Builder convertUriStrToRid(String uriString,
+ YangSerializerContext context) {
+ if (uriString == null || uriString.isEmpty()) {
+ return null;
+ }
+ List<String> paths = Arrays.asList(uriString.split(SLASH));
+
+ if (!paths.isEmpty()) {
+ ResourceId.Builder ridBuilder =
+ SerializerHelper.initializeResourceId(context);
+ processPathSegments(paths, ridBuilder);
+ return ridBuilder;
+ }
+
+ return null;
+ }
+
+ /**
+ * Converts a list of path from the original format to ISO-8859-1 code.
+ *
+ * @param paths the original paths
+ * @return list of decoded paths
+ */
+ @Deprecated
+ public static List<String> urlPathArgsDecode(Iterable<String> paths) {
+ try {
+ List<String> decodedPathArgs = new ArrayList<>();
+ for (String pathArg : paths) {
+ String decode = URLDecoder.decode(pathArg,
+ URI_ENCODING_CHAR_SET);
+ decodedPathArgs.add(decode);
+ }
+ return decodedPathArgs;
+ } catch (UnsupportedEncodingException e) {
+ throw new SerializerUtilException("Invalid URL path arg '" +
+ paths + "': ", e);
+ }
+ }
+
+ private static ResourceId.Builder processPathSegments(List<String> paths,
+ ResourceId.Builder builder) {
+ if (paths.isEmpty()) {
+ return builder;
+ }
+
+ boolean isLastSegment = paths.size() == 1;
+
+ String segment = paths.iterator().next();
+ processSinglePathSegment(segment, builder);
+
+ if (isLastSegment) {
+ // We have hit the base case of recursion.
+ return builder;
+ }
+
+ /*
+ * Chop off the first segment, and recursively process the rest
+ * of the path segments.
+ */
+ List<String> remainPaths = paths.subList(1, paths.size());
+ processPathSegments(remainPaths, builder);
+
+ return builder;
+ }
+
+ private static void processSinglePathSegment(String pathSegment,
+ ResourceId.Builder builder) {
+ if (pathSegment.contains(COLON)) {
+ processPathSegmentWithNamespace(pathSegment, builder);
+ } else {
+ processPathSegmentWithoutNamespace(pathSegment, builder);
+ }
+ }
+
+ private static void processPathSegmentWithNamespace(String pathSegment,
+ ResourceId.Builder builder) {
+
+ String nodeName = getLatterSegment(pathSegment, COLON);
+ String namespace = getPreSegment(pathSegment, COLON);
+ addNodeNameToRid(nodeName, namespace, builder);
+ }
+
+ private static void processPathSegmentWithoutNamespace(String nodeName,
+ ResourceId.Builder builder) {
+ addNodeNameToRid(nodeName, null, builder);
+ }
+
+ private static void addNodeNameToRid(String nodeName,
+ String namespace,
+ ResourceId.Builder builder) {
+ if (nodeName.contains(EQUAL)) {
+ addListOrLeafList(nodeName, namespace, builder);
+ } else {
+ addLeaf(nodeName, namespace, builder);
+ }
+ }
+
+ private static void addListOrLeafList(String path,
+ String namespace,
+ ResourceId.Builder builder) {
+ String nodeName = getPreSegment(path, EQUAL);
+ String keyStr = getLatterSegment(path, EQUAL);
+ if (keyStr == null) {
+ throw new SerializerUtilException(ERROR_LIST_MSG);
+ }
+
+ List<String> keys = uriDecodedKeys(keyStr);
+ SerializerHelper.addToResourceId(builder, nodeName, namespace, keys);
+ }
+
+ private static List<String> uriDecodedKeys(String keyStr) {
+ List<String> decodedKeys = Lists.newArrayList();
+
+ if (keyStr.contains(COMMA)) {
+ List<String> encodedKeys = Lists.newArrayList(COMMA_SPLITTER.split(keyStr));
+ for (String encodedKey : encodedKeys) {
+ decodedKeys.add(uriDecodedString(encodedKey));
+ }
+ } else {
+ decodedKeys.add(uriDecodedString(keyStr));
+ }
+
+ return decodedKeys;
+ }
+
+
+ private static String uriDecodedString(String keyStr) {
+ try {
+ keyStr = URLDecoder.decode(keyStr, UTF8_ENCODING);
+ } catch (UnsupportedEncodingException ex) {
+ throw new SerializerUtilException("UnsupportedEncodingException: " + ex.getMessage());
+ }
+
+ return keyStr;
+ }
+
+ private static void addLeaf(String nodeName,
+ String namespace,
+ ResourceId.Builder builder) {
+ checkNotNull(nodeName);
+ String value = null;
+ SerializerHelper.addToResourceId(builder, nodeName, namespace, value);
+ }
+
+ /**
+ * Returns the previous segment of a path which is separated by a split char.
+ * For example:
+ * <pre>
+ * "foo:bar", ":" to "foo"
+ * </pre>
+ *
+ * @param path the original path string
+ * @param splitChar char used to split the path
+ * @return the previous segment of the path
+ */
+ public static String getPreSegment(String path, String splitChar) {
+ int idx = path.lastIndexOf(splitChar);
+ if (idx == -1) {
+ return null;
+ }
+ return path.substring(0, idx);
+ }
+
+ /**
+ * Returns the latter segment of a path which is separated by a split char.
+ * For example:
+ * <pre>
+ * "foo:bar", ":" to "bar"
+ * </pre>
+ *
+ * @param path the original path string
+ * @param splitChar char used to split the path
+ * @return the latter segment of the path
+ */
+ public static String getLatterSegment(String path, String splitChar) {
+ int idx = path.lastIndexOf(splitChar);
+ if (idx == -1) {
+ return path;
+ }
+
+ return path.substring(idx + 1);
+ }
+
+ /**
+ * Converts a resource identifier to URI string.
+ *
+ * @param rid resource identifier
+ * @return URI
+ */
+ public static String convertRidToUriStr(ResourceId rid) {
+ if (rid == null) {
+ return null;
+ }
+
+ RuntimeContext.Builder runtimeContextBuilder = new DefaultRuntimeContext.Builder();
+ runtimeContextBuilder.setDataFormat(JSON_FORMAT);
+ RuntimeContext rc = runtimeContextBuilder.build();
+ YangSerializerContext context = new DefaultYangSerializerContext(null,
+ rc.getProtocolAnnotations());
+
+ StringBuilder uriBuilder = new StringBuilder();
+ List<NodeKey> nodeKeyList = rid.nodeKeys();
+ String curNameSpace = null;
+ for (NodeKey key : nodeKeyList) {
+ curNameSpace = addNodeKeyToUri(key, curNameSpace, uriBuilder, context);
+ }
+ return trimAtLast(uriBuilder.toString(), SLASH);
+ }
+
+ private static String addNodeKeyToUri(NodeKey key,
+ String curNameSpace,
+ StringBuilder uriBuilder,
+ YangSerializerContext context) {
+ String newNameSpace = null;
+ if (key instanceof LeafListKey) {
+ newNameSpace = addLeafListNodeToUri((LeafListKey) key,
+ curNameSpace, uriBuilder, context);
+ } else if (key instanceof ListKey) {
+ newNameSpace = addListNodeToUri((ListKey) key, curNameSpace,
+ uriBuilder, context);
+ } else {
+ String name = key.schemaId().name();
+ if (!name.equals(SLASH)) {
+ newNameSpace = addNodeNameToUri(key, curNameSpace,
+ uriBuilder, context);
+ }
+ }
+ return newNameSpace;
+ }
+
+ private static String addLeafListNodeToUri(LeafListKey key,
+ String curNameSpace,
+ StringBuilder uriBuilder,
+ YangSerializerContext context) {
+
+ String newNameSpace = addNodeNameToUri(key, curNameSpace, uriBuilder,
+ context);
+ uriBuilder.append(EQUAL);
+ uriBuilder.append(key.asString());
+ return newNameSpace;
+ }
+
+ private static String addListNodeToUri(ListKey key,
+ String curNameSpace,
+ StringBuilder uriBuilder,
+ YangSerializerContext context) {
+ String newNameSpace = addNodeNameToUri(key, curNameSpace, uriBuilder,
+ context);
+ uriBuilder.append(EQUAL);
+ String prefix = "";
+ for (KeyLeaf keyLeaf : key.keyLeafs()) {
+ uriBuilder.append(prefix);
+ prefix = COMMA;
+ uriBuilder.append(keyLeaf.leafValue().toString());
+ }
+
+ return newNameSpace;
+ }
+
+ private static String addNodeNameToUri(NodeKey key,
+ String curNameSpace,
+ StringBuilder uriBuilder,
+ YangSerializerContext context) {
+ String newNameSpace = key.schemaId().namespace();
+ if (newNameSpace == null) {
+ return curNameSpace;
+ }
+
+ if (!newNameSpace.equals(curNameSpace)) {
+ uriBuilder.append(getModuleNameFromNameSpace(context, newNameSpace));
+ uriBuilder.append(COLON);
+ }
+ uriBuilder.append(key.schemaId().name());
+ uriBuilder.append(SLASH);
+
+ return newNameSpace;
+ }
+
+ public static String trimAtLast(String valueString, String...
+ removalString) {
+ StringBuilder stringBuilder = new StringBuilder(valueString);
+ String midString;
+ int index;
+ for (String remove : removalString) {
+ midString = stringBuilder.toString();
+ index = midString.lastIndexOf(remove);
+ if (index != -1) {
+ stringBuilder.deleteCharAt(index);
+ }
+ }
+ return stringBuilder.toString();
+ }
+
+ public static String getModuleNameFromNameSpace(YangSerializerContext c,
+ String ns) {
+
+ YangSchemaNode schemaNode = ((DefaultYangModelRegistry) c.getContext())
+ .getForNameSpace(ns, false);
+ if (schemaNode != null) {
+ return schemaNode.getName();
+ }
+ return null;
+ }
+
+ public static URI rmLastPathSegment(URI uri) {
+ if (uri == null) {
+ return null;
+ }
+
+ UriBuilder builder = UriBuilder.fromUri(uri);
+ String newPath = rmLastPathSegmentStr(uri.getRawPath());
+ builder.replacePath(newPath);
+
+ return builder.build();
+ }
+
+ public static String rmLastPathSegmentStr(String rawPath) {
+ if (rawPath == null) {
+ return null;
+ }
+ int pos = rawPath.lastIndexOf(SLASH);
+ if (pos <= 0) {
+ return null;
+ }
+
+ return rawPath.substring(0, pos);
+ }
+
+ public static ResourceId parentOf(ResourceId path) {
+ try {
+ return path.copyBuilder().removeLastKey().build();
+ } catch (CloneNotSupportedException e) {
+ log.error("ERROR: parentOf: Could not copy {}", path, e);
+ throw new IllegalArgumentException("Could not copy " + path, e);
+ }
+ }
+
+ public static boolean isRootRid(ResourceId path) {
+ if (path == null) {
+ // null is a valid presentation of root resource ID
+ return true;
+ }
+
+ if ((path.nodeKeys().size() == 1) && (path.nodeKeys().get(0).schemaId().name().equals("/"))) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public static boolean isRidLeafListEntry(ResourceId rId) {
+ if (rId == null) {
+ return false;
+ }
+
+ List<NodeKey> nodeKeyList = rId.nodeKeys();
+ if (CollectionUtils.isEmpty(nodeKeyList)) {
+ return false;
+ }
+
+ NodeKey lastNodeKey = nodeKeyList.get(nodeKeyList.size() - 1);
+ if (lastNodeKey instanceof LeafListKey) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public static String getKeyStrFromLeafListKey(LeafListKey key) {
+ return key.asString();
+ }
+
+ public static String getNodeNameFromNodeKey(NodeKey key) {
+ return key.schemaId().name();
+ }
+
+ public static String getNameSpaceFromNodeKey(NodeKey key) {
+ return key.schemaId().namespace();
+ }
+
+ public static String getRawUriPath(URI uri) {
+ if (uri == null) {
+ return null;
+ }
+
+ String path = uri.getRawPath();
+ if (path.equals("/restconf/data")) {
+ return null;
+ }
+
+ return path.replaceAll("^/restconf/data/", "")
+ .replaceAll("^/restconf/configdata/", "")
+ .replaceAll("^/restconf/operations/", "");
+ }
+
+ public static ResourceId getResourceIdInRange(ResourceId rsId, int fromIdx, int toIdx) {
+ checkArgument(rsId.nodeKeys().size() >= toIdx,
+ "%s path must be deeper than base prefix %d", rsId, toIdx);
+
+ // FIXME waiting for Yang tools 2.2.0-b4 or later
+ // return ResourceId.builder().append(child.nodeKeys().subList(fromIdx, toIdx+1).build();
+
+ ResourceId.Builder builder = ResourceId.builder();
+ for (NodeKey nodeKey : rsId.nodeKeys().subList(fromIdx, toIdx + 1)) {
+ if (nodeKey instanceof ListKey) {
+ ListKey listKey = (ListKey) nodeKey;
+ builder.addBranchPointSchema(nodeKey.schemaId().name(),
+ nodeKey.schemaId().namespace());
+ for (KeyLeaf keyLeaf : listKey.keyLeafs()) {
+ builder.addKeyLeaf(keyLeaf.leafSchema().name(),
+ keyLeaf.leafSchema().namespace(),
+ keyLeaf.leafValAsString());
+ }
+ } else if (nodeKey instanceof LeafListKey) {
+ LeafListKey llKey = (LeafListKey) nodeKey;
+ builder.addLeafListBranchPoint(llKey.schemaId().name(),
+ llKey.schemaId().namespace(),
+ llKey.value());
+
+ } else {
+ builder.addBranchPointSchema(nodeKey.schemaId().name(),
+ nodeKey.schemaId().namespace());
+ }
+ }
+ return builder.build();
+ }
+
+ public static List<String> getResourceIdTokens(ResourceId rId) {
+ if (rId == null) {
+ return null;
+ }
+ List<NodeKey> nodeKeys = rId.nodeKeys();
+ if (CollectionUtils.isEmpty(nodeKeys)) {
+ return null;
+ }
+ List<String> res = Lists.newArrayList();
+ for (NodeKey nodeKey : nodeKeys) {
+ res.add(nodeKey.schemaId().name());
+ }
+
+ return res;
+ }
+
+ public static boolean nodeKeysMatchPrefix(ResourceId rid, List<String> nodeKeyPrefix) {
+ if (rid == null || CollectionUtils.isEmpty(rid.nodeKeys())) {
+ return false;
+ }
+ return nodeKeysMatchPrefix(rid.nodeKeys(), nodeKeyPrefix);
+ }
+
+ public static boolean nodeKeysMatchPrefix(List<NodeKey> nodeKeys, List<String> nodeKeyPrefix) {
+ if (nodeKeyPrefix == null || nodeKeyPrefix.isEmpty()) {
+ return true; // no prefix, so match is true
+ }
+ if (nodeKeys == null || nodeKeys.isEmpty() || nodeKeys.size() < nodeKeyPrefix.size()) {
+ return false;
+ }
+
+ for (int i = 0; i < nodeKeyPrefix.size(); i++) {
+ if (!nodeKeys.get(i).schemaId().name().equals(nodeKeyPrefix.get(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean nodeKeysMatch(List<NodeKey> nodeKeys, List<String> nodeKeyNames) {
+ int size = nodeKeyNames.size();
+ if (nodeKeys == null || nodeKeys.isEmpty() || nodeKeys.size() != size) {
+ return false;
+ }
+
+ for (int i = 0; i < size; i++) {
+ if (!nodeKeys.get(i).schemaId().name().equals(nodeKeyNames.get(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static boolean listKeySchemaMatch(ListKey listKeyA, ListKey listKeyB) {
+ List<KeyLeaf> keyLeavesA = listKeyA.keyLeafs();
+ List<KeyLeaf> keyLeavesB = listKeyB.keyLeafs();
+ if (keyLeavesA.size() != keyLeavesB.size()) {
+ return false;
+ }
+
+ for (int i = 0; i < keyLeavesA.size(); i++) {
+ KeyLeaf keyLeafA = keyLeavesA.get(i);
+ KeyLeaf keyLeafB = keyLeavesB.get(i);
+ if (!keyLeafA.leafSchema().name().equals(keyLeafB.leafSchema().name())) {
+ //should we compare keyLeaf.leafSchema().namespace()?
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static String getPrintableForm(ResourceId rid) {
+ if (rid == null || CollectionUtils.isEmpty(rid.nodeKeys())) {
+ return "null";
+ }
+
+ StringBuilder builder = new StringBuilder();
+ List<NodeKey> nodeKeys = rid.nodeKeys();
+ for (NodeKey nodeKey : nodeKeys) {
+ if (nodeKey instanceof ListKey) {
+ builder.append("/").append(nodeKey.schemaId().name());
+ builder.append("=");
+ List<KeyLeaf> keyLeafList = ((ListKey) nodeKey).keyLeafs();
+ int i = 0;
+ for (KeyLeaf keyLeaf : keyLeafList) {
+ if (i > 0) {
+ builder.append(",");
+ }
+ builder.append(keyLeaf.leafValue());
+ builder.append("(").append(keyLeaf.leafSchema().name()).append(")");
+ i++;
+ }
+ } else if (nodeKey instanceof LeafListKey) {
+ builder.append("/")
+ .append(((LeafListKey) nodeKey).value())
+ .append("(").append(nodeKey.schemaId().name()).append(")");
+
+ } else if (nodeKey instanceof NodeKey) {
+ if (!nodeKey.schemaId().name().equals("/")) {
+ builder.append("/").append(nodeKey.schemaId().name());
+ }
+ } else {
+ builder.append("ERROR: ").append(nodeKey.toString());
+ }
+ }
+ return builder.toString();
+ }
+
+ public static boolean ridSchemaMatchPrefix(ResourceId ridA, ResourceId prefixRid) {
+ if (ridA == null || prefixRid == null) {
+ return false;
+ }
+
+ List<NodeKey> nodeKeysA = ridA.nodeKeys();
+ List<NodeKey> nodeKeysB = prefixRid.nodeKeys();
+
+ if (nodeKeysA.size() < nodeKeysB.size()) {
+ return false;
+ }
+
+ for (int i = 0; i < nodeKeysB.size(); i++) {
+ NodeKey nodeKeyA = nodeKeysA.get(i);
+ NodeKey nodeKeyB = nodeKeysB.get(i);
+
+ if (nodeKeyA instanceof ListKey) {
+ if (!(nodeKeyB instanceof ListKey)) {
+ return false;
+ }
+ if (!listKeySchemaMatch((ListKey) nodeKeyA, (ListKey) nodeKeyB)) {
+ return false;
+ }
+
+ } else if (nodeKeyA instanceof LeafListKey) {
+ if (!(nodeKeyB instanceof LeafListKey)) {
+ return false;
+ }
+ LeafListKey llKeyA = (LeafListKey) nodeKeyA;
+ LeafListKey llKeyB = (LeafListKey) nodeKeyB;
+
+ if (!llKeyA.schemaId().name().equals(llKeyB.schemaId().name())) {
+ //should we also compare nodeKey.schemaId().namespace()?
+ return false;
+ }
+ } else {
+ if (nodeKeyB instanceof ListKey || nodeKeyB instanceof LeafListKey) {
+ return false;
+ }
+ if (!nodeKeyA.schemaId().name().equals(nodeKeyB.schemaId().name())) {
+ //should we also compare nodeKey.schemaId().namespace()?
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public static String convertRidToString(ResourceId rid) {
+ return getPrintableForm(rid);
+ }
+
+ public static boolean ridSchemaMatch(ResourceId ridA, ResourceId ridB) {
+ if (ridA == null || ridB == null) {
+ return false;
+ }
+
+ List<NodeKey> nodeKeysA = ridA.nodeKeys();
+ List<NodeKey> nodeKeysB = ridB.nodeKeys();
+
+ if (nodeKeysA.size() != nodeKeysB.size()) {
+ return false;
+ }
+
+ for (int i = 0; i < nodeKeysA.size(); i++) {
+ NodeKey nodeKeyA = nodeKeysA.get(i);
+ NodeKey nodeKeyB = nodeKeysB.get(i);
+
+ if (nodeKeyA instanceof ListKey) {
+ if (!(nodeKeyB instanceof ListKey)) {
+ return false;
+ }
+ if (!listKeySchemaMatch((ListKey) nodeKeyA, (ListKey) nodeKeyB)) {
+ return false;
+ }
+
+ } else if (nodeKeyA instanceof LeafListKey) {
+ if (!(nodeKeyB instanceof LeafListKey)) {
+ return false;
+ }
+ LeafListKey llKeyA = (LeafListKey) nodeKeyA;
+ LeafListKey llKeyB = (LeafListKey) nodeKeyB;
+
+ if (!llKeyA.schemaId().name().equals(llKeyB.schemaId().name())) {
+ //should we also compare nodeKey.schemaId().namespace()?
+ return false;
+ }
+ } else {
+ if (nodeKeyB instanceof ListKey || nodeKeyB instanceof LeafListKey) {
+ return false;
+ }
+ if (!nodeKeyA.schemaId().name().equals(nodeKeyB.schemaId().name())) {
+ //should we also compare nodeKey.schemaId().namespace()?
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public static ResourceId getGenericRidForNetworkLink() {
+ ResourceId rid = ResourceId.builder()
+ .addBranchPointSchema("/", null)
+ .addBranchPointSchema("networks", "generic-ns")
+ .addBranchPointSchema("network", "generic-ns")
+ .addKeyLeaf("network-id", "generic-ns", "generic-network-id")
+ .addBranchPointSchema("link", "generic-ns")
+ .addKeyLeaf("link-id", "generic-ns", "generic-link-id")
+ .build();
+ return rid;
+ }
+
+ public static ResourceId getGenericRidForNetworkNode() {
+ ResourceId rid = ResourceId.builder()
+ .addBranchPointSchema("/", null)
+ .addBranchPointSchema("networks", "generic-ns")
+ .addBranchPointSchema("network", "generic-ns")
+ .addKeyLeaf("network-id", "generic-ns", "generic-network-id")
+ .addBranchPointSchema("node", "generic-ns")
+ .addKeyLeaf("node-id", "generic-ns", "generic-node-id")
+ .build();
+ return rid;
+ }
+
+ public static ResourceId getGenericRidForNetworkNodeTp() {
+ ResourceId rid = ResourceId.builder()
+ .addBranchPointSchema("/", null)
+ .addBranchPointSchema("networks", "generic-ns")
+ .addBranchPointSchema("network", "generic-ns")
+ .addKeyLeaf("network-id", "generic-ns", "generic-network-id")
+ .addBranchPointSchema("node", "generic-ns")
+ .addKeyLeaf("node-id", "generic-ns", "generic-node-id")
+ .addBranchPointSchema("termination-point", "generic-ns")
+ .addKeyLeaf("tp-id", "generic-ns", "generic-tp-id")
+ .build();
+ return rid;
+ }
+
+ public static ResourceId getGenericRidForNetworkNodeTtp() {
+ ResourceId rid = ResourceId.builder()
+ .addBranchPointSchema("/", null)
+ .addBranchPointSchema("networks", "generic-ns")
+ .addBranchPointSchema("network", "generic-ns")
+ .addKeyLeaf("network-id", "generic-ns", "generic-network-id")
+ .addBranchPointSchema("node", "generic-ns")
+ .addKeyLeaf("node-id", "generic-ns", "generic-node-id")
+ .addBranchPointSchema("te", "generic-ns")
+ .addBranchPointSchema("tunnel-termination-point", "generic-ns")
+ .addKeyLeaf("tunnel-tp-id", "generic-ns", "generic-ttp-id")
+ .build();
+ return rid;
+ }
+
+ public static ResourceId getGenericRidForJuniperConfigGroups() {
+ ResourceId rid = ResourceId.builder()
+ .addBranchPointSchema("/", null)
+ .addBranchPointSchema("configuration", "generic-ns")
+ .addBranchPointSchema("groups", "generic-ns")
+ .addKeyLeaf("name", "generic-ns", "generic-name")
+ .build();
+ return rid;
+ }
+
+ public static ResourceId getGenericRidForEthPmStateParam() {
+ ResourceId rid = ResourceId.builder()
+ .addBranchPointSchema("/", null)
+ .addBranchPointSchema("performance-monitoring", "generic-ns")
+ .addBranchPointSchema("service-pm", "generic-ns")
+ .addKeyLeaf("service-name", "generic-ns", "generic-list-key")
+ .addBranchPointSchema("service-pm-state", "generic-ns")
+ .addBranchPointSchema("performance-data", "generic-ns")
+ .addKeyLeaf("parameter-name", "generic-ns", "generic-list-key")
+ .addBranchPointSchema("parameter-value", "generic-ns")
+ .addKeyLeaf("index", "generic-ns", "generic-list-key")
+ .build();
+ return rid;
+ }
+
+ public static ResourceId getGenericRidForTeTunnel() {
+ ResourceId rid = ResourceId.builder()
+ .addBranchPointSchema("/", null)
+ .addBranchPointSchema("te", "generic-ns")
+ .addBranchPointSchema("tunnels", "generic-ns")
+ .addBranchPointSchema("tunnel", "generic-ns")
+ .addKeyLeaf("name", "generic-ns", "generic-tunnel-name")
+ .build();
+ return rid;
+ }
+
+ public static ResourceId getGenericRidForEthtSvcInstances() {
+ ResourceId rid = ResourceId.builder()
+ .addBranchPointSchema("/", null)
+ .addBranchPointSchema("etht-svc", "generic-ns")
+ .addBranchPointSchema("etht-svc-instances", "generic-ns")
+ .addKeyLeaf("etht-svc-name", "generic-ns", "generic-key-id")
+ .build();
+ return rid;
+ }
+
+ public static ResourceId convertToGenericRid(ResourceId rid) {
+ if (rid == null) {
+ return null;
+ }
+
+ ResourceId genericRid = null;
+
+ genericRid = getGenericRidForEthPmStateParam();
+ if (ridSchemaMatch(rid, genericRid)) {
+ return genericRid;
+ }
+
+ genericRid = getGenericRidForNetworkLink();
+ if (ridSchemaMatch(rid, genericRid)) {
+ return genericRid;
+ }
+
+ genericRid = getGenericRidForTeTunnel();
+ if (ridSchemaMatch(rid, genericRid)) {
+ return genericRid;
+ }
+
+ genericRid = getGenericRidForNetworkNode();
+ if (ridSchemaMatch(rid, genericRid)) {
+ return genericRid;
+ }
+
+ genericRid = getGenericRidForEthtSvcInstances();
+ if (ridSchemaMatch(rid, genericRid)) {
+ return genericRid;
+ }
+
+ genericRid = getGenericRidForNetworkNodeTp();
+ if (ridSchemaMatch(rid, genericRid)) {
+ return genericRid;
+ }
+
+ genericRid = getGenericRidForNetworkNodeTtp();
+ if (ridSchemaMatch(rid, genericRid)) {
+ return genericRid;
+ }
+
+ genericRid = getGenericRidForJuniperConfigGroups();
+ if (ridSchemaMatch(rid, genericRid)) {
+ return genericRid;
+ }
+ //TODO: HENRY: add other generic RIDs.
+
+ return null;
+ }
+
+ public static String convertRid2Uri(ResourceId rid) {
+ if (rid == null) {
+ return "";
+ }
+
+ StringBuilder sb = new StringBuilder();
+ List<NodeKey> nodeKeys = rid.nodeKeys();
+
+ for (int i = 0; i < nodeKeys.size(); i++) {
+ NodeKey nodeKey = nodeKeys.get(i);
+ String nodeName = nodeKey.schemaId().name();
+
+ if (nodeKey instanceof ListKey) {
+ sb.append("/");
+ sb.append(nodeName);
+ sb.append("=");
+ sb.append(listKeyValues2UriString((ListKey) nodeKey));
+ } else if (nodeKey instanceof LeafListKey) {
+ sb.append("/");
+ sb.append(nodeName);
+ sb.append("=");
+ sb.append(leafListKey2UriString((LeafListKey) nodeKey));
+ } else {
+ if (!nodeName.equals("/")) {
+ sb.append("/");
+ sb.append(nodeName);
+ //should we also compare nodeKey.schemaId().namespace()?
+ }
+ }
+ }
+
+ return sb.toString();
+ }
+
+ private static String leafListKey2UriString(LeafListKey leafListKey) {
+ String decodedValue = leafListKey.asString();
+ try {
+ return URLEncoder.encode(decodedValue, "utf-8");
+ } catch (UnsupportedEncodingException e) {
+ log.error("ERROR: leafListKey2UriString: {}", e.getMessage());
+ }
+
+ return "";
+ }
+
+ private static String listKeyValues2UriString(ListKey listKey) {
+ if (listKey == null) {
+ return "";
+ }
+
+ StringBuilder sb = new StringBuilder();
+ List<KeyLeaf> keyLeaves = listKey.keyLeafs();
+
+ for (int i = 0; i < keyLeaves.size(); i++) {
+ sb.append(",");
+ KeyLeaf keyLeaf = keyLeaves.get(i);
+ String rawValue = keyLeaf.leafValue().toString();
+ try {
+ sb.append(URLEncoder.encode(rawValue, "utf-8"));
+ } catch (UnsupportedEncodingException e) {
+ log.error("ERROR: listKey2UriString: {}", e.getMessage());
+ }
+ }
+
+ sb.deleteCharAt(sb.lastIndexOf(","));
+ return sb.toString();
+ }
+}
diff --git a/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/YangToolsUtil.java b/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/YangToolsUtil.java
new file mode 100644
index 0000000..b6cde3a
--- /dev/null
+++ b/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/YangToolsUtil.java
@@ -0,0 +1,560 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Actn Interface Tools
+ * ================================================================================
+ * Copyright (C) 2023 Huawei Canada Limited.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.integration.actninterfacetools.yangutils;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onap.integration.actninterfacetools.globalapi.GlobalService;
+import org.onosproject.yang.gen.v11.ietfethtranservice.rev20210111.ietfethtranservice.DefaultEthtSvc;
+import org.onosproject.yang.gen.v11.ietfethtranservice.rev20210111.ietfethtranservice.ethtsvc.DefaultEthtSvcInstances;
+import org.onosproject.yang.gen.v11.ietfethtranservice.rev20210111.ietfethtranservice.ethtsvc.EthtSvcInstancesKeys;
+import org.onosproject.yang.gen.v11.ietfnetwork.rev20180226.ietfnetwork.DefaultNetworks;
+import org.onosproject.yang.gen.v11.ietfnetwork.rev20180226.ietfnetwork.NetworkId;
+import org.onosproject.yang.gen.v11.ietfnetwork.rev20180226.ietfnetwork.NodeId;
+import org.onosproject.yang.gen.v11.ietfnetwork.rev20180226.ietfnetwork.networks.DefaultNetwork;
+import org.onosproject.yang.gen.v11.ietfnetwork.rev20180226.ietfnetwork.networks.NetworkKeys;
+import org.onosproject.yang.gen.v11.ietfnetwork.rev20180226.ietfnetwork.networks.network.DefaultNode;
+import org.onosproject.yang.gen.v11.ietfnetwork.rev20180226.ietfnetwork.networks.network.NodeKeys;
+import org.onosproject.yang.gen.v11.ietfnetworktopology.rev20180226.ietfnetworktopology.LinkId;
+import org.onosproject.yang.gen.v11.ietfnetworktopology.rev20180226.ietfnetworktopology.networks.network.augmentednwnetwork.DefaultLink;
+import org.onosproject.yang.gen.v11.ietfnetworktopology.rev20180226.ietfnetworktopology.networks.network.augmentednwnetwork.LinkKeys;
+import org.onosproject.yang.gen.v11.ietfte.rev20210220.ietfte.DefaultTe;
+import org.onosproject.yang.gen.v11.ietfte.rev20210220.ietfte.globalsgrouping.DefaultGlobals;
+import org.onosproject.yang.gen.v11.ietfte.rev20210220.ietfte.lspsgrouping.DefaultLsps;
+import org.onosproject.yang.gen.v11.ietfte.rev20210220.ietfte.lspsgrouping.lsps.DefaultLsp;
+import org.onosproject.yang.gen.v11.ietfte.rev20210220.ietfte.lspsgrouping.lsps.LspKeys;
+import org.onosproject.yang.gen.v11.ietfte.rev20210220.ietfte.namedpathconstraints.DefaultNamedPathConstraints;
+import org.onosproject.yang.gen.v11.ietfte.rev20210220.ietfte.namedpathconstraints.namedpathconstraints.DefaultNamedPathConstraint;
+import org.onosproject.yang.gen.v11.ietfte.rev20210220.ietfte.namedpathconstraints.namedpathconstraints.NamedPathConstraintKeys;
+import org.onosproject.yang.gen.v11.ietfte.rev20210220.ietfte.tunnelsgrouping.DefaultTunnels;
+import org.onosproject.yang.gen.v11.ietfte.rev20210220.ietfte.tunnelsgrouping.tunnels.DefaultTunnel;
+import org.onosproject.yang.gen.v11.ietfte.rev20210220.ietfte.tunnelsgrouping.tunnels.TunnelKeys;
+import org.onosproject.yang.gen.v11.ietftetopology.rev20200806.ietftetopology.telinkconfigattributes.DefaultTeLinkAttributes;
+import org.onosproject.yang.gen.v11.ietftetopology.rev20200806.ietftetopology.telinkconfigattributes.telinkattributes.DefaultUnderlay;
+import org.onosproject.yang.gen.v11.ietftransclientservice.rev20210111.ietftransclientservice.DefaultClientSvc;
+import org.onosproject.yang.model.ModelConverter;
+import org.onosproject.yang.model.ModelObjectId;
+import org.onosproject.yang.model.ResourceData;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.DefaultResourceData;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.DefaultModelObjectData;
+import org.onosproject.yang.model.ModelObjectData;
+import org.onosproject.yang.model.ModelObject;
+import org.onosproject.yang.model.InnerModelObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+/**
+ * The class services as a placeholder for utilities related to
+ * generic YangTools operations.
+ */
+public final class YangToolsUtil {
+
+ private static final Logger log = LoggerFactory.getLogger(YangToolsUtil.class);
+ private static ModelConverter MODEL_CONVERTER = null;
+ public static void active(){
+ ServiceLoader<GlobalService> serviceLoader = ServiceLoader.load(GlobalService.class);
+ for (GlobalService service : serviceLoader) {
+ MODEL_CONVERTER = service.getModelConverter();
+ }
+ }
+ public YangToolsUtil() {
+
+ }
+
+
+ /**
+ * Returns the model object id for networks container.
+ *
+ * @return model object id
+ */
+ public static ModelObjectId getModIdForRoot() {
+ return ModelObjectId.builder().build();
+ }
+
+ public static ModelObjectId getModIdForLink(String networkIdStr, String linkIdStr) {
+ NetworkId nid = NetworkId.fromString(networkIdStr);
+ NetworkKeys nkeys = new NetworkKeys();
+ nkeys.networkId(nid);
+ LinkId lid = LinkId.fromString(linkIdStr);
+ LinkKeys lkeys = new LinkKeys();
+ lkeys.linkId(lid);
+ return ModelObjectId.builder()
+ .addChild(DefaultNetworks.class)
+ .addChild(DefaultNetwork.class, nkeys)
+ .addChild(DefaultLink.class, lkeys)
+ .build();
+ }
+
+ /**
+ * Returns the model object id for networks container.
+ *
+ * @return model object id
+ */
+ public static ModelObjectId getModIdForNetworks() {
+ return ModelObjectId.builder()
+ .addChild(DefaultNetworks.class)
+ .build();
+ }
+
+ public static ModelObjectId getModIdForNetwork(String networkIdStr) {
+ NetworkId nid = NetworkId.fromString(networkIdStr);
+ NetworkKeys nkeys = new NetworkKeys();
+ nkeys.networkId(nid);
+ return ModelObjectId.builder()
+ .addChild(DefaultNetworks.class)
+ .addChild(DefaultNetwork.class, nkeys)
+ .build();
+ }
+
+ /**
+ * Returns the resource data from the data node and the resource id.
+ *
+ * @param dataNode data node
+ * @param resId resource id
+ * @return resource data
+ */
+ public static ResourceData getResourceData(DataNode dataNode, ResourceId resId) {
+ return DefaultResourceData.builder()
+ .addDataNode(dataNode)
+ .resourceId(resId)
+ .build();
+ }
+
+ /**
+ * Returns the model object id for networks/network/node container.
+ *
+ * @return model object id
+ */
+ public static ModelObjectId getModIdForNode() {
+ return ModelObjectId.builder()
+ .addChild(DefaultNetworks.class)
+ .addChild(DefaultNetwork.class, new NetworkKeys())
+ .addChild(DefaultNode.class, new NodeKeys())
+ .build();
+ }
+
+ /**
+ * Returns the model object id for networks/network container.
+ *
+ * @param networkId identifier of the target network
+ * @return model object id
+ */
+ public static ModelObjectId getModIdForYangNetwork(NetworkId networkId) {
+ NetworkKeys networkKeys = new NetworkKeys();
+ networkKeys.networkId(networkId);
+ return ModelObjectId.builder()
+ .addChild(DefaultNetworks.class)
+ .addChild(DefaultNetwork.class, networkKeys)
+ .build();
+ }
+
+ public static ModelObjectId getModIdForTe() {
+ return ModelObjectId.builder()
+ .addChild(DefaultTe.class)
+ .build();
+ }
+
+
+ public static ModelObjectId getModIdForTeTunnels() {
+ return ModelObjectId.builder()
+ .addChild(DefaultTe.class)
+ .addChild(DefaultTunnels.class)
+ .build();
+ }
+
+ public static ModelObjectId getModIdForTeGlobals() {
+ return ModelObjectId.builder()
+ .addChild(DefaultTe.class)
+ .addChild(DefaultGlobals.class)
+ .build();
+ }
+
+ public static ModelObjectId getModIdForLsps() {
+ return ModelObjectId.builder()
+ .addChild(DefaultTe.class)
+ .addChild(DefaultLsps.class)
+ .build();
+ }
+
+ public static ModelObjectId getModIdForLsp(String tunnelNameStr) {
+ LspKeys k = new LspKeys();
+ k.tunnelName(tunnelNameStr);
+ return ModelObjectId.builder()
+ .addChild(DefaultTe.class)
+ .addChild(DefaultLsps.class)
+ .addChild(DefaultLsp.class, k)
+ .build();
+ }
+
+ public static ModelObjectId getModIdForTeTunnel(String tunnelNameStr) {
+ TunnelKeys tkeys = new TunnelKeys();
+ tkeys.name(tunnelNameStr);
+ return ModelObjectId.builder()
+ .addChild(DefaultTe.class)
+ .addChild(DefaultTunnels.class)
+ .addChild(DefaultTunnel.class, tkeys)
+ .build();
+ }
+ public static ModelObjectId getModIdForTeLspsState() {
+ throw new RuntimeException("YangToolsUtil.getModIdForTeLspsState not implemented");
+ }
+
+ public static ModelObjectId getModIdForTeGlobalsPathConstraint(String pathConstraintName) {
+ NamedPathConstraintKeys keys = new NamedPathConstraintKeys();
+ keys.name(pathConstraintName);
+ return ModelObjectId.builder()
+ .addChild(DefaultTe.class)
+ .addChild(DefaultGlobals.class)
+ .addChild(DefaultNamedPathConstraints.class)
+ .addChild(DefaultNamedPathConstraint.class, keys)
+ .build();
+ }
+ public static ResourceId getRidForNetwork(String networkIdStr) {
+ if (networkIdStr == null) {
+ return null;
+ }
+ ModelObjectId modId = getModIdForNetwork(networkIdStr);
+ return modelObjId2ResourceId(modId);
+ }
+
+ public static ResourceId getRidForTunnel(String tunnelNameStr) {
+ if (tunnelNameStr != null && !tunnelNameStr.isEmpty()){
+ ModelObjectId modId = getModIdForTeTunnel(tunnelNameStr);
+ return modelObjId2ResourceId(modId);
+ }
+ return null;
+ }
+
+ public static ResourceId getRidForPhyConnections() {
+ throw new RuntimeException("YangToolsUtil.getRidForPhyConnections not implemented");
+ }
+ public static ResourceId getRidForLink(String networkIdStr, String linkIdStr) {
+ return modelObjId2ResourceId(getModIdForLink(networkIdStr, linkIdStr));
+ }
+
+
+ public static ResourceId getRidForNetworks() {
+ return modelObjId2ResourceId(getModIdForNetworks());
+ }
+
+ private static ModelObjectId getModIdForNetworkLinkUnderlay(String networkIdStr, String linkIdStr) {
+ NetworkId nid = NetworkId.fromString(networkIdStr);
+ NetworkKeys nkeys = new NetworkKeys();
+ nkeys.networkId(nid);
+ LinkId lid = LinkId.fromString(linkIdStr);
+ LinkKeys lkeys = new LinkKeys();
+ lkeys.linkId(lid);
+ return ModelObjectId.builder()
+ .addChild(DefaultNetworks.class)
+ .addChild(DefaultNetwork.class, nkeys)
+ .addChild(DefaultLink.class, lkeys)
+ .addChild(org.onosproject.yang.gen.v11.ietftetopology.rev20200806.ietftetopology.networks.network.link.augmentedntlink.DefaultTe.class)
+ .addChild(DefaultTeLinkAttributes.class)
+ .addChild(DefaultUnderlay.class)
+ .build();
+ }
+
+ private static ModelObjectId getModIdForNode(String networkIdStr, String nodeIdStr) {
+ NetworkId networkId = NetworkId.fromString(networkIdStr);
+ NetworkKeys networkKeys = new NetworkKeys();
+ networkKeys.networkId(networkId);
+
+ NodeId nodeId = NodeId.fromString(nodeIdStr);
+ NodeKeys nodeKeys = new NodeKeys();
+ nodeKeys.nodeId(nodeId);
+
+ return ModelObjectId.builder()
+ .addChild(DefaultNetworks.class)
+ .addChild(DefaultNetwork.class, networkKeys)
+ .addChild(DefaultNode.class, nodeKeys)
+ .build();
+ }
+
+ private static ModelObjectId getModIdForNetworkLink(String networkIdStr, String linkIdStr) {
+ NetworkId nid = NetworkId.fromString(networkIdStr);
+ NetworkKeys nkeys = new NetworkKeys();
+ nkeys.networkId(nid);
+ LinkId lid = LinkId.fromString(linkIdStr);
+ LinkKeys lkeys = new LinkKeys();
+ lkeys.linkId(lid);
+ return ModelObjectId.builder()
+ .addChild(DefaultNetworks.class)
+ .addChild(DefaultNetwork.class, nkeys)
+ .addChild(DefaultLink.class, lkeys)
+ .build();
+ }
+
+ /**
+ * Returns resource id from model converter.
+ *
+ * @param modelId model object id
+ * @return resource id
+ */
+ public static ResourceId modelObjId2ResourceId(ModelObjectId modelId) {
+ DefaultModelObjectData.Builder data = DefaultModelObjectData.builder().identifier(modelId);
+ ResourceData resData = MODEL_CONVERTER.createDataNode(data.build());
+ return resData.resourceId();
+ }
+
+ public static ResourceId getRidForTe() {
+ return modelObjId2ResourceId(getModIdForTe());
+ }
+
+ public static ResourceId getRidForRoot() {
+ return modelObjId2ResourceId(getModIdForRoot());
+ }
+
+ public static ResourceId getRidForTeTunnels() {
+ return modelObjId2ResourceId(getModIdForTeTunnels());
+ }
+
+ public static ResourceId getRidForTeLsps(){
+ return modelObjId2ResourceId(ModelObjectId.builder()
+ .addChild(DefaultTe.class)
+ .addChild(DefaultLsps.class)
+ .build()
+ );
+ }
+
+ public static ResourceId getRidForNetworkNode(String networkIdStr, String nodeIdStr) {
+ return modelObjId2ResourceId(getModIdForNetworkNode(networkIdStr, nodeIdStr));
+ }
+
+ public static ModelObjectId getModIdForNetworkNode(String networkIdStr, String nodeIdStr) {
+ NetworkId nid = NetworkId.fromString(networkIdStr);
+ NetworkKeys networkKeys = new NetworkKeys();
+ networkKeys.networkId(nid);
+
+ NodeId nodeId = NodeId.fromString(nodeIdStr);
+ NodeKeys nodeKeys = new NodeKeys();
+ nodeKeys.nodeId(nodeId);
+
+ return ModelObjectId.builder()
+ .addChild(DefaultNetworks.class)
+ .addChild(DefaultNetwork.class, networkKeys)
+ .addChild(DefaultNode.class, nodeKeys)
+ .build();
+ }
+
+ public static ResourceId getRidForTeTunnel(String tunnelName) {
+ return modelObjId2ResourceId(getModIdForTeTunnel(tunnelName));
+ }
+
+ public static ResourceId getRidForLsp(String tunnelName) {
+ return modelObjId2ResourceId(getModIdForLsp(tunnelName));
+ }
+
+ public static ResourceId getRidForNamedPathConstraint(String pathConstraintName) {
+ return modelObjId2ResourceId(getModIdForTeGlobalsPathConstraint(pathConstraintName));
+ }
+
+ public static ResourceId getRidForTeGlobals() {
+ return modelObjId2ResourceId(getModIdForTeGlobals());
+ }
+
+ public static ResourceId getRidForTeLspsState() {
+ return modelObjId2ResourceId(getModIdForTeLspsState());
+ }
+
+ public static ResourceId getRidForTeTunnelStateDepTunnels(String teTunnelName) {
+ return modelObjId2ResourceId(getModIdForTeTunnelStateDepTunnels(teTunnelName));
+ }
+
+ public static ResourceId getClientSvcRid() {
+ return modelObjId2ResourceId(getModIdForClientSvc());
+
+ }
+
+ private static ModelObjectId getModIdForClientSvc() {
+ return ModelObjectId.builder()
+ .addChild(DefaultClientSvc.class)
+ .build();
+ }
+
+ private static ModelObjectId getModIdForTeTunnelStateDepTunnels(String teTunnelName) {
+ TunnelKeys tkeys = new TunnelKeys();
+ tkeys.name(teTunnelName);
+ return ModelObjectId.builder()
+ .addChild(DefaultTe.class)
+ .addChild(DefaultTunnels.class)
+ .addChild(DefaultTunnel.class, tkeys)
+ .build();
+ }
+
+ public static ModelObjectId getModIdForEthSvc() {
+ return ModelObjectId.builder()
+ .addChild(DefaultEthtSvc.class)
+ .build();
+ }
+
+ public static ModelObjectId getModIdForEthGlobals() {
+ return ModelObjectId.builder()
+ .addChild(DefaultEthtSvc.class)
+ .addChild(org.onosproject.yang.gen.v11.ietfethtranservice.rev20210111.ietfethtranservice.ethtsvc.DefaultGlobals.class)
+ .build();
+ }
+
+ public static ModelObjectId getModIdForEthSvInstances(String ethSvcInstanceName) {
+ EthtSvcInstancesKeys ethtSvcInstancesKeys = new EthtSvcInstancesKeys();
+ ethtSvcInstancesKeys.ethtSvcName(ethSvcInstanceName);
+ return ModelObjectId.builder()
+ .addChild(DefaultEthtSvc.class)
+ .addChild(DefaultEthtSvcInstances.class, ethtSvcInstancesKeys)
+ .build();
+ }
+
+ public static ModelObjectId getModIdForEthSvState(String ethSvcInstanceName) {
+ EthtSvcInstancesKeys ethtSvcInstancesKeys = new EthtSvcInstancesKeys();
+ ethtSvcInstancesKeys.ethtSvcName(ethSvcInstanceName);
+ return ModelObjectId.builder()
+ .addChild(DefaultEthtSvc.class)
+ .addChild(DefaultEthtSvcInstances.class, ethtSvcInstancesKeys)
+ .build();
+ }
+
+ public static ModelObjectId getModIdForEthSvcConfig(String ethSvcName) {
+ EthtSvcInstancesKeys ethtSvcInstancesKeys = new EthtSvcInstancesKeys();
+ ethtSvcInstancesKeys.ethtSvcName(ethSvcName);
+
+ return ModelObjectId.builder()
+ .addChild(DefaultEthtSvc.class)
+ .addChild(DefaultEthtSvcInstances.class, ethtSvcInstancesKeys)
+ .build();
+ }
+ public static ResourceId getRIdForEthGlobals() {
+ return modelObjId2ResourceId(getModIdForEthGlobals());
+ }
+ public static ResourceId getRIdForEthSvcInstances(String ethSvcInstanceName) {
+ return modelObjId2ResourceId(getModIdForEthSvInstances(ethSvcInstanceName));
+ }
+ public static ResourceId getRidForTeTunnelP2p2ndPaths(String teTunnelName) {
+ throw new RuntimeException("YangToolsUtil.getRidForTeTunnelP2p2nndPaths not implemented");
+ }
+ public static ResourceId getRidForTunnelState(String tunnelName) {
+ throw new RuntimeException("YangToolsUtil.getRidForTunnelState not implemented");
+ }
+ public static ModelObjectId getModIdForNameExplicitPathState(String pathName) {
+ return null;
+ }
+
+ public static ResourceId getRidForNameExplicitPathState(String name) {
+ return modelObjId2ResourceId(getModIdForNameExplicitPathState(name));
+ }
+
+ public static ModelObjectId getModIdForPathConstraintState(String constraintName) {
+ NamedPathConstraintKeys constraintKeys = new NamedPathConstraintKeys();
+ constraintKeys.name(constraintName);
+ return ModelObjectId.builder()
+ .addChild(DefaultTe.class)
+ .addChild(DefaultGlobals.class)
+ .addChild(DefaultNamedPathConstraints.class)
+ .addChild(DefaultNamedPathConstraint.class, constraintKeys)
+ .build();
+ }
+
+ public static ResourceId getRidForNamePathConstraintState(String constraintName) {
+ return modelObjId2ResourceId(getModIdForPathConstraintState(constraintName));
+ }
+
+
+
+
+ public static DataNode yangPojo2DataNode(ModelObjectId parentModId, ModelObject yangPojo) {
+ ModelObjectData outputMo = yangPojo2ModData(parentModId, yangPojo);
+ ResourceData resourceData = MODEL_CONVERTER.createDataNode(outputMo);
+
+ return resourceData.dataNodes().get(0);
+ }
+
+ public static ModelObjectData yangPojo2ModData(ModelObjectId modId, ModelObject yangPojo) {
+ return DefaultModelObjectData.builder().identifier(modId)
+ .addModelObject(yangPojo).build();
+ }
+
+ public static <T extends InnerModelObject> T convertJsonToYangObj(String parentRidStr,
+ ObjectNode jsonNode,
+ Class<T> modelClass) {
+ if (jsonNode == null) {
+ log.error("ERROR: convertJsonToYangObj: jsonNode is null");
+ return null;
+ }
+
+ ResourceData resourceData = CodecConverter.objectNodeToResourceData(parentRidStr, jsonNode);
+ if (resourceData == null || resourceData.dataNodes() == null) {
+ log.error("ERROR: convertJsonToYangObj: {} is null",
+ resourceData == null ? "resourceData" : "resourceData.dataNodes()");
+ return null;
+ }
+
+ DataNode dataNode = resourceData.dataNodes().get(0);
+ ResourceId parentRid = resourceData.resourceId();
+
+ if (parentRid == null) {
+ parentRid = ResourceId.builder().addBranchPointSchema("/", null).build();
+ dataNode = CodecConverter.removeTopDataNode(dataNode);
+ }
+
+ return convertDataNodeToYangObj(parentRid, dataNode, modelClass);
+ }
+
+ public static <T extends InnerModelObject> T convertDataNodeToYangObj(ResourceId parentRid,
+ DataNode dataNode,
+ Class<T> modelClass) {
+ List<ModelObject> objects = getModelObjects(dataNode, parentRid);
+
+ for (ModelObject obj : objects) {
+ if (modelClass.isInstance(obj)) {
+ return (T) obj;
+ }
+ }
+
+ log.error("ERROR: convertDataNodeToYangObj: conversion failed. parentRid={}, class={}",
+ parentRid, modelClass.getName());
+
+ return null;
+ }
+
+ /**
+ * Returns model objects of the store. The data node read from store
+ * gives the particular node. So the node's parent resource id is taken
+ * and the data node is given to model converter.
+ *
+ * @param dataNode data node from store
+ * @param parentRid parent resource id
+ * @return model objects
+ */
+ public static List<ModelObject> getModelObjects(DataNode dataNode,
+ ResourceId parentRid) {
+ if (dataNode == null || parentRid == null) {
+ log.error("ERROR: getModelObjects: {} is null", dataNode == null ? "dataNode" : "parentRid");
+ return null;
+ }
+
+ ResourceData data = getResourceData(dataNode, parentRid);
+ ModelObjectData modelData = MODEL_CONVERTER.createModel(data);
+ return modelData.modelObjects();
+ }
+}
diff --git a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/RequestId.java b/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/package-info.java
index d875880..90c4bb7 100644
--- a/actn-interface-tools/actn-client/src/main/java/org/onap/integration/actninterfacetools/actnclient/api/RequestId.java
+++ b/actn-interface-tools/yang-utils/src/main/java/org/onap/integration/actninterfacetools/yangutils/package-info.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Actn Interface Tools
* ================================================================================
- * Copyright (C) 2022 Huawei Canada Limited.
+ * Copyright (C) 2023 Huawei Canada Limited.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,8 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
-package org.onap.integration.actninterfacetools.actnclient.api;
-
-public class RequestId {
-}
+/**
+ * The utilities for conversions between TE Topology core subsystem and
+ * IETF TE Topology Yang generated Java code.
+ */
+package org.onap.integration.actninterfacetools.yangutils;