diff options
author | 2018-08-23 18:04:32 +0800 | |
---|---|---|
committer | 2018-08-23 18:04:32 +0800 | |
commit | 862e94760bdc0d628236f7222dda5cb7bfa28297 (patch) | |
tree | 457e9692a5958eb07fc06f59cfda267cc49f9c4a /holmes-actions/src/main/java/org/onap | |
parent | 6965c239c338bd8b9e16cdcdd2bf9e4ee3ff22fb (diff) |
Add Several Fields to the AAI section
Change-Id: Idda04e81398fa049027df47ac581d755d3194f06
Issue-ID: HOLMES-160
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/main/java/org/onap')
-rw-r--r-- | holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java | 34 |
1 files changed, 30 insertions, 4 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); } |