use of org.onap.so.apihandlerinfra.Actions in project so by onap.
the class PlatformLOBValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
int reqVersion = info.getReqVersion();
Platform platform;
LineOfBusiness lineOfBusiness;
String requestScope = info.getRequestScope();
Actions action = info.getAction();
platform = info.getSir().getRequestDetails().getPlatform();
lineOfBusiness = info.getSir().getRequestDetails().getLineOfBusiness();
if (reqVersion >= 5 && requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.createInstance) {
if (reqVersion > 5 && platform == null) {
throw new ValidationException("platform");
}
if (platform != null && empty(platform.getPlatformName())) {
throw new ValidationException("platformName");
}
if (lineOfBusiness != null && empty(lineOfBusiness.getLineOfBusinessName())) {
throw new ValidationException("lineOfBusinessName");
}
}
info.setPlatform(platform);
info.setLOB(lineOfBusiness);
return info;
}
use of org.onap.so.apihandlerinfra.Actions in project so by onap.
the class RelatedInstancesValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
ServiceInstancesRequest sir = info.getSir();
Actions action = info.getAction();
int reqVersion = info.getReqVersion();
String requestScope = info.getRequestScope();
String serviceInstanceType = null;
String networkType = null;
String vnfType = null;
String vfModuleType = null;
String vfModuleModelName = null;
ModelInfo modelInfo = info.getSir().getRequestDetails().getModelInfo();
RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList();
String serviceModelName = null;
String vnfModelName = null;
String asdcServiceModelVersion = null;
String volumeGroupId = null;
boolean isRelatedServiceInstancePresent = false;
boolean isRelatedVnfInstancePresent = false;
boolean isSourceVnfPresent = false;
boolean isDestinationVnfPresent = false;
boolean isConnectionPointPresent = false;
if (requestScope.equalsIgnoreCase(ModelType.service.name())) {
serviceInstanceType = modelInfo.getModelName();
info.setServiceInstanceType(serviceInstanceType);
}
if (requestScope.equalsIgnoreCase(ModelType.network.name())) {
networkType = modelInfo.getModelName();
info.setNetworkType(networkType);
}
if (instanceList != null) {
for (RelatedInstanceList relatedInstanceList : instanceList) {
RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
ModelInfo relatedInstanceModelInfo = relatedInstance.getModelInfo();
if (relatedInstanceModelInfo == null) {
throw new ValidationException("modelInfo in relatedInstance");
}
if (relatedInstanceModelInfo.getModelType() == null) {
throw new ValidationException("modelType in relatedInstance");
}
if (empty(relatedInstance.getInstanceName()) && ModelType.pnf.equals(relatedInstanceModelInfo.getModelType())) {
throw new ValidationException("instanceName in relatedInstance for pnf modelType");
}
if (!empty(relatedInstance.getInstanceName())) {
if (!relatedInstance.getInstanceName().matches(Constants.VALID_INSTANCE_NAME_FORMAT)) {
throw new ValidationException("instanceName format in relatedInstance");
}
}
if (empty(relatedInstance.getInstanceId()) && !ModelType.pnf.equals(relatedInstanceModelInfo.getModelType())) {
throw new ValidationException("instanceId in relatedInstance");
}
if (!empty(relatedInstance.getInstanceId()) && !UUIDChecker.isValidUUID(relatedInstance.getInstanceId())) {
throw new ValidationException("instanceId format in relatedInstance");
}
if (empty(relatedInstanceModelInfo.getModelVersionId()) && requestScope.equals(ModelType.instanceGroup.toString()) && relatedInstanceModelInfo.getModelType().equals(ModelType.service)) {
throw new ValidationException("modelVersionId in relatedInstance", true);
}
if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString()) && relatedInstanceModelInfo.getModelType().equals(ModelType.service)) {
isRelatedServiceInstancePresent = true;
}
if (requestScope.equalsIgnoreCase(ModelType.service.name())) {
if (empty(relatedInstance.getInstanceName()) && ModelType.vpnBinding.equals(relatedInstanceModelInfo.getModelType())) {
throw new ValidationException("instanceName in relatedInstance for vpnBinding modelType", true);
}
if (empty(relatedInstance.getInstanceName()) && ModelType.network.equals(relatedInstanceModelInfo.getModelType())) {
throw new ValidationException("instanceName in relatedInstance for network modelType", true);
}
}
if (action != Action.deleteInstance && !requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())) {
if (!(relatedInstanceModelInfo.getModelType().equals(ModelType.volumeGroup) || relatedInstanceModelInfo.getModelType().equals(ModelType.connectionPoint) || relatedInstanceModelInfo.getModelType().equals(ModelType.pnf) || relatedInstanceModelInfo.getModelType().equals(ModelType.networkInstanceGroup) || relatedInstanceModelInfo.getModelType().equals(ModelType.network) || relatedInstanceModelInfo.getModelType().equals(ModelType.vpnBinding))) {
if (empty(relatedInstanceModelInfo.getModelInvariantId())) {
throw new ValidationException("modelInvariantId in relatedInstance");
} else if (reqVersion >= 4 && empty(relatedInstanceModelInfo.getModelVersionId())) {
throw new ValidationException("modelVersionId in relatedInstance");
} else if (empty(relatedInstanceModelInfo.getModelName())) {
throw new ValidationException("modelName in relatedInstance");
} else if (empty(relatedInstanceModelInfo.getModelVersion())) {
throw new ValidationException("modelVersion in relatedInstance");
}
}
if (!empty(relatedInstanceModelInfo.getModelInvariantId()) && !UUIDChecker.isValidUUID(relatedInstanceModelInfo.getModelInvariantId())) {
throw new ValidationException("modelInvariantId format in relatedInstance");
}
if (ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
if (InstanceDirection.source.equals(relatedInstance.getInstanceDirection()) && relatedInstanceModelInfo.getModelType().equals(ModelType.vnf)) {
isSourceVnfPresent = true;
} else if (InstanceDirection.destination.equals(relatedInstance.getInstanceDirection()) && (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) || (relatedInstanceModelInfo.getModelType().equals(ModelType.pnf)))) {
isDestinationVnfPresent = true;
}
}
if (ModelType.connectionPoint.equals(relatedInstanceModelInfo.getModelType()) && ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
isConnectionPointPresent = true;
}
}
if (empty(relatedInstanceModelInfo.getModelCustomizationName()) && relatedInstanceModelInfo.getModelType().equals(ModelType.vnf)) {
if (reqVersion >= 4 && empty(relatedInstanceModelInfo.getModelCustomizationId()) && action != Action.deleteInstance) {
throw new ValidationException("modelCustomizationName or modelCustomizationId in relatedInstance of vnf");
}
}
if (relatedInstanceModelInfo.getModelType().equals(ModelType.service) && !(requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString()) && action == Action.createInstance)) {
isRelatedServiceInstancePresent = true;
if (!relatedInstance.getInstanceId().equals(sir.getServiceInstanceId())) {
throw new ValidationException("serviceInstanceId matching the serviceInstanceId in request URI");
}
serviceModelName = relatedInstanceModelInfo.getModelName();
asdcServiceModelVersion = relatedInstanceModelInfo.getModelVersion();
} else if (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) && !(ModelType.configuration.name().equalsIgnoreCase(requestScope))) {
isRelatedVnfInstancePresent = true;
if (!relatedInstance.getInstanceId().equals(sir.getVnfInstanceId())) {
throw new ValidationException("vnfInstanceId matching the vnfInstanceId in request URI");
}
vnfModelName = relatedInstanceModelInfo.getModelCustomizationName();
} else if (relatedInstanceModelInfo.getModelType().equals(ModelType.volumeGroup)) {
volumeGroupId = relatedInstance.getInstanceId();
}
}
if (action == Action.createInstance && ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
if (!isSourceVnfPresent) {
throw new ValidationException("source vnf relatedInstance for Port Configuration");
}
if (!isDestinationVnfPresent) {
throw new ValidationException("destination vnf relatedInstance for Port Configuration");
}
}
if ((action == Action.enablePort || action == Action.disablePort) && ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
if (!isConnectionPointPresent) {
throw new ValidationException("connectionPoint relatedInstance for Port Configuration");
}
}
if (requestScope.equals(ModelType.instanceGroup.toString())) {
if (!isRelatedServiceInstancePresent) {
throw new ValidationException("related service instance for instanceGroup request", true);
}
}
if (requestScope.equalsIgnoreCase(ModelType.volumeGroup.name())) {
if (!isRelatedServiceInstancePresent) {
throw new ValidationException("related service instance for volumeGroup request");
}
if (!isRelatedVnfInstancePresent) {
throw new ValidationException("related vnf instance for volumeGroup request");
}
serviceInstanceType = serviceModelName;
vnfType = serviceModelName + "/" + vnfModelName;
info.setServiceInstanceType(serviceInstanceType);
info.setVnfType(vnfType);
} else if (requestScope.equalsIgnoreCase(ModelType.vfModule.name())) {
if (!isRelatedServiceInstancePresent) {
throw new ValidationException("related service instance for vfModule request");
}
if (!isRelatedVnfInstancePresent) {
throw new ValidationException("related vnf instance for vfModule request");
}
vfModuleModelName = modelInfo.getModelName();
serviceInstanceType = serviceModelName;
vnfType = serviceModelName + "/" + vnfModelName;
vfModuleType = vnfType + "::" + vfModuleModelName;
sir.setVolumeGroupInstanceId(volumeGroupId);
info.setVfModuleModelName(vfModuleModelName);
info.setVnfType(vnfType);
info.setServiceInstanceType(serviceInstanceType);
info.setVfModuleType(vfModuleType);
} else if (requestScope.equalsIgnoreCase(ModelType.vnf.name())) {
if (!isRelatedServiceInstancePresent) {
throw new ValidationException("related service instance for vnf request");
}
vnfType = serviceModelName + "/" + sir.getRequestDetails().getModelInfo().getModelCustomizationName();
info.setVnfType(vnfType);
}
} else if (((requestScope.equalsIgnoreCase(ModelType.vnf.name()) || requestScope.equalsIgnoreCase(ModelType.volumeGroup.name()) || requestScope.equalsIgnoreCase(ModelType.vfModule.name()) || requestScope.equalsIgnoreCase(ModelType.configuration.name())) && (action == Action.createInstance || action == Action.enablePort || action == Action.disablePort)) || (reqVersion >= 4 && (requestScope.equalsIgnoreCase(ModelType.volumeGroup.name()) || requestScope.equalsIgnoreCase(ModelType.vfModule.name())) && action == Action.updateInstance || (requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.scaleOut)) || (requestScope.equalsIgnoreCase(ModelType.service.name()) && (action.equals(Action.addRelationships) || action.equals(Action.removeRelationships)))) {
logger.debug("related instance exception");
throw new ValidationException("related instances");
}
if (instanceList == null && requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString()) && action == Action.createInstance) {
throw new ValidationException("relatedInstanceList", true);
}
info.setVfModuleModelName(vfModuleModelName);
info.setServiceInstanceType(serviceInstanceType);
info.setVnfType(vnfType);
info.setAsdcServiceModelVersion(asdcServiceModelVersion);
info.setVfModuleType(vfModuleType);
return info;
}
use of org.onap.so.apihandlerinfra.Actions in project so by onap.
the class RequestParametersValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
int reqVersion = info.getReqVersion();
String requestScope = info.getRequestScope();
Actions action = info.getAction();
RequestParameters requestParameters = info.getReqParameters();
if (requestScope.equalsIgnoreCase(ModelType.service.name()) && (action == Action.createInstance || action == Action.assignInstance)) {
if (requestParameters == null) {
throw new ValidationException("requestParameters");
}
if (empty(requestParameters.getSubscriptionServiceType())) {
throw new ValidationException("subscriptionServiceType");
}
}
if (reqVersion >= 4) {
if (Action.addRelationships.equals(action) || Action.removeRelationships.equals(action)) {
if (requestParameters == null || requestParameters.getALaCarte() == null) {
throw new ValidationException("aLaCarte in requestParameters");
}
}
}
if (requestParameters == null && !requestScope.equalsIgnoreCase(ModelType.service.name())) {
info.setALaCarteFlag(true);
}
if (requestParameters != null) {
if (requestScope.equalsIgnoreCase(ModelType.vnf.name())) {
if (action == Action.updateInstance) {
if (requestParameters.isUsePreload() == null) {
requestParameters.setUsePreload(true);
}
}
if (action == Action.replaceInstance) {
if (requestParameters.getRebuildVolumeGroups() == null) {
requestParameters.setRebuildVolumeGroups(false);
}
}
}
if (requestScope.equalsIgnoreCase(ModelType.vfModule.name())) {
if (action == Action.createInstance || action == Action.updateInstance) {
if (requestParameters.isUsePreload() == null) {
if (reqVersion >= 4) {
if (requestParameters.getALaCarte() == null || requestParameters.getALaCarte() == true) {
requestParameters.setUsePreload(true);
} else {
requestParameters.setUsePreload(false);
}
} else {
requestParameters.setUsePreload(true);
}
}
}
}
if (requestScope.equalsIgnoreCase(ModelType.service.name())) {
if (action == Action.createInstance) {
if (requestParameters.isUsePreload() == null) {
if (reqVersion >= 4) {
if (requestParameters.getALaCarte() == null || requestParameters.getALaCarte() == false) {
requestParameters.setUsePreload(false);
} else {
requestParameters.setUsePreload(true);
}
} else {
requestParameters.setUsePreload(true);
}
}
}
}
if (reqVersion >= 4) {
if (requestParameters.getALaCarte() != null) {
info.setALaCarteFlag(requestParameters.getALaCarte());
} else if (requestScope.equalsIgnoreCase(ModelType.service.name())) {
if (action == Action.createInstance || action == Action.deleteInstance || action == Action.activateInstance || action == Action.deactivateInstance) {
if (requestParameters.getALaCarte() == null) {
requestParameters.setaLaCarte(false);
info.setALaCarteFlag(requestParameters.getALaCarte());
}
}
} else {
info.setALaCarteFlag(true);
}
} else {
info.setALaCarteFlag(true);
}
}
return info;
}
use of org.onap.so.apihandlerinfra.Actions in project so by onap.
the class SubscriberInfoValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
String requestScope = info.getRequestScope();
int reqVersion = info.getReqVersion();
Actions action = info.getAction();
if (reqVersion > 4 && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.createInstance || action == Action.assignInstance) {
SubscriberInfo subscriberInfo = info.getSir().getRequestDetails().getSubscriberInfo();
if (subscriberInfo == null) {
throw new ValidationException("subscriberInfo");
}
if (empty(subscriberInfo.getGlobalSubscriberId())) {
throw new ValidationException("globalSubscriberId");
}
}
return info;
}
use of org.onap.so.apihandlerinfra.Actions in project so by onap.
the class UserParamsValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
Service validate = info.getUserParams();
if (validate.getModelInfo() == null) {
throw new ValidationException("modelInfo in userParams", true);
} else if (validate.getModelInfo().getModelType() == null) {
throw new ValidationException("modelType in userParams service modelInfo", true);
} else if (validate.getModelInfo().getModelVersionId() == null) {
throw new ValidationException("modelVersionId in userParams service modelInfo", true);
}
modelInfoValidation(info.getSir().getRequestDetails().getModelInfo(), validate.getModelInfo());
if (validate.getInstanceName() != null && info.getRequestInfo().getInstanceName() != null) {
instanceNameValidation(info, validate);
}
Actions action = info.getAction();
Map<String, Set<String>> vnfCustomIdToInstanceNames = new HashMap<>();
Map<String, Set<String>> vfModuleCustomIdToInstanceNames = new HashMap<>();
for (Vnfs vnf : validate.getResources().getVnfs()) {
if (vnf.getModelInfo() == null) {
throw new ValidationException("modelInfo in userParams vnf resources", true);
} else if (vnf.getModelInfo().getModelCustomizationId() == null) {
throw new ValidationException("modelCustomizationId in userParams vnf resources", true);
} else if (vnf.getModelInfo().getModelVersionId() == null) {
throw new ValidationException("modelVersionId in userParams vnf resources", true);
}
if (vnf.getCloudConfiguration() == null) {
throw new ValidationException("cloudConfiguration in userParams vnf resources", true);
}
if (action == Action.createInstance || action == Action.assignInstance) {
if (vnf.getPlatform() == null) {
throw new ValidationException("platform in userParams vnf resources", true);
}
if (vnf.getProductFamilyId() == null) {
throw new ValidationException("productFamilyId in userParams vnf resources", true);
}
}
if (vnf.getPlatform() != null && vnf.getPlatform().getPlatformName() == null) {
throw new ValidationException("platformName in userParams vnf resources", true);
}
String vnfCustomizationId = vnf.getModelInfo().getModelCustomizationId();
vnfCustomIdToInstanceNames.putIfAbsent(vnfCustomizationId, new HashSet<>());
String vnfInstanceName = StringUtils.defaultString(vnf.getInstanceName());
Set<String> vnfVisitedInstanceNames = vnfCustomIdToInstanceNames.get(vnfCustomizationId);
if (!vnfVisitedInstanceNames.add(vnfInstanceName)) {
throw new ValidationException("instanceName: same instanceName with same modelCustomizationId in userParams vnf resources", true);
}
if (vnf.getVfModules().isEmpty()) {
throw new ValidationException("vfModules in userParams vnf resources", true);
}
for (VfModules vfModule : vnf.getVfModules()) {
if (vfModule.getModelInfo() == null) {
throw new ValidationException("modelInfo in userParams vfModules resources", true);
} else if (vfModule.getModelInfo().getModelCustomizationId() == null) {
throw new ValidationException("modelCustomizationId in userParams vfModule resources", true);
} else if (vfModule.getModelInfo().getModelVersionId() == null) {
throw new ValidationException("modelVersionId in userParams vfModule resources", true);
}
String vfModulecustomizationId = vfModule.getModelInfo().getModelCustomizationId();
vfModuleCustomIdToInstanceNames.putIfAbsent(vfModulecustomizationId, new HashSet<>());
String vfModuleInstanceName = StringUtils.defaultString(vfModule.getInstanceName());
Set<String> vfModuleVisitedInstanceNames = vfModuleCustomIdToInstanceNames.get(vfModulecustomizationId);
if (!vfModuleVisitedInstanceNames.add(vfModuleInstanceName)) {
throw new ValidationException("instanceName: same instanceName with same modelCustomizationId in userParams vfModule resources", true);
}
}
}
validateDuplicateInstanceNames(vnfCustomIdToInstanceNames, "vnf");
validateDuplicateInstanceNames(vfModuleCustomIdToInstanceNames, "vfModule");
List<Networks> validateNetworks = new ArrayList<>();
validateNetworks = validate.getResources().getNetworks();
if (validateNetworks != null) {
for (Networks networks : validateNetworks) {
if (networks.getModelInfo() == null) {
throw new ValidationException("modelInfo in userParams network resources", true);
} else if (networks.getModelInfo().getModelCustomizationId() == null) {
throw new ValidationException("modelCustomizationId in userParams network resources", true);
} else if (networks.getModelInfo().getModelVersionId() == null) {
throw new ValidationException("modelVersionId in userParams network resources", true);
}
if (networks.getCloudConfiguration() == null) {
throw new ValidationException("cloudConfiguration in userParams network resources", true);
}
}
}
return info;
}
Aggregations