Search in sources :

Example 56 with GeneralBuildingBlock

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

the class SniroHomingV2 method callSniro.

/**
 * Generates the request payload then sends to sniro manager to perform homing and licensing for the provided
 * demands
 *
 * @param execution
 */
public void callSniro(BuildingBlockExecution execution) {
    logger.debug("Started Sniro Homing Call Sniro");
    try {
        GeneralBuildingBlock bb = execution.getGeneralBuildingBlock();
        RequestContext requestContext = bb.getRequestContext();
        RequestParameters requestParams = requestContext.getRequestParameters();
        String requestId = requestContext.getMsoRequestId();
        ServiceInstance serviceInstance = bb.getCustomer().getServiceSubscription().getServiceInstances().get(0);
        Customer customer = bb.getCustomer();
        String timeout = execution.getVariable("timeout");
        if (isBlank(timeout)) {
            timeout = env.getProperty("sniro.manager.timeout", "PT30M");
        }
        SniroManagerRequest request = new SniroManagerRequest();
        RequestInfo requestInfo = buildRequestInfo(requestId, timeout);
        request.setRequestInformation(requestInfo);
        ServiceInfo serviceInfo = buildServiceInfo(serviceInstance);
        request.setServiceInformation(serviceInfo);
        PlacementInfo placementInfo = buildPlacementInfo(customer, requestParams);
        List<Demand> placementDemands = buildPlacementDemands(serviceInstance);
        placementInfo.setDemands(placementDemands);
        request.setPlacementInformation(placementInfo);
        LicenseInfo licenseInfo = new LicenseInfo();
        List<Demand> licenseDemands = buildLicenseDemands(serviceInstance);
        licenseInfo.setDemands(licenseDemands);
        request.setLicenseInformation(licenseInfo);
        if (!placementDemands.isEmpty() || !licenseDemands.isEmpty()) {
            client.postDemands(request);
        } else {
            logger.debug(SERVICE_MISSING_DATA + "resources eligible for homing or licensing");
            throw new BpmnError(UNPROCESSABLE, SERVICE_MISSING_DATA + "resources eligible for homing or licensing");
        }
        // Variables for ReceiveWorkflowMessage subflow
        execution.setVariable("asyncCorrelator", requestId);
        execution.setVariable("asyncMessageType", "SNIROResponse");
        execution.setVariable("asyncTimeout", timeout);
        logger.trace("Completed Sniro Homing Call Sniro");
    } catch (BpmnError e) {
        logger.error(EXCEPTION_OCCURRED, e);
        exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage(), ONAPComponents.SNIRO);
    } catch (BadResponseException e) {
        logger.error(EXCEPTION_OCCURRED, e);
        exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage(), ONAPComponents.SNIRO);
    } catch (Exception e) {
        logger.error(EXCEPTION_OCCURRED, e);
        exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, "Internal Error - occurred while preparing sniro request: " + e.getMessage(), ONAPComponents.SO);
    }
}
Also used : Demand(org.onap.so.client.sniro.beans.Demand) LicenseInfo(org.onap.so.client.sniro.beans.LicenseInfo) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) Customer(org.onap.so.bpmn.servicedecomposition.bbobjects.Customer) BadResponseException(org.onap.so.client.exception.BadResponseException) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) ModelInfoServiceInstance(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance) RequestInfo(org.onap.so.client.sniro.beans.RequestInfo) BadResponseException(org.onap.so.client.exception.BadResponseException) RequestParameters(org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters) SniroManagerRequest(org.onap.so.client.sniro.beans.SniroManagerRequest) ServiceInfo(org.onap.so.client.sniro.beans.ServiceInfo) PlacementInfo(org.onap.so.client.sniro.beans.PlacementInfo) RequestContext(org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 57 with GeneralBuildingBlock

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

the class VnfAdapterCreateTasks method createVfModule.

/**
 * This method is used for creating the request for the VfModule.
 *
 * @param execution
 * @return
 */
public void createVfModule(BuildingBlockExecution execution) {
    try {
        GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
        ServiceInstance serviceInstance = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0);
        VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
        GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
        VolumeGroup volumeGroup = null;
        try {
            volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
        } catch (BBObjectNotFoundException bbException) {
            logger.info("Volume Group not found in GBB. ");
        }
        CloudRegion cloudRegion = gBBInput.getCloudRegion();
        RequestContext requestContext = gBBInput.getRequestContext();
        OrchestrationContext orchestrationContext = gBBInput.getOrchContext();
        String sdncVfModuleQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + vfModule.getVfModuleId());
        String sdncVnfQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + genericVnf.getVnfId());
        CreateVfModuleRequest createVfModuleRequest = vnfAdapterVfModuleResources.createVfModuleRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, vfModule, volumeGroup, sdncVnfQueryResponse, sdncVfModuleQueryResponse);
        execution.setVariable(VNFREST_REQUEST, createVfModuleRequest.toXmlString());
    } catch (Exception ex) {
        logger.error("Exception occurred", ex);
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException) CloudRegion(org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion) CreateVfModuleRequest(org.onap.so.adapters.vnfrest.CreateVfModuleRequest) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) VolumeGroup(org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) RequestContext(org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) OrchestrationContext(org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext) BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException)

