use of org.onap.so.db.catalog.beans.ConfigurationResourceCustomization in project so by onap.
the class ToscaResourceInstaller method processServiceProxyAndConfiguration.
protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
List<IEntityDetails> spEntityList = getEntityDetails(toscaResourceStruct, EntityQuery.newBuilder(SdcTypes.SERVICE_PROXY), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false);
List<IEntityDetails> configEntityList = getEntityDetails(toscaResourceStruct, EntityQuery.newBuilder(SdcTypes.CONFIGURATION), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false);
List<ServiceProxyResourceCustomization> serviceProxyList = new ArrayList<>();
List<ConfigurationResourceCustomization> configurationResourceList = new ArrayList<>();
ServiceProxyResourceCustomization serviceProxy = null;
if (spEntityList != null) {
for (IEntityDetails spEntity : spEntityList) {
serviceProxy = createServiceProxy(spEntity, service, toscaResourceStruct);
serviceProxyList.add(serviceProxy);
for (IEntityDetails configEntity : configEntityList) {
List<RequirementAssignment> requirements = configEntity.getRequirements();
for (RequirementAssignment requirement : requirements) {
if (requirement.getNodeTemplateName().equals(spEntity.getName())) {
ConfigurationResourceCustomization configurationResource = createConfiguration(configEntity, toscaResourceStruct, serviceProxy, service, configurationResourceList);
Optional<ConfigurationResourceCustomization> matchingObject = configurationResourceList.stream().filter(configurationResourceCustomization -> configEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).equals(configurationResource.getModelCustomizationUUID())).filter(configurationResourceCustomization -> configurationResourceCustomization.getModelInstanceName().equals(configurationResource.getModelInstanceName())).findFirst();
if (!matchingObject.isPresent()) {
configurationResourceList.add(configurationResource);
}
break;
}
}
}
}
}
service.setConfigurationCustomizations(configurationResourceList);
service.setServiceProxyCustomizations(serviceProxyList);
}
use of org.onap.so.db.catalog.beans.ConfigurationResourceCustomization in project so by onap.
the class ToscaResourceInstaller method getConfigurationResourceCustomization.
protected ConfigurationResourceCustomization getConfigurationResourceCustomization(IEntityDetails configEntity, ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization, Service service) {
Metadata metadata = configEntity.getMetadata();
ConfigurationResource configResource = getConfigurationResource(configEntity);
ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
configCustomizationResource.setModelInstanceName(configEntity.getName());
configCustomizationResource.setFunction(getLeafPropertyValue(configEntity, "function"));
configCustomizationResource.setRole(getLeafPropertyValue(configEntity, "role"));
configCustomizationResource.setType(getLeafPropertyValue(configEntity, "type"));
configCustomizationResource.setServiceProxyResourceCustomization(spResourceCustomization);
configCustomizationResource.setConfigurationResource(configResource);
configCustomizationResource.setService(service);
configResourceCustomizationSet.add(configCustomizationResource);
configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
return configCustomizationResource;
}
use of org.onap.so.db.catalog.beans.ConfigurationResourceCustomization in project so by onap.
the class BBInputSetupTest method testPopulateConfigurationReplace.
@Test
public void testPopulateConfigurationReplace() throws JsonParseException, JsonMappingException, IOException {
String instanceName = "configurationName";
ModelInfo modelInfo = new ModelInfo();
modelInfo.setModelCustomizationUuid("72d9d1cd-f46d-447a-abdb-451d6fb05fa9");
ServiceInstance serviceInstance = new ServiceInstance();
Configuration configuration = new Configuration();
configuration.setConfigurationId("configurationId");
configuration.setConfigurationName("configurationName");
serviceInstance.getConfigurations().add(configuration);
String resourceId = "configurationId";
String vnfcName = "vnfcName";
// Mock service
Service service = mapper.readValue(new File(RESOURCE_PATH + "CatalogDBService_getServiceInstanceNOAAIInput.json"), Service.class);
ConfigurationResourceCustomization configurationCust = new ConfigurationResourceCustomization();
configurationCust.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa9");
service.getConfigurationCustomizations().add(configurationCust);
Map<ResourceKey, String> lookupKeyMap = new HashMap<>();
lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, "configurationId");
String bbName = AssignFlows.FABRIC_CONFIGURATION.toString();
ServiceModel serviceModel = new ServiceModel();
serviceModel.setNewService(service);
ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys();
configResourceKeys.setVnfcName(vnfcName);
Vnfc vnfc = new Vnfc();
vnfc.setVnfcName(vnfcName);
RequestDetails requestDetails = mapper.readValue(new File(RESOURCE_PATH + "RequestDetailsInput_withRelatedInstanceList.json"), RequestDetails.class);
doNothing().when(SPY_bbInputSetup).mapCatalogConfiguration(configuration, modelInfo, service, configResourceKeys);
doReturn(vnfc).when(SPY_bbInputSetup).getVnfcToConfiguration(vnfcName);
BBInputSetupParameter parameter = new BBInputSetupParameter.Builder().setRequestId(REQUEST_ID).setModelInfo(modelInfo).setService(service).setBbName(bbName).setServiceInstance(serviceInstance).setLookupKeyMap(lookupKeyMap).setResourceId(resourceId).setInstanceName(instanceName).setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails).setServiceModel(serviceModel).setIsReplace(true).build();
SPY_bbInputSetup.populateConfiguration(parameter);
configResourceKeys.setVnfResourceCustomizationUUID("my-test-uuid");
verify(SPY_bbInputSetup, times(1)).mapCatalogConfiguration(configuration, modelInfo, service, configResourceKeys);
}
use of org.onap.so.db.catalog.beans.ConfigurationResourceCustomization in project so by onap.
the class BBInputSetupPopulateMethodsTest method test_getGBBMacro_populateConfiguration_shouldBeCalled.
@Test
public void test_getGBBMacro_populateConfiguration_shouldBeCalled() throws Exception {
// given
String requestAction = "createInstance";
Service service = Mockito.mock(Service.class);
GeneralBuildingBlock gBB = mapper.readValue(new File(RESOURCE_PATH + "GeneralBuildingBlockExpected.json"), GeneralBuildingBlock.class);
RequestDetails requestDetails = mapper.readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class);
GenericVnf aaiVnf = new GenericVnf();
aaiVnf.setModelCustomizationId("modelCustId");
Map<ResourceKey, String> lookupKeyMap = prepareLookupKeyMap();
ConfigurationResourceKeys configResourceKeys = prepareConfigurationResourceKeys();
ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), ExecuteBuildingBlock.class);
executeBB.setConfigurationResourceKeys(configResourceKeys).setRequestDetails(requestDetails);
BuildingBlock buildingBlock = executeBB.getBuildingBlock();
buildingBlock.setBpmnFlowName("AssignFabricConfigurationBB").setKey("72d9d1cd-f46d-447a-abdb-451d6fb05fa9");
Configuration configuration = new Configuration();
configuration.setConfigurationId("configurationId");
gBB.getServiceInstance().getConfigurations().add(configuration);
List<ConfigurationResourceCustomization> configurationCustList = new ArrayList<>();
ConfigurationResourceCustomization configurationCust = new ConfigurationResourceCustomization();
configurationCust.setModelCustomizationUUID("72d9d1cd-f46d-447a-abdb-451d6fb05fa9");
configurationCustList.add(configurationCust);
doReturn(configurationCustList).when(service).getConfigurationCustomizations();
doReturn(gBB).when(SPY_bbInputSetup).getGBBALaCarteService(executeBB, requestDetails, lookupKeyMap, requestAction, lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID));
doReturn(service).when(bbInputSetupUtils).getCatalogServiceByModelUUID(gBB.getServiceInstance().getModelInfoServiceInstance().getModelUuid());
doNothing().when(SPY_bbInputSetup).populateConfiguration(any(BBInputSetupParameter.class));
// when
SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType);
// then
verify(SPY_bbInputSetup, times(1)).populateConfiguration(any(BBInputSetupParameter.class));
}
use of org.onap.so.db.catalog.beans.ConfigurationResourceCustomization 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;
}
Aggregations