Search in sources :

Example 31 with ServiceInstancesRequest

use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.

the class VolumeRestHandlerTest method createTestRequest.

private ServiceInstancesRequest createTestRequest() {
    ServiceInstancesRequest request = new ServiceInstancesRequest();
    RequestDetails requestDetails = new RequestDetails();
    RequestInfo requestInfo = new RequestInfo();
    requestInfo.setInstanceName("instanceName");
    requestDetails.setRequestInfo(requestInfo);
    request.setRequestDetails(requestDetails);
    return request;
}
Also used : RequestInfo(org.onap.so.serviceinstancebeans.RequestInfo) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails)

Example 32 with ServiceInstancesRequest

use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.

the class VfModuleRestHandlerTest method createTestRequest.

private ServiceInstancesRequest createTestRequest() {
    ServiceInstancesRequest request = new ServiceInstancesRequest();
    RequestDetails requestDetails = new RequestDetails();
    RequestInfo requestInfo = new RequestInfo();
    requestInfo.setInstanceName("instanceName");
    requestDetails.setRequestInfo(requestInfo);
    request.setRequestDetails(requestDetails);
    return request;
}
Also used : RequestInfo(org.onap.so.serviceinstancebeans.RequestInfo) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails)

Example 33 with ServiceInstancesRequest

use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest 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)

Example 34 with ServiceInstancesRequest

use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.

the class MsoRequest method createRequestObject.

public InfraActiveRequests createRequestObject(ServiceInstancesRequest servInsReq, Actions action, String requestId, Status status, String originalRequestJSON, String requestScope) {
    InfraActiveRequests aq = new InfraActiveRequests();
    try {
        if (null == servInsReq) {
            servInsReq = new ServiceInstancesRequest();
        }
        String networkType = "";
        String vnfType = "";
        aq.setRequestId(requestId);
        aq.setRequestAction(action.toString());
        aq.setRequestUrl(MDC.get(LogConstants.HTTP_URL));
        Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());
        aq.setStartTime(startTimeStamp);
        if (requestScope.equals(ModelType.instanceGroup.name()) && action == Action.deleteInstance) {
            aq.setRequestScope(requestScope);
        } else {
            RequestInfo requestInfo = servInsReq.getRequestDetails().getRequestInfo();
            if (requestInfo != null) {
                if (requestInfo.getSource() != null) {
                    aq.setSource(requestInfo.getSource());
                }
                if (requestInfo.getCallbackUrl() != null) {
                    aq.setCallBackUrl(requestInfo.getCallbackUrl());
                }
                if (requestInfo.getCorrelator() != null) {
                    aq.setCorrelator(requestInfo.getCorrelator());
                }
                if (requestInfo.getRequestorId() != null) {
                    aq.setRequestorId(requestInfo.getRequestorId());
                }
            }
            if (servInsReq.getRequestDetails().getModelInfo() != null || (action == Action.inPlaceSoftwareUpdate || action == Action.applyUpdatedConfig)) {
                aq.setRequestScope(requestScope);
            }
            if (servInsReq.getRequestDetails().getCloudConfiguration() != null) {
                CloudConfiguration cloudConfiguration = servInsReq.getRequestDetails().getCloudConfiguration();
                if (cloudConfiguration.getLcpCloudRegionId() != null) {
                    aq.setCloudRegion(cloudConfiguration.getLcpCloudRegionId());
                }
                if (cloudConfiguration.getTenantId() != null) {
                    aq.setTenantId(cloudConfiguration.getTenantId());
                }
            }
            if (servInsReq.getServiceInstanceId() != null) {
                aq.setServiceInstanceId(servInsReq.getServiceInstanceId());
            }
            if (servInsReq.getVnfInstanceId() != null) {
                aq.setVnfId(servInsReq.getVnfInstanceId());
            }
            if (servInsReq.getPnfName() != null) {
                aq.setRequestScope(requestScope);
                aq.setPnfName(servInsReq.getPnfName());
            }
            if (servInsReq.getRequestDetails() != null && servInsReq.getRequestDetails().getRequestInfo() != null && servInsReq.getRequestDetails().getRequestInfo().getProductFamilyId() != null) {
                logger.debug("Retrieving productFamilyName to put into requests db");
                org.onap.aai.domain.yang.Service service = aaiDataRet.getService(servInsReq.getRequestDetails().getRequestInfo().getProductFamilyId());
                if (service != null) {
                    logger.debug("Found service by service-id");
                    String productFamilyName = service.getServiceDescription();
                    if (productFamilyName != null) {
                        aq.setProductFamilyName(productFamilyName);
                    }
                }
            }
            aq.setProductFamilyName(getProductFamilyNameFromAAI(servInsReq));
            aq.setTenantName(getTenantNameFromAAI(servInsReq));
            if (ModelType.service.name().equalsIgnoreCase(requestScope)) {
                if (servInsReq.getRequestDetails().getRequestInfo() != null) {
                    if (servInsReq.getRequestDetails().getRequestInfo().getInstanceName() != null) {
                        aq.setServiceInstanceName(requestInfo.getInstanceName());
                    }
                }
            }
            if (ModelType.network.name().equalsIgnoreCase(requestScope)) {
                aq.setNetworkName(servInsReq.getRequestDetails().getRequestInfo().getInstanceName());
                aq.setNetworkType(networkType);
                aq.setNetworkId(servInsReq.getNetworkInstanceId());
            }
            if (ModelType.volumeGroup.name().equalsIgnoreCase(requestScope)) {
                aq.setVolumeGroupId(servInsReq.getVolumeGroupInstanceId());
                aq.setVolumeGroupName(servInsReq.getRequestDetails().getRequestInfo().getInstanceName());
                aq.setVnfType(vnfType);
            }
            if (ModelType.vfModule.name().equalsIgnoreCase(requestScope)) {
                aq.setVfModuleName(requestInfo.getInstanceName());
                aq.setVfModuleModelName(servInsReq.getRequestDetails().getModelInfo().getModelName());
                aq.setVfModuleId(servInsReq.getVfModuleInstanceId());
                aq.setVolumeGroupId(servInsReq.getVolumeGroupInstanceId());
                aq.setVnfType(vnfType);
            }
            if (ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
                aq.setConfigurationId(servInsReq.getConfigurationId());
                aq.setConfigurationName(requestInfo.getInstanceName());
            }
            if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.name())) {
                aq.setInstanceGroupId(servInsReq.getInstanceGroupId());
                aq.setInstanceGroupName(requestInfo.getInstanceName());
            }
            if (ModelType.vnf.name().equalsIgnoreCase(requestScope)) {
                if (requestInfo != null) {
                    aq.setVnfName(requestInfo.getInstanceName());
                }
                if (null != servInsReq.getRequestDetails()) {
                    RelatedInstanceList[] instanceList = servInsReq.getRequestDetails().getRelatedInstanceList();
                    if (instanceList != null) {
                        for (RelatedInstanceList relatedInstanceList : instanceList) {
                            RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
                            if (relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) {
                                aq.setVnfType(vnfType);
                            }
                        }
                    }
                }
            }
        }
        aq.setRequestBody(originalRequestJSON);
        aq.setRequestStatus(status.toString());
        aq.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
    } catch (Exception e) {
        logger.error("Exception when creation record request", e);
        if (!status.equals(Status.FAILED)) {
            throw e;
        }
    }
    return aq;
}
Also used : RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) RequestInfo(org.onap.so.serviceinstancebeans.RequestInfo) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) Timestamp(java.sql.Timestamp) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) PolicyException(org.onap.so.serviceinstancebeans.PolicyException) ServiceException(org.onap.so.serviceinstancebeans.ServiceException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) IOException(java.io.IOException) ValidationException(org.onap.so.exceptions.ValidationException) CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration)

Example 35 with ServiceInstancesRequest

use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.

the class ResumeOrchestrationRequest method resumeRequest.

protected Response resumeRequest(InfraActiveRequests infraActiveRequest, InfraActiveRequests currentActiveRequest, String version, String requestUri) throws ApiException {
    String requestBody = infraActiveRequest.getRequestBody();
    Action action = Action.valueOf(infraActiveRequest.getRequestAction());
    String requestId = currentActiveRequest.getRequestId();
    String requestScope = infraActiveRequest.getRequestScope();
    String instanceName = getInstanceName(infraActiveRequest, requestScope, currentActiveRequest);
    HashMap<String, String> instanceIdMap = setInstanceIdMap(infraActiveRequest, requestScope);
    checkForInProgressRequest(currentActiveRequest, instanceIdMap, requestScope, instanceName, action);
    ServiceInstancesRequest sir = null;
    sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestBody, action, requestId, requestUri);
    Boolean aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte();
    String pnfCorrelationId = serviceInstances.getPnfCorrelationId(sir);
    RecipeLookupResult recipeLookupResult = requestHandlerUtils.getServiceInstanceOrchestrationURI(sir, action, msoRequest.getAlacarteFlag(sir), currentActiveRequest);
    requestDbSave(currentActiveRequest);
    if (aLaCarte == null) {
        aLaCarte = setALaCarteFlagIfNull(requestScope, action);
    }
    RequestClientParameter requestClientParameter = setRequestClientParameter(recipeLookupResult, version, infraActiveRequest, currentActiveRequest, pnfCorrelationId, aLaCarte, sir);
    return requestHandlerUtils.postBPELRequest(currentActiveRequest, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope);
}
Also used : ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter)

Aggregations

ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)100 Test (org.junit.Test)58 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)36 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)17 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)15 RequestInfo (org.onap.so.serviceinstancebeans.RequestInfo)15 IOException (java.io.IOException)11 BaseTest (org.onap.so.apihandlerinfra.BaseTest)11 CloudConfiguration (org.onap.so.serviceinstancebeans.CloudConfiguration)11 ValidationException (org.onap.so.exceptions.ValidationException)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)8 CloudConfigurationNotFoundException (org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFoundException)8 Service (org.onap.so.db.catalog.beans.Service)8 ArrayList (java.util.ArrayList)7 RequestClientParameter (org.onap.so.apihandler.common.RequestClientParameter)7 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)7 ServiceInstancesResponse (org.onap.so.serviceinstancebeans.ServiceInstancesResponse)7 GenericVnf (org.onap.aai.domain.yang.GenericVnf)6