Example 58 with GeneralBuildingBlock

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

the class VnfAdapterCreateTasks method createVolumeGroupRequest.

/**
 * This method is used for creating the request for the VolumeGroup.
 *
 * @param execution
 * @return
 */
public void createVolumeGroupRequest(BuildingBlockExecution execution) {
    try {
        GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
        ServiceInstance serviceInstance = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0);
        GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
        VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
        VfModule vfModule;
        String sdncVfModuleQueryResponse = null;
        try {
            vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
            if (vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) {
                sdncVfModuleQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + vfModule.getVfModuleId());
            } else {
                throw new Exception("Vf Module " + vfModule.getVfModuleId() + " exists in gBuildingBlock but does not have a selflink value");
            }
        } catch (BBObjectNotFoundException bbException) {
            logger.error("Exception occurred", bbException);
        // If there is not a vf module in the general building block (in aLaCarte case),
        // we will not retrieve
        // the SDNCQueryResponse and proceed as normal without throwing an error
        }
        CreateVolumeGroupRequest createVolumeGroupRequest = vnfAdapterVolumeGroupResources.createVolumeGroupRequest(gBBInput.getRequestContext(), gBBInput.getCloudRegion(), gBBInput.getOrchContext(), serviceInstance, genericVnf, volumeGroup, sdncVfModuleQueryResponse);
        execution.setVariable(VNFREST_REQUEST, createVolumeGroupRequest.toXmlString());
    } catch (Exception ex) {
        logger.error("Exception occurred", ex);
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException) CreateVolumeGroupRequest(org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) VolumeGroup(org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException)

Example 59 with GeneralBuildingBlock

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

the class CnfHealthCheckTasks method prepareCnfAdaperRequest.

public void prepareCnfAdaperRequest(BuildingBlockExecution execution) {
    GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
    ServiceInstance serviceInstance = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0);
    GenericVnf genericVnf = serviceInstance.getVnfs().get(0);
    List<VfModule> listOfVfModules = genericVnf.getVfModules();
    List<String> listOfHeatStackIds = listOfVfModules.stream().map(x -> x.getHeatStackId()).collect(Collectors.toList());
    LOGGER.debug("listOfHeatStackIds from prepareCnfAdaperRequest: {}", listOfHeatStackIds);
    // Prepare values to pass in execution variable for CNF Adapter async Handling
    String requestId = execution.getVariable("mso-request-id");
    execution.setVariable("messageType", CNF_ADAPTER_MESSAGE_TYPE);
    execution.setVariable("correlator", requestId);
    execution.setVariable("timeout", "PT30M");
    // Replace with environment values
    String callBackUrl = "http://so-bpmn-infra.onap:8081/mso/WorkflowMessage/" + CNF_ADAPTER_MESSAGE_TYPE + "/" + requestId;
    HealthcheckInstanceRequest request = new HealthcheckInstanceRequest();
    try {
        request = createStatusCheckRequest(listOfHeatStackIds, callBackUrl);
    } catch (JsonProcessingException e) {
        exceptionUtil.buildAndThrowWorkflowException(execution, 6822, e);
    }
    LOGGER.debug("request: {}", request);
    String requestPayload = "";
    try {
        requestPayload = mapper.writeValueAsString(request);
    } catch (JsonProcessingException e) {
        LOGGER.error("Error in JSON");
    }
    execution.setVariable("cnfRequestPayload", requestPayload);
    ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK);
    BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock();
    String action = Optional.ofNullable(buildingBlock.getBpmnAction()).orElseThrow(() -> new NullPointerException("BPMN Action is NULL in the orchestration_flow_reference table "));
    // Replace values with environment values
    String uri = "http://so-cnf-adapter:8090";
    String apiPath = "";
    if (STATUS_CHECK_SCOPE.equals(action)) {
        apiPath = uri + "/api/cnf-adapter/v1/statuscheck/";
    } else if (HEALTH_CHECK_SCOPE.equals(action)) {
        apiPath = uri + "/api/cnf-adapter/v1/healthcheck/";
    }
    LOGGER.debug("apiPath: {}", apiPath);
    execution.setVariable("apiPath", apiPath);
}
Also used : ONAPComponents(org.onap.logging.filter.base.ONAPComponents) HealthcheckInstanceResponse(org.onap.so.client.adapter.cnf.entities.HealthcheckInstanceResponse) StatusCheckInstanceResponse(org.onap.so.client.adapter.cnf.entities.StatusCheckInstanceResponse) HealthcheckInstanceRequest(org.onap.so.client.adapter.cnf.entities.HealthcheckInstanceRequest) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) StatusCheckResponse(org.onap.so.client.adapter.cnf.entities.StatusCheckResponse) ArrayList(java.util.ArrayList) ExceptionBuilder(org.onap.so.client.exception.ExceptionBuilder) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) Logger(org.slf4j.Logger) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) HealthcheckResponse(org.onap.so.client.adapter.cnf.entities.HealthcheckResponse) BuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) HealthcheckInstance(org.onap.so.client.adapter.cnf.entities.HealthcheckInstance) List(java.util.List) Component(org.springframework.stereotype.Component) BuildingBlockExecution(org.onap.so.bpmn.common.BuildingBlockExecution) Optional(java.util.Optional) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) BuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) HealthcheckInstanceRequest(org.onap.so.client.adapter.cnf.entities.HealthcheckInstanceRequest) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 60 with GeneralBuildingBlock

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

the class NetworkAdapterDeleteTasks method deleteNetwork.

public void deleteNetwork(BuildingBlockExecution execution) {
    try {
        GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
        L3Network l3Network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
        ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
        DeleteNetworkRequest deleteNetworkRequest = networkAdapterObjectMapper.deleteNetworkRequestMapper(gBBInput.getRequestContext(), gBBInput.getCloudRegion(), serviceInstance, l3Network);
        execution.setVariable("networkAdapterRequest", deleteNetworkRequest.toXmlString());
    } catch (Exception ex) {
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : L3Network(org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) DeleteNetworkRequest(org.onap.so.adapters.nwrest.DeleteNetworkRequest) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)

Aggregations

GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)117 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)61 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)51 ResourceKey (org.onap.so.bpmn.servicedecomposition.entities.ResourceKey)40 Test (org.junit.Test)37 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)37 RequestContext (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext)35 File (java.io.File)34 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)34 CloudRegion (org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion)29 Service (org.onap.so.db.catalog.beans.Service)27 VfModule (org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule)25 Customer (org.onap.so.bpmn.servicedecomposition.bbobjects.Customer)23 HashMap (java.util.HashMap)22 BuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock)22 L3Network (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network)20 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)19 SDNCRequest (org.onap.so.client.sdnc.beans.SDNCRequest)19 ConfigurationResourceKeys (org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys)16 BBObjectNotFoundException (org.onap.so.client.exception.BBObjectNotFoundException)16