Search in sources :

Example 26 with ValidationException

use of org.onap.so.exceptions.ValidationException in project so by onap.

the class RequestInfoValidation method validate.

@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
    RequestInfo requestInfo = info.getSir().getRequestDetails().getRequestInfo();
    int reqVersion = info.getReqVersion();
    String requestScope = info.getRequestScope();
    Actions action = info.getAction();
    Boolean aLaCarteFlag = info.getALaCarteFlag();
    // required for all operations in V4
    if (empty(requestInfo.getRequestorId()) && reqVersion >= 4) {
        throw new ValidationException("requestorId");
    }
    if (empty(requestInfo.getSource())) {
        throw new ValidationException("source");
    }
    if (!empty(requestInfo.getInstanceName())) {
        if (!requestInfo.getInstanceName().matches(Constants.VALID_INSTANCE_NAME_FORMAT)) {
            throw new ValidationException("instanceName format");
        }
    }
    if (empty(requestInfo.getProductFamilyId())) {
        // Mandatory for macro request create service instance
        if ((requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.createInstance) || (requestScope.equalsIgnoreCase(ModelType.network.name()) && (action == Action.createInstance || action == Action.updateInstance)) || (reqVersion > 3 && (aLaCarteFlag != null && !aLaCarteFlag) && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.createInstance)) {
            throw new ValidationException("productFamilyId");
        }
    }
    return info;
}
Also used : ValidationException(org.onap.so.exceptions.ValidationException) Actions(org.onap.so.apihandlerinfra.Actions) RequestInfo(org.onap.so.serviceinstancebeans.RequestInfo)

Example 27 with ValidationException

use of org.onap.so.exceptions.ValidationException in project so by onap.

the class RequestScopeValidation method validate.

@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
    ModelInfo modelInfo = info.getSir().getRequestDetails().getModelInfo();
    RequestInfo requestInfo = info.getSir().getRequestDetails().getRequestInfo();
    String requestScope;
    if (modelInfo == null) {
        throw new ValidationException("model-info");
    }
    if (requestInfo == null) {
        throw new ValidationException("requestInfo");
    }
    info.setRequestInfo(requestInfo);
    if (modelInfo.getModelType() == null) {
        throw new ValidationException("modelType");
    }
    requestScope = info.getSir().getRequestDetails().getModelInfo().getModelType().name();
    info.setRequestScope(requestScope);
    return info;
}
Also used : ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) ValidationException(org.onap.so.exceptions.ValidationException) RequestInfo(org.onap.so.serviceinstancebeans.RequestInfo)

Example 28 with ValidationException

use of org.onap.so.exceptions.ValidationException in project so by onap.

the class InPlaceSoftwareUpdateValidation method validate.

@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
    RequestParameters requestParameters = info.getSir().getRequestDetails().getRequestParameters();
    CloudConfiguration cloudConfiguration = info.getSir().getRequestDetails().getCloudConfiguration();
    RequestInfo requestInfo = info.getSir().getRequestDetails().getRequestInfo();
    if (cloudConfiguration == null) {
        throw new ValidationException("cloudConfiguration");
    } else if (empty(cloudConfiguration.getLcpCloudRegionId())) {
        throw new ValidationException("lcpCloudRegionId");
    } else if (empty(cloudConfiguration.getTenantId())) {
        throw new ValidationException("tenantId");
    }
    if (requestInfo == null) {
        throw new ValidationException("requestInfo");
    } else if (empty(requestInfo.getRequestorId())) {
        throw new ValidationException("requestorId");
    } else if (empty(requestInfo.getSource())) {
        throw new ValidationException("source");
    }
    if (requestParameters == null) {
        throw new ValidationException("requestParameters");
    }
    return info;
}
Also used : ValidationException(org.onap.so.exceptions.ValidationException) CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration) RequestInfo(org.onap.so.serviceinstancebeans.RequestInfo) RequestParameters(org.onap.so.serviceinstancebeans.RequestParameters)

Example 29 with ValidationException

use of org.onap.so.exceptions.ValidationException in project so by onap.

the class MembersValidation method validate.

@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
    RequestInfo requestInfo = info.getSir().getRequestDetails().getRequestInfo();
    RelatedInstanceList[] relatedInstanceList = info.getSir().getRequestDetails().getRelatedInstanceList();
    boolean vnfRelatedInstance = false;
    if (requestInfo == null) {
        throw new ValidationException("requestInfo", true);
    } else if (empty(requestInfo.getRequestorId())) {
        throw new ValidationException("requestorId", true);
    } else if (empty(requestInfo.getSource())) {
        throw new ValidationException("source", true);
    }
    if (relatedInstanceList == null) {
        throw new ValidationException("related instances", true);
    } else {
        for (RelatedInstanceList instanceList : relatedInstanceList) {
            RelatedInstance relatedInstance = instanceList.getRelatedInstance();
            ModelType modelType = relatedInstance.getModelInfo().getModelType();
            if (empty(relatedInstance.getInstanceId())) {
                throw new ValidationException("instanceId in relatedInstances", true);
            }
            if (modelType == null) {
                throw new ValidationException("modelType in relatedInstance", true);
            }
            if (modelType == ModelType.vnf) {
                vnfRelatedInstance = true;
            }
        }
        if (!vnfRelatedInstance) {
            throw new ValidationException("vnf relatedInstance", true);
        }
    }
    return info;
}
Also used : ValidationException(org.onap.so.exceptions.ValidationException) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) ModelType(org.onap.so.serviceinstancebeans.ModelType) RequestInfo(org.onap.so.serviceinstancebeans.RequestInfo)

Example 30 with ValidationException

use of org.onap.so.exceptions.ValidationException in project so by onap.

the class CloudOrchestration method cloudOrchestration.

private Response cloudOrchestration(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version, String requestId) throws ApiException {
    logger.info(LoggingAnchor.TWO, MessageEnum.APIH_GENERATED_REQUEST_ID.toString(), requestId);
    long startTime = System.currentTimeMillis();
    CloudOrchestrationRequest cor = null;
    tenantIsolationRequest.setRequestId(requestId);
    cor = convertJsonToCloudOrchestrationRequest(requestJSON, action, startTime, cor);
    try {
        tenantIsolationRequest.parse(cor, instanceIdMap, action);
    } catch (ValidationException e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
        throw 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();
    }
    String instanceName = cor.getRequestDetails().getRequestInfo().getInstanceName();
    String resourceType = cor.getRequestDetails().getRequestInfo().getResourceType().name();
    InfraActiveRequests dup = null;
    dup = duplicateCheck(action, instanceIdMap, startTime, instanceName, resourceType);
    if (dup == null && (Action.activate.equals(action) || Action.deactivate.equals(action))) {
        dup = requestsDbClient.checkVnfIdStatus(cor.getOperationalEnvironmentId());
    }
    if (dup != null) {
        String instance = null;
        if (instanceName != null) {
            instance = instanceName;
        } else if (instanceIdMap != null) {
            instance = instanceIdMap.get(resourceType + "InstanceId");
        }
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DUPLICATE_FOUND, ErrorCode.SchemaError).build();
        throw new DuplicateRequestException.Builder(resourceType, instance, dup.getRequestStatus(), dup.getRequestId(), HttpStatus.SC_CONFLICT, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
    }
    String instanceId = null;
    if (instanceIdMap != null && instanceIdMap.get(ENVIRONMENT_ID_KEY) != null) {
        instanceId = instanceIdMap.get(ENVIRONMENT_ID_KEY);
    } else {
        instanceId = UUID.randomUUID().toString();
        tenantIsolationRequest.setOperationalEnvironmentId(instanceId);
        cor.setOperationalEnvironmentId(instanceId);
    }
    tenantIsolationRequest.createRequestRecord(Status.IN_PROGRESS, action);
    OperationalEnvironment opEnv = cor.getRequestDetails().getRequestParameters().getOperationalEnvironmentType();
    String operationalEnvType = opEnv != null ? opEnv.name() : null;
    TenantIsolationRunnable runnable = tenantIsolationRunnable.get();
    runnable.run(action, operationalEnvType, cor, requestId);
    String encodedValue;
    try {
        encodedValue = new String(instanceId.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException ex) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.DataError).build();
        throw new ValidateException.Builder("Could not encode instanceID" + ex.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(ex).errorInfo(errorLoggerInfo).build();
    }
    TenantSyncResponse tenantResponse = new TenantSyncResponse();
    RequestReferences reqReference = new RequestReferences();
    reqReference.setInstanceId(encodedValue);
    reqReference.setRequestId(requestId);
    tenantResponse.setRequestReferences(reqReference);
    return Response.ok(tenantResponse).build();
}
Also used : TenantSyncResponse(org.onap.so.apihandlerinfra.tenantisolationbeans.TenantSyncResponse) ValidationException(org.onap.so.exceptions.ValidationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) OperationalEnvironment(org.onap.so.apihandlerinfra.tenantisolationbeans.OperationalEnvironment) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) RequestReferences(org.onap.so.apihandlerinfra.tenantisolationbeans.RequestReferences)

Aggregations

ValidationException (org.onap.so.exceptions.ValidationException)35 Actions (org.onap.so.apihandlerinfra.Actions)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)9 IOException (java.io.IOException)8 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)8 HashMap (java.util.HashMap)6 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)6 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)6 Operation (io.swagger.v3.oas.annotations.Operation)5 Transactional (javax.transaction.Transactional)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)5 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 Consumes (javax.ws.rs.Consumes)4 Test (org.junit.Test)4 BaseTest (org.onap.so.apihandlerinfra.BaseTest)4 RequestInfo (org.onap.so.serviceinstancebeans.RequestInfo)4