use of org.onap.so.serviceinstancebeans.VfModules 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;
}
use of org.onap.so.serviceinstancebeans.VfModules in project so by onap.
the class BBInputSetupTest method testGetVfModulesByInstanceName.
@Test
public void testGetVfModulesByInstanceName() throws IOException {
org.onap.so.serviceinstancebeans.Service serviceMacro = mapper.readValue(new File(RESOURCE_PATH + "ServiceMacroVfModules.json"), org.onap.so.serviceinstancebeans.Service.class);
Resources resources = serviceMacro.getResources();
VfModules expectedVfModule = resources.getVnfs().get(0).getVfModules().get(2);
assertEquals(expectedVfModule, SPY_bbInputSetup.getVfModulesByInstanceName("vmxnjr001_AVPN_base_vRE_BV_expansion_002", resources));
}
use of org.onap.so.serviceinstancebeans.VfModules in project so by onap.
the class BBInputSetup method getGBBMacroUserParams.
protected GeneralBuildingBlock getGBBMacroUserParams(ExecuteBuildingBlock executeBB, RequestDetails requestDetails, Map<ResourceKey, String> lookupKeyMap, String vnfType, String bbName, String key, GeneralBuildingBlock gBB, RequestParameters requestParams, Service service, String input) throws Exception {
ServiceInstance serviceInstance = gBB.getServiceInstance();
org.onap.so.serviceinstancebeans.Service serviceMacro = mapper.readValue(input, org.onap.so.serviceinstancebeans.Service.class);
Resources resources = serviceMacro.getResources();
Vnfs vnfs = null;
VfModules vfModules = null;
Networks networks = null;
CloudConfiguration cloudConfiguration = requestDetails.getCloudConfiguration();
CloudRegion cloudRegion = setCloudConfiguration(gBB, cloudConfiguration);
BBInputSetupParameter parameter = new BBInputSetupParameter.Builder().setRequestId(executeBB.getRequestId()).setService(service).setBbName(bbName).setServiceInstance(serviceInstance).setLookupKeyMap(lookupKeyMap).build();
if (bbName.contains(VNF) || (bbName.contains(CONTROLLER) && (VNF).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) {
String vnfInstanceName = lookupKeyMap.get(ResourceKey.VNF_INSTANCE_NAME);
if (StringUtils.isNotBlank(vnfInstanceName)) {
vnfs = findVnfsByInstanceName(vnfInstanceName, resources);
} else {
vnfs = findVnfsByKey(key, resources);
}
// Vnf level cloud configuration takes precedence over service level cloud configuration.
if (vnfs.getCloudConfiguration() != null) {
setCloudConfiguration(gBB, vnfs.getCloudConfiguration());
}
String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID);
// This stores the vnf id in request db to be retrieved later when
// working on a vf module or volume group
InfraActiveRequests request = this.bbInputSetupUtils.getInfraActiveRequest(executeBB.getRequestId());
if (request != null) {
this.bbInputSetupUtils.updateInfraActiveRequestVnfId(request, vnfId);
}
parameter.setModelInfo(vnfs.getModelInfo());
parameter.setInstanceName(vnfs.getInstanceName());
parameter.setPlatform(vnfs.getPlatform());
parameter.setLineOfBusiness(vnfs.getLineOfBusiness());
parameter.setResourceId(vnfId);
parameter.setVnfType(vnfType);
parameter.setInstanceParams(vnfs.getInstanceParams());
parameter.setProductFamilyId(requestDetails.getRequestInfo().getProductFamilyId());
String applicationId = "";
if (vnfs.getApplicationId() != null) {
applicationId = vnfs.getApplicationId();
}
parameter.setApplicationId(applicationId);
this.populateGenericVnf(parameter);
} else if (bbName.contains(PNF) || (bbName.contains(CONTROLLER) && (PNF).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) {
String pnfId = lookupKeyMap.get(ResourceKey.PNF);
resources.getPnfs().stream().filter(pnfs -> Objects.equals(key, pnfs.getModelInfo().getModelCustomizationId())).findFirst().ifPresent(pnfs -> BBInputSetupPnf.populatePnfToServiceInstance(pnfs, pnfId, serviceInstance));
} else if (bbName.contains(VF_MODULE) || bbName.contains(VOLUME_GROUP) || (bbName.contains(CONTROLLER) && (VF_MODULE).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) {
String vfModuleInstanceName = lookupKeyMap.get(ResourceKey.VF_MODULE_INSTANCE_NAME);
if (StringUtils.isNotBlank(vfModuleInstanceName)) {
vfModules = getVfModulesByInstanceName(vfModuleInstanceName, resources);
} else {
vfModules = getVfModulesByKey(key, resources);
}
String vfModulesName = vfModules.getInstanceName();
String vfModulesModelCustId = vfModules.getModelInfo().getModelCustomizationId();
// Get the Vnf associated with vfModule
Optional<org.onap.so.serviceinstancebeans.Vnfs> parentVnf = resources.getVnfs().stream().filter(aVnf -> aVnf.getCloudConfiguration() != null).filter(aVnf -> aVnf.getVfModules().stream().anyMatch(aVfModules -> aVfModules.getInstanceName().equals(vfModulesName) && aVfModules.getModelInfo().getModelCustomizationId().equals(vfModulesModelCustId))).findAny();
// Get the cloud configuration from this Vnf
if (parentVnf.isPresent()) {
cloudRegion = setCloudConfiguration(gBB, parentVnf.get().getCloudConfiguration());
}
lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, getVnfId(executeBB, lookupKeyMap));
parameter.setModelInfo(vfModules.getModelInfo());
if (bbName.contains(VOLUME_GROUP)) {
parameter.setResourceId(lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID));
parameter.setInstanceName(vfModules.getVolumeGroupInstanceName());
parameter.setVnfType(vnfType);
parameter.setInstanceParams(vfModules.getInstanceParams());
ServiceModel serviceModel = new ServiceModel();
serviceModel.setCurrentService(service);
parameter.setServiceModel(serviceModel);
this.populateVolumeGroup(parameter);
} else {
parameter.setResourceId(lookupKeyMap.get(ResourceKey.VF_MODULE_ID));
CloudConfiguration cloudConfig = new CloudConfiguration();
cloudConfig.setLcpCloudRegionId(cloudRegion.getLcpCloudRegionId());
cloudConfig.setCloudOwner(cloudRegion.getCloudOwner());
ServiceModel serviceModel = new ServiceModel();
serviceModel.setCurrentService(service);
parameter.setServiceModel(serviceModel);
parameter.setCloudConfiguration(cloudConfig);
parameter.setInstanceName(vfModules.getInstanceName());
parameter.setInstanceParams(vfModules.getInstanceParams());
this.populateVfModule(parameter);
gBB.getRequestContext().setIsHelm(parameter.getIsHelm());
}
} else if (bbName.contains(NETWORK)) {
networks = findNetworksByKey(key, resources);
String networkId = lookupKeyMap.get(ResourceKey.NETWORK_ID);
if (networks != null) {
// If service level cloud configuration is not provided then get it from networks.
if (cloudConfiguration == null) {
Optional<org.onap.so.serviceinstancebeans.Networks> netWithCloudConfig = resources.getNetworks().stream().filter(aNetwork -> aNetwork.getCloudConfiguration() != null).findAny();
if (netWithCloudConfig.isPresent()) {
setCloudConfiguration(gBB, netWithCloudConfig.get().getCloudConfiguration());
} else {
logger.debug("Could not find any cloud configuration for this request.");
}
}
parameter.setInstanceName(networks.getInstanceName());
parameter.setModelInfo(networks.getModelInfo());
parameter.setInstanceParams(networks.getInstanceParams());
parameter.setResourceId(networkId);
this.populateL3Network(parameter);
}
} else if (bbName.contains("Configuration")) {
String configurationId = lookupKeyMap.get(ResourceKey.CONFIGURATION_ID);
ModelInfo configurationModelInfo = new ModelInfo();
configurationModelInfo.setModelCustomizationUuid(key);
ConfigurationResourceCustomization configurationCust = findConfigurationResourceCustomization(configurationModelInfo, service);
if (configurationCust != null) {
parameter.setModelInfo(configurationModelInfo);
parameter.setResourceId(configurationId);
parameter.setConfigurationResourceKeys(executeBB.getConfigurationResourceKeys());
parameter.setRequestDetails(executeBB.getRequestDetails());
this.populateConfiguration(parameter);
} else {
logger.debug("Could not find a configuration customization with key: {}", key);
}
}
return gBB;
}
use of org.onap.so.serviceinstancebeans.VfModules in project so by onap.
the class ConfigureInstanceParamsForVfModule method getInstanceParams.
private List<Map<String, String>> getInstanceParams(Service service, String vnfCustomizationUuid, String vfModuleCustomizationUuid) throws PayloadGenerationException {
Vnfs foundedVnf = service.getResources().getVnfs().stream().filter(vnfs -> vnfs.getModelInfo().getModelCustomizationId().equals(vnfCustomizationUuid)).findFirst().orElseThrow(() -> new PayloadGenerationException(String.format("Can not find vnf for genericVnfModelCustomizationUuid: %s", vnfCustomizationUuid)));
VfModules vfModule = foundedVnf.getVfModules().stream().filter(vfModules -> vfModules.getModelInfo().getModelCustomizationId().equals(vfModuleCustomizationUuid)).findFirst().orElseThrow(() -> new PayloadGenerationException(String.format("Can not find vnf for vfModuleCustomizationUuid: %s", vfModuleCustomizationUuid)));
return vfModule.getInstanceParams();
}
use of org.onap.so.serviceinstancebeans.VfModules in project so by onap.
the class BBInputSetupTest method testGetVfModulesByKey.
@Test
public void testGetVfModulesByKey() throws IOException {
org.onap.so.serviceinstancebeans.Service serviceMacro = mapper.readValue(new File(RESOURCE_PATH + "ServiceMacroVfModules.json"), org.onap.so.serviceinstancebeans.Service.class);
Resources resources = serviceMacro.getResources();
VfModules expectedVfModule = resources.getVnfs().get(0).getVfModules().get(0);
assertEquals(expectedVfModule, SPY_bbInputSetup.getVfModulesByKey("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f", resources));
}
Aggregations