diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main')
11 files changed, 192 insertions, 109 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java index 3eee14e3bf..5b08cc1b17 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java @@ -42,5 +42,6 @@ public enum Action implements Actions{ unassignInstance, compareModel, scaleInstance, - deactivateAndCloudDelete + deactivateAndCloudDelete, + scaleOut } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java index ee50d920fe..e8a6beb278 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java @@ -56,10 +56,8 @@ import org.onap.so.apihandlerinfra.exceptions.ValidateException; import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.ServiceRecipe; -import org.onap.so.db.catalog.data.repository.ServiceRecipeRepository; -import org.onap.so.db.catalog.data.repository.ServiceRepository; +import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.OperationStatus; -import org.onap.so.db.request.data.repository.OperationStatusRepository; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoAlarmLogger; import org.onap.so.logger.MsoLogger; @@ -84,14 +82,12 @@ import com.wordnik.swagger.annotations.ApiOperation; public class E2EServiceInstances { private HashMap<String, String> instanceIdMap = new HashMap<>(); - private static MsoLogger msoLogger = MsoLogger + private static final MsoLogger msoLogger = MsoLogger .getMsoLogger(MsoLogger.Catalog.APIH, E2EServiceInstances.class); - private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger(); - public static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA"; + private static final MsoAlarmLogger alarmLogger = new MsoAlarmLogger(); + private static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA"; - public static final String END_OF_THE_TRANSACTION = "End of the transaction, the final response is: "; - public static final String EXCEPTION_CREATING_DB_RECORD = "Exception while creating record in DB"; - public static final String EXCEPTION_COMMUNICATE_BPMN_ENGINE = "Exception while communicate with BPMN engine"; + private static final String END_OF_THE_TRANSACTION = "End of the transaction, the final response is: "; @Autowired private MsoRequest msoRequest; @@ -100,13 +96,10 @@ public class E2EServiceInstances { private RequestClientFactory requestClientFactory; @Autowired - private OperationStatusRepository osRepo; + private RequestsDbClient requestsDbClient; @Autowired - private ServiceRepository serviceRepo; - - @Autowired - private ServiceRecipeRepository sRecipeRepo; + private CatalogDbClient catalogDbClient; @Autowired private ResponseBuilder builder; @@ -224,7 +217,7 @@ public class E2EServiceInstances { long startTime = System.currentTimeMillis(); msoLogger.debug("requestId is: " + requestId); - CompareModelsRequest e2eCompareModelReq = null; + CompareModelsRequest e2eCompareModelReq; ObjectMapper mapper = new ObjectMapper(); try { @@ -256,8 +249,8 @@ public class E2EServiceInstances { String workflowUrl = "/mso/async/services/CompareModelofE2EServiceInstance"; int recipeTimeout = 180; - RequestClient requestClient = null; - HttpResponse response = null; + RequestClient requestClient; + HttpResponse response; long subStartTime = System.currentTimeMillis(); @@ -327,12 +320,11 @@ public class E2EServiceInstances { long startTime = System.currentTimeMillis(); - OperationStatus operationStatus = null; + OperationStatus operationStatus; try { - operationStatus = osRepo.findOneByServiceIdAndOperationId(serviceId, + operationStatus = requestsDbClient.getOneByServiceIdAndOperationId(serviceId, operationId); - } catch (Exception e) { msoLogger .error(MessageEnum.APIH_DB_ACCESS_EXC, @@ -353,7 +345,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with Request DB"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } @@ -371,7 +363,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.DataNotFound, "Null response from RequestDB when searching by serviceId"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) resp.getEntity()); + + resp.getEntity()); return resp; } @@ -387,7 +379,7 @@ public class E2EServiceInstances { String requestId = UUIDChecker.generateUUID(msoLogger); long startTime = System.currentTimeMillis(); msoLogger.debug("requestId is: " + requestId); - E2EServiceInstanceDeleteRequest e2eDelReq = null; + E2EServiceInstanceDeleteRequest e2eDelReq; ObjectMapper mapper = new ObjectMapper(); try { @@ -410,11 +402,11 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.SchemaError, "Mapping of request to JSON object failed"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } - RecipeLookupResult recipeLookupResult = null; + RecipeLookupResult recipeLookupResult; try { //TODO Get the service template model version uuid from AAI. recipeLookupResult = getServiceInstanceOrchestrationURI(null, action); @@ -436,7 +428,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with DB"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } if (recipeLookupResult == null) { @@ -454,12 +446,12 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.DataNotFound, "No recipe found in DB"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } - RequestClient requestClient = null; - HttpResponse response = null; + RequestClient requestClient; + HttpResponse response; long subStartTime = System.currentTimeMillis(); try { @@ -514,7 +506,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine"); msoLogger.debug("End of the transaction, the final response is: " - + (String) resp.getEntity()); + + resp.getEntity()); return resp; } @@ -530,7 +522,7 @@ public class E2EServiceInstances { msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Null response from BPMN"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } @@ -548,7 +540,7 @@ public class E2EServiceInstances { String requestId = UUIDChecker.generateUUID(msoLogger); long startTime = System.currentTimeMillis(); msoLogger.debug("requestId is: " + requestId); - E2EServiceInstanceRequest e2eSir = null; + E2EServiceInstanceRequest e2eSir; String serviceId = instanceIdMap.get("serviceId"); ObjectMapper mapper = new ObjectMapper(); @@ -565,7 +557,7 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.SchemaError, requestJSON, e); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Mapping of request to JSON object failed"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -585,11 +577,11 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.SchemaError, requestJSON, e); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Validation of the input request failed"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } - RecipeLookupResult recipeLookupResult = null; + RecipeLookupResult recipeLookupResult; try { recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), action); } catch (Exception e) { @@ -603,7 +595,7 @@ public class E2EServiceInstances { msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with DB"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -617,15 +609,15 @@ public class E2EServiceInstances { msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, "No recipe found in DB"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } String serviceInstanceType = e2eSir.getService().getServiceType(); - RequestClient requestClient = null; - HttpResponse response = null; + RequestClient requestClient; + HttpResponse response; long subStartTime = System.currentTimeMillis(); String sirRequestJson = convertToString(sir); @@ -665,7 +657,7 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine"); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) getBPMNResp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + getBPMNResp.getEntity()); return getBPMNResp; } @@ -677,7 +669,7 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL"); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Null response from BPMN"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) getBPMNResp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + getBPMNResp.getEntity()); return getBPMNResp; } @@ -694,7 +686,7 @@ public class E2EServiceInstances { String requestId = UUIDChecker.generateUUID(msoLogger); long startTime = System.currentTimeMillis(); msoLogger.debug("requestId is: " + requestId); - E2EServiceInstanceRequest e2eSir = null; + E2EServiceInstanceRequest e2eSir; MsoRequest msoRequest = new MsoRequest(); ObjectMapper mapper = new ObjectMapper(); @@ -711,7 +703,7 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.SchemaError, requestJSON, e); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Mapping of request to JSON object failed"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -731,11 +723,11 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.SchemaError, requestJSON, e); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError, "Validation of the input request failed"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } - RecipeLookupResult recipeLookupResult = null; + RecipeLookupResult recipeLookupResult; try { recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), action); } catch (Exception e) { @@ -749,7 +741,7 @@ public class E2EServiceInstances { msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with DB"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -762,15 +754,15 @@ public class E2EServiceInstances { msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataNotFound, "No recipe found in DB"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) response.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } String serviceInstanceType = e2eSir.getService().getServiceType(); String serviceId = ""; - RequestClient requestClient = null; - HttpResponse response = null; + RequestClient requestClient; + HttpResponse response; long subStartTime = System.currentTimeMillis(); String sirRequestJson = convertToString(sir); @@ -809,7 +801,7 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine"); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } @@ -820,7 +812,7 @@ public class E2EServiceInstances { MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL"); msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Null response from BPMN"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } @@ -837,7 +829,7 @@ public class E2EServiceInstances { String requestId = UUIDChecker.generateUUID(msoLogger); long startTime = System.currentTimeMillis(); msoLogger.debug("requestId is: " + requestId); - E2EServiceInstanceScaleRequest e2eScaleReq = null; + E2EServiceInstanceScaleRequest e2eScaleReq; ObjectMapper mapper = new ObjectMapper(); try { @@ -860,11 +852,11 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.SchemaError, "Mapping of request to JSON object failed"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } - RecipeLookupResult recipeLookupResult = null; + RecipeLookupResult recipeLookupResult; try { //TODO Get the service template model version uuid from AAI. recipeLookupResult = getServiceInstanceOrchestrationURI(null, action); @@ -886,7 +878,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.DBAccessError, "Exception while communciate with DB"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } if (recipeLookupResult == null) { @@ -903,12 +895,12 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.DataNotFound, "No recipe found in DB"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) response.getEntity()); + + response.getEntity()); return response; } - RequestClient requestClient = null; - HttpResponse response = null; + RequestClient requestClient; + HttpResponse response; long subStartTime = System.currentTimeMillis(); try { @@ -963,7 +955,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) resp.getEntity()); + + resp.getEntity()); return resp; } @@ -979,7 +971,7 @@ public class E2EServiceInstances { msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError, "Null response from BPMN"); - msoLogger.debug(END_OF_THE_TRANSACTION + (String) resp.getEntity()); + msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity()); return resp; } @@ -1028,7 +1020,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.InternalError, "Response from BPMN engine is failed"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) resp.getEntity()); + + resp.getEntity()); return resp; } else { Response resp = msoRequest @@ -1047,7 +1039,7 @@ public class E2EServiceInstances { MsoLogger.ResponseCode.InternalError, "Response from BPEL engine is empty"); msoLogger.debug(END_OF_THE_TRANSACTION - + (String) resp.getEntity()); + + resp.getEntity()); return resp; } } @@ -1056,7 +1048,6 @@ public class E2EServiceInstances { /** * Getting recipes from catalogDb * - * @param db the catalog db * @param serviceModelUUID the service model version uuid * @param action the action for the service * @return the service recipe result @@ -1079,7 +1070,6 @@ public class E2EServiceInstances { /** * Getting recipes from catalogDb * If Service recipe is not set, use default recipe, if set , use special recipe. - * @param db the catalog db * @param serviceModelUUID the service version uuid * @param action the action of the service. * @return the service recipe result. @@ -1088,13 +1078,12 @@ public class E2EServiceInstances { String defaultServiceModelName = "UUI_DEFAULT"; - Service defaultServiceRecord = serviceRepo.findFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName); - ServiceRecipe defaultRecipe = sRecipeRepo.findFirstByServiceModelUUIDAndAction(defaultServiceRecord.getModelUUID(), action.name()); + Service defaultServiceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName); //set recipe as default generic recipe - ServiceRecipe recipe = defaultRecipe; + ServiceRecipe recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(defaultServiceRecord.getModelUUID(), action.name()); //check the service special recipe if(null != serviceModelUUID && ! serviceModelUUID.isEmpty()){ - ServiceRecipe serviceSpecialRecipe = sRecipeRepo.findFirstByServiceModelUUIDAndAction( + ServiceRecipe serviceSpecialRecipe = catalogDbClient.getFirstByServiceModelUUIDAndAction( serviceModelUUID, action.name()); if(null != serviceSpecialRecipe){ //set service special recipe. diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java index a93feb6cd9..66afcf3738 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java @@ -44,6 +44,7 @@ import org.onap.so.apihandler.common.ResponseBuilder; import org.onap.so.apihandlerinfra.tasksbeans.TasksRequest; import org.onap.so.apihandlerinfra.validation.ApplyUpdatedConfigValidation; import org.onap.so.apihandlerinfra.validation.CloudConfigurationValidation; +import org.onap.so.apihandlerinfra.validation.ConfigurationParametersValidation; import org.onap.so.apihandlerinfra.validation.InPlaceSoftwareUpdateValidation; import org.onap.so.apihandlerinfra.validation.InstanceIdMapValidation; import org.onap.so.apihandlerinfra.validation.ModelInfoValidation; @@ -95,7 +96,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class MsoRequest { @Autowired - private InfraActiveRequestsRepository iarRepo; + private RequestsDbClient requestsDbClient; @Autowired private ResponseBuilder builder; @@ -178,6 +179,7 @@ public class MsoRequest { rules.add(new PlatformLOBValidation()); rules.add(new ProjectOwningEntityValidation()); rules.add(new RelatedInstancesValidation()); + rules.add(new ConfigurationParametersValidation()); } if(reqVersion >= 7 && requestParameters != null && requestParameters.getUserParams() != null){ for(Map<String, Object> params : requestParameters.getUserParams()){ @@ -426,7 +428,7 @@ public class MsoRequest { request.setRequestBody(requestJSON); Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis()); request.setEndTime(endTimeStamp); - iarRepo.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); 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 3a944473d9..014739d581 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 @@ -102,7 +102,7 @@ public class OrchestrationRequests { requestDB = requestsDbClient.getInfraActiveRequestbyRequestId(requestId); } catch (Exception e) { - + msoLogger.error(e); ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, MsoLogger.ErrorCode.AvailabilityError).build(); AlarmLoggerInfo alarmLoggerInfo = new AlarmLoggerInfo.Builder("MsoDatabaseAccessError", MsoAlarmLogger.CRITICAL, Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB)).build(); @@ -156,12 +156,10 @@ public class OrchestrationRequests { throw new ValidationException("At least one filter query param must be specified"); } }catch(ValidationException ex){ + msoLogger.error(ex); ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MsoLogger.ErrorCode.DataError).build(); - - ValidateException validateException = new ValidateException.Builder(ex.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).cause(ex).errorInfo(errorLoggerInfo).build(); - throw validateException; } @@ -202,10 +200,8 @@ public class OrchestrationRequests { ObjectMapper mapper = new ObjectMapper(); sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class); } catch(IOException e){ - + msoLogger.error(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(); @@ -215,6 +211,7 @@ public class OrchestrationRequests { try{ msoRequest.parseOrchestration(sir); } catch (Exception e) { + msoLogger.error(e); ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MsoLogger.ErrorCode.SchemaError).build(); ValidateException validateException = new ValidateException.Builder("Error parsing request: " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e) .errorInfo(errorLoggerInfo).build(); @@ -301,7 +298,7 @@ public class OrchestrationRequests { requestDetails = mapper.readValue(requestBody, RequestDetails.class); } } catch (IOException e) { - + msoLogger.error(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 : ", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).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 index 466de0aa0e..380ee2c6ad 100644 --- 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 @@ -22,6 +22,7 @@ package org.onap.so.apihandlerinfra; import org.apache.http.HttpStatus; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.beans.OperationStatus; import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -30,10 +31,6 @@ 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; @@ -41,10 +38,9 @@ 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 javax.ws.rs.core.UriBuilder; import java.net.URI; import java.util.HashMap; import java.util.List; @@ -53,7 +49,11 @@ import java.util.Map; @Component("RequestDbClient") public class RequestsDbClient { + private static final String SERVICE_ID = "SERVICE_ID"; + private static final String OPERATION_ID = "OPERATION_ID"; + private Client<InfraActiveRequests> infraActiveRequestClient; + private Client<OperationStatus> operationStatusClient; @Value("${mso.adapters.requestDb.endpoint}") private String endpoint; @@ -62,12 +62,15 @@ public class RequestsDbClient { private String msoAdaptersAuth; private String getOrchestrationFilterURI = "/infraActiveRequests/getOrchestrationFiltersFromInfraActive/"; + private static final String OPERATION_STATUS_REPOSITORY_SEARCH = "/operationStatusRepository/search"; private String checkVnfIdStatus = "/infraActiveRequests/checkVnfIdStatus/"; private String infraActiveRequestURI = "/infraActiveRequests/"; private String checkInstanceNameDuplicate = "/infraActiveRequests/checkInstanceNameDuplicate"; + + private String findOneByServiceIdAndOperationIdURI = "/findOneByServiceIdAndOperationId"; private String cloudOrchestrationFiltersFromInfraActive = "/infraActiveRequests/getCloudOrchestrationFiltersFromInfraActive"; @@ -83,27 +86,18 @@ public class RequestsDbClient { checkVnfIdStatus = endpoint + checkVnfIdStatus; checkInstanceNameDuplicate = endpoint + checkInstanceNameDuplicate; cloudOrchestrationFiltersFromInfraActive = endpoint + cloudOrchestrationFiltersFromInfraActive; + findOneByServiceIdAndOperationIdURI = endpoint + OPERATION_STATUS_REPOSITORY_SEARCH + findOneByServiceIdAndOperationIdURI; 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(); + ClientFactory clientFactory = Configuration.builder().setRestTemplateConfigurer(restTemplate -> restTemplate.getInterceptors().add((request, body, execution) -> { + request.getHeaders().add("Authorization", msoAdaptersAuth); + return execution.execute(request, body); + })).build().buildClientFactory(); infraActiveRequestClient = clientFactory.create(InfraActiveRequests.class); + operationStatusClient = clientFactory.create(OperationStatus.class); } public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive(Map<String, String> orchestrationMap){ @@ -145,6 +139,13 @@ public class RequestsDbClient { } } + + public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId){ + return this.getSingleOperationStatus(UriBuilder.fromUri(findOneByServiceIdAndOperationIdURI) + .queryParam(SERVICE_ID,serviceId) + .queryParam(OPERATION_ID,operationId) + .build()); + } public void save(InfraActiveRequests infraActiveRequests) { URI uri = getUri(infraActiveRequestURI); @@ -159,6 +160,10 @@ public class RequestsDbClient { public void updateInfraActiveRequests(InfraActiveRequests request) { infraActiveRequestClient.put(request); } + + public OperationStatus getSingleOperationStatus(URI uri){ + return operationStatusClient.get(uri); + } protected URI getUri(String uri) { return URI.create(uri); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java index e259839d6e..ced69df55c 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java @@ -525,6 +525,21 @@ public class ServiceInstances { Response response = serviceInstances(request, Action.deactivateAndCloudDelete, instanceIdMap, version, requestId, getRequestUri(requestContext)); return response; } + + @POST + @Path("/{version:[vV][7]}/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/scaleOut") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value="VF Auto Scale Out",response=Response.class) + @Transactional + public Response scaleOutVfModule(String request, @PathParam("version") String version, @PathParam("serviceInstanceId") String serviceInstanceId, + @PathParam("vnfInstanceId") String vnfInstanceId, @Context ContainerRequestContext requestContext) throws ApiException { + String requestId = getRequestId(requestContext); + HashMap<String, String> instanceIdMap = new HashMap<>(); + instanceIdMap.put("serviceInstanceId", serviceInstanceId); + instanceIdMap.put("vnfInstanceId", vnfInstanceId); + return serviceInstances(request, Action.scaleOut, instanceIdMap, version, requestId, getRequestUri(requestContext)); + } @POST @@ -845,8 +860,20 @@ public class ServiceInstances { throw clientException; } - ResponseHandler respHandler = new ResponseHandler (response, requestClient.getType ()); - int bpelStatus = respHandler.getStatus (); + ResponseHandler respHandler = null; + int bpelStatus = 500; + try { + respHandler = new ResponseHandler (response, requestClient.getType ()); + bpelStatus = respHandler.getStatus (); + } catch (ApiException e) { + msoLogger.error(e); + ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, MsoLogger.ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + ValidateException validateException = new ValidateException.Builder("Exception caught mapping Camunda JSON response to object", HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).cause(e) + .errorInfo(errorLoggerInfo).build(); + currentActiveReq.setRequestStatus(Status.FAILED.name()); + currentActiveReq.setStatusMessage(validateException.getMessage()); + throw validateException; + } // BPEL accepted the request, the request is in progress if (bpelStatus == HttpStatus.SC_ACCEPTED) { @@ -858,7 +885,7 @@ public class ServiceInstances { ObjectMapper mapper = new ObjectMapper(); jsonResponse = mapper.readValue(camundaResp.getResponse(), ServiceInstancesResponse.class); } catch (IOException e) { - e.printStackTrace(); + msoLogger.error(e); ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, MsoLogger.ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); ValidateException validateException = new ValidateException.Builder("Exception caught mapping Camunda JSON response to object", HttpStatus.SC_NOT_ACCEPTABLE, ErrorNumbers.SVC_BAD_PARAMETER).cause(e) .errorInfo(errorLoggerInfo).build(); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CloudConfigurationValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CloudConfigurationValidation.java index 4c7365b187..f366c7e74b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CloudConfigurationValidation.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CloudConfigurationValidation.java @@ -53,7 +53,7 @@ public class CloudConfigurationValidation implements ValidationRule{ (action == Action.enablePort || action == Action.disablePort || action == Action.activateInstance || action == Action.deactivateInstance)){ throw new ValidationException ("cloudConfiguration"); } - if(requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.deactivateAndCloudDelete){ + if(requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && (action == Action.deactivateAndCloudDelete || action == Action.scaleOut)){ throw new ValidationException("cloudConfiguration"); } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ConfigurationParametersValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ConfigurationParametersValidation.java new file mode 100644 index 0000000000..edd1b1a10e --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ConfigurationParametersValidation.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.validation; + +import java.util.List; +import java.util.Map; + +import org.onap.so.apihandlerinfra.Action; +import org.onap.so.apihandlerinfra.Actions; +import org.onap.so.exceptions.ValidationException; +import org.onap.so.serviceinstancebeans.ModelType; +import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; + +public class ConfigurationParametersValidation implements ValidationRule{ + private static boolean empty(String s) { + return (s == null || s.trim().isEmpty()); + } + @Override + public ValidationInformation validate(ValidationInformation info) throws ValidationException{ + ServiceInstancesRequest sir = info.getSir(); + List<Map<String, String>> configParams = sir.getRequestDetails().getConfigurationParameters(); + String requestScope = info.getRequestScope(); + Actions action = info.getAction(); + + if(requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.scaleOut && configParams.isEmpty()){ + throw new ValidationException("configuration parameters"); + } + return info; + } +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ModelInfoValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ModelInfoValidation.java index 8ab7fccdff..aa98d2abf2 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ModelInfoValidation.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ModelInfoValidation.java @@ -23,6 +23,7 @@ package org.onap.so.apihandlerinfra.validation; import org.onap.so.apihandlerinfra.Action; import org.onap.so.apihandlerinfra.Actions; +import org.onap.so.apihandlerinfra.TestApi; import org.onap.so.exceptions.ValidationException; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.ModelType; @@ -73,19 +74,22 @@ public class ModelInfoValidation implements ValidationRule{ (requestScope.equalsIgnoreCase(ModelType.configuration.name()) && (action == Action.activateInstance || action == Action.deactivateInstance))))) { throw new ValidationException ("modelInvariantId"); } + if(empty(modelInfo.getModelInvariantId()) && (requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.scaleOut)){ + throw new ValidationException("modelInvariantId"); + } if (!empty (modelInfo.getModelInvariantId ()) && !UUIDChecker.isValidUUID (modelInfo.getModelInvariantId ())) { throw new ValidationException ("modelInvariantId format"); } if(reqVersion >= 4 && !(requestScope.equalsIgnoreCase(ModelType.configuration.name())) && empty (modelInfo.getModelName ()) && (action == Action.createInstance || action == Action.updateInstance || - action == Action.addRelationships || action == Action.removeRelationships || (action == Action.deleteInstance && (requestScope.equalsIgnoreCase (ModelType.vfModule.name ()))))){ + action == Action.addRelationships || action == Action.removeRelationships || ((action == Action.deleteInstance || action == Action.scaleOut) && (requestScope.equalsIgnoreCase (ModelType.vfModule.name ()))))){ throw new ValidationException ("modelName"); } if (empty (modelInfo.getModelVersion ()) && !(requestScope.equalsIgnoreCase(ModelType.configuration.name())) && (!(reqVersion < 4 && requestScope.equalsIgnoreCase (ModelType.network.name ())) - && (action == Action.createInstance || action == Action.updateInstance || action == Action.addRelationships || action == Action.removeRelationships))) { + && (action == Action.createInstance || action == Action.updateInstance || action == Action.addRelationships || action == Action.removeRelationships || action == Action.scaleOut))) { throw new ValidationException ("modelVersion"); } @@ -95,6 +99,9 @@ public class ModelInfoValidation implements ValidationRule{ (requestScope.equalsIgnoreCase(ModelType.configuration.name()) && (action == Action.activateInstance || action == Action.deactivateInstance))))) { throw new ValidationException ("modelVersionId"); } + if(empty(modelInfo.getModelVersionId()) && (requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.scaleOut)){ + throw new ValidationException("modelVersionId"); + } if(requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action != Action.deleteInstance && empty (modelInfo.getModelCustomizationName ())) { if (!UUIDChecker.isValidUUID (modelInfo.getModelCustomizationId())) { @@ -106,6 +113,9 @@ public class ModelInfoValidation implements ValidationRule{ && (action == Action.updateInstance || action == Action.createInstance)){ throw new ValidationException ("modelCustomizationId"); } + if(empty(modelInfo.getModelCustomizationId()) && action == Action.scaleOut && !(requestParameters.getTestApi() == TestApi.VNF_API.name() && requestParameters.isUsePreload() == true)){ + throw new ValidationException ("modelCustomizationId"); + } return info; } }
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/RelatedInstancesValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/RelatedInstancesValidation.java index 096b30939b..1f4fbc974a 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/RelatedInstancesValidation.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/RelatedInstancesValidation.java @@ -217,7 +217,8 @@ public class RelatedInstancesValidation implements ValidationRule{ } else if ((( requestScope.equalsIgnoreCase(ModelType.vnf.name ()) || requestScope.equalsIgnoreCase(ModelType.volumeGroup.name ()) || requestScope.equalsIgnoreCase(ModelType.vfModule.name ()) || requestScope.equalsIgnoreCase(ModelType.configuration.name())) && (action == Action.createInstance || action == Action.enablePort || action == Action.disablePort)) || - (reqVersion >= 4 && (requestScope.equalsIgnoreCase(ModelType.volumeGroup.name ()) || requestScope.equalsIgnoreCase(ModelType.vfModule.name ())) && action == Action.updateInstance) || + (reqVersion >= 4 && (requestScope.equalsIgnoreCase(ModelType.volumeGroup.name ()) || requestScope.equalsIgnoreCase(ModelType.vfModule.name ())) && action == Action.updateInstance || + (requestScope.equalsIgnoreCase(ModelType.vfModule.name ()) && action == Action.scaleOut)) || (requestScope.equalsIgnoreCase(ModelType.service.name()) && (action.equals(Action.addRelationships) || action.equals(Action.removeRelationships)))){ msoLogger.debug ("related instance exception"); throw new ValidationException ("related instances"); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml b/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml index 3252146bfa..acc04061cf 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml +++ b/mso-api-handlers/mso-api-handler-infra/src/main/resources/application-local.yaml @@ -17,6 +17,10 @@ camunda-nodehealthcheck-urn: /mso/nodehealthcheck mso: + adapters: + requestDb: + auth: Basic YnBlbDptc28tZGItMTUwNyE= + endpoint: http://localhost:8081 logPath: logs site-name: mtanj catalog: @@ -42,8 +46,6 @@ mso: sdna: url: http://localhost:8089/ password: 4112B789E942B161228F7D5AFC654C0F - bpelURL: http://localhost:8080/ - bpelAuth: 786864AA53D0DCD881AED1154230C0C3058D58B9339D2EFB6193A0F0D82530E1 camundaURL: http://localhost:8089/ camundaAuth: F8E9452B55DDE4CCE77547B0E748105C54CF5EF1351B4E2CBAABF2981EFE776D async: |