Search in sources :

Example 11 with BadResponseException

use of org.onap.so.client.exception.BadResponseException in project so by onap.

the class AbstractCDSProcessingBBUtils method getCdsResponse.

private CDSResponse getCdsResponse(ExecutionServiceInput executionServiceInput) throws BadResponseException {
    CDSProperties props = RestPropertiesLoader.getInstance().getNewImpl(CDSProperties.class);
    if (props == null) {
        throw new PreconditionFailedException("No RestProperty.CDSProperties implementation found on classpath, can't create client.");
    }
    CDSResponse cdsResponse = new CDSResponse();
    try (CDSProcessingClient cdsClient = new CDSProcessingClient(new ResponseHandler(cdsResponse))) {
        CountDownLatch countDownLatch = cdsClient.sendRequest(executionServiceInput);
        countDownLatch.await(props.getTimeout(), TimeUnit.SECONDS);
    } catch (InterruptedException ex) {
        logger.error("Caught exception in sendRequestToCDSClient in AbstractCDSProcessingBBUtils : ", ex);
        Thread.currentThread().interrupt();
    }
    String cdsResponseStatus = cdsResponse.status;
    /**
     * throw CDS failed exception.
     */
    if (!cdsResponseStatus.equals(SUCCESS)) {
        throw new BadResponseException("CDS call failed with status: " + cdsResponse.status + " and errorMessage: " + cdsResponse.errorMessage);
    }
    return cdsResponse;
}
Also used : BadResponseException(org.onap.so.client.exception.BadResponseException) PreconditionFailedException(org.onap.so.client.PreconditionFailedException) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 12 with BadResponseException

use of org.onap.so.client.exception.BadResponseException in project so by onap.

the class SDNCQueryTasks method queryVfModule.

/**
 * BPMN access method to query the SDNC for fetching the VfModule details.
 *
 * It will get the vnf details according to service instance id, vnf id & Vf module id.
 *
 * @param execution
 * @throws Exception
 */
public void queryVfModule(BuildingBlockExecution execution) throws BBObjectNotFoundException {
    ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
    GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
    VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
    String selfLink = "restconf/config/GENERIC-RESOURCE-API:services/service/" + serviceInstance.getServiceInstanceId() + "/service-data/vnfs/vnf/" + genericVnf.getVnfId() + "/vnf-data/vf-modules/vf-module/" + vfModule.getVfModuleId() + "/vf-module-data/vf-module-topology/";
    try {
        if (vfModule.getSelflink() == null || (vfModule.getSelflink() != null && vfModule.getSelflink().isEmpty())) {
            vfModule.setSelflink(selfLink);
        }
        if (vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) {
            String response = sdncVfModuleResources.queryVfModule(vfModule);
            execution.setVariable(SDNCQUERY_RESPONSE + vfModule.getVfModuleId(), response);
        } else {
            throw new Exception("Vf Module " + vfModule.getVfModuleId() + " exists in gBuildingBlock but does not have a selflink value");
        }
    } catch (BadResponseException ex) {
        logger.error("Exception occurred for BadResponse ", ex);
        if (!ex.getMessage().equals(NO_RESPONSE_FROM_SDNC)) {
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, ONAPComponents.SDNC);
        } else {
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, ONAPComponents.SO);
        }
    } catch (Exception ex) {
        logger.error("Exception occurred", ex);
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) BadResponseException(org.onap.so.client.exception.BadResponseException) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) BadResponseException(org.onap.so.client.exception.BadResponseException) BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException)

Example 13 with BadResponseException

use of org.onap.so.client.exception.BadResponseException in project so by onap.

the class SDNCQueryTasks method queryVfModuleForVolumeGroup.

/**
 * BPMN access method to query the SDNC for fetching the VfModuleForVolumeGroup details.
 *
 * It will get the vnf details according to Vf module id.
 *
 * @param execution @throws
 */
