use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.
the class ActivateVnfStatusOperationalEnvironmentTest method checkOrUpdateOverallStatusTest_Error.
@Test
public void checkOrUpdateOverallStatusTest_Error() throws JsonProcessingException {
OperationalEnvServiceModelStatus serviceModelDb = new OperationalEnvServiceModelStatus();
serviceModelDb.setRequestId(requestIdOrig);
serviceModelDb.setServiceModelVersionId(serviceModelVersionId);
serviceModelDb.setWorkloadContext(workloadContext);
serviceModelDb.setRecoveryAction(recoveryActionRetry);
serviceModelDb.setOperationalEnvId(operationalEnvironmentId);
serviceModelDb.setRetryCount(retryCountZero);
serviceModelDb.setServiceModelVersionDistrStatus(statusError);
serviceModelDb.setVnfOperationalEnvId(vnfOperationalEnvironmentId);
wireMockServer.stubFor(get(urlPathEqualTo("/operationalEnvServiceModelStatus/search/findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(serviceModelDb)).withStatus(HttpStatus.SC_OK)));
InfraActiveRequests iar = new InfraActiveRequests();
iar.setRequestId(requestIdOrig);
iar.setRequestStatus("PENDING");
wireMockServer.stubFor(get(urlPathEqualTo("/infraActiveRequests/" + requestIdOrig)).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(iar)).withStatus(HttpStatus.SC_OK)));
try {
activateVnfStatus.checkOrUpdateOverallStatus(operationalEnvironmentId, requestIdOrig);
} catch (ApiException e) {
assertThat(e.getMessage(), startsWith("Overall Activation process is a Failure. "));
assertEquals(e.getHttpResponseCode(), HttpStatus.SC_BAD_REQUEST);
assertEquals(e.getMessageID(), ErrorNumbers.SVC_DETAILED_SERVICE_ERROR);
}
}
use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.
the class CreateVnfOperationalEnvironment method execute.
public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
try {
setRequest(request);
ObjectMapper objectMapper = new ObjectMapper();
AAIResultWrapper aaiResultWrapper = aaiHelper.getAaiOperationalEnvironment(getEcompManagingEnvironmentId());
if (aaiResultWrapper.isEmpty()) {
throw new NotFoundException(getEcompManagingEnvironmentId() + " not found in A&AI");
}
OperationalEnvironment aaiEnv = aaiResultWrapper.asBean(OperationalEnvironment.class).get();
// Find ECOMP environments in GRM
logger.debug(" Start of GRM findRunningServicesAsString");
String searchKey = getSearchKey(aaiEnv);
String tenantContext = getTenantContext().toUpperCase();
String jsonResponse = getGrmClient().findRunningServicesAsString(searchKey, 1, tenantContext);
ServiceEndPointList sel = objectMapper.readValue(jsonResponse, ServiceEndPointList.class);
if (sel.getServiceEndPointList().size() == 0) {
throw new TenantIsolationException("GRM did not find any matches for " + searchKey + " in " + tenantContext);
}
// Replicate end-point for VNF Operating environment in GRM
List<ServiceEndPointRequest> serviceEndpointRequestList = buildEndPointRequestList(sel);
int ctr = 0;
int total = serviceEndpointRequestList.size();
for (ServiceEndPointRequest requestList : serviceEndpointRequestList) {
logger.debug("Creating endpoint " + ++ctr + " of " + total + ": " + requestList.getServiceEndPoint().getName());
getGrmClient().addServiceEndPoint(requestList);
}
// Create VNF operating in A&AI
aaiHelper.createOperationalEnvironment(aaiClientObjectBuilder.buildAAIOperationalEnvironment("INACTIVE", request));
aaiHelper.createRelationship(request.getOperationalEnvironmentId(), getEcompManagingEnvironmentId());
// Update request database
requestDb.updateInfraSuccessCompletion("SUCCESSFULLY created VNF operational environment", requestId, request.getOperationalEnvironmentId());
} catch (Exception e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
}
use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.
the class CloudResourcesOrchestration method unlockOrchestrationRequest.
@POST
@Path("/{version: [vV][1]}/{requestId}/unlock")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Unlock CloudOrchestration requests for a specified requestId")
@Transactional
public Response unlockOrchestrationRequest(String requestJSON, @PathParam("requestId") String requestId, @PathParam("version") String version) throws ApiException {
TenantIsolationRequest msoRequest = new TenantIsolationRequest(requestId);
InfraActiveRequests infraActiveRequest;
CloudOrchestrationRequest cor;
logger.debug("requestId is: {}", requestId);
try {
ObjectMapper mapper = new ObjectMapper();
cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
} catch (IOException e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, 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;
}
try {
msoRequest.parseOrchestration(cor);
} catch (ValidationException e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
try {
infraActiveRequest = requestDbClient.getInfraActiveRequestbyRequestId(requestId);
} catch (Exception e) {
ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).build();
throw validateException;
}
if (infraActiveRequest == null) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.BusinessProcessError).build();
ValidateException validateException = new ValidateException.Builder("Orchestration RequestId " + requestId + " is not found in DB", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
throw validateException;
} else {
String status = infraActiveRequest.getRequestStatus();
if ("IN_PROGRESS".equalsIgnoreCase(status) || "PENDING".equalsIgnoreCase(status) || "PENDING_MANUAL_TASK".equalsIgnoreCase(status)) {
infraActiveRequest.setRequestStatus("UNLOCKED");
infraActiveRequest.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
infraActiveRequest.setRequestId(requestId);
requestDbClient.save(infraActiveRequest);
} else {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.DataError).build();
ValidateException validateException = new ValidateException.Builder("Orchestration RequestId " + requestId + " has a status of " + status + " and can not be unlocked", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
throw validateException;
}
}
return Response.status(HttpStatus.SC_NO_CONTENT).entity("").build();
}
use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.
the class CloudResourcesOrchestration method getOperationEnvironmentStatusFilter.
@GET
@Path("/{version:[vV][1]}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Get status of an Operational Environment based on filter criteria", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response getOperationEnvironmentStatusFilter(@Context UriInfo ui, @PathParam("version") String version) throws ApiException {
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
List<String> requestIdKey = queryParams.get("requestId");
String apiVersion = version.substring(1);
if (queryParams.size() == 1 && requestIdKey != null) {
String requestId = requestIdKey.get(0);
CloudOrchestrationResponse cloudOrchestrationGetResponse = new CloudOrchestrationResponse();
InfraActiveRequests requestDB;
try {
requestDB = requestDbClient.getInfraActiveRequestbyRequestId(requestId);
} catch (Exception e) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.AvailabilityError).build();
ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
if (requestDB == null) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, ErrorCode.BusinessProcessError).build();
ValidateException validateException = new ValidateException.Builder("Orchestration RequestId " + requestId + " is not found in DB", HttpStatus.SC_NO_CONTENT, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
throw validateException;
}
Request request = mapInfraActiveRequestToRequest(requestDB);
cloudOrchestrationGetResponse.setRequest(request);
return builder.buildResponse(HttpStatus.SC_OK, requestId, cloudOrchestrationGetResponse, apiVersion);
} else {
TenantIsolationRequest tenantIsolationRequest = new TenantIsolationRequest();
List<InfraActiveRequests> activeRequests;
CloudOrchestrationRequestList orchestrationList;
Map<String, String> orchestrationMap;
try {
orchestrationMap = tenantIsolationRequest.getOrchestrationFilters(queryParams);
} catch (ValidationException ex) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
ValidateException validateException = new ValidateException.Builder(ex.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).cause(ex).errorInfo(errorLoggerInfo).build();
throw validateException;
}
activeRequests = requestDbClient.getCloudOrchestrationFiltersFromInfraActive(orchestrationMap);
orchestrationList = new CloudOrchestrationRequestList();
List<CloudOrchestrationResponse> requestLists = new ArrayList<>();
for (InfraActiveRequests infraActive : activeRequests) {
Request request = mapInfraActiveRequestToRequest(infraActive);
CloudOrchestrationResponse requestList = new CloudOrchestrationResponse();
requestList.setRequest(request);
requestLists.add(requestList);
}
orchestrationList.setRequestList(requestLists);
return builder.buildResponse(HttpStatus.SC_OK, null, orchestrationList, apiVersion);
}
}
Aggregations