Search in sources :

Example 1 with Demand

use of org.onap.so.client.sniro.beans.Demand in project so by onap.

the class SniroHomingV2 method buildDemand.

/**
 * Builds a single demand object
 */
private Demand buildDemand(String id, ModelInfoMetadata metadata) {
    logger.debug("Building demand for service or resource: " + id);
    Demand demand = new Demand();
    if (isNotBlank(id) && isNotBlank(metadata.getModelInstanceName())) {
        demand.setServiceResourceId(id);
        demand.setResourceModuleName(metadata.getModelInstanceName());
        demand.setModelInfo(buildModelInfo(metadata));
    } else {
        throw new BpmnError(UNPROCESSABLE, RESOURCE_MISSING_DATA + "modelInstanceName");
    }
    return demand;
}
Also used : Demand(org.onap.so.client.sniro.beans.Demand) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 2 with Demand

use of org.onap.so.client.sniro.beans.Demand in project so by onap.

the class SniroHomingV2 method buildPlacementDemands.

/**
 * Builds the placement demand list for the homing/licensing request
 */
private List<Demand> buildPlacementDemands(ServiceInstance serviceInstance) {
    logger.trace("Building placement information demands");
    List<Demand> placementDemands = new ArrayList<>();
    List<AllottedResource> allottedResourceList = serviceInstance.getAllottedResources();
    if (!allottedResourceList.isEmpty()) {
        logger.debug("Adding allotted resources to placement demands list");
        for (AllottedResource ar : allottedResourceList) {
            if (isBlank(ar.getId())) {
                ar.setId(UUID.randomUUID().toString());
            }
            Demand demand = buildDemand(ar.getId(), ar.getModelInfoAllottedResource());
            addCandidates(ar, demand);
            placementDemands.add(demand);
        }
    }
    List<VpnBondingLink> vpnBondingLinkList = serviceInstance.getVpnBondingLinks();
    if (!vpnBondingLinkList.isEmpty()) {
        logger.debug("Adding vpn bonding links to placement demands list");
        for (VpnBondingLink vbl : vpnBondingLinkList) {
            List<ServiceProxy> serviceProxyList = vbl.getServiceProxies();
            for (ServiceProxy sp : serviceProxyList) {
                if (isBlank(sp.getId())) {
                    sp.setId(UUID.randomUUID().toString());
                }
                Demand demand = buildDemand(sp.getId(), sp.getModelInfoServiceProxy());
                addCandidates(sp, demand);
                placementDemands.add(demand);
            }
        }
    }
    List<ServiceProxy> serviceProxies = serviceInstance.getServiceProxies();
    if (!serviceProxies.isEmpty()) {
        logger.debug("Adding service proxies to placement demands list");
        for (ServiceProxy sp : serviceProxies) {
            if (isBlank(sp.getId())) {
                sp.setId(UUID.randomUUID().toString());
            }
            Demand demand = buildDemand(sp.getId(), sp.getModelInfoServiceProxy());
            addCandidates(sp, demand);
            placementDemands.add(demand);
        }
    }
    return placementDemands;
}
Also used : Demand(org.onap.so.client.sniro.beans.Demand) VpnBondingLink(org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink) ServiceProxy(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy) ArrayList(java.util.ArrayList) AllottedResource(org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource)

Example 3 with Demand

use of org.onap.so.client.sniro.beans.Demand in project so by onap.

the class SniroHomingV2 method buildLicenseDemands.

/**
 * Builds the license demand list for the homing/licensing request
 */
private List<Demand> buildLicenseDemands(ServiceInstance serviceInstance) {
    logger.trace("Building license information");
    List<Demand> licenseDemands = new ArrayList<>();
    List<GenericVnf> vnfList = serviceInstance.getVnfs();
    if (!vnfList.isEmpty()) {
        logger.debug("Adding vnfs to license demands list");
        for (GenericVnf vnf : vnfList) {
            Demand demand = buildDemand(vnf.getVnfId(), vnf.getModelInfoGenericVnf());
            licenseDemands.add(demand);
        }
    }
    return licenseDemands;
}
Also used : Demand(org.onap.so.client.sniro.beans.Demand) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) ArrayList(java.util.ArrayList)

Example 4 with Demand

use of org.onap.so.client.sniro.beans.Demand 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)

Aggregations

Demand (org.onap.so.client.sniro.beans.Demand)4 ArrayList (java.util.ArrayList)2 BpmnError (org.camunda.bpm.engine.delegate.BpmnError)2 AllottedResource (org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource)1 Customer (org.onap.so.bpmn.servicedecomposition.bbobjects.Customer)1 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)1 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)1 ServiceProxy (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy)1 VpnBondingLink (org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBondingLink)1 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)1 RequestContext (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext)1 RequestParameters (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters)1 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)1 BadResponseException (org.onap.so.client.exception.BadResponseException)1 LicenseInfo (org.onap.so.client.sniro.beans.LicenseInfo)1 PlacementInfo (org.onap.so.client.sniro.beans.PlacementInfo)1 RequestInfo (org.onap.so.client.sniro.beans.RequestInfo)1 ServiceInfo (org.onap.so.client.sniro.beans.ServiceInfo)1 SniroManagerRequest (org.onap.so.client.sniro.beans.SniroManagerRequest)1