public void queryVfModuleForVolumeGroup(BuildingBlockExecution execution) {
    try {
        VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
        if (vfModule.getSelflink() != null && !vfModule.getSelflink().isEmpty()) {
            String response = sdncVfModuleResources.queryVfModule(vfModule);
            execution.setVariable(SDNCQUERY_RESPONSE + vfModule.getVfModuleId(), response);
        } else {
            throw new Exception("Vf Module " + vfModule.getVfModuleId() + " exists in gBuildingBlock but does not have a selflink value");
        }
    } catch (BBObjectNotFoundException bbException) {
        logger.error("Error occurred if bb object not found in SDNCQueryTasks queryVfModuleForVolumeGroup ", bbException);
        // the error as normal
        if (!ResourceKey.VF_MODULE_ID.equals(bbException.getResourceKey())) {
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, bbException, ONAPComponents.SO);
        }
    } catch (BadResponseException ex) {
        logger.error("Error occurred for BadResponseException in SDNCQueryTasks queryVfModuleForVolumeGroup ", ex);
        if (!ex.getMessage().equals(NO_RESPONSE_FROM_SDNC)) {
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, ONAPComponents.SDNC);
        } else {
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, ONAPComponents.SO);
        }
    } catch (Exception ex) {
        logger.error("Exception occurred", ex);
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex, ONAPComponents.SO);
    }
}
Also used : BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException) BadResponseException(org.onap.so.client.exception.BadResponseException) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) BadResponseException(org.onap.so.client.exception.BadResponseException) BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException)

Example 14 with BadResponseException

use of org.onap.so.client.exception.BadResponseException in project so by onap.

the class SDNCRequestTasks method callSDNC.

public void callSDNC(DelegateExecution execution) {
    SDNCRequest request = (SDNCRequest) execution.getVariable(SDNC_REQUEST);
    try {
        String response = sdncClient.post(request.getSDNCPayload(), request.getTopology());
        String finalMessageIndicator = JsonPath.read(response, "$.output.ack-final-indicator");
        execution.setVariable("isSDNCCompleted", convertIndicatorToBoolean(finalMessageIndicator));
    } catch (PathNotFoundException e) {
        logger.error("Error Parsing SDNC Response. Could not find read final ack indicator from JSON.", e);
        exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Recieved invalid response from SDNC, unable to read message content.", ONAPComponents.SO);
    } catch (MapperException e) {
        logger.error("Failed to map SDNC object to JSON prior to POST.", e);
        exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Failed to map SDNC object to JSON prior to POST.", ONAPComponents.SO);
    } catch (BadResponseException e) {
        logger.error("Did not receive a successful response from SDNC.", e);
        exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getLocalizedMessage(), ONAPComponents.SDNC);
    } catch (HttpClientErrorException e) {
        logger.error("HttpClientErrorException: 404 Not Found, Failed to contact SDNC", e);
        exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "SDNC cannot be contacted.", ONAPComponents.SO);
    }
}
Also used : SDNCRequest(org.onap.so.client.sdnc.beans.SDNCRequest) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) BadResponseException(org.onap.so.client.exception.BadResponseException) MapperException(org.onap.so.client.exception.MapperException) PathNotFoundException(com.jayway.jsonpath.PathNotFoundException)

Example 15 with BadResponseException

use of org.onap.so.client.exception.BadResponseException 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

BadResponseException (org.onap.so.client.exception.BadResponseException)27 JSONObject (org.json.JSONObject)6 Test (org.junit.Test)6 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)6 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 BpmnError (org.camunda.bpm.engine.delegate.BpmnError)4 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)4 BBObjectNotFoundException (org.onap.so.client.exception.BBObjectNotFoundException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JSONArray (org.json.JSONArray)2 NameGenDeleteResponse (org.onap.namingservice.model.NameGenDeleteResponse)2 NameGenResponse (org.onap.namingservice.model.NameGenResponse)2 Customer (org.onap.so.bpmn.servicedecomposition.bbobjects.Customer)2 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)2 VfModule (org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule)2 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)2 RequestContext (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext)2 MapperException (org.onap.so.client.exception.MapperException)2 PayloadGenerationException (org.onap.so.client.exception.PayloadGenerationException)2