Search in sources :

Example 1 with ErrorLoggerInfo

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;
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) Response(javax.ws.rs.core.Response) JSONObject(org.json.JSONObject) UriBuilder(javax.ws.rs.core.UriBuilder) HttpClient(org.onap.so.client.HttpClient) URL(java.net.URL) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) JSONException(org.json.JSONException)

Example 2 with ErrorLoggerInfo

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();
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ValidationException(org.onap.so.exceptions.ValidationException) Distribution(org.onap.so.apihandlerinfra.tenantisolationbeans.Distribution) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) PATCH(javax.ws.rs.PATCH) Transactional(javax.transaction.Transactional)

Example 3 with ErrorLoggerInfo

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);
}
Also used : ServiceModelList(org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) OperationalEnvironment(org.onap.aai.domain.yang.OperationalEnvironment)

Example 4 with ErrorLoggerInfo

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);
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestProcessingData(org.onap.so.db.request.beans.RequestProcessingData) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Request(org.onap.so.serviceinstancebeans.Request) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) ValidationException(org.onap.so.exceptions.ValidationException) GetOrchestrationResponse(org.onap.so.serviceinstancebeans.GetOrchestrationResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) Transactional(javax.transaction.Transactional)

Example 5 with ErrorLoggerInfo

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;
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Request(org.onap.so.serviceinstancebeans.Request) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) IOException(java.io.IOException) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) ValidationException(org.onap.so.exceptions.ValidationException) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) InstanceReferences(org.onap.so.serviceinstancebeans.InstanceReferences) CloudRequestData(org.onap.so.serviceinstancebeans.CloudRequestData) SimpleDateFormat(java.text.SimpleDateFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestStatus(org.onap.so.serviceinstancebeans.RequestStatus)

Aggregations

ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)42 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)34 IOException (java.io.IOException)22 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)20 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)19 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)18 ValidationException (org.onap.so.exceptions.ValidationException)17 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 RequestClientParameter (org.onap.so.apihandler.common.RequestClientParameter)10 RequestDbFailureException (org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException)10 Operation (io.swagger.v3.oas.annotations.Operation)9 Transactional (javax.transaction.Transactional)9 Path (javax.ws.rs.Path)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 Produces (javax.ws.rs.Produces)8 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)8 Consumes (javax.ws.rs.Consumes)6 Response (javax.ws.rs.core.Response)6 BPMNFailureException (org.onap.so.apihandlerinfra.exceptions.BPMNFailureException)6 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)5