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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations