Search in sources :

Example 26 with ResourceKey

use of org.onap.so.bpmn.servicedecomposition.entities.ResourceKey in project so by onap.

the class BBInputSetupTest method testgetGBBMacroException.

@Test(expected = Exception.class)
public void testgetGBBMacroException() throws Exception {
    ExecuteBuildingBlock executeBB = mapper.readValue(new File(RESOURCE_PATH + "ExecuteBuildingBlockSimple.json"), ExecuteBuildingBlock.class);
    RequestDetails requestDetails = mapper.readValue(new File(RESOURCE_PATH + "RequestDetailsInput_serviceMacro.json"), RequestDetails.class);
    Map<ResourceKey, String> lookupKeyMap = new HashMap<>();
    String resourceId = "123";
    String vnfType = "vnfType";
    String requestAction = "createInstance";
    BuildingBlock buildingBlock = executeBB.getBuildingBlock();
    buildingBlock.setBpmnFlowName("Network").setKey("ab153b6e-c364-44c0-bef6-1f2982117f04");
    SPY_bbInputSetup.getGBBMacro(executeBB, requestDetails, lookupKeyMap, requestAction, resourceId, vnfType);
}
Also used : ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) BuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock) HashMap(java.util.HashMap) File(java.io.File) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) ResourceKey(org.onap.so.bpmn.servicedecomposition.entities.ResourceKey) Test(org.junit.Test)

Example 27 with ResourceKey

use of org.onap.so.bpmn.servicedecomposition.entities.ResourceKey in project so by onap.

the class BBInputSetup method execute.

/**
 * This method is used for executing the building block.
 *
 * It will get the BB from the execution object by checking if the aLaCarte and homing is true.
 *
 * Then it will get the GBB and execute it.
 *
 * @param execution
 * @throws Exception
 * @return
 */
@Override
public void execute(DelegateExecution execution) throws Exception {
    try {
        GeneralBuildingBlock outputBB = null;
        ExecuteBuildingBlock executeBB = this.getExecuteBBFromExecution(execution);
        String resourceId = executeBB.getResourceId();
        String requestAction = executeBB.getRequestAction();
        String vnfType = executeBB.getVnfType();
        boolean aLaCarte = Boolean.TRUE.equals(executeBB.isaLaCarte());
        boolean homing = Boolean.TRUE.equals(executeBB.isHoming());
        Map<ResourceKey, String> lookupKeyMap = new HashMap<>();
        outputBB = this.getGBB(executeBB, lookupKeyMap, requestAction, aLaCarte, resourceId, vnfType);
        ObjectMapper mapper = new ObjectMapper();
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
        logger.debug("GeneralBB: " + mapper.writeValueAsString(outputBB));
        setHomingFlag(outputBB, homing, lookupKeyMap);
        execution.setVariable(FLOW_VAR_NAME, executeBB.getBuildingBlock().getBpmnFlowName());
        execution.setVariable(GBB_INPUT_VAR_NAME, outputBB);
        execution.setVariable(LOOKUP_KEY_MAP_VAR_NAME, lookupKeyMap);
        if (outputBB.getRequestContext().getIsHelm()) {
            execution.setVariable("isHelm", true);
        } else {
            execution.setVariable("isHelm", false);
        }
        BuildingBlockExecution gBuildingBlockExecution = new DelegateExecutionImpl(execution);
        execution.setVariable("gBuildingBlockExecution", gBuildingBlockExecution);
        execution.setVariable("RetryCount", 1);
        execution.setVariable("handlingCode", "Success");
    } catch (Exception e) {
        logger.error("Exception occurred", e);
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e.getMessage());
    }
}
Also used : GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) BuildingBlockExecution(org.onap.so.bpmn.common.BuildingBlockExecution) HashMap(java.util.HashMap) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ServiceModelNotFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.ServiceModelNotFoundException) NoServiceInstanceFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException) ResourceNotFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.ResourceNotFoundException) ResourceKey(org.onap.so.bpmn.servicedecomposition.entities.ResourceKey)

Example 28 with ResourceKey

