Search in sources :

Example 1 with ServiceInfo

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

the class SniroHomingV2 method buildServiceInfo.

/**
 * Builds the request information section for the homing/licensing request
 */
private ServiceInfo buildServiceInfo(ServiceInstance serviceInstance) {
    logger.trace("Building service information");
    ServiceInfo info = new ServiceInfo();
    ModelInfoServiceInstance modelInfo = serviceInstance.getModelInfoServiceInstance();
    if (isNotBlank(modelInfo.getModelInvariantUuid()) && isNotBlank(modelInfo.getModelUuid())) {
        info.setServiceInstanceId(serviceInstance.getServiceInstanceId());
        if (modelInfo.getServiceType() != null && modelInfo.getServiceType().length() > 0) {
            // temp solution
            info.setServiceName(modelInfo.getServiceType());
        }
        if (modelInfo.getServiceRole() != null) {
            info.setServiceRole(modelInfo.getServiceRole());
        }
        info.setModelInfo(buildModelInfo(modelInfo));
    } else {
        throw new BpmnError(UNPROCESSABLE, SERVICE_MISSING_DATA + MODEL_VERSION_ID + ", " + MODEL_INVARIANT_ID);
    }
    return info;
}
Also used : ServiceInfo(org.onap.so.client.sniro.beans.ServiceInfo) ModelInfoServiceInstance(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 2 with ServiceInfo

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

BpmnError (org.camunda.bpm.engine.delegate.BpmnError)2 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)2 ServiceInfo (org.onap.so.client.sniro.beans.ServiceInfo)2 Customer (org.onap.so.bpmn.servicedecomposition.bbobjects.Customer)1 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)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 BadResponseException (org.onap.so.client.exception.BadResponseException)1 Demand (org.onap.so.client.sniro.beans.Demand)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 SniroManagerRequest (org.onap.so.client.sniro.beans.SniroManagerRequest)1