Search in sources :

Example 6 with MapperException

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

the class SdnCommonTasks method buildJsonRequest.

/**
 * @param request
 * @return
 * @throws MapperException
 */
public String buildJsonRequest(Object request) throws MapperException {
    String jsonRequest;
    ObjectMapper objMapper = new ObjectMapper();
    objMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    try {
        jsonRequest = objMapper.writerWithDefaultPrettyPrinter().writeValueAsString(request);
    } catch (JsonProcessingException e) {
        logger.error(BRACKETS, MessageEnum.JAXB_EXCEPTION.toString(), COULD_NOT_CONVERT_SDNC_POJO_TO_JSON, "BPMN", ErrorCode.DataError.getValue(), e.getMessage());
        throw new MapperException(COULD_NOT_CONVERT_SDNC_POJO_TO_JSON);
    }
    jsonRequest = "{\"input\":" + jsonRequest + "}";
    logger.info(jsonRequest);
    return jsonRequest;
}
Also used : MapperException(org.onap.so.client.exception.MapperException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with MapperException

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

the class GeneralTopologyObjectMapper method buildVfModuleInformation.

/*
     * Build GenericResourceApiVfModuleinformationVfModuleInformation
     */
public GenericResourceApiVfmoduleinformationVfModuleInformation buildVfModuleInformation(VfModule vfModule, GenericVnf vnf, ServiceInstance serviceInstance, RequestContext requestContext, boolean includeModelInformation) throws MapperException {
    GenericResourceApiVfmoduleinformationVfModuleInformation vfModuleInformation = new GenericResourceApiVfmoduleinformationVfModuleInformation();
    if (includeModelInformation) {
        if (vfModule.getModelInfoVfModule() == null) {
            throw new MapperException("VF Module model info is null for " + vfModule.getVfModuleId());
        } else {
            GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation = new GenericResourceApiOnapmodelinformationOnapModelInformation();
            onapModelInformation.setModelInvariantUuid(vfModule.getModelInfoVfModule().getModelInvariantUUID());
            onapModelInformation.setModelName(vfModule.getModelInfoVfModule().getModelName());
            onapModelInformation.setModelVersion(vfModule.getModelInfoVfModule().getModelVersion());
            onapModelInformation.setModelUuid(vfModule.getModelInfoVfModule().getModelUUID());
            onapModelInformation.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
            vfModuleInformation.setOnapModelInformation(onapModelInformation);
        }
    }
    if (vfModule.getModelInfoVfModule() != null) {
        vfModuleInformation.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
    }
    vfModuleInformation.setVfModuleId(vfModule.getVfModuleId());
    if (requestContext != null && requestContext.getRequestParameters() != null) {
        vfModuleInformation.setFromPreload(requestContext.getRequestParameters().getUsePreload());
    } else {
        vfModuleInformation.setFromPreload(true);
    }
    return vfModuleInformation;
}
Also used : GenericResourceApiOnapmodelinformationOnapModelInformation(org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation) MapperException(org.onap.so.client.exception.MapperException) GenericResourceApiVfmoduleinformationVfModuleInformation(org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleinformationVfModuleInformation)

Example 8 with MapperException

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

Aggregations

MapperException (org.onap.so.client.exception.MapperException)8 GenericResourceApiVfmoduleinformationVfModuleInformation (org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleinformationVfModuleInformation)6 Test (org.junit.Test)5 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)5 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)5 VfModule (org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule)5 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)5 ModelInfoVfModule (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule)5 RequestContext (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext)4 RequestParameters (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)1 GenericResourceApiOnapmodelinformationOnapModelInformation (org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation)1 BadResponseException (org.onap.so.client.exception.BadResponseException)1 SDNCRequest (org.onap.so.client.sdnc.beans.SDNCRequest)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1