use of org.onap.so.bpmn.servicedecomposition.entities.ResourceKey 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;
}
Also used : WorkflowResourceIds(org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds) AAIUriFactory(org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory) VpnBinding(org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding) Vnfs(org.onap.so.serviceinstancebeans.Vnfs) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) StringUtils(org.apache.commons.lang3.StringUtils) ServiceProxyResourceCustomization(org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization) ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) JavaDelegate(org.camunda.bpm.engine.delegate.JavaDelegate) Pnf(org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf) Service(org.onap.so.db.catalog.beans.Service) Map(java.util.Map) Tenant(org.onap.so.bpmn.servicedecomposition.bbobjects.Tenant) OrchestrationStatus(org.onap.so.db.catalog.beans.OrchestrationStatus) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) NetworkPolicy(org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy) ResourceKey(org.onap.so.bpmn.servicedecomposition.entities.ResourceKey) ServiceProxy(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy) ConfigurationResourceCustomization(org.onap.so.db.catalog.beans.ConfigurationResourceCustomization) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) LineOfBusiness(org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness) ConfigurationResourceKeys(org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) UUID(java.util.UUID) Pair(org.javatuples.Pair) ServiceModelNotFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.ServiceModelNotFoundException) Objects(java.util.Objects) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) List(java.util.List) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) CollectionResourceCustomization(org.onap.so.db.catalog.beans.CollectionResourceCustomization) ServiceSubscription(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription) ModelType(org.onap.so.serviceinstancebeans.ModelType) Optional(java.util.Optional) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) Vnfc(org.onap.so.bpmn.servicedecomposition.bbobjects.Vnfc) Customer(org.onap.so.bpmn.servicedecomposition.bbobjects.Customer) OrchestrationContext(org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext) CloudRegion(org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion) CollectionResource(org.onap.so.db.catalog.beans.CollectionResource) Types(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types) Collection(org.onap.so.bpmn.servicedecomposition.bbobjects.Collection) CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration) NoServiceInstanceFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException) HashMap(java.util.HashMap) InstanceGroup(org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup) RequestContext(org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext) ResourceNotFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.ResourceNotFoundException) ArrayList(java.util.ArrayList) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) VfModules(org.onap.so.serviceinstancebeans.VfModules) RouteTableReference(org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTableReference) VolumeGroup(org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup) ExceptionBuilder(org.onap.so.client.exception.ExceptionBuilder) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) VfModuleCustomization(org.onap.so.db.catalog.beans.VfModuleCustomization) OwningEntity(org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity) CollectionNetworkResourceCustomization(org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization) Logger(org.slf4j.Logger) ServiceModel(org.onap.so.bpmn.servicedecomposition.entities.ServiceModel) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) Configuration(org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration) Project(org.onap.so.bpmn.servicedecomposition.bbobjects.Project) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) NetworkCollectionResourceCustomization(org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VnfcInstanceGroupCustomization(org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) AAICommonObjectMapperProvider(org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider) Networks(org.onap.so.serviceinstancebeans.Networks) Component(org.springframework.stereotype.Component) Platform(org.onap.so.bpmn.servicedecomposition.bbobjects.Platform) CvnfcConfigurationCustomization(org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization) L3Network(org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network) BuildingBlockExecution(org.onap.so.bpmn.common.BuildingBlockExecution) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) RequestParameters(org.onap.so.serviceinstancebeans.RequestParameters) Resources(org.onap.so.serviceinstancebeans.Resources) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) VfModules(org.onap.so.serviceinstancebeans.VfModules) Networks(org.onap.so.serviceinstancebeans.Networks) CloudRegion(org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion) ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) Optional(java.util.Optional) ExceptionBuilder(org.onap.so.client.exception.ExceptionBuilder) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) Vnfs(org.onap.so.serviceinstancebeans.Vnfs) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration) ServiceModel(org.onap.so.bpmn.servicedecomposition.entities.ServiceModel) Resources(org.onap.so.serviceinstancebeans.Resources) ConfigurationResourceCustomization(org.onap.so.db.catalog.beans.ConfigurationResourceCustomization)

Example 29 with ResourceKey

use of org.onap.so.bpmn.servicedecomposition.entities.ResourceKey in project so by onap.

the class BBInputSetupTest method testPopulateLookupKeyMapWithIds.

