summaryrefslogtreecommitdiffstats
path: root/holmes-actions/src
diff options
context:
space:
mode:
Diffstat (limited to 'holmes-actions/src')
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java34
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java19
-rw-r--r--holmes-actions/src/test/resources/ccvpn.data.json33
3 files changed, 79 insertions, 7 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 0e28ff9..103f242 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
@@ -17,7 +17,6 @@ package org.onap.holmes.common.aai;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
-import lombok.extern.slf4j.Slf4j;
import org.onap.holmes.common.aai.config.AaiConfig;
import org.onap.holmes.common.config.MicroServiceConfig;
import org.onap.holmes.common.exception.CorrelationException;
@@ -34,12 +33,15 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-@Slf4j
public class AaiQuery4Ccvpn {
private MultivaluedMap<String, Object> headers;
- public AaiQuery4Ccvpn() {
+ static public AaiQuery4Ccvpn newInstance() {
+ return new AaiQuery4Ccvpn();
+ }
+
+ private AaiQuery4Ccvpn() {
headers = new MultivaluedHashMap<>();
headers.add("X-TransactionId", AaiConfig.X_TRANSACTION_ID);
headers.add("X-FromAppId", AaiConfig.X_FROMAPP_ID);
@@ -99,12 +101,36 @@ public class AaiQuery4Ccvpn {
String serviceInstancePath = serviceInstanceInfo.getString("related-link");
serviceInstancePath = serviceInstancePath.substring(0, serviceInstancePath.lastIndexOf('/'));
+ String[] params = new String[2];
+
+ Pattern pattern = Pattern.compile("/aai/v\\d+/business/customers/customer/(.+)/service-subscriptions/service-subscription/(.+)");
+ Matcher matcher = pattern.matcher(serviceInstancePath);
+ if (matcher.find()) {
+ params[0] = matcher.group(1);
+ params[1] = matcher.group(2);
+ }
+
Response response = get(getHostAddr(), getPath(serviceInstancePath));
if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
throw new RuntimeException("Failed to connect to AAI. Cause: "
+ response.getStatusInfo().getReasonPhrase());
}
- return getInstances(JSONObject.toJSONString(response.getEntity()));
+ JSONArray instances = getInstances(JSONObject.toJSONString(response.getEntity()));
+ 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"));
+ if (res.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
+ throw new RuntimeException("Failed to connect to AAI. Cause: "
+ + response.getStatusInfo().getReasonPhrase());
+ }
+ String inputParams = JSONObject.parseObject(response.readEntity(String.class)).getString("input-parameters");
+ instance.put("input-parameters", inputParams);
+ instance.put("globalSubscriberId", params[0]);
+ instance.put("serviceType", params[1]);
+ }
+
+ return instances;
} catch (CorrelationException e) {
throw new RuntimeException(e.getMessage(), e);
}
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 c7c32eb..ef12982 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
@@ -51,7 +51,7 @@ public class AaiQuery4CcvpnTest {
private static JSONObject data;
- private static AaiQuery4Ccvpn aai = new AaiQuery4Ccvpn();
+ private static AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance();
private static MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
private static Client client;
@@ -169,6 +169,10 @@ public class AaiQuery4CcvpnTest {
EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("service-instances-by-service-type"));
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2);
+ mockGetMethod();
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("service-instance").toString());
+ EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2);
+
thrown.expect(RuntimeException.class);
PowerMock.replayAll();
@@ -199,6 +203,16 @@ public class AaiQuery4CcvpnTest {
EasyMock.expect(response.getEntity()).andReturn(data.getJSONObject("service-instances-by-service-type"));
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");
@@ -208,6 +222,9 @@ public class AaiQuery4CcvpnTest {
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"));
}
@Test
diff --git a/holmes-actions/src/test/resources/ccvpn.data.json b/holmes-actions/src/test/resources/ccvpn.data.json
index ecdb7d5..d60aae5 100644
--- a/holmes-actions/src/test/resources/ccvpn.data.json
+++ b/holmes-actions/src/test/resources/ccvpn.data.json
@@ -111,7 +111,7 @@
"relationship": [
{
"related-to": "service-instance",
- "related-link": "/aai/v14/business/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/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-id=service-1",
"relationship-data": [
{
"relationship-key": "service-instance.service-instance-id",
@@ -129,7 +129,7 @@
"results": [
{
"service-subscription": {
- "service-type": "{service-type}",
+ "service-type": "volte",
"temp-ub-sub-account-id": "some sub account",
"service-instances": {
"service-instance": [
@@ -172,5 +172,34 @@
}
}
]
+ },
+ "service-instance": {
+ "service-instance-id": "176d9eba-1662-4289-8396-0097b50fd485",
+ "service-type": "E2E Service",
+ "service-role": "E2E Service",
+ "model-invariant-id": "c22a9483-d2b6-49cc-b1f7-ef34c93572a1",
+ "model-version-id": "71d0e396-e246-4c23-aa57-6da2043d6209",
+ "input-parameters": "This is the service instance recreation input looked up by CL.",
+ "resource-version": "1528975017336",
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "pnf",
+ "related-link": "/aai/v11/network/pnfs/pnf/MME-0001",
+ "relationship-data": [
+ {
+ "relationship-key": "pnf.pnf-id",
+ "relationship-value": "176d9eba-1662-4289-8396-0097b50fd466"
+ }
+ ],
+ "related-to-property": [
+ {
+ "property-key": "pnf.pnf-name",
+ "property-value": "MME-0001"
+ }
+ ]
+ }
+ ]
+ }
}
} \ No newline at end of file