From c4814252e8ef58dde843824d1c4d57ea708a961e Mon Sep 17 00:00:00 2001 From: as221v Date: Mon, 9 Sep 2019 17:56:41 +0300 Subject: Reduce vnf data response from A&AI in change management flows Issue-ID: VID-596 Signed-off-by: Amir Skalka Change-Id: I4462ef0c2dbc9880d1a0d204f6552e3842aad821 Signed-off-by: Alexey Sandler --- .../src/main/java/org/onap/vid/aai/AaiClient.java | 52 +++++++++++++++++++--- 1 file changed, 45 insertions(+), 7 deletions(-) (limited to 'vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java') 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 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 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 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 params){ int i = 0; for(String param: params){ -- cgit 1.2.3-korg