@Test
public void testPopulateLookupKeyMapWithIds() {
    Map<ResourceKey, String> expected = new HashMap<>();
    Map<ResourceKey, String> actual = new HashMap<>();
    String serviceInstanceId = "serviceInstanceId";
    String networkId = "networkId";
    String vnfId = "vnfId";
    String pnfId = "pnfId";
    String vfModuleId = "vfModuleId";
    String volumeGroupId = "volumeGroupId";
    String configurationId = "configurationId";
    String instanceGroupId = "instancegroupId";
    String vnfInstanceName = "vnfInstanceName";
    String vfModuleInstanceName = "vfModuleInstanceName";
    expected.put(ResourceKey.SERVICE_INSTANCE_ID, serviceInstanceId);
    expected.put(ResourceKey.NETWORK_ID, networkId);
    expected.put(ResourceKey.GENERIC_VNF_ID, vnfId);
    expected.put(ResourceKey.PNF, pnfId);
    expected.put(ResourceKey.VF_MODULE_ID, vfModuleId);
    expected.put(ResourceKey.VOLUME_GROUP_ID, volumeGroupId);
    expected.put(ResourceKey.CONFIGURATION_ID, configurationId);
    expected.put(ResourceKey.INSTANCE_GROUP_ID, instanceGroupId);
    expected.put(ResourceKey.VNF_INSTANCE_NAME, vnfInstanceName);
    expected.put(ResourceKey.VF_MODULE_INSTANCE_NAME, vfModuleInstanceName);
    WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
    workflowResourceIds.setServiceInstanceId(serviceInstanceId);
    workflowResourceIds.setNetworkId(networkId);
    workflowResourceIds.setVnfId(vnfId);
    workflowResourceIds.setPnfId(pnfId);
    workflowResourceIds.setVfModuleId(vfModuleId);
    workflowResourceIds.setVolumeGroupId(volumeGroupId);
    workflowResourceIds.setConfigurationId(configurationId);
    workflowResourceIds.setInstanceGroupId(instanceGroupId);
    workflowResourceIds.setVnfInstanceName(vnfInstanceName);
    workflowResourceIds.setVfModuleInstanceName(vfModuleInstanceName);
    SPY_bbInputSetup.populateLookupKeyMapWithIds(workflowResourceIds, actual);
    assertThat(actual, sameBeanAs(expected));
}
Also used : HashMap(java.util.HashMap) ResourceKey(org.onap.so.bpmn.servicedecomposition.entities.ResourceKey) WorkflowResourceIds(org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds) Test(org.junit.Test)

Example 30 with ResourceKey

use of org.onap.so.bpmn.servicedecomposition.entities.ResourceKey in project so by onap.

the class ExecuteBuildingBlockRainyDay method queryRainyDayTable.

