use of org.onap.so.apihandlerinfra.exceptions.ValidateException in project so by onap.
the class ActivateVnfStatusOperationalEnvironment method callSDClientForRetry.
/**
* The Method to call SDC for recoveryActioin RETRY
*
* @param queryDistributionDbResponse - OperationalEnvDistributionStatus object
* @param queryServiceModelResponse - OperationalEnvServiceModelStatus object
* @param sdcStatus - Distribution object
* @return JSONObject object
*/
public JSONObject callSDClientForRetry(OperationalEnvDistributionStatus queryDistributionDbResponse, OperationalEnvServiceModelStatus queryServiceModelResponse, Distribution sdcStatus) throws ApiException {
JSONObject jsonResponse = null;
String operEnvironmentId = queryDistributionDbResponse.getOperationalEnvId();
String serviceModelVersionId = queryDistributionDbResponse.getServiceModelVersionId();
String originalRequestId = queryServiceModelResponse.getRequestId();
int retryCount = queryServiceModelResponse.getRetryCount();
String workloadContext = queryServiceModelResponse.getWorkloadContext();
jsonResponse = sdcClientHelper.postActivateOperationalEnvironment(serviceModelVersionId, operEnvironmentId, workloadContext);
String statusCode = jsonResponse.get("statusCode").toString();
if (statusCode.equals(String.valueOf(Response.Status.ACCEPTED.getStatusCode()))) {
String newDistributionId = jsonResponse.get("distributionId").toString();
// should insert 1 row, NEW distributionId for replacement of the serviceModelServiceId record
OperationalEnvDistributionStatus insertNewDistributionId = dbHelper.insertRecordToOperationalEnvDistributionStatus(newDistributionId, operEnvironmentId, serviceModelVersionId, originalRequestId, DISTRIBUTION_STATUS_SENT, "");
client.save(insertNewDistributionId);
// update retryCount (less 1) for the serviceModelServiceId
retryCount = retryCount - 1;
// should update 1 row, original insert
OperationalEnvServiceModelStatus updateRetryCountAndStatus = dbHelper.updateRetryCountAndStatusInOperationalEnvServiceModelStatus(queryServiceModelResponse, DISTRIBUTION_STATUS_SENT, retryCount);
client.save(updateRetryCountAndStatus);
// should update 1 row, OLD distributionId set to status error (ie, old distributionId is DONE!).
OperationalEnvDistributionStatus updateStatus = dbHelper.updateStatusInOperationalEnvDistributionStatus(queryDistributionDbResponse, DISTRIBUTION_STATUS_ERROR, sdcStatus.getErrorReason());
client.save(updateStatus);
} else {
String dbErrorMessage = "Failure calling SDC: statusCode: " + statusCode + "; messageId: " + jsonResponse.get("messageId") + "; message: " + jsonResponse.get("message");
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
ValidateException validateException = new ValidateException.Builder(dbErrorMessage, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
requestDb.updateInfraFailureCompletion(dbErrorMessage, this.origRequestId, operEnvironmentId);
throw validateException;
}
return jsonResponse;
}
use of org.onap.so.apihandlerinfra.exceptions.ValidateException in project so by onap.
the class ActivateVnfStatusOperationalEnvironment method checkOrUpdateOverallStatus.
/**
* The Method to check the overall status of the Activation for an operationalEnvironmentId
*
* @param operationalEnvironmentId - string
* @param origRequestId - string
* @return void - nothing
*/
public void checkOrUpdateOverallStatus(String operationalEnvironmentId, String origRequestId) throws ApiException {
List<OperationalEnvServiceModelStatus> queryServiceModelResponseList = client.getAllByOperationalEnvIdAndRequestId(operationalEnvironmentId, origRequestId);
String status = "Waiting";
int count = 0;
// loop through the statuses of the service model
for (OperationalEnvServiceModelStatus querySrvModelResponse : queryServiceModelResponseList) {
status = querySrvModelResponse.getServiceModelVersionDistrStatus();
// all should be OK to be completed.
if ((status.equals(DistributionStatus.DISTRIBUTION_COMPLETE_OK.toString()) && (querySrvModelResponse.getRetryCount() == 0))) {
status = "Completed";
count++;
}
// one error with zero retry, means all are failures.
if ((status.equals(DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString()) && (querySrvModelResponse.getRetryCount() == 0))) {
status = "Failure";
count = queryServiceModelResponseList.size();
break;
}
}
if (status.equals("Completed") && queryServiceModelResponseList.size() == count) {
String messageStatus = "Overall Activation process is complete. " + status;
isOverallSuccess = true;
requestDb.updateInfraSuccessCompletion(messageStatus, origRequestId, operationalEnvironmentId);
} else {
if (status.equals("Failure") && queryServiceModelResponseList.size() == count) {
this.errorMessage = "Overall Activation process is a Failure. " + status;
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
ValidateException validateException = new ValidateException.Builder(this.errorMessage, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
requestDb.updateInfraFailureCompletion(this.errorMessage, origRequestId, operationalEnvironmentId);
throw validateException;
}
}
}
use of org.onap.so.apihandlerinfra.exceptions.ValidateException 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.ValidateException in project so by onap.
the class CloudOrchestration method convertJsonToCloudOrchestrationRequest.
private CloudOrchestrationRequest convertJsonToCloudOrchestrationRequest(String requestJSON, Action action, long startTime, CloudOrchestrationRequest cor) throws ApiException {
try {
logger.debug("Converting incoming JSON request to Object");
ObjectMapper mapper = new ObjectMapper();
return 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();
if (tenantIsolationRequest.getRequestId() != null) {
tenantIsolationRequest.createRequestRecord(Status.FAILED, action);
}
throw validateException;
}
}
use of org.onap.so.apihandlerinfra.exceptions.ValidateException 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();
}
Aggregations