diff options
Diffstat (limited to 'vid-app-common/src/main')
5 files changed, 80 insertions, 18 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){ diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java index 1350461b0..8c3c66d17 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java @@ -21,6 +21,10 @@ package org.onap.vid.aai; import com.fasterxml.jackson.databind.JsonNode; +import java.net.URI; +import java.util.List; +import java.util.Map; +import javax.ws.rs.core.Response; import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList; import org.onap.vid.aai.model.AaiGetPnfs.Pnf; import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; @@ -32,11 +36,6 @@ import org.onap.vid.model.SubscriberList; import org.onap.vid.services.ProbeInterface; import org.springframework.http.HttpMethod; -import javax.ws.rs.core.Response; -import java.net.URI; -import java.util.List; -import java.util.Map; - /** * Created by Oren on 7/4/17. */ @@ -103,4 +102,6 @@ public interface AaiClientInterface extends ProbeInterface { void resetCache(String cacheName); Map<String, Properties> getCloudRegionAndTenantByVnfId(String vnfId); + + AaiResponse getVnfsByParamsForChangeManagement(String subscriberId, String serviceType, String nfRole, String cloudRegion); } diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java index e0d211c24..d1f7a97b5 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java @@ -20,7 +20,9 @@ package org.onap.vid.controller; +import java.util.List; import java.util.stream.Collectors; +import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; import org.onap.vid.aai.AaiClientInterface; import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; @@ -29,15 +31,20 @@ import org.onap.vid.aai.model.Permissions; import org.onap.vid.model.aaiTree.Network; import org.onap.vid.model.aaiTree.RelatedVnf; import org.onap.vid.model.aaiTree.VpnBinding; +import org.onap.vid.properties.Features; import org.onap.vid.roles.RoleProvider; import org.onap.vid.services.AaiService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import java.util.List; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; +import org.togglz.core.manager.FeatureManager; /** * Controller to handle a&ai new requests. @@ -49,12 +56,14 @@ public class AaiController2 extends VidRestrictedBaseController { private final AaiService aaiService; private final RoleProvider roleProvider; private final AaiClientInterface aaiClient; + private final FeatureManager featureManager; @Autowired - public AaiController2(AaiService aaiService, RoleProvider roleProvider, AaiClientInterface aaiClient) { + public AaiController2(AaiService aaiService, RoleProvider roleProvider, AaiClientInterface aaiClient, FeatureManager featureManager) { this.aaiService = aaiService; this.roleProvider = roleProvider; this.aaiClient = aaiClient; + this.featureManager = featureManager; } @RequestMapping(value = "/aai_get_homing_by_vfmodule/{vnfInstanceId}/{vfModuleId}", method = RequestMethod.GET) @@ -123,4 +132,16 @@ public class AaiController2 extends VidRestrictedBaseController { public ModelVer getNewestModelVersionByInvariant(@PathVariable("invariantId") String invariantId) { return aaiService.getNewestModelVersionByInvariantId(invariantId); } + + @GetMapping(value = "/get_vnf_data_by_globalid_and_service_type/{globalCustomerId}/{serviceType}") + public Object getVnfDataByGlobalIdAndServiceType( + @PathVariable("globalCustomerId") String globalCustomerId, + @PathVariable("serviceType") String serviceType, + @RequestParam(name="nfRole", required = false) String nfRole, + @RequestParam(name="cloudRegion", required = false) String cloudRegion) { + if (featureManager.isActive(Features.FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG)){ + return aaiClient.getVnfsByParamsForChangeManagement(globalCustomerId, serviceType, nfRole, cloudRegion).getT(); + } + return aaiService.getVNFData(globalCustomerId, serviceType).getT(); + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/properties/Features.java b/vid-app-common/src/main/java/org/onap/vid/properties/Features.java index 394fc9cd4..9abf68bca 100644 --- a/vid-app-common/src/main/java/org/onap/vid/properties/Features.java +++ b/vid-app-common/src/main/java/org/onap/vid/properties/Features.java @@ -74,6 +74,7 @@ public enum Features implements Feature { FLAG_PNP_INSTANTIATION, FLAG_HANDLE_SO_WORKFLOWS, FLAG_CREATE_ERROR_REPORTS, + FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG, FLAG_FLASH_MORE_ACTIONS_BUTTON_IN_OLD_VIEW_EDIT, FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH, ; diff --git a/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties b/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties index 70eaae964..8438172e3 100644 --- a/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties +++ b/vid-app-common/src/main/webapp/WEB-INF/conf/dev.features.properties @@ -32,4 +32,5 @@ FLAG_1810_AAI_LOCAL_CACHE = true FLAG_1902_NEW_VIEW_EDIT= false FLAG_EXP_USE_DEFAULT_HOST_NAME_VERIFIER = false FLAG_1902_VNF_GROUPING = true -FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH=false
\ No newline at end of file +FLAG_FLASH_CLOUD_REGION_AND_NF_ROLE_OPTIONAL_SEARCH=false +FLAG_FLASH_REDUCED_RESPONSE_CHANGEMG = false |