public void queryRainyDayTable(DelegateExecution execution, boolean primaryPolicy) {
    try {
        ExecuteBuildingBlock ebb = (ExecuteBuildingBlock) execution.getVariable("buildingBlock");
        String bbName = ebb.getBuildingBlock().getBpmnFlowName();
        GeneralBuildingBlock gBBInput = (GeneralBuildingBlock) execution.getVariable("gBBInput");
        String requestId = (String) execution.getVariable("mso-request-id");
        Map<ResourceKey, String> lookupKeyMap = (Map<ResourceKey, String>) execution.getVariable("lookupKeyMap");
        String serviceType = ASTERISK;
        boolean aLaCarte = (boolean) execution.getVariable("aLaCarte");
        boolean suppressRollback = (boolean) execution.getVariable("suppressRollback");
        WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException");
        if (workflowException != null) {
            execution.setVariable("WorkflowExceptionErrorMessage", workflowException.getErrorMessage());
        } else {
            logger.debug("WorkflowException is null, unable to set WorkflowExceptionErrorMessage");
        }
        String handlingCode = "";
        if (suppressRollback) {
            handlingCode = "Abort";
        } else {
            try {
                if (gBBInput.getCustomer() != null && gBBInput.getCustomer().getServiceSubscription() != null) {
                    serviceType = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getModelInfoServiceInstance().getServiceType();
                }
                if (serviceType == null || serviceType.isEmpty()) {
                    serviceType = ASTERISK;
                }
            } catch (Exception ex) {
                // keep default serviceType value
                logger.error("Exception in serviceType retrieval", ex);
            }
            execution.setVariable(RAINY_DAY_SERVICE_TYPE, serviceType);
            String vnfType = ASTERISK;
            String vnfName = ASTERISK;
            try {
                if (gBBInput.getCustomer() != null && gBBInput.getCustomer().getServiceSubscription() != null) {
                    for (GenericVnf vnf : gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getVnfs()) {
                        if (vnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
                            vnfType = vnf.getVnfType();
                            vnfName = vnf.getVnfName();
                        }
                    }
                } else {
                    for (GenericVnf vnf : gBBInput.getServiceInstance().getVnfs()) {
                        if (vnf.getVnfId().equalsIgnoreCase(lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID))) {
                            vnfType = vnf.getVnfType();
                            vnfName = vnf.getVnfName();
                        }
                    }
                }
            } catch (Exception ex) {
                // keep default vnfType value
                logger.error("Exception in vnfType retrieval", ex);
            }
            execution.setVariable(RAINY_DAY_VNF_TYPE, vnfType);
            execution.setVariable(RAINY_DAY_VNF_NAME, vnfName);
            String errorCode = ASTERISK;
            if (workflowException != null) {
                errorCode = "" + workflowException.getErrorCode();
            } else {
                logger.debug("WorkflowException is null, unable to get error code");
            }
            try {
                errorCode = "" + (String) execution.getVariable("WorkflowExceptionCode");
            } catch (Exception ex) {
                // keep default errorCode value
                logger.error("Exception in errorCode retrieval", ex);
            }
            String workStep = ASTERISK;
            try {
                workStep = workflowException.getWorkStep();
            } catch (Exception ex) {
                // keep default workStep value
                logger.error("Exception in workStep retrieval", ex);
            }
            String errorMessage = ASTERISK;
            try {
                errorMessage = workflowException.getErrorMessage();
            } catch (Exception ex) {
                // keep default workStep value
                logger.error("Exception in errorMessage retrieval", ex);
            }
            String serviceRole = ASTERISK;
            try {
                if (gBBInput.getCustomer() != null && gBBInput.getCustomer().getServiceSubscription() != null) {
                    serviceRole = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getModelInfoServiceInstance().getServiceRole();
                }
                if (serviceRole == null || serviceRole.isEmpty()) {
                    serviceRole = ASTERISK;
                }
            } catch (Exception ex) {
            // keep default serviceRole value
            }
            RainyDayHandlerStatus rainyDayHandlerStatus;
            rainyDayHandlerStatus = catalogDbClient.getRainyDayHandlerStatus(bbName, serviceType, vnfType, errorCode, workStep, errorMessage, serviceRole);
            if (rainyDayHandlerStatus == null) {
                handlingCode = "Abort";
            } else {
                if (primaryPolicy) {
                    handlingCode = rainyDayHandlerStatus.getPolicy();
                } else {
                    handlingCode = rainyDayHandlerStatus.getSecondaryPolicy();
                }
            }
            if (!primaryPolicy) {
                try {
                    InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId);
                    request.setRetryStatusMessage("Retries have been exhausted.");
                    requestDbclient.updateInfraActiveRequests(request);
                } catch (Exception ex) {
                    logger.error("Failed to update Request Db Infra Active Requests with Retry Status", ex);
                }
            }
            if ("RollbackToAssigned".equals(handlingCode) && !aLaCarte) {
                handlingCode = "Rollback";
            }
            if (handlingCode.startsWith("Rollback")) {
                String targetState = "";
                if ("RollbackToAssigned".equalsIgnoreCase(handlingCode)) {
                    targetState = Status.ROLLED_BACK_TO_ASSIGNED.toString();
                } else if ("RollbackToCreated".equalsIgnoreCase(handlingCode) || "RollbackToCreatedNoConfiguration".equalsIgnoreCase(handlingCode)) {
                    targetState = Status.ROLLED_BACK_TO_CREATED.toString();
                } else {
                    targetState = Status.ROLLED_BACK.toString();
                }
                execution.setVariable(ROLLBACK_TARGET_STATE, targetState);
                logger.debug("Rollback target state is: {}", targetState);
            }
        }
        logger.debug("RainyDayHandler Status Code is: {}", handlingCode);
        execution.setVariable(HANDLING_CODE, handlingCode);
    } catch (Exception e) {
        String code = this.environment.getProperty(defaultCode);
        logger.error("Failed to determine RainyDayHandler Status. Seting handlingCode = {}", code, e);
        execution.setVariable(HANDLING_CODE, code);
    }
    try {
        int envMaxRetries = Integer.parseInt(this.environment.getProperty(maxRetries));
        execution.setVariable("maxRetries", envMaxRetries);
    } catch (Exception ex) {
        logger.error("Could not read maxRetries from config file. Setting max to 5 retries", ex);
        execution.setVariable("maxRetries", 5);
    }
}
Also used : GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) WorkflowException(org.onap.so.bpmn.core.WorkflowException) RainyDayHandlerStatus(org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) WorkflowException(org.onap.so.bpmn.core.WorkflowException) ResourceKey(org.onap.so.bpmn.servicedecomposition.entities.ResourceKey) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) Map(java.util.Map)

Aggregations

ResourceKey (org.onap.so.bpmn.servicedecomposition.entities.ResourceKey)72 Test (org.junit.Test)66 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)51 File (java.io.File)50 HashMap (java.util.HashMap)48 Service (org.onap.so.db.catalog.beans.Service)45 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)41 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)41 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)41 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)39 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)25 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)23 BuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock)22 ModelInfoGenericVnf (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf)22 ConfigurationResourceKeys (org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys)19 CloudConfiguration (org.onap.so.serviceinstancebeans.CloudConfiguration)19 BaseBBInputSetupTestHelper.prepareConfigurationResourceKeys (org.onap.so.bpmn.servicedecomposition.tasks.BaseBBInputSetupTestHelper.prepareConfigurationResourceKeys)18 ServiceModel (org.onap.so.bpmn.servicedecomposition.entities.ServiceModel)13 Customer (org.onap.so.bpmn.servicedecomposition.bbobjects.Customer)11 L3Network (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network)11