diff options
author | rama-huawei <rama.subba.reddy.s@huawei.com> | 2018-09-07 17:37:19 +0530 |
---|---|---|
committer | rama-huawei <rama.subba.reddy.s@huawei.com> | 2018-09-07 18:53:29 +0530 |
commit | 904bb036bbcf1fb0e2ac5bc30cde7bfa94dd5de0 (patch) | |
tree | eda6eba40c9ac0b6b4561e3f8b6a9a099ee59771 /holmes-actions/src | |
parent | 310a77fb3e99c4057b80098d0bcec7ecda62680d (diff) |
Fixed integration issues for CCVPN usecase
1) Currently holmes is updating the AAI record without resource-version
2) Also corrected some of the AAI URL's
Issue-ID: HOLMES-164
Change-Id: I7b0ba5cc786e57a282ee917bed07030dd9e74678
Signed-off-by: rama-huawei <rama.subba.reddy.s@huawei.com>
Diffstat (limited to 'holmes-actions/src')
4 files changed, 142 insertions, 122 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java index 3e056d5..d2208a3 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java @@ -95,7 +95,7 @@ public class AaiQuery4Ccvpn { "vpn-binding.vpn-id"); JSONObject connectivityInfo = getConnectivityInfo(vpnBindingId); String connectivityId = extractValueFromJsonArray(connectivityInfo.getJSONArray("relationship-data"), - "connectivity. connectivity-id"); + "connectivity.connectivity-id"); JSONObject serviceInstanceInfo = getServiceInstanceByConn(connectivityId); String serviceInstancePath = serviceInstanceInfo.getString("related-link"); serviceInstancePath = serviceInstancePath.substring(0, serviceInstancePath.lastIndexOf('/')); @@ -133,14 +133,19 @@ public class AaiQuery4Ccvpn { params.put("networkId", networkId); params.put("pnfName", pnfName); params.put("ifName", ifName); - patch(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_TP_UPDATE, params), body); + Response r = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_TP_UPDATE, params)); + JSONObject jsonObject = JSONObject.parseObject(r.readEntity(String.class)); + body.put("resource-version", jsonObject.get("resource-version").toString()); + + put(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_TP_UPDATE, params), body); } public void updateLogicLinkStatus(String linkName, Map<String, Object> body) throws CorrelationException { - patch(getHostAddr(), - getPath(AaiConfig.MsbConsts.AAI_TP_UPDATE, "linkName", linkName), body); + Response r = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_LINK_UPDATE, "linkName", linkName)); + JSONObject jsonObject = JSONObject.parseObject(r.readEntity(String.class)); + body.put("resource-version", jsonObject.get("resource-version").toString()); + put(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_LINK_UPDATE, "linkName", linkName), body); } - private JSONObject getVpnBindingInfo(String networkId, String pnfName, String ifName, String status) throws CorrelationException { Map<String, String> params = new HashMap(); @@ -213,11 +218,11 @@ public class AaiQuery4Ccvpn { } } - private void patch(String host, String path, Map<String, Object> body) throws CorrelationException { + private void put(String host, String path, Map<String, Object> body) throws CorrelationException { Client client = ClientBuilder.newClient(); WebTarget target = client.target(host).path(path); try { - Response response = target.request().headers(getAaiHeaders()).build("PATCH", Entity.json(body)) + Response response = target.request().headers(getAaiHeaders()).build("PUT", Entity.json(body)) .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true).invoke(); if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { throw new CorrelationException("Failed to connect to AAI. \nCause: " @@ -233,8 +238,11 @@ public class AaiQuery4Ccvpn { } private JSONObject getInfo(String response, String pField, String field) { - JSONArray results = extractJsonArray(JSONObject.parseObject(response), "results"); - JSONObject pInterface = extractJsonObject(results.getJSONObject(0), pField); + JSONObject jObject = JSONObject.parseObject(response); + JSONObject pInterface = extractJsonObject(jObject, pField); + if (pInterface == null) { + pInterface = jObject; + } JSONObject relationshipList = extractJsonObject(pInterface, "relationship-list"); JSONArray relationShip = extractJsonArray(relationshipList, "relationship"); if (relationShip != null) { diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/config/AaiConfig.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/config/AaiConfig.java index f1b3e21..c16dd24 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/config/AaiConfig.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/config/AaiConfig.java @@ -37,17 +37,17 @@ public class AaiConfig { public static final String AAI_VNF_ADDR = AAI_PREF + AAI_API_VERSION + "/network/generic-vnfs/generic-vnf"; - public static final String AAI_TP_UPDATE = AAI_PREF + AAI_API_VERSION + "/network/network-resources/network-resource/{networkId}/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{ifName}"; + public static final String AAI_TP_UPDATE = AAI_PREF + AAI_API_VERSION + "/network/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{ifName}"; - public static final String AAI_LINK_QUERY = AAI_PREF + AAI_API_VERSION + "/network-resources/network-resource/{networkId}/pnfs/pnf/{pnfName}/p-interfaces?interface-name={ifName}"; + public static final String AAI_LINK_QUERY = AAI_PREF + AAI_API_VERSION + "/network/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{ifName}"; public static final String AAI_LINK_UPDATE = AAI_PREF + AAI_API_VERSION + "/network/logical-links/logical-link/{linkName}"; public static final String AAI_TP_ADDR = AAI_PREF + AAI_API_VERSION + "/network/pnfs/pnf/{node-Id}/p-interfaces/p-interface/{tp-id}"; - public static final String AAI_VPN_ADDR = AAI_PREF + AAI_API_VERSION + "/network/network-resources/network-resource/{networkId}/pnfs/pnf/{pnfName}/p-interfaces?interface-name={ifName}&operational-status={status}"; + public static final String AAI_VPN_ADDR = AAI_PREF + AAI_API_VERSION + "/network/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{ifName}"; - public static final String AAI_CONN_ADDR =AAI_PREF + AAI_API_VERSION + "/network/vpn-bindings?vpn-id={vpnId}"; + public static final String AAI_CONN_ADDR = AAI_PREF + AAI_API_VERSION + "/network/vpn-bindings/vpn-binding/{vpnId}"; public static final String AAI_SERVICE_INSTANCE_ADDR_4_CCVPN = AAI_PREF + AAI_API_VERSION + "/network/connectivities/connectivity/{connectivityId}"; @@ -69,19 +69,19 @@ public class AaiConfig { public static final String AAI_VNF_ADDR = AAI_MSB_PREF + AAI_NETWORK + AAI_API_VERSION + "/generic-vnfs/generic-vnf"; - public static final String AAI_TP_UPDATE = AAI_MSB_PREF + AAI_NETWORK + AAI_API_VERSION + "/network-resources/network-resource/{networkId}/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{ifName}"; + public static final String AAI_TP_UPDATE = AAI_MSB_PREF + AAI_NETWORK + AAI_API_VERSION + "/network/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{ifName}"; - public static final String AAI_LINK_QUERY = AAI_MSB_PREF + AAI_NETWORK + AAI_API_VERSION + "/network-resources/network-resource/{networkId}/pnfs/pnf/{pnfName}/p-interfaces?interface-name={ifName}"; + public static final String AAI_LINK_QUERY = AAI_MSB_PREF + AAI_NETWORK + AAI_API_VERSION + "/network/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{ifName}"; public static final String AAI_LINK_UPDATE = AAI_MSB_PREF + AAI_NETWORK + AAI_API_VERSION + "/logical-links/logical-link/{linkName}"; public static final String AAI_TP_ADDR = AAI_MSB_PREF + AAI_NETWORK + AAI_API_VERSION + "/pnfs/pnf/{node-Id}/p-interfaces/p-interface/{tp-id}"; - public static final String AAI_VPN_ADDR = AAI_MSB_PREF + AAI_NETWORK + AAI_API_VERSION + "/network-resources/network-resource/{networkId}/pnfs/pnf/{pnfName}/p-interfaces?interface-name={ifName}&operational-status={status}"; + public static final String AAI_VPN_ADDR = AAI_MSB_PREF + AAI_NETWORK + AAI_API_VERSION + "/network/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{ifName}"; - public static final String AAI_CONN_ADDR =AAI_MSB_PREF + AAI_NETWORK + AAI_API_VERSION + "/vpn-bindings?vpn-id={vpnId}"; + public static final String AAI_CONN_ADDR = AAI_MSB_PREF + AAI_NETWORK + AAI_API_VERSION + "/network/vpn-bindings/vpn-binding/{vpnId}"; - public static final String AAI_SERVICE_INSTANCE_ADDR_4_CCVPN = AAI_MSB_PREF + AAI_NETWORK + AAI_API_VERSION + "/connectivities/connectivity/{connectivityId}"; + public static final String AAI_SERVICE_INSTANCE_ADDR_4_CCVPN = AAI_MSB_PREF + AAI_NETWORK + AAI_API_VERSION + "/network/connectivities/connectivity/{connectivityId}"; public static final String AAI_SERVICE_INSTANCES_ADDR_4_CCVPN = AAI_MSB_PREF + AAI_BUSINESS + AAI_API_VERSION + "/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}"; diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java index 52593aa..c094e4f 100644 --- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java +++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java @@ -18,7 +18,11 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.easymock.EasyMock; import org.glassfish.jersey.client.HttpUrlConnectorProvider; -import org.junit.*; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.onap.holmes.common.aai.config.AaiConfig; @@ -28,16 +32,23 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; -import javax.ws.rs.client.*; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation; import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; -import java.util.Map; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; @@ -245,7 +256,7 @@ public class AaiQuery4CcvpnTest { PowerMock.replayAll(); JSONArray instances = (JSONArray) Whitebox.invokeMethod(aai, "getServiceInstances", - "custom-1", "service-type-1"); + "custom-1", "service-type-1"); PowerMock.verifyAll(); @@ -265,7 +276,7 @@ public class AaiQuery4CcvpnTest { PowerMock.replayAll(); JSONArray instances = (JSONArray) Whitebox.invokeMethod(aai, "getServiceInstances", - "custom-1", "service-type-1"); + "custom-1", "service-type-1"); PowerMock.verifyAll(); @@ -276,6 +287,10 @@ public class AaiQuery4CcvpnTest { @Test public void test_updateTerminalPointStatus() throws CorrelationException { + mockGetMethod(); + EasyMock.expect(response.readEntity(String.class)).andReturn(data.toJSONString()); + EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); + mockPatchMethod(); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); @@ -288,6 +303,10 @@ public class AaiQuery4CcvpnTest { @Test public void test_updateTerminalPointStatus_exception() throws CorrelationException { + mockGetMethod(); + EasyMock.expect(response.readEntity(String.class)).andReturn(data.toJSONString()); + EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); + mockPatchMethod(); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2); EasyMock.expect(response.readEntity(String.class)).andReturn("Failed to update the TP information."); @@ -303,6 +322,10 @@ public class AaiQuery4CcvpnTest { @Test public void test_updateLogicLinkStatus() throws CorrelationException { + mockGetMethod(); + EasyMock.expect(response.readEntity(String.class)).andReturn(data.toJSONString()); + EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); + mockPatchMethod(); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); @@ -315,6 +338,10 @@ public class AaiQuery4CcvpnTest { @Test public void test_updateLogicLinkStatus_exception() throws CorrelationException { + mockGetMethod(); + EasyMock.expect(response.readEntity(String.class)).andReturn(data.toJSONString()); + EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); + mockPatchMethod(); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2); EasyMock.expect(response.readEntity(String.class)).andReturn("Failed to update the logic link information."); diff --git a/holmes-actions/src/test/resources/ccvpn.data.json b/holmes-actions/src/test/resources/ccvpn.data.json index d60aae5..773b91b 100644 --- a/holmes-actions/src/test/resources/ccvpn.data.json +++ b/holmes-actions/src/test/resources/ccvpn.data.json @@ -1,129 +1,114 @@ { + "resource-version": "1536316872154", "logic-link": { - "results": [ - { - "p-interface": { - "interface-name": "{ifName}", - "network-ref": "some ref", - "transparent": "some value", - "operational-status ": "{status}", - "speed-value": "some speed", - "relationship-list": { - "relationship": [ + "p-interface": { + "interface-name": "{ifName}", + "network-ref": "some ref", + "transparent": "some value", + "operational-status ": "{status}", + "speed-value": "some speed", + "relationship-list": { + "relationship": [ + { + "related-to": "logical-link", + "related-link": "url of logical-link", + "relationship-data": [ { - "related-to": "logical-link", - "related-link": "url of logical-link", - "relationship-data": [ - { - "relationship-key": "logical-link.link-name", - "relationship-value": "logic-link-1" - } - ] + "relationship-key": "logical-link.link-name", + "relationship-value": "logic-link-1" } ] } - } + ] } - ] + } }, "vpn-binding": { - "results": [ - { - "p-interface": { - "interface-name": "{ifName}", - "network-ref": "some ref", - "transparent": "some value", - "operational-status ": "{status}", - "speed-value": "some speed", - "relationship-list": { - "relationship": [ + "p-interface": { + "interface-name": "{ifName}", + "network-ref": "some ref", + "transparent": "some value", + "operational-status ": "{status}", + "speed-value": "some speed", + "relationship-list": { + "relationship": [ + { + "related-to": "vpn-binding", + "related-link": "url of vpn-binding", + "relationship-data": [ { - "related-to": "vpn-binding", - "related-link": "url of vpn-binding", - "relationship-data": [ - { - "relationship-key": "vpn-binding.vpn-id", - "relationship-value": "some id" - } - ] + "relationship-key": "vpn-binding.vpn-id", + "relationship-value": "some id" } ] } - } + ] } - ] + } }, "connectivity": { - "results": [ - { - "vpn-binding": { - "vpn-id": "{vpnId}", - "vpn-name": "some name", - "access-provider-id": "provider id", - "access-client-id": "client id", - "access-topology-id": "topology id", - "src-access-node-id": "src node id", - "src-access-ltp-id": "src ltp id", - "dst-access-node-id": "dst node id", - "dst-access-ltp-id": "dst ltp id", - "operational-status": "some status", - "relationship-list": { - "relationship": [ + "vpn-binding": { + "vpn-id": "{vpnId}", + "vpn-name": "some name", + "access-provider-id": "provider id", + "access-client-id": "client id", + "access-topology-id": "topology id", + "src-access-node-id": "src node id", + "src-access-ltp-id": "src ltp id", + "dst-access-node-id": "dst node id", + "dst-access-ltp-id": "dst ltp id", + "operational-status": "some status", + "relationship-list": { + "relationship": [ + { + "related-to": "connectivity", + "related-link": "url of connectivity", + "relationship-data": [ { - "related-to": "connectivity", - "related-link": "url of connectivity", - "relationship-data": [ - { - "relationship-key": "connectivity. connectivity-id", - "relationship-value": "some id" - } - ] + "relationship-key": "connectivity.connectivity-id", + "relationship-value": "some id" } ] } - } + ] } - ] + } }, "service-instance-by-connectivity": { - "results": [ - { - "connectivity": { - "connectivity-id": "{connectivityId}", - "bandwidth-profile-name": "some profile", - "vpn-type": "some type", - "cir": "cir value", - "eir": "eir value", - "cbs": "cbs value", - "ebs": "ebs value", - "color-aware": "color value", - "coupling-flag": "flag value", - "etht-svc-name": "some name", - "access-provider-id": "provider id", - "access-client-id": "client id", - "access-topology-id": "topology id", - "access-node-id": "node id", - "access-ltp-id": "ltp id", - "connectivity-selflink": "some URL", - "cvlan ": "some tag", - "operational-status": "some status", - "relationship-list": { - "relationship": [ + "connectivity": { + "connectivity-id": "{connectivityId}", + "bandwidth-profile-name": "some profile", + "vpn-type": "some type", + "cir": "cir value", + "eir": "eir value", + "cbs": "cbs value", + "ebs": "ebs value", + "color-aware": "color value", + "coupling-flag": "flag value", + "etht-svc-name": "some name", + "access-provider-id": "provider id", + "access-client-id": "client id", + "access-topology-id": "topology id", + "access-node-id": "node id", + "access-ltp-id": "ltp id", + "connectivity-selflink": "some URL", + "cvlan ": "some tag", + "operational-status": "some status", + "relationship-list": { + "relationship": [ + { + "related-to": "service-instance", + "related-link": "/aai/v14/business/customers/customer/e151059a-d924-4629-845f-264db19e50b4/service-subscriptions/service-subscription/volte/service-instances?service-instance-id=service-1", + "relationship-data": [ { - "related-to": "service-instance", - "related-link": "/aai/v14/business/customers/customer/e151059a-d924-4629-845f-264db19e50b4/service-subscriptions/service-subscription/volte/service-instances?service-instance-id=service-1", - "relationship-data": [ - { - "relationship-key": "service-instance.service-instance-id", - "relationship-value": "some id" - } - ] + "relationship-key": "service-instance.service-instance-id", + "relationship-value": "some id" } ] } - } + ] } - ] + } }, "service-instances-by-service-type": { "results": [ |