Search in sources :

Example 21 with RelatedInstance

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);
    }
}
Also used : ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) ConfigurationResourceKeys(org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys) CvnfcConfigurationCustomization(org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization) EntityNotFoundException(javax.persistence.EntityNotFoundException) Vnfc(org.onap.aai.domain.yang.Vnfc) EntityNotFoundException(javax.persistence.EntityNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 22 with RelatedInstance

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));
}
Also used : ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) ModelInfoGenericVnf(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) HashMap(java.util.HashMap) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) ModelInfoServiceInstance(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) ModelInfoVfModule(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule) ServiceModel(org.onap.so.bpmn.servicedecomposition.entities.ServiceModel) VolumeGroup(org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) Service(org.onap.so.db.catalog.beans.Service) ResourceKey(org.onap.so.bpmn.servicedecomposition.entities.ResourceKey) CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration) Map(java.util.Map) BaseBBInputSetupTestHelper.prepareLookupKeyMap(org.onap.so.bpmn.servicedecomposition.tasks.BaseBBInputSetupTestHelper.prepareLookupKeyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

RelatedInstance (org.onap.so.serviceinstancebeans.RelatedInstance)22 RelatedInstanceList (org.onap.so.serviceinstancebeans.RelatedInstanceList)18 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)13 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)7 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)7 Test (org.junit.Test)6 Service (org.onap.so.db.catalog.beans.Service)6 CloudConfiguration (org.onap.so.serviceinstancebeans.CloudConfiguration)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 VolumeGroup (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup)4 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)4 ResourceKey (org.onap.so.bpmn.servicedecomposition.entities.ResourceKey)4 ServiceModel (org.onap.so.bpmn.servicedecomposition.entities.ServiceModel)4 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)4 NoServiceInstanceFoundException (org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException)4 Map (java.util.Map)3 WorkflowResourceIds (org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds)3 ModelInfoGenericVnf (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf)3 ModelInfoVfModule (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule)3