Search in sources :

Example 96 with ServiceInstance

use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance in project so by onap.

the class OofHomingV2 method callOof.

/**
 * Generates the request payload then sends to Oof to perform homing and licensing for the provided demands
 *
 * @param execution
 */
public void callOof(BuildingBlockExecution execution) {
    logger.trace("Started Oof Homing Call Oof");
    try {
        GeneralBuildingBlock bb = execution.getGeneralBuildingBlock();
        RequestContext requestContext = bb.getRequestContext();
        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("oof.timeout", "PT30M");
        }
        OofRequest oofRequest = new OofRequest();
        RequestInfo requestInfo = buildRequestInfo(requestId, timeout);
        oofRequest.setRequestInformation(requestInfo);
        ServiceInfo serviceInfo = buildServiceInfo(serviceInstance);
        oofRequest.setServiceInformation(serviceInfo);
        PlacementInfo placementInfo = buildPlacementInfo(customer);
        placementInfo = buildPlacementDemands(serviceInstance, placementInfo);
        oofRequest.setPlacementInformation(placementInfo);
        LicenseInfo licenseInfo = buildLicenseInfo(serviceInstance);
        oofRequest.setLicenseInformation(licenseInfo);
        if (!placementInfo.getPlacementDemands().isEmpty() || !licenseInfo.getLicenseDemands().isEmpty()) {
            oofClient.postDemands(oofRequest);
        } 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", "OofResponse");
        execution.setVariable("asyncTimeout", timeout);
        logger.trace("Completed Oof Homing Call Oof");
    } catch (BpmnError e) {
        logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
        exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage());
    } catch (BadResponseException e) {
        logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
        exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage());
    } catch (Exception e) {
        logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
        exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, "Internal Error - occurred while " + "preparing oof request: " + e + "   Stack:" + ExceptionUtils.getFullStackTrace(e));
    }
}
Also used : LicenseInfo(org.onap.so.client.oof.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.oof.beans.RequestInfo) BadResponseException(org.onap.so.client.exception.BadResponseException) ServiceInfo(org.onap.so.client.oof.beans.ServiceInfo) PlacementInfo(org.onap.so.client.oof.beans.PlacementInfo) RequestContext(org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext) OofRequest(org.onap.so.client.oof.beans.OofRequest) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 97 with ServiceInstance

use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance in project so by onap.

the class OofHomingV2 method processPlacementSolution.

/**
 * Processes a placement solution list then correlates and sets each placement solution to its corresponding
 * resource
 */
private void processPlacementSolution(ServiceInstance serviceInstance, JSONArray placements, int i) {
    List<VpnBondingLink> links = serviceInstance.getVpnBondingLinks();
    List<AllottedResource> allottes = serviceInstance.getAllottedResources();
    List<GenericVnf> vnfs = serviceInstance.getVnfs();
    logger.debug("Processing placement solution " + i + 1);
    for (int p = 0; p < placements.length(); p++) {
        JSONObject placement = placements.getJSONObject(p);
        SolutionInfo solutionInfo = new SolutionInfo();
        solutionInfo.setSolutionId(i + 1);
        search: {
            for (VpnBondingLink vbl : links) {
                List<ServiceProxy> proxies = vbl.getServiceProxies();
                for (ServiceProxy sp : proxies) {
                    if (placement.getString(SERVICE_RESOURCE_ID).equals(sp.getId())) {
                        if (i > 0) {
                            if (p % 2 == 0) {
                                VpnBondingLink vblNew = (VpnBondingLink) SerializationUtils.clone(vbl);
                                vblNew.setVpnBondingLinkId(UUID.randomUUID().toString());
                                links.add(vblNew);
                            }
                            links.get(links.size() - 1).getServiceProxy(sp.getId()).setServiceInstance(setSolution(solutionInfo, placement));
                        } else {
                            sp.setServiceInstance(setSolution(solutionInfo, placement));
                        }
                        break search;
                    }
                }
            }
            for (AllottedResource ar : allottes) {
                if (placement.getString(SERVICE_RESOURCE_ID).equals(ar.getId())) {
                    ar.setParentServiceInstance(setSolution(solutionInfo, placement));
                    break search;
                }
            }
            for (GenericVnf vnf : vnfs) {
                if (placement.getString(SERVICE_RESOURCE_ID).equals(vnf.getVnfId())) {
                    ServiceInstance si = setSolution(solutionInfo, placement);
                    serviceInstance.setSolutionInfo(si.getSolutionInfo());
                    serviceInstance.getVnfs().add(si.getVnfs().get(0));
                    break search;
                }
            }
        }
    }
}
Also used : SolutionInfo(org.onap.so.bpmn.servicedecomposition.homingobjects.SolutionInfo) VpnBondingLink(org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) JSONObject(org.json.JSONObject) ServiceProxy(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) ModelInfoServiceInstance(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance) AllottedResource(org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource)

Example 98 with ServiceInstance

use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance in project so by onap.

the class OofHomingV2 method setSolution.

/**
 * Creates and sets necessary pojos with placement solution data for a given demand
 */
private ServiceInstance setSolution(SolutionInfo solutionInfo, JSONObject placement) {
    logger.debug("Mapping placement solution");
    String invalidMessage = "Oof Response contains invalid: ";
    JSONObject solution = placement.getJSONObject("solution");
    String identifierType = solution.getString(IDENTIFIER_TYPE);
    List<String> identifiersList = jsonUtils.StringArrayToList(solution.getJSONArray("identifiers").toString());
    String identifierValue = identifiersList.get(0);
    JSONArray assignments = placement.getJSONArray("assignmentInfo");
    Map<String, String> assignmentsMap = jsonUtils.entryArrayToMap(assignments.toString(), "key", "value");
    solutionInfo.setRehome(Boolean.parseBoolean(assignmentsMap.get("isRehome")));
    String type = identifierType;
    ServiceInstance si = new ServiceInstance();
    CloudRegion cloud = setCloud(assignmentsMap);
    if (type.equals("serviceInstanceId")) {
        if (identifierType.equals(CandidateType.SERVICE_INSTANCE_ID.toString())) {
            solutionInfo.setHomed(true);
            si.setServiceInstanceId(identifierValue);
            si.setOrchestrationStatus(OrchestrationStatus.CREATED);
            cloud.setLcpCloudRegionId(assignmentsMap.get("cloudRegionId"));
            if (assignmentsMap.containsKey("vnfHostName")) {
                logger.debug("Resources has been homed to a vnf");
                GenericVnf vnf = setVnf(assignmentsMap);
                vnf.setCloudRegion(cloud);
                si.getVnfs().add(vnf);
            } else if (assignmentsMap.containsKey("primaryPnfName")) {
                logger.debug("Resources has been homed to a pnf");
                Pnf priPnf = setPnf(assignmentsMap, "primary");
                priPnf.setCloudRegion(cloud);
                si.getPnfs().add(priPnf);
                if (assignmentsMap.containsKey("secondaryPnfName")) {
                    Pnf secPnf = setPnf(assignmentsMap, "secondary");
                    secPnf.setCloudRegion(cloud);
                    si.getPnfs().add(secPnf);
                }
            }
        } else {
            logger.debug(invalidMessage + IDENTIFIER_TYPE);
            throw new BpmnError(UNPROCESSABLE, invalidMessage + IDENTIFIER_TYPE);
        }
    } else if (type.equals("cloudRegionId")) {
        if (identifierType.equals(CandidateType.CLOUD_REGION_ID.toString())) {
            logger.debug("Resources has been homed to a cloud region");
            cloud.setLcpCloudRegionId(identifierValue);
            solutionInfo.setHomed(false);
            solutionInfo.setTargetedCloudRegion(cloud);
            si.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
        } else {
            logger.debug(invalidMessage + IDENTIFIER_TYPE);
            throw new BpmnError(UNPROCESSABLE, invalidMessage + IDENTIFIER_TYPE);
        }
    }
    si.setSolutionInfo(solutionInfo);
    return si;
}
Also used : CloudRegion(org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion) JSONObject(org.json.JSONObject) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) JSONArray(org.json.JSONArray) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) ModelInfoServiceInstance(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance) Pnf(org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 99 with ServiceInstance

use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance in project so by onap.

the class SniroHomingV2 method processSolution.

/**
 * Validates, processes, and sets the homing and licensing solutions that are returned by sniro manager
 *
 * @param execution
 * @param asyncResponse
 */
public void processSolution(BuildingBlockExecution execution, String asyncResponse) {
    logger.trace("Started Sniro Homing Process Solution");
    try {
        // TODO improve handling multiple solutions but is dependent on sniro enhancing api + work with sniro
        validateSolution(asyncResponse);
        ServiceInstance serviceInstance = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
        logger.debug("Processing sniro manager asyncronous response");
        JSONObject response = new JSONObject(asyncResponse);
        if (response.has(SOLUTIONS)) {
            JSONObject allSolutions = response.getJSONObject(SOLUTIONS);
            if (allSolutions.has("placementSolutions")) {
                JSONArray placementSolutions = allSolutions.getJSONArray("placementSolutions");
                for (int i = 0; i < placementSolutions.length(); i++) {
                    JSONArray placements = placementSolutions.getJSONArray(i);
                    processPlacementSolution(serviceInstance, placements, i);
                }
            }
            if (allSolutions.has("licenseSolutions")) {
                JSONArray licenseSolutions = allSolutions.getJSONArray("licenseSolutions");
                if (licenseSolutions.length() > 0) {
                    processLicenseSolution(serviceInstance, licenseSolutions);
                }
            }
        } else {
            throw new BpmnError(UNPROCESSABLE, "Sniro Managers response does not contain: " + SOLUTIONS);
        }
        execution.setVariable("generalBuildingBlock", execution.getGeneralBuildingBlock());
        logger.trace("Completed Sniro Homing Process Solution");
    } 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 processing sniro asynchronous response: " + e.getMessage(), ONAPComponents.SO);
    }
}
Also used : JSONObject(org.json.JSONObject) BadResponseException(org.onap.so.client.exception.BadResponseException) JSONArray(org.json.JSONArray) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) ModelInfoServiceInstance(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance) BadResponseException(org.onap.so.client.exception.BadResponseException) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 100 with ServiceInstance

use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance in project so by onap.

the class BBInputSetup method getGBBALaCarteService.

protected GeneralBuildingBlock getGBBALaCarteService(ExecuteBuildingBlock executeBB, RequestDetails requestDetails, Map<ResourceKey, String> lookupKeyMap, String requestAction, String resourceId) throws Exception {
    Customer customer = getCustomerAndServiceSubscription(requestDetails, resourceId);
    if (customer != null) {
        Project project = null;
        OwningEntity owningEntity = null;
        if (requestDetails.getProject() != null)
            project = mapperLayer.mapRequestProject(requestDetails.getProject());
        if (requestDetails.getOwningEntity() != null)
            owningEntity = mapperLayer.mapRequestOwningEntity(requestDetails.getOwningEntity());
        String modelVersionId = requestDetails.getModelInfo().getModelVersionId();
        if (ModelType.vnf == requestDetails.getModelInfo().getModelType()) {
            for (RelatedInstanceList relatedInstanceList : requestDetails.getRelatedInstanceList()) {
                if (ModelType.service == relatedInstanceList.getRelatedInstance().getModelInfo().getModelType()) {
                    modelVersionId = relatedInstanceList.getRelatedInstance().getModelInfo().getModelVersionId();
                    break;
                }
            }
        }
        Service service = bbInputSetupUtils.getCatalogServiceByModelUUID(modelVersionId);
        if (service == null) {
            service = bbInputSetupUtils.getCatalogServiceByModelVersionAndModelInvariantUUID(requestDetails.getModelInfo().getModelVersion(), requestDetails.getModelInfo().getModelInvariantId());
            if (service == null) {
                throw new Exception("Could not find service for model version Id: " + requestDetails.getModelInfo().getModelVersionId() + " and for model invariant Id: " + requestDetails.getModelInfo().getModelInvariantId());
            }
        }
        ServiceInstance serviceInstance = this.getALaCarteServiceInstance(service, requestDetails, customer, project, owningEntity, lookupKeyMap, resourceId, Boolean.TRUE.equals(executeBB.isaLaCarte()), executeBB.getBuildingBlock().getBpmnFlowName());
        BBInputSetupParameter parameter = new BBInputSetupParameter.Builder().setRequestDetails(requestDetails).setServiceInstance(serviceInstance).setExecuteBB(executeBB).setRequestAction(requestAction).setCustomer(customer).build();
        return this.populateGBBWithSIAndAdditionalInfo(parameter);
    } else {
        throw new Exception("Could not find customer");
    }
}
Also used : Project(org.onap.so.bpmn.servicedecomposition.bbobjects.Project) Customer(org.onap.so.bpmn.servicedecomposition.bbobjects.Customer) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) ExceptionBuilder(org.onap.so.client.exception.ExceptionBuilder) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) OwningEntity(org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity) Service(org.onap.so.db.catalog.beans.Service) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) 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)

Aggregations

ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)228 Test (org.junit.Test)118 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)110 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)84 RequestContext (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext)70 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)61 CloudRegion (org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion)54 Customer (org.onap.so.bpmn.servicedecomposition.bbobjects.Customer)53 VfModule (org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule)51 HashMap (java.util.HashMap)50 Service (org.onap.so.db.catalog.beans.Service)46 BBObjectNotFoundException (org.onap.so.client.exception.BBObjectNotFoundException)40 L3Network (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network)38 ResourceKey (org.onap.so.bpmn.servicedecomposition.entities.ResourceKey)37 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)35 ModelInfoGenericVnf (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf)33 ModelInfoVfModule (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule)33 File (java.io.File)31 OrchestrationContext (org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext)25 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)24