aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
diff options
context:
space:
mode:
authoras221v <as221v@intl.att.com>2019-09-09 17:56:41 +0300
committerAlexey Sandler <alexey.sandler@intl.att.com>2019-09-12 15:55:52 +0300
commitc4814252e8ef58dde843824d1c4d57ea708a961e (patch)
treeb870ffa4e3fbc4791b87fcbc2815a6dec7f97276 /vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
parent2609cc76f0565466667fff8ae4d0707b94993877 (diff)
Reduce vnf data response from A&AI in change management flows
Issue-ID: VID-596 Signed-off-by: Amir Skalka <as221v@intl.att.com> Change-Id: I4462ef0c2dbc9880d1a0d204f6552e3842aad821 Signed-off-by: Alexey Sandler <alexey.sandler@intl.att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java52
1 files changed, 45 insertions, 7 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
index c43779df1..c82f5485e 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
@@ -27,10 +27,15 @@ import static java.util.stream.Collectors.toMap;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
import static org.apache.commons.lang3.StringUtils.isEmpty;
+import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import java.io.IOException;
+import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
@@ -44,10 +49,12 @@ import javax.inject.Inject;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.http.HttpStatus;
import org.apache.http.client.utils.URIBuilder;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@@ -281,6 +288,36 @@ public class AaiClient implements AaiClientInterface {
.collect(toMap(SimpleResult::getNodeType, SimpleResult::getProperties));
}
+ @Override
+ public AaiResponse getVnfsByParamsForChangeManagement(String subscriberId, String serviceType, @Nullable String nfRole,
+ @Nullable String cloudRegion) {
+ String payloadAsString = "";
+ ResponseWithRequestInfo response;
+ ImmutableMap<String, Serializable> payload = getMapForAAIQueryByParams(subscriberId, serviceType,
+ nfRole, cloudRegion);
+ try {
+ payloadAsString = JACKSON_OBJECT_MAPPER.writeValueAsString(payload);
+ } catch (JsonProcessingException e) {
+ logger.error(e.getMessage());
+ ExceptionUtils.rethrow(e);
+ }
+ response = doAaiPut(QUERY_FORMAT_SIMPLE, payloadAsString, false, false);
+ AaiResponseWithRequestInfo aaiResponse = processAaiResponse(response, JsonNode.class, false);
+ verifyAaiResponseValidityOrThrowExc(aaiResponse, aaiResponse.getAaiResponse().getHttpCode());
+ return aaiResponse.getAaiResponse();
+ }
+
+ private ImmutableMap<String, Serializable> getMapForAAIQueryByParams(String subscriberId,
+ String serviceType, @Nullable String nfRole, @Nullable String cloudRegion) {
+ String nfRoleParam = nfRole != null ? "?nfRole=" + nfRole : "";
+ String query = "query/vnfs-fromServiceInstance-filter" + nfRoleParam;
+ return ImmutableMap.of(
+ "start", ImmutableList
+ .of("/business/customers/customer/" + subscriberId + "/service-subscriptions/service-subscription/" + serviceType + "/service-instances"),
+ "query", query
+ );
+ }
+
private boolean isResourceExistByStatusCode(ResponseWithRequestInfo responseWithRequestInfo) {
// 200 - is found
// 404 - resource not found
@@ -315,19 +352,20 @@ public class AaiClient implements AaiClientInterface {
}
final AaiResponseWithRequestInfo<T> aaiResponse = processAaiResponse(responseWithRequestInfo, clz, VidObjectMapperType.FASTERXML, true);
+ verifyAaiResponseValidityOrThrowExc(aaiResponse, responseWithRequestInfo.getResponse().getStatus());
+ return aaiResponse.getAaiResponse().getT();
+ }
+ private void verifyAaiResponseValidityOrThrowExc(AaiResponseWithRequestInfo aaiResponse, int httpCode) {
if (aaiResponse.getAaiResponse().getHttpCode() > 399 || aaiResponse.getAaiResponse().getT() == null) {
throw new ExceptionWithRequestInfo(aaiResponse.getHttpMethod(),
- aaiResponse.getRequestedUrl(),
- aaiResponse.getRawData(),
- responseWithRequestInfo.getResponse().getStatus(),
- new InvalidAAIResponseException(aaiResponse.getAaiResponse()));
+ aaiResponse.getRequestedUrl(),
+ aaiResponse.getRawData(),
+ httpCode,
+ new InvalidAAIResponseException(aaiResponse.getAaiResponse()));
}
-
- return aaiResponse.getAaiResponse().getT();
}
-
private String getUrlFromLIst(String url, String paramKey, List<String> params){
int i = 0;
for(String param: params){