aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java52
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java11
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java94
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java31
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/properties/Features.java1
5 files changed, 158 insertions, 31 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/client/SyncRestClient.java b/vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java
index 398d81dfb..5c65c8af4 100644
--- a/vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java
+++ b/vid-app-common/src/main/java/org/onap/vid/client/SyncRestClient.java
@@ -55,6 +55,7 @@ import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.properties.VidProperties;
import org.onap.vid.utils.Logging;
+import org.springframework.http.HttpMethod;
public class SyncRestClient implements SyncRestClientInterface {
private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SyncRestClient.class);
@@ -90,68 +91,133 @@ public class SyncRestClient implements SyncRestClientInterface {
@Override
public HttpResponse<JsonNode> post(String url, Map<String, String> headers, Object body) {
- return callWithRetryOverHttp(url, url2 -> restClient.post(url2).headers(headers).body(body).asJson());
+ loggingService.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, body);
+
+ HttpResponse<JsonNode> response = callWithRetryOverHttp(url,
+ url2 -> restClient.post(url2).headers(headers).body(body).asJson());
+
+ loggingService.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, response);
+
+ return response;
}
@Override
public <T> HttpResponse<T> post(String url, Map<String, String> headers, Object body, Class<T> responseClass) {
- return callWithRetryOverHttp(url,
- url2 -> restClient.post(url2).headers(headers).body(body).asObject(responseClass));
+ loggingService.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, body);
+
+ HttpResponse<T> response = callWithRetryOverHttp(url,
+ url2 -> restClient.post(url2).headers(headers).body(body).asObject(responseClass));
+
+ loggingService.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, response);
+
+ return response;
}
@Override
public HttpResponse<JsonNode> get(String url, Map<String, String> headers, Map<String, String> routeParams) {
- return callWithRetryOverHttp(url, url2 -> {
+ loggingService.logRequest(outgoingRequestsLogger, HttpMethod.GET, url, routeParams);
+
+ HttpResponse<JsonNode> response = callWithRetryOverHttp(url, url2 -> {
GetRequest getRequest = restClient.get(url2).headers(headers);
routeParams.forEach(getRequest::routeParam);
return getRequest.asJson();
});
+
+ loggingService.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, response);
+
+ return response;
}
@Override
public <T> HttpResponse<T> get(String url, Map<String, String> headers, Map<String, String> routeParams,
Class<T> responseClass) {
- return callWithRetryOverHttp(url, url2 -> {
+ loggingService.logRequest(outgoingRequestsLogger, HttpMethod.GET, url, routeParams);
+
+ HttpResponse<T> response = callWithRetryOverHttp(url, url2 -> {
GetRequest getRequest = restClient.get(url2).headers(headers);
routeParams.forEach(getRequest::routeParam);
return getRequest.asObject(responseClass);
});
+
+ loggingService.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, response);
+
+ return response;
}
@Override
public HttpResponse<InputStream> getStream(String url, Map<String, String> headers,
Map<String, String> routeParams) {
- return callWithRetryOverHttp(url, url2 -> {
+ loggingService.logRequest(outgoingRequestsLogger, HttpMethod.GET, url, routeParams);
+
+ HttpResponse<InputStream> response = callWithRetryOverHttp(url, url2 -> {
GetRequest getRequest = restClient.get(url2).headers(headers);
routeParams.forEach(getRequest::routeParam);
return getRequest.asBinary();
});
+
+ //no logging of the response since the response is too long
+ return response;
+
}
@Override
public HttpResponse<JsonNode> put(String url, Map<String, String> headers, Object body) {
- return callWithRetryOverHttp(url, url2 -> restClient.put(url2).headers(headers).body(body).asJson());
+ loggingService.logRequest(outgoingRequestsLogger, HttpMethod.PUT, url, body);
+
+ HttpResponse<JsonNode> response = callWithRetryOverHttp(url,
+ url2 -> restClient.put(url2).headers(headers).body(body).asJson());
+
+ loggingService.logResponse(outgoingRequestsLogger, HttpMethod.PUT, url, response);
+
+ return response;
}
@Override
public <T> HttpResponse<T> put(String url, Map<String, String> headers, Object body, Class<T> responseClass) {
- return callWithRetryOverHttp(url,
- url2 -> restClient.put(url2).headers(headers).body(body).asObject(responseClass));
+ loggingService.logRequest(outgoingRequestsLogger, HttpMethod.PUT, url, body);
+
+ HttpResponse<T> response = callWithRetryOverHttp(url,
+ url2 -> restClient.put(url2).headers(headers).body(body).asObject(responseClass));
+
+ loggingService.logResponse(outgoingRequestsLogger, HttpMethod.PUT, url, response);
+
+ return response;
}
@Override
public <T> HttpResponse<T> delete(String url, Map<String, String> headers, Object body, Class<T> responseClass) {
- return callWithRetryOverHttp(url, url2 -> restClient.delete(url2).headers(headers).body(body).asObject(responseClass));
+ loggingService.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url, body);
+
+ HttpResponse<T> response = callWithRetryOverHttp(url,
+ url2 -> restClient.delete(url2).headers(headers).body(body).asObject(responseClass));
+
+ loggingService.logResponse(outgoingRequestsLogger, HttpMethod.DELETE, url, response);
+
+ return response;
}
@Override
public <T> HttpResponse<T> delete(String url, Map<String, String> headers, Class<T> responseClass) {
- return callWithRetryOverHttp(url, url2 -> restClient.delete(url2).headers(headers).asObject(responseClass));
+ loggingService.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url);
+
+ HttpResponse<T> response = callWithRetryOverHttp(url,
+ url2 -> restClient.delete(url2).headers(headers).asObject(responseClass));
+
+ loggingService.logResponse(outgoingRequestsLogger, HttpMethod.DELETE, url, response);
+
+ return response;
}
@Override
public HttpResponse<JsonNode> delete(String url, Map<String, String> headers) {
- return callWithRetryOverHttp(url, url2 -> restClient.delete(url2).headers(headers).asJson());
+ loggingService.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url);
+
+ HttpResponse<JsonNode> response = callWithRetryOverHttp(url,
+ url2 -> restClient.delete(url2).headers(headers).asJson());
+
+ loggingService.logResponse(outgoingRequestsLogger, HttpMethod.DELETE, url, response);
+
+ return response;
}
@Override
@@ -172,7 +238,7 @@ public class SyncRestClient implements SyncRestClientInterface {
return patched(httpRequest.apply(url));
} catch (RestClientException e) {
if (causedBySslHandshakeError(e)) {
- logger.warn(EELFLoggerDelegate.debugLogger, "SSL Handshake problem occured. Will try to retry over Http.", e);
+ logger.warn("SSL Handshake problem occured. Will try to retry over Http.", e);
return patched(httpRequest.apply(url.replaceFirst(HTTPS_SCHEMA, HTTP_SCHEMA)));
}
throw e;
@@ -199,7 +265,7 @@ public class SyncRestClient implements SyncRestClientInterface {
return HttpClients.custom().setSSLSocketFactory(sslSf).build();
} catch (IOException | CertificateException | UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
- logger.warn(EELFLoggerDelegate.debugLogger, "Cannot initialize custom http client from current configuration. Using default one.", e);
+ logger.warn("Cannot initialize custom http client from current configuration. Using default one.", e);
return HttpClients.createDefault();
}
}
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,
;