aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2018-08-02 11:34:07 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2018-08-02 14:57:56 -0400
commit0f12815d373a4a656bca88e3093128c1fda4ae80 (patch)
treeeed04d892b16bb261d48a1406487b1b569c153a3 /mso-api-handlers/mso-api-handler-infra/src/main
parentacf060932b78061e590d1aa48e726d4ab1e70420 (diff)
update infra apihandler to utilize rest
rather than direct access Change-Id: I0cd3d3902e32249263298f91263401ce05c34be3 Issue-ID: SO-790 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java20
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java171
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java9
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java78
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java86
5 files changed, 224 insertions, 140 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
index e1993aa632..3a944473d9 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
@@ -48,7 +48,6 @@ import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.apihandlerinfra.logging.AlarmLoggerInfo;
import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
import org.onap.so.db.request.beans.InfraActiveRequests;
-import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
import org.onap.so.exceptions.ValidationException;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoAlarmLogger;
@@ -76,11 +75,10 @@ public class OrchestrationRequests {
private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH, OrchestrationRequests.class);
- private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger ();
-
+
@Autowired
- private InfraActiveRequestsRepository infraActiveRequestsRepository;
-
+ private RequestsDbClient requestsDbClient;
+
@Autowired
private MsoRequest msoRequest;
@@ -101,7 +99,8 @@ public class OrchestrationRequests {
InfraActiveRequests requestDB = null;
try {
- requestDB = infraActiveRequestsRepository.findOneByRequestIdOrClientRequestId(requestId, requestId);
+ requestDB = requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
+
} catch (Exception e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, MsoLogger.ErrorCode.AvailabilityError).build();
@@ -128,7 +127,7 @@ public class OrchestrationRequests {
}
Request request = mapInfraActiveRequestToRequest(requestDB);
-
+ request.setRequestId(requestId);
orchestrationResponse.setRequest(request);
return builder.buildResponse(HttpStatus.SC_OK, requestId, orchestrationResponse, apiVersion);
@@ -167,7 +166,7 @@ public class OrchestrationRequests {
}
- activeRequests = infraActiveRequestsRepository.getOrchestrationFiltersFromInfraActive(orchestrationMap);
+ activeRequests = requestsDbClient.getOrchestrationFiltersFromInfraActive(orchestrationMap);
orchestrationList = new GetOrchestrationListResponse();
List<RequestList> requestLists = new ArrayList<>();
@@ -222,7 +221,7 @@ public class OrchestrationRequests {
throw validateException;
}
- infraActiveRequest = infraActiveRequestsRepository.findOneByRequestIdOrClientRequestId(requestId, requestId);
+ infraActiveRequest = requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
if(infraActiveRequest == null) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MsoLogger.ErrorCode.BusinessProcesssError).build();
@@ -237,7 +236,8 @@ public class OrchestrationRequests {
if(status.equalsIgnoreCase("IN_PROGRESS") || status.equalsIgnoreCase("PENDING") || status.equalsIgnoreCase("PENDING_MANUAL_TASK")){
infraActiveRequest.setRequestStatus("UNLOCKED");
infraActiveRequest.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
- infraActiveRequestsRepository.save(infraActiveRequest);
+ infraActiveRequest.setRequestId(requestId);
+ requestsDbClient.save(infraActiveRequest);
}else{
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, MsoLogger.ErrorCode.DataError).build();
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java
new file mode 100644
index 0000000000..721fe2fe6b
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestsDbClient.java
@@ -0,0 +1,171 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.apihandlerinfra;
+
+import org.apache.http.HttpStatus;
+import org.onap.so.db.request.beans.InfraActiveRequests;
+import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpRequest;
+import org.springframework.http.client.ClientHttpRequestExecution;
+import org.springframework.http.client.ClientHttpRequestInterceptor;
+import org.springframework.http.client.ClientHttpResponse;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.RestTemplate;
+import uk.co.blackpepper.bowman.Client;
+import uk.co.blackpepper.bowman.ClientFactory;
+import uk.co.blackpepper.bowman.Configuration;
+import uk.co.blackpepper.bowman.RestTemplateConfigurer;
+
+import javax.annotation.PostConstruct;
+import java.io.IOException;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Component("RequestDbClient")
+public class RequestsDbClient {
+
+ private Client<InfraActiveRequests> infraActiveRequestClient;
+
+ @Value("${mso.adapters.db.spring.endpoint:}")
+ private String endpoint;
+
+ @Value("${mso.db.auth:}")
+ private String msoAdaptersAuth;
+
+ private String getOrchestrationFilterURI = "/getOrchestrationFiltersFromInfraActive/";
+
+ private String checkVnfIdStatus = "/infraActiveRequests/checkVnfIdStatus/";
+
+ private String infraActiveRequestURI = "/infraActiveRequests/";
+
+ private String checkInstanceNameDuplicate = "/infraActiveRequests/checkInstanceNameDuplicate";
+
+ private String cloudOrchestrationFiltersFromInfraActive = "/infraActiveRequests/getCloudOrchestrationFiltersFromInfraActive";
+
+ private HttpHeaders headers;
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ @PostConstruct
+ public void init() {
+ getOrchestrationFilterURI = endpoint + getOrchestrationFilterURI;
+ infraActiveRequestURI = endpoint + infraActiveRequestURI;
+ checkVnfIdStatus = endpoint + checkVnfIdStatus;
+ checkInstanceNameDuplicate = endpoint + checkInstanceNameDuplicate;
+ cloudOrchestrationFiltersFromInfraActive = endpoint + cloudOrchestrationFiltersFromInfraActive;
+ headers = new HttpHeaders();
+ headers.set("Authorization", msoAdaptersAuth);
+ }
+
+ public RequestsDbClient() {
+ ClientFactory clientFactory = Configuration.builder().setRestTemplateConfigurer(new RestTemplateConfigurer() {
+
+ public void configure(RestTemplate restTemplate) {
+
+ restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() {
+
+ public ClientHttpResponse intercept(HttpRequest request, byte[] body,
+ ClientHttpRequestExecution execution) throws IOException {
+
+ request.getHeaders().add("Authorization", msoAdaptersAuth);
+ return execution.execute(request, body);
+ }
+ });
+ }
+ }).build().buildClientFactory();
+ infraActiveRequestClient = clientFactory.create(InfraActiveRequests.class);
+
+ }
+ public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive(Map<String, String> orchestrationMap){
+ URI uri = getUri(cloudOrchestrationFiltersFromInfraActive);
+ HttpEntity<Map> entity = new HttpEntity<>(orchestrationMap, headers);
+ try{
+ return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {}).getBody();
+ }catch(HttpClientErrorException e){
+ if(HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()){
+ return null;
+ }
+ throw e;
+ }
+ }
+ public InfraActiveRequests getInfraActiveRequestbyRequestId(String requestId) {
+ return this.getSingleInfraActiveRequests(this.getUri(endpoint + "/infraActiveRequests/" + requestId));
+ }
+
+ public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive(Map<String, List<String>> orchestrationMap) {
+ URI uri = getUri(getOrchestrationFilterURI);
+ HttpEntity<Map<String, List<String>>> entity = new HttpEntity<>(orchestrationMap, headers);
+ return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {}).getBody();
+ }
+
+ public InfraActiveRequests checkVnfIdStatus(String operationalEnvironmentId) {
+ URI uri = getUri(checkVnfIdStatus + operationalEnvironmentId);
+ return restTemplate.exchange(uri, HttpMethod.GET, HttpEntity.EMPTY, InfraActiveRequests.class).getBody();
+ }
+ public InfraActiveRequests checkInstanceNameDuplicate(HashMap<String, String> instanceIdMap, String instanceName, String requestScope) {
+ URI uri = getUri(checkInstanceNameDuplicate);
+ HttpEntity<InstanceNameDuplicateCheckRequest> entity = new HttpEntity<>(new InstanceNameDuplicateCheckRequest(instanceIdMap, instanceName, requestScope), headers);
+ try{
+ return restTemplate.exchange(uri, HttpMethod.POST, entity, InfraActiveRequests.class).getBody();
+ }catch(HttpClientErrorException e){
+ if(HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()){
+ return null;
+ }
+ throw e;
+ }
+
+ }
+
+ public void save(InfraActiveRequests infraActiveRequests) {
+ URI uri = getUri(infraActiveRequestURI);
+ HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(infraActiveRequests, headers);
+ restTemplate.postForLocation(uri, entity);
+ }
+
+ protected InfraActiveRequests getSingleInfraActiveRequests(URI uri) {
+ return infraActiveRequestClient.get(uri);
+ }
+
+ public void updateInfraActiveRequests(InfraActiveRequests request) {
+ infraActiveRequestClient.put(request);
+ }
+
+ protected URI getUri(String uri) {
+ return URI.create(uri);
+ }
+
+ @Bean
+ public RestTemplate restTemplate() {
+ return new RestTemplate( new HttpComponentsClientHttpRequestFactory());
+ }
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java
index dd1f19ff62..910b9f70cb 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudOrchestration.java
@@ -40,6 +40,7 @@ import javax.ws.rs.core.Response;
import org.apache.http.HttpStatus;
import org.onap.so.apihandler.common.ErrorNumbers;
import org.onap.so.apihandlerinfra.Constants;
+import org.onap.so.apihandlerinfra.RequestsDbClient;
import org.onap.so.apihandlerinfra.Status;
import org.onap.so.apihandlerinfra.exceptions.ApiException;
import org.onap.so.apihandlerinfra.exceptions.DuplicateRequestException;
@@ -73,8 +74,10 @@ public class CloudOrchestration {
@Autowired
private TenantIsolationRequest tenantIsolationRequest ;
+
@Autowired
- private InfraActiveRequestsRepository iarRepo;
+ private RequestsDbClient requestsDbClient;
+
@Autowired
private Provider<TenantIsolationRunnable> tenantIsolationRunnable;
@@ -143,7 +146,7 @@ public class CloudOrchestration {
dup = duplicateCheck(action, instanceIdMap, startTime, instanceName, resourceType);
if(dup == null && (Action.activate.equals(action) || Action.deactivate.equals(action))) {
- dup = iarRepo.checkVnfIdStatus(cor.getOperationalEnvironmentId());
+ dup = requestsDbClient.checkVnfIdStatus(cor.getOperationalEnvironmentId());
}
if(dup != null) {
@@ -202,7 +205,7 @@ public class CloudOrchestration {
private InfraActiveRequests duplicateCheck(Action action, HashMap<String, String> instanceIdMap, long startTime,
String instanceName, String requestScope) throws ApiException {
try {
- return iarRepo.checkInstanceNameDuplicate (instanceIdMap, instanceName, requestScope);
+ return requestsDbClient.checkInstanceNameDuplicate (instanceIdMap, instanceName, requestScope);
} catch (Exception e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DUPLICATE_CHECK_EXC, MsoLogger.ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java
index a3835f1551..746f5a57b3 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/CloudResourcesOrchestration.java
@@ -20,56 +20,39 @@
package org.onap.so.apihandlerinfra.tenantisolation;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.transaction.Transactional;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.wordnik.swagger.annotations.Api;
+import com.wordnik.swagger.annotations.ApiOperation;
import org.apache.http.HttpStatus;
-import org.onap.so.apihandler.common.CommonConstants;
import org.onap.so.apihandler.common.ErrorNumbers;
import org.onap.so.apihandler.common.ResponseBuilder;
import org.onap.so.apihandlerinfra.Constants;
import org.onap.so.apihandlerinfra.Messages;
+import org.onap.so.apihandlerinfra.RequestsDbClient;
import org.onap.so.apihandlerinfra.exceptions.ApiException;
import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.apihandlerinfra.logging.AlarmLoggerInfo;
import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
-import org.onap.so.apihandlerinfra.tenantisolationbeans.CloudOrchestrationRequestList;
-import org.onap.so.apihandlerinfra.tenantisolationbeans.CloudOrchestrationResponse;
-import org.onap.so.apihandlerinfra.tenantisolationbeans.InstanceReferences;
+import org.onap.so.apihandlerinfra.tenantisolationbeans.*;
import org.onap.so.apihandlerinfra.tenantisolationbeans.Request;
-import org.onap.so.apihandlerinfra.tenantisolationbeans.RequestDetails;
-import org.onap.so.apihandlerinfra.tenantisolationbeans.RequestStatus;
import org.onap.so.db.request.beans.InfraActiveRequests;
-import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
import org.onap.so.exceptions.ValidationException;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoAlarmLogger;
import org.onap.so.logger.MsoLogger;
import org.onap.so.utils.UUIDChecker;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.wordnik.swagger.annotations.Api;
-import com.wordnik.swagger.annotations.ApiOperation;
+import javax.transaction.Transactional;
+import javax.ws.rs.*;
+import javax.ws.rs.core.*;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
@Component
@Path("onap/so/infra/cloudResourcesRequests")
@@ -77,11 +60,10 @@ import com.wordnik.swagger.annotations.ApiOperation;
public class CloudResourcesOrchestration {
private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH, CloudResourcesOrchestration.class);
- private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger ();
- @Autowired
- private InfraActiveRequestsRepository iarRepo;
+
@Autowired
- private InfraActiveRequestsRepository infraActiveRequestsRepository;
+ RequestsDbClient requestDbClient;
+
@Autowired
private ResponseBuilder builder;
@@ -119,7 +101,7 @@ public class CloudResourcesOrchestration {
throw validateException;
}
try {
- infraActiveRequest = infraActiveRequestsRepository.findOneByRequestIdOrClientRequestId(requestId, requestId);
+ infraActiveRequest = requestDbClient.getInfraActiveRequestbyRequestId(requestId);
}catch(Exception e){
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, MsoLogger.ErrorCode.AvailabilityError).build();
AlarmLoggerInfo alarmLoggerInfo = new AlarmLoggerInfo.Builder("MsoDatabaseAccessError", MsoAlarmLogger.CRITICAL,
@@ -142,7 +124,7 @@ public class CloudResourcesOrchestration {
if(status.equalsIgnoreCase("IN_PROGRESS") || status.equalsIgnoreCase("PENDING") || status.equalsIgnoreCase("PENDING_MANUAL_TASK")){
infraActiveRequest.setRequestStatus("UNLOCKED");
infraActiveRequest.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
- infraActiveRequestsRepository.save(infraActiveRequest);
+ requestDbClient.save(infraActiveRequest);
}else{
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND,MsoLogger.ErrorCode.DataError).build();
ValidateException validateException = new ValidateException.Builder("Orchestration RequestId " + requestId + " has a status of " + status + " and can not be unlocked",
@@ -177,7 +159,7 @@ public class CloudResourcesOrchestration {
InfraActiveRequests requestDB = null;
try {
- requestDB = infraActiveRequestsRepository.findOneByRequestIdOrClientRequestId(requestId, requestId);
+ requestDB = requestDbClient.getInfraActiveRequestbyRequestId(requestId);
} catch (Exception e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, MsoLogger.ErrorCode.AvailabilityError).build();
AlarmLoggerInfo alarmLoggerInfo = new AlarmLoggerInfo.Builder("MsoDatabaseAccessError", MsoAlarmLogger.CRITICAL,
@@ -221,7 +203,7 @@ public class CloudResourcesOrchestration {
throw validateException;
}
- activeRequests = iarRepo.getCloudOrchestrationFiltersFromInfraActive(orchestrationMap);
+ activeRequests = requestDbClient.getCloudOrchestrationFiltersFromInfraActive(orchestrationMap);
orchestrationList = new CloudOrchestrationRequestList();
List<CloudOrchestrationResponse> requestLists = new ArrayList<CloudOrchestrationResponse>();
@@ -257,14 +239,16 @@ public class CloudResourcesOrchestration {
String requestBody = iar.getRequestBody();
RequestDetails requestDetails = null;
- try{
- ObjectMapper mapper = new ObjectMapper();
- requestDetails = mapper.readValue(requestBody, RequestDetails.class);
- }catch(IOException e){
- ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR,MsoLogger.ErrorCode.SchemaError).build();
- ValidateException validateException = new ValidateException.Builder("Mapping of request to JSON object failed. " + e.getMessage(), HttpStatus.SC_BAD_REQUEST,ErrorNumbers.SVC_BAD_PARAMETER)
- .cause(e).errorInfo(errorLoggerInfo).build();
- throw validateException;
+ if (requestBody != null) {
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ requestDetails = mapper.readValue(requestBody, RequestDetails.class);
+ } catch (IOException e) {
+ ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MsoLogger.ErrorCode.SchemaError).build();
+ ValidateException validateException = new ValidateException.Builder("Mapping of request to JSON object failed. " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER)
+ .cause(e).errorInfo(errorLoggerInfo).build();
+ throw validateException;
+ }
}
request.setRequestDetails(requestDetails);
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java
index a6452a44ac..b35b669208 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java
@@ -27,11 +27,10 @@ import java.util.Map;
import java.util.Map.Entry;
import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.onap.so.apihandlerinfra.Constants;
-import org.onap.so.apihandlerinfra.MsoException;
+import org.onap.so.apihandlerinfra.RequestsDbClient;
import org.onap.so.apihandlerinfra.Status;
import org.onap.so.apihandlerinfra.tenantisolationbeans.Action;
import org.onap.so.apihandlerinfra.tenantisolationbeans.Manifest;
@@ -45,19 +44,15 @@ import org.onap.so.apihandlerinfra.tenantisolationbeans.ResourceType;
import org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList;
import org.onap.so.apihandlerinfra.vnfbeans.RequestStatusType;
import org.onap.so.db.request.beans.InfraActiveRequests;
-import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
import org.onap.so.exceptions.ValidationException;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
-import org.onap.so.serviceinstancebeans.PolicyException;
-import org.onap.so.serviceinstancebeans.RequestError;
-import org.onap.so.serviceinstancebeans.ServiceException;
+
import org.onap.so.utils.UUIDChecker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -70,8 +65,6 @@ public class TenantIsolationRequest {
private RequestInfo requestInfo;
private String errorMessage;
- private String errorCode;
- private String httpResponse;
private String responseBody;
private RequestStatusType status;
private String operationalEnvironmentId;
@@ -79,8 +72,8 @@ public class TenantIsolationRequest {
private String requestScope;
private CloudOrchestrationRequest cor;
- @Autowired
- private InfraActiveRequestsRepository infraActiveRequestsRepository;
+ @Autowired
+ private RequestsDbClient requestsDbClient;
private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH, TenantIsolationRequest.class);
@@ -311,7 +304,7 @@ public class TenantIsolationRequest {
} else if(status == Status.IN_PROGRESS) {
aq.setProgress(Constants.PROGRESS_REQUEST_IN_PROGRESS);
}
- infraActiveRequestsRepository.save(aq);
+ requestsDbClient.save(aq);
}
@@ -336,73 +329,6 @@ public class TenantIsolationRequest {
return orchestrationFilterParams;
}
- /**
- * Build Error Response for Exception handling.
- *
- * @param int
- * @param httpResponseCode the HTTP response code
- * @param exceptionType.
- * @param text the error description
- * @param messageId
- * @return the web service response
- *
- */
- public Response buildServiceErrorResponse (int httpResponseCode,
- MsoException exceptionType,
- String text,
- String messageId,
- List<String> variables) {
-
- this.errorCode = messageId;
-
- this.errorCode = text != null ? text : "";
- this.httpResponse = Integer.toString(httpResponseCode);
-
- if(errorMessage.length() > 1999){
- errorMessage = errorMessage.substring(0, 1999);
- }
-
- RequestError re = new RequestError();
-
- if(exceptionType.name().equals("PolicyException")){
-
- PolicyException pe = new PolicyException();
- pe.setMessageId(messageId);
- pe.setText(text);
- if(variables != null){
- for(String variable: variables){
- pe.getVariables().add(variable);
- }
- }
- re.setPolicyException(pe);
-
- } else {
-
- ServiceException se = new ServiceException();
- se.setMessageId(messageId);
- se.setText(text);
- if(variables != null){
- for(String variable: variables){
- se.getVariables().add(variable);
- }
- }
- re.setServiceException(se);
- }
-
- String requestErrorStr = null;
-
- try{
- ObjectMapper mapper = new ObjectMapper();
- mapper.setSerializationInclusion(Include.NON_DEFAULT);
- requestErrorStr = mapper.writeValueAsString(re);
- }catch(Exception e){
- msoLogger.error (MessageEnum.APIH_VALIDATION_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in buildServiceErrorResponse writing exceptionType to string ", e);
- }
-
- return Response.status (httpResponseCode).entity(requestErrorStr).build ();
-
- }
-
private static boolean empty(String s) {
return (s == null || s.trim().isEmpty());
}
@@ -423,7 +349,7 @@ public class TenantIsolationRequest {
request.setProgress(this.progress);
request.setResponseBody(this.responseBody);
request.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
- infraActiveRequestsRepository.save(request);
+ requestsDbClient.save(request);
} catch (Exception e) {
msoLogger.error(MessageEnum.APIH_DB_UPDATE_EXC, e.getMessage(), "", "", MsoLogger.ErrorCode.DataError, "Exception when updating record in DB");
msoLogger.debug ("Exception: ", e);