use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.
the class SDCClientHelper method postActivateOperationalEnvironment.
/**
* Send POST request to SDC for operational activation
*
* @param serviceModelVersionI - String
* @param operationalEnvironmentId - String
* @param workloadContext - String
* @return sdcResponseJsonObj - JSONObject object
* @throws JSONException
*/
public JSONObject postActivateOperationalEnvironment(String serviceModelVersionId, String operationalEnvironmentId, String workloadContext) throws ApiException {
JSONObject sdcResponseJsonObj = new JSONObject();
try {
String urlString = this.buildUriBuilder(serviceModelVersionId, operationalEnvironmentId);
String jsonPayload = this.buildJsonWorkloadContext(workloadContext);
String basicAuthCred = getBasicAuth();
if (basicAuthCred == null || "".equals(basicAuthCred)) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
throw new ValidateException.Builder(" SDC credentials 'mso.sdc.client.auth' not setup in properties file!", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
}
URL url = new URL(urlString);
HttpClient httpClient = httpClientFactory.newJsonClient(url, ONAPComponents.SDC);
httpClient.addBasicAuthHeader(sdcClientAuth, msoKey);
httpClient.addAdditionalHeader("X-ECOMP-InstanceID", sdcActivateInstanceId);
httpClient.addAdditionalHeader("Content-Type", SDCClientHelper.SDC_CONTENT_TYPE);
httpClient.addAdditionalHeader("Accept", SDCClientHelper.SDC_ACCEPT_TYPE);
httpClient.addAdditionalHeader("USER_ID", sdcActivateUserId);
Response apiResponse = setHttpPostResponse(httpClient, jsonPayload);
int statusCode = apiResponse.getStatus();
;
String responseData = apiResponse.readEntity(String.class);
sdcResponseJsonObj = enhanceJsonResponse(new JSONObject(responseData), statusCode);
} catch (Exception ex) {
logger.debug("calling SDC Exception message:", ex);
String errorMessage = " Encountered Error while calling SDC POST Activate. " + ex.getMessage();
logger.debug(errorMessage);
sdcResponseJsonObj.put(STATUS_CODE, String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
sdcResponseJsonObj.put(MESSAGE_ID, "");
sdcResponseJsonObj.put(MESSAGE, errorMessage);
}
return sdcResponseJsonObj;
}
use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.
the class ModelDistributionRequest method updateModelDistributionStatus.
@PATCH
@Path("/{version:[vV][1]}/distributions/{distributionId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Update model distribution status", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response updateModelDistributionStatus(String requestJSON, @PathParam("version") String version, @PathParam("distributionId") String distributionId) throws ApiException {
Distribution distributionRequest;
try {
ObjectMapper mapper = new ObjectMapper();
distributionRequest = mapper.readValue(requestJSON, Distribution.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 {
parse(distributionRequest);
} 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;
}
CloudOrchestrationRequest cor = new CloudOrchestrationRequest();
cor.setDistribution(distributionRequest);
cor.setDistributionId(distributionId);
TenantIsolationRunnable runnable = tenantIsolationRunnable.get();
runnable.run(Action.distributionStatus, null, cor, null);
return Response.ok().build();
}
use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.
the class ActivateVnfOperationalEnvironment method execute.
/**
* The Point-Of-Entry from APIH with VID request to send activate request
*
* @param requestId - String
* @param request - CloudOrchestrationRequest object
* @return void - nothing
*/
public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
String vnfOperationalEnvironmentId = request.getOperationalEnvironmentId();
String vidWorkloadContext = request.getRequestDetails().getRequestParameters().getWorkloadContext();
List<ServiceModelList> serviceModelVersionIdList = request.getRequestDetails().getRequestParameters().getManifest().getServiceModelList();
String ecompOperationalEnvironmentId = null;
AAIResultWrapper wrapper = getAAIOperationalEnvironment(vnfOperationalEnvironmentId);
Optional<Relationships> optRelationships = wrapper.getRelationships();
if (optRelationships.isPresent()) {
Relationships relationships = optRelationships.get();
List<AAIResourceUri> operationalEnvironments = relationships.getRelatedUris(Types.OPERATIONAL_ENVIRONMENT);
if (!operationalEnvironments.isEmpty()) {
ecompOperationalEnvironmentId = operationalEnvironments.get(0).getURIKeys().get(AAIFluentTypeBuilder.Types.OPERATIONAL_ENVIRONMENT.getUriParams().operationalEnvironmentId);
}
}
logger.debug(" vnfOperationalEnvironmentId : {}", vnfOperationalEnvironmentId);
logger.debug(" ecompOperationalEnvironmentId : {}", ecompOperationalEnvironmentId);
OperationalEnvironment operationalEnv = wrapper.asBean(OperationalEnvironment.class).get();
String workloadContext = operationalEnv.getWorkloadContext();
logger.debug(" aai workloadContext: {}", workloadContext);
if (!vidWorkloadContext.equals(workloadContext)) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
throw new ValidateException.Builder(" The vid workloadContext did not match from aai record. " + " vid workloadContext:" + vidWorkloadContext + " aai workloadContext:" + workloadContext, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
}
if (ecompOperationalEnvironmentId == null) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
throw new ValidateException.Builder(" The ECOMP OE was not in aai record; the value of relationship.relationship-data key: " + AAIFluentTypeBuilder.Types.OPERATIONAL_ENVIRONMENT.getUriParams().operationalEnvironmentId, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
}
processActivateSDCRequest(requestId, ecompOperationalEnvironmentId, serviceModelVersionIdList, workloadContext, vnfOperationalEnvironmentId);
}
use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.
the class OrchestrationRequests method getOrchestrationRequest.
@GET
@Path("/{version:[vV][4-8]}/{requestId}")
@Operation(description = "Find Orchestrated Requests for a given requestId", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public Response getOrchestrationRequest(@PathParam("requestId") String requestId, @PathParam("version") String version, @QueryParam("includeCloudRequest") boolean includeCloudRequest, @QueryParam(value = "format") String format) throws ApiException {
GetOrchestrationResponse orchestrationResponse = new GetOrchestrationResponse();
InfraActiveRequests infraActiveRequest = null;
List<org.onap.so.db.request.beans.RequestProcessingData> requestProcessingData = null;
if (!UUIDChecker.isValidUUID(requestId)) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.SchemaError).errorSource(Constants.MODIFIED_BY_APIHANDLER).build();
throw new ValidateException.Builder("Request Id " + requestId + " is not a valid UUID", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
}
infraActiveRequest = infraActiveRequestLookup(requestId);
if (isRequestProcessingDataRequired(format)) {
try {
requestProcessingData = requestsDbClient.getExternalRequestProcessingDataBySoRequestId(requestId);
} catch (Exception e) {
logger.error("Exception occurred while communicating with RequestDb during requestProcessingData lookup ", e);
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.AvailabilityError).build();
ValidateException validateException = new ValidateException.Builder("Exception occurred while communicating with RequestDb during requestProcessingData lookup", HttpStatus.SC_NOT_FOUND, ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
}
Request request = mapInfraActiveRequestToRequest(infraActiveRequest, includeCloudRequest, format, version);
if (null != requestProcessingData && !requestProcessingData.isEmpty()) {
request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData));
}
request.setRequestId(requestId);
orchestrationResponse.setRequest(request);
return builder.buildResponse(HttpStatus.SC_OK, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID), orchestrationResponse, version);
}
use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.
the class OrchestrationRequests method mapInfraActiveRequestToRequest.
protected Request mapInfraActiveRequestToRequest(InfraActiveRequests iar, boolean includeCloudRequest, String format, String version) throws ApiException {
String requestBody = iar.getRequestBody();
Request request = new Request();
ObjectMapper mapper = new ObjectMapper();
request.setRequestId(iar.getRequestId());
request.setRequestScope(iar.getRequestScope());
request.setRequestType(iar.getRequestAction());
String originalRequestId = iar.getOriginalRequestId();
if (originalRequestId != null) {
request.setOriginalRequestId(originalRequestId);
}
if (!version.matches("v[1-7]")) {
String workflowName = iar.getWorkflowName();
if (workflowName == null) {
workflowName = iar.getRequestAction();
}
request.setWorkflowName(workflowName);
String operationName = iar.getOperationName();
if (operationName != null) {
request.setOperationName(operationName);
}
}
InstanceReferences ir = new InstanceReferences();
if (iar.getNetworkId() != null)
ir.setNetworkInstanceId(iar.getNetworkId());
if (iar.getNetworkName() != null)
ir.setNetworkInstanceName(iar.getNetworkName());
if (iar.getServiceInstanceId() != null)
ir.setServiceInstanceId(iar.getServiceInstanceId());
if (iar.getServiceInstanceName() != null)
ir.setServiceInstanceName(iar.getServiceInstanceName());
if (iar.getVfModuleId() != null)
ir.setVfModuleInstanceId(iar.getVfModuleId());
if (iar.getVfModuleName() != null)
ir.setVfModuleInstanceName(iar.getVfModuleName());
if (iar.getVnfId() != null)
ir.setVnfInstanceId(iar.getVnfId());
if (iar.getVnfName() != null)
ir.setVnfInstanceName(iar.getVnfName());
if (iar.getVolumeGroupId() != null)
ir.setVolumeGroupInstanceId(iar.getVolumeGroupId());
if (iar.getVolumeGroupName() != null)
ir.setVolumeGroupInstanceName(iar.getVolumeGroupName());
if (iar.getInstanceGroupId() != null)
ir.setInstanceGroupId(iar.getInstanceGroupId());
if (iar.getInstanceGroupName() != null)
ir.setInstanceGroupName(iar.getInstanceGroupName());
request.setInstanceReferences(ir);
RequestDetails requestDetails = null;
if (StringUtils.isNotBlank(requestBody)) {
try {
if (requestBody.contains("\"requestDetails\":")) {
ServiceInstancesRequest sir = mapper.readValue(requestBody, ServiceInstancesRequest.class);
requestDetails = sir.getRequestDetails();
} else {
requestDetails = mapper.readValue(requestBody, RequestDetails.class);
}
if (requestDetails.getRequestInfo() != null && iar.getProductFamilyName() != null) {
requestDetails.getRequestInfo().setProductFamilyName(iar.getProductFamilyName());
}
if (requestDetails.getCloudConfiguration() != null && iar.getTenantName() != null) {
requestDetails.getCloudConfiguration().setTenantName(iar.getTenantName());
}
} catch (IOException e) {
logger.error("Exception occurred", 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 : ", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
}
request.setRequestDetails(requestDetails);
if (iar.getStartTime() != null) {
String startTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getStartTime()) + " GMT";
request.setStartTime(startTimeStamp);
}
if (iar.getEndTime() != null) {
String endTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getEndTime()) + " GMT";
request.setFinishTime(endTimeStamp);
}
RequestStatus status = new RequestStatus();
if (iar.getModifyTime() != null) {
String timeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getModifyTime()) + " GMT";
status.setTimeStamp(timeStamp);
}
status.setRequestState(mapRequestStatusToRequest(iar, format));
if (iar.getProgress() != null) {
status.setPercentProgress(iar.getProgress().intValue());
}
if (iar.getCloudApiRequests() != null && !iar.getCloudApiRequests().isEmpty() && includeCloudRequest) {
iar.getCloudApiRequests().stream().forEach(cloudRequest -> {
try {
request.getCloudRequestData().add(new CloudRequestData(mapper.readValue(cloudRequest.getRequestBody(), Object.class), cloudRequest.getCloudIdentifier()));
} catch (Exception e) {
logger.error("Error reading Cloud Request", e);
}
});
}
mapRequestStatusAndExtSysErrSrcToRequest(iar, status, format, version);
request.setRequestStatus(status);
return request;
}
Aggregations