use of org.onap.so.serviceinstancebeans.RelatedInstance in project so by onap.
the class WorkflowActionBBTasks method postProcessingExecuteBBActivateVfModule.
protected void postProcessingExecuteBBActivateVfModule(DelegateExecution execution, ExecuteBuildingBlock ebb, List<ExecuteBuildingBlock> flowsToExecute) {
try {
String requestAction = (String) execution.getVariable(BBConstants.G_ACTION);
String serviceInstanceId = ebb.getWorkflowResourceIds().getServiceInstanceId();
String vnfId = ebb.getWorkflowResourceIds().getVnfId();
String vfModuleId = ebb.getResourceId();
ebb.getWorkflowResourceIds().setVfModuleId(vfModuleId);
String serviceModelUUID = "";
String vnfCustomizationUUID = "";
String vfModuleCustomizationUUID = "";
if (requestAction.equalsIgnoreCase("replaceInstance") || requestAction.equalsIgnoreCase("replaceInstanceRetainAssignments")) {
for (RelatedInstanceList relatedInstList : ebb.getRequestDetails().getRelatedInstanceList()) {
RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
vnfCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
}
if (relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) {
serviceModelUUID = relatedInstance.getModelInfo().getModelVersionId();
}
}
vfModuleCustomizationUUID = ebb.getRequestDetails().getModelInfo().getModelCustomizationId();
} else {
serviceModelUUID = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId).getModelVersionId();
vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
vfModuleCustomizationUUID = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId).getModelCustomizationId();
}
List<Vnfc> vnfcs = workflowAction.getRelatedResourcesInVfModule(vnfId, vfModuleId, Vnfc.class, Types.VNFC);
logger.debug("Vnfc Size: {}", vnfcs.size());
for (Vnfc vnfc : vnfcs) {
String modelCustomizationId = vnfc.getModelCustomizationId();
logger.debug("Processing Vnfc: {}", modelCustomizationId);
CvnfcConfigurationCustomization fabricConfig = catalogDbClient.getCvnfcCustomization(serviceModelUUID, vnfCustomizationUUID, vfModuleCustomizationUUID, modelCustomizationId);
if (fabricConfig != null && fabricConfig.getConfigurationResource() != null && fabricConfig.getConfigurationResource().getToscaNodeType() != null && fabricConfig.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) {
String configurationId = getConfigurationId(vnfc);
ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
configurationResourceKeys.setCvnfcCustomizationUUID(modelCustomizationId);
configurationResourceKeys.setVfModuleCustomizationUUID(vfModuleCustomizationUUID);
configurationResourceKeys.setVnfResourceCustomizationUUID(vnfCustomizationUUID);
configurationResourceKeys.setVnfcName(vnfc.getVnfcName());
ExecuteBuildingBlock addConfigBB = getExecuteBBForConfig(ADD_FABRIC_CONFIGURATION_BB, ebb, configurationId, configurationResourceKeys);
flowsToExecute.add(addConfigBB);
flowsToExecute.stream().forEach(executeBB -> logger.info("Flows to Execute After Post Processing: {}", executeBB.getBuildingBlock().getBpmnFlowName()));
execution.setVariable("flowsToExecute", flowsToExecute);
execution.setVariable(COMPLETED, false);
} else {
logger.debug("No cvnfcCustomization found for customizationId: {}", modelCustomizationId);
}
}
} catch (EntityNotFoundException e) {
logger.debug("Will not be running Fabric Config Building Blocks", e);
} catch (Exception e) {
String errorMessage = "Error occurred in post processing of Vf Module create";
execution.setVariable(HANDLINGCODE, ROLLBACKTOCREATED);
execution.setVariable("WorkflowActionErrorMessage", errorMessage);
logger.error(errorMessage, e);
}
}
use of org.onap.so.serviceinstancebeans.RelatedInstance in project so by onap.
the class BBInputSetupTest method testPopulateVfModuleIsReplaceCorrectPopulationOfVfs.
@Test
public void testPopulateVfModuleIsReplaceCorrectPopulationOfVfs() throws Exception {
String vnfId = "vnfId";
String vfModuleId = "vfModuleId";
String volumeGroupId = "volumeGroupId";
String vfModuleCustomizationId = "vfModuleCustomizationId";
ModelInfo modelInfo = new ModelInfo();
modelInfo.setModelCustomizationId(vfModuleCustomizationId);
Service currentService = new Service();
currentService.setModelUUID("currentUUID");
Service newService = new Service();
newService.setModelUUID("newUUID");
ServiceModel serviceModel = new ServiceModel();
serviceModel.setCurrentService(currentService);
serviceModel.setNewService(newService);
String bbName = "ActivateVfModuleBB";
ServiceInstance serviceInstance = new ServiceInstance();
GenericVnf vnf = new GenericVnf();
vnf.setVnfId(vnfId);
VolumeGroup volumeGroup = new VolumeGroup();
volumeGroup.setVolumeGroupId(volumeGroupId);
vnf.getVolumeGroups().add(volumeGroup);
serviceInstance.getVnfs().add(vnf);
VfModule vfModule1 = new VfModule();
vfModule1.setVfModuleId("vfModuleId1");
VfModule vfModule2 = new VfModule();
vfModule2.setVfModuleId("vfModuleId2");
vnf.getVfModules().add(vfModule1);
vnf.getVfModules().add(vfModule2);
Map<ResourceKey, String> lookupKeyMap = new HashMap<>();
lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnfId);
lookupKeyMap.put(ResourceKey.VF_MODULE_ID, "vfModuleId1");
String resourceId = vfModuleId;
RelatedInstanceList[] relatedInstanceList = new RelatedInstanceList[1];
RelatedInstanceList relatedInstanceListObj = new RelatedInstanceList();
RelatedInstance relatedInstance = new RelatedInstance();
relatedInstance.setInstanceId(vnfId);
ModelInfo vnfModelInfo = new ModelInfo();
vnfModelInfo.setModelCustomizationId("vnfCustomizationId");
vnfModelInfo.setModelType(ModelType.vnf);
relatedInstance.setModelInfo(vnfModelInfo);
relatedInstanceListObj.setRelatedInstance(relatedInstance);
relatedInstanceList[0] = relatedInstanceListObj;
String instanceName = "vfModuleName";
List<Map<String, String>> instanceParams = null;
CloudConfiguration cloudConfiguration = new CloudConfiguration();
org.onap.aai.domain.yang.GenericVnf vnfAAI = new org.onap.aai.domain.yang.GenericVnf();
vnfAAI.setModelCustomizationId("vnfModelCustId");
org.onap.aai.domain.yang.VolumeGroup volumeGroupAAI = new org.onap.aai.domain.yang.VolumeGroup();
volumeGroupAAI.setModelCustomizationId(vfModuleCustomizationId);
org.onap.aai.domain.yang.VfModule vfModuleAAI = new org.onap.aai.domain.yang.VfModule();
vfModuleAAI.setModelCustomizationId(vfModuleCustomizationId);
doReturn(vnfAAI).when(SPY_bbInputSetupUtils).getAAIGenericVnf(vnf.getVnfId());
doReturn(volumeGroupAAI).when(SPY_bbInputSetupUtils).getAAIVolumeGroup(CLOUD_OWNER, cloudConfiguration.getLcpCloudRegionId(), volumeGroup.getVolumeGroupId());
doReturn(vfModuleAAI).when(SPY_bbInputSetupUtils).getAAIVfModule(isA(String.class), isA(String.class));
doNothing().when(SPY_bbInputSetup).mapCatalogVnf(isA(GenericVnf.class), isA(ModelInfo.class), isA(Service.class));
doNothing().when(SPY_bbInputSetup).mapCatalogVfModule(isA(VfModule.class), isA(ModelInfo.class), isA(Service.class), isA(String.class));
BBInputSetupParameter parameter = new BBInputSetupParameter.Builder().setModelInfo(modelInfo).setService(newService).setBbName(bbName).setServiceInstance(serviceInstance).setLookupKeyMap(lookupKeyMap).setResourceId(resourceId).setRelatedInstanceList(relatedInstanceList).setInstanceName(instanceName).setInstanceParams(instanceParams).setCloudConfiguration(cloudConfiguration).setIsReplace(true).setServiceModel(serviceModel).build();
SPY_bbInputSetup.populateVfModule(parameter);
verify(SPY_bbInputSetup, times(1)).mapCatalogVfModule(isA(VfModule.class), isA(ModelInfo.class), eq(currentService), eq("vnfModelCustId"));
verify(SPY_bbInputSetup, times(1)).mapCatalogVfModule(isA(VfModule.class), isA(ModelInfo.class), eq(newService), eq("vnfCustomizationId"));
assertEquals("Lookup Key Map populated with VfModule Id", "vfModuleId1", lookupKeyMap.get(ResourceKey.VF_MODULE_ID));
assertEquals("Lookup Key Map populated with VolumeGroup Id", volumeGroupId, lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID));
}
Aggregations