From: Vidyashree Rama Date: Wed, 12 Sep 2018 12:14:19 +0000 (+0530) Subject: Fixed CCVPN closed loop integration issue X-Git-Tag: 1.2.0~1 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=holmes%2Fcommon.git;a=commitdiff_plain;h=5728f2d081afbf4c89d2128ba952200877155f7d Fixed CCVPN closed loop integration issue 1.Service instance will be single instance not list of instances 2.URL for AAI query has to be modified. Issue-ID: HOLMES-166 Change-Id: I205917531f15ece9a32c61bd5bf0e26f1b089c12 Signed-off-by: Vidyashree Rama --- 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 d2208a3..89cc991 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 @@ -14,8 +14,10 @@ package org.onap.holmes.common.aai; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import org.glassfish.jersey.client.HttpUrlConnectorProvider; import org.onap.holmes.common.aai.config.AaiConfig; import org.onap.holmes.common.config.MicroServiceConfig; import org.onap.holmes.common.exception.CorrelationException; @@ -27,9 +29,6 @@ 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 org.glassfish.jersey.client.HttpUrlConnectorProvider; - import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; @@ -76,7 +75,7 @@ public class AaiQuery4Ccvpn { } /** - * Query all the instances related to a terminal point. This method is mainly based on the API: + * Query the service instances related to a terminal point. This method is mainly based on the API: * https://:/aai/v14/network/connectivities?connectivity-id={connectivityId} * and * https://:/aai/v14/business/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type} @@ -86,42 +85,34 @@ public class AaiQuery4Ccvpn { * @param pnfName * @param ifName * @param status - * @return all related service instances in JSONArray format + * @return service instances in JSONObject format */ - public JSONArray getServiceInstances(String networkId, String pnfName, String ifName, String status) { + public JSONObject getServiceInstance(String networkId, String pnfName, String ifName, String status) { try { JSONObject vpnBindingInfo = getVpnBindingInfo(networkId, pnfName, ifName, status); String vpnBindingId = extractValueFromJsonArray(vpnBindingInfo.getJSONArray("relationship-data"), - "vpn-binding.vpn-id"); + "vpn-binding.vpn-id"); JSONObject connectivityInfo = getConnectivityInfo(vpnBindingId); String connectivityId = extractValueFromJsonArray(connectivityInfo.getJSONArray("relationship-data"), "connectivity.connectivity-id"); JSONObject serviceInstanceInfo = getServiceInstanceByConn(connectivityId); String serviceInstancePath = serviceInstanceInfo.getString("related-link"); - serviceInstancePath = serviceInstancePath.substring(0, serviceInstancePath.lastIndexOf('/')); - String[] params = new String[2]; + Response response = get(getHostAddr(), getPath(serviceInstancePath)); + JSONObject instance = JSON.parseObject(response.readEntity(String.class)); - Pattern pattern = Pattern.compile("/aai/v\\d+/business/customers/customer/(.+)/service-subscriptions/service-subscription/(.+)"); + String[] params = new String[2]; + Pattern pattern = Pattern.compile("/aai/v\\d+/business/customers/customer/(.+)" + + "/service-subscriptions/service-subscription/(.+)" + + "/service-instances/service-instance/(.+)"); Matcher matcher = pattern.matcher(serviceInstancePath); if (matcher.find()) { params[0] = matcher.group(1); params[1] = matcher.group(2); } - - Response response = get(getHostAddr(), getPath(serviceInstancePath)); - JSONArray instances = getInstances(response.readEntity(String.class)); - for (int i = 0; i < instances.size(); ++i) { - JSONObject instance = instances.getJSONObject(i); - Response res = get(getHostAddr(), serviceInstancePath + "/service-instances?service-instance-id=" - + instance.getString("service-instance-id")); - String inputParams = JSONObject.parseObject(res.readEntity(String.class)).getString("input-parameters"); - instance.put("input-parameters", inputParams); - instance.put("globalSubscriberId", params[0]); - instance.put("serviceType", params[1]); - } - - return instances; + instance.put("globalSubscriberId", params[0]); + instance.put("serviceType", params[1]); + return instance; } catch (CorrelationException e) { throw new RuntimeException(e.getMessage(), e); } @@ -144,8 +135,10 @@ public class AaiQuery4Ccvpn { 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()); + body.put("link-type", jsonObject.get("link-type").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 params = new HashMap(); @@ -164,16 +157,16 @@ public class AaiQuery4Ccvpn { private JSONObject getServiceInstanceByConn(String connectivityId) throws CorrelationException { Response response = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_SERVICE_INSTANCE_ADDR_4_CCVPN, - "connectivityId", connectivityId)); + "connectivityId", connectivityId)); return getInfo(response.readEntity(String.class), "connectivity", "service-instance"); } - private JSONArray getServiceInstances(String globalCustomerId, String serviceType) throws CorrelationException { + private JSONObject getServiceInstance(String globalCustomerId, String serviceType) throws CorrelationException { Map params = new HashMap(); params.put("global-customer-id", globalCustomerId); params.put("service-type", serviceType); Response response = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_SERVICE_INSTANCES_ADDR_4_CCVPN, params)); - return getInstances(response.readEntity(String.class)); + return JSON.parseObject(response.readEntity(String.class)); } private String getPath(String urlTemplate, Map pathParams) { @@ -206,15 +199,15 @@ public class AaiQuery4Ccvpn { Response response = target.request().headers(getAaiHeaders()).get(); if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { throw new CorrelationException("Failed to connect to AAI. \nCause: " - + response.getStatusInfo().getReasonPhrase() + "\nDetails: \n" - + getErrorMsg(String.format("%s%s", host, path), null, response)); + + response.getStatusInfo().getReasonPhrase() + "\nDetails: \n" + + getErrorMsg(String.format("%s%s", host, path), null, response)); } return response; } catch (CorrelationException e) { throw e; } catch (Exception e) { throw new CorrelationException(e.getMessage() + "More info: " - + getErrorMsg(String.format("%s%s", host, path), null, null), e); + + getErrorMsg(String.format("%s%s", host, path), null, null), e); } } @@ -226,14 +219,14 @@ public class AaiQuery4Ccvpn { .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true).invoke(); if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { throw new CorrelationException("Failed to connect to AAI. \nCause: " - + response.getStatusInfo().getReasonPhrase() + "\nDetails: \n" - + getErrorMsg(String.format("%s%s", host, path), body, response)); + + response.getStatusInfo().getReasonPhrase() + "\nDetails: \n" + + getErrorMsg(String.format("%s%s", host, path), body, response)); } } catch (CorrelationException e) { throw e; } catch (Exception e) { throw new CorrelationException(e.getMessage() + "More info: " - + getErrorMsg(String.format("%s%s", host, path), body, null), e); + + getErrorMsg(String.format("%s%s", host, path), body, null), e); } } @@ -256,14 +249,6 @@ public class AaiQuery4Ccvpn { return null; } - private JSONArray getInstances(String response) { - JSONArray results = extractJsonArray(JSONObject.parseObject(response), "results"); - JSONObject pInterface = extractJsonObject(results.getJSONObject(0), "service-subscription"); - JSONObject serviceInstances = extractJsonObject(pInterface, "service-instances"); - JSONArray instance = extractJsonArray(serviceInstances, "service-instance"); - return instance; - } - private JSONObject extractJsonObject(JSONObject obj, String key) { if (obj != null && key != null && obj.containsKey(key)) { return obj.getJSONObject(key); 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 c16dd24..af1a592 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 @@ -14,7 +14,7 @@ package org.onap.holmes.common.aai.config; public class AaiConfig { - + private static final String AAI_API_VERSION = "v14"; public static final String X_TRANSACTION_ID = "9999"; @@ -30,22 +30,22 @@ public class AaiConfig { + AAI_AUTHENTICATION_PAASWORD; return "Basic " + java.util.Base64.getEncoder().encodeToString(usernameAndPassword.getBytes()); } - + public static class AaiConsts { private static final String AAI_PREF = "/aai/"; - + 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/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/nodeId-{pnfName}-ltpId-{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_QUERY = AAI_PREF + AAI_API_VERSION + "/network/pnfs/pnf/{pnfName}/p-interfaces/p-interface/nodeId-{pnfName}-ltpId-{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/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{ifName}"; + public static final String AAI_VPN_ADDR = AAI_PREF + AAI_API_VERSION + "/network/pnfs/pnf/{pnfName}/p-interfaces/p-interface/nodeId-{pnfName}-ltpId-{ifName}"; public static final String AAI_CONN_ADDR = AAI_PREF + AAI_API_VERSION + "/network/vpn-bindings/vpn-binding/{vpnId}"; @@ -55,36 +55,34 @@ public class AaiConfig { public static final String AAI_VM_ADDR = AAI_PREF + AAI_API_VERSION + "/search/nodes-query?search-node-type=vserver&filter="; } - + public static class MsbConsts { - private static final String AAI_MSB_PREF = "/api"; - - private static final String AAI_NETWORK = "/aai-network/"; - + private static final String AAI_NETWORK = "/aai/"; + private static final String AAI_BUSINESS = "/aai-business/"; - + private static final String AAI_SEARCH = "/aai-search/"; - - 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/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{ifName}"; + public static final String AAI_VNF_ADDR = AAI_NETWORK + AAI_API_VERSION + "/generic-vnfs/generic-vnf"; + + public static final String AAI_TP_UPDATE = AAI_NETWORK + AAI_API_VERSION + "/network/pnfs/pnf/{pnfName}/p-interfaces/p-interface/nodeId-{pnfName}-ltpId-{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_QUERY = AAI_NETWORK + AAI_API_VERSION + "/network/pnfs/pnf/{pnfName}/p-interfaces/p-interface/nodeId-{pnfName}-ltpId-{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_LINK_UPDATE = AAI_NETWORK + AAI_API_VERSION + "/network/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_TP_ADDR = 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/pnfs/pnf/{pnfName}/p-interfaces/p-interface/{ifName}"; + public static final String AAI_VPN_ADDR = AAI_NETWORK + AAI_API_VERSION + "/network/pnfs/pnf/{pnfName}/p-interfaces/p-interface/nodeId-{pnfName}-ltpId-{ifName}"; - 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_CONN_ADDR = 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 + "/network/connectivities/connectivity/{connectivityId}"; + public static final String AAI_SERVICE_INSTANCE_ADDR_4_CCVPN = 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}"; + public static final String AAI_SERVICE_INSTANCES_ADDR_4_CCVPN = AAI_BUSINESS + AAI_API_VERSION + "/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}"; - public static final String AAI_VM_ADDR = AAI_MSB_PREF + AAI_SEARCH + AAI_API_VERSION + "/nodes-query?search-node-type=vserver&filter="; + public static final String AAI_VM_ADDR = AAI_SEARCH + AAI_API_VERSION + "/nodes-query?search-node-type=vserver&filter="; } } 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 c094e4f..b75e61d 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 @@ -14,7 +14,6 @@ package org.onap.holmes.common.aai; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.easymock.EasyMock; import org.glassfish.jersey.client.HttpUrlConnectorProvider; @@ -194,16 +193,16 @@ public class AaiQuery4CcvpnTest { PowerMock.replayAll(); - JSONArray instances = aai.getServiceInstances("network-1", "pnf-1", "interface-1", "DOWN"); + JSONObject instance = aai.getServiceInstance("network-1", "pnf-1", "interface-1", "DOWN"); PowerMock.verifyAll(); - assertThat(instances, equalTo("logic-link-1")); + assertThat(instance, equalTo("logic-link-1")); } @Test - public void test_getServiceInstances() { + public void test_getServiceInstance() { mockGetMethod(); EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("vpn-binding").toJSONString()); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); @@ -222,32 +221,19 @@ public class AaiQuery4CcvpnTest { .andReturn(data.getJSONObject("service-instances-by-service-type").toJSONString()); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); - mockGetMethod(); - EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("service-instance").toString()); - EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); - mockGetMethod(); - EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("service-instance").toString()); - EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); - mockGetMethod(); - EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("service-instance").toString()); - EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK); - PowerMock.replayAll(); - JSONArray instances = aai.getServiceInstances("network-1", "pnf-1", "interface-1", "DOWN"); + JSONObject instance = aai.getServiceInstance("network-1", "pnf-1", "interface-1", "DOWN"); PowerMock.verifyAll(); - assertThat(instances.getJSONObject(0).getString("service-instance-id"), equalTo("some id 1")); - assertThat(instances.getJSONObject(1).getString("service-instance-id"), equalTo("some id 2")); - assertThat(instances.getJSONObject(2).getString("service-instance-id"), equalTo("some id 3")); - assertThat(instances.getJSONObject(0).getString("input-parameters"), equalTo("This is the service instance recreation input looked up by CL.")); - assertThat(instances.getJSONObject(0).getString("globalSubscriberId"), equalTo("e151059a-d924-4629-845f-264db19e50b4")); - assertThat(instances.getJSONObject(0).getString("serviceType"), equalTo("volte")); + assertThat(instance.getString("service-instance-id"), equalTo("some id 1")); + assertThat(instance.getString("globalSubscriberId"), equalTo("e151059a-d924-4629-845f-264db19e50b4")); + assertThat(instance.getString("serviceType"), equalTo("volte")); } @Test - public void test_getServiceInstances_1() throws Exception { + public void test_getServiceInstance_1() throws Exception { mockGetMethod(); EasyMock.expect(response.readEntity(String.class)) .andReturn(data.getJSONObject("service-instances-by-service-type").toJSONString()); @@ -255,18 +241,16 @@ public class AaiQuery4CcvpnTest { PowerMock.replayAll(); - JSONArray instances = (JSONArray) Whitebox.invokeMethod(aai, "getServiceInstances", - "custom-1", "service-type-1"); + JSONObject instance = Whitebox.invokeMethod(aai, "getServiceInstance", + "custom-1", "service-type-1"); PowerMock.verifyAll(); - assertThat(instances.getJSONObject(0).getString("service-instance-id"), equalTo("some id 1")); - assertThat(instances.getJSONObject(1).getString("service-instance-id"), equalTo("some id 2")); - assertThat(instances.getJSONObject(2).getString("service-instance-id"), equalTo("some id 3")); + assertThat(instance.getString("service-instance-id"), equalTo("some id 1")); } @Test - public void test_getServiceInstances_1_exception() throws Exception { + public void test_getServiceInstance_1_exception() throws Exception { mockGetMethod(); EasyMock.expect(response.readEntity(String.class)).andReturn("Failed to get the service instance by type."); EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2); @@ -275,14 +259,14 @@ public class AaiQuery4CcvpnTest { PowerMock.replayAll(); - JSONArray instances = (JSONArray) Whitebox.invokeMethod(aai, "getServiceInstances", - "custom-1", "service-type-1"); + JSONObject instance = Whitebox.invokeMethod(aai, "getServiceInstance", + "custom-1", "service-type-1"); PowerMock.verifyAll(); - assertThat(instances.getJSONObject(0).getString("service-instance-id"), equalTo("some id 1")); - assertThat(instances.getJSONObject(1).getString("service-instance-id"), equalTo("some id 2")); - assertThat(instances.getJSONObject(2).getString("service-instance-id"), equalTo("some id 3")); + assertThat(instance.getString("service-instance-id"), equalTo("some id 1")); + assertThat(instance.getString("service-instance-id"), equalTo("some id 2")); + assertThat(instance.getString("service-instance-id"), equalTo("some id 3")); } @Test diff --git a/holmes-actions/src/test/resources/ccvpn.data.json b/holmes-actions/src/test/resources/ccvpn.data.json index 773b91b..5f47cd1 100644 --- a/holmes-actions/src/test/resources/ccvpn.data.json +++ b/holmes-actions/src/test/resources/ccvpn.data.json @@ -1,5 +1,6 @@ { "resource-version": "1536316872154", + "link-type": "VL", "logic-link": { "p-interface": { "interface-name": "{ifName}", @@ -98,7 +99,7 @@ "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", + "related-link": "/aai/v14/business/customers/customer/e151059a-d924-4629-845f-264db19e50b4/service-subscriptions/service-subscription/volte/service-instances/service-instance/service-1", "relationship-data": [ { "relationship-key": "service-instance.service-instance-id", @@ -111,52 +112,14 @@ } }, "service-instances-by-service-type": { - "results": [ - { - "service-subscription": { - "service-type": "volte", - "temp-ub-sub-account-id": "some sub account", - "service-instances": { - "service-instance": [ - { - "service-instance-id": "some id 1", - "service-instance-name": "some name 1", - "environment-context": "some context 1", - "workload-context": "some workload 1", - "relationship-list": { - "relationship": [ - ] - } - }, - { - "service-instance-id": "some id 2", - "service-instance-name": "some name 2", - "environment-context": "some context 2", - "workload-context": "some workload 2", - "relationship-list": { - "relationship": [ - ] - } - }, - { - "service-instance-id": "some id 3", - "service-instance-name": "some name 3", - "environment-context": "some context 3", - "workload-context": "some workload 3", - "relationship-list": { - "relationship": [ - ] - } - } - ] - }, - "relationship-list": { - "relationship": [ - ] - } - } - } - ] + "service-instance-id": "some id 1", + "service-instance-name": "some name 1", + "environment-context": "some context 1", + "workload-context": "some workload 1", + "relationship-list": { + "relationship": [ + ] + } }, "service-instance": { "service-instance-id": "176d9eba-1662-4289-8396-0097b50fd485",