Search in sources :

Example 1 with BadResponseException

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

the class SDNCQueryTasks method queryVnf.

/**
 * BPMN access method to query the SDNC for fetching the vnf details.
 *
 * It will get the vnf details according to service instance id.
 *
 * @param execution
 * @throws Exception
 */
public void queryVnf(BuildingBlockExecution execution) throws BBObjectNotFoundException {
    ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
    GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
    String selfLink = "restconf/config/GENERIC-RESOURCE-API:services/service/" + serviceInstance.getServiceInstanceId() + "/service-data/vnfs/vnf/" + genericVnf.getVnfId() + "/vnf-data/vnf-topology/";
    try {
        if (genericVnf.getSelflink() == null) {
            genericVnf.setSelflink(selfLink);
        }
        String response = sdncVnfResources.queryVnf(genericVnf);
        execution.setVariable(SDNCQUERY_RESPONSE + genericVnf.getVnfId(), response);
    } catch (BadResponseException ex) {
        logger.error("Exception occurred", 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 : GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) BadResponseException(org.onap.so.client.exception.BadResponseException) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) BadResponseException(org.onap.so.client.exception.BadResponseException) BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException)

Example 2 with BadResponseException

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

the class SdncControllerDE method sendSyncRequest.

private LcmOutput sendSyncRequest(String operation, LcmInput lcmInput) throws BadResponseException {
    SDNCLcmClientBuilder sdncLcmClientBuilder = new SDNCLcmClientBuilder();
    SDNCLcmRestClient sdncLcmRestClient;
    try {
        sdncLcmRestClient = sdncLcmClientBuilder.newSDNCLcmRestClient(operation);
    } catch (SDNCLcmClientBuilderException e) {
        logger.error("Create SDNCLcmRestClient error: ", e);
        throw new BadResponseException("Can not send request to SDNC.");
    }
    LcmOutput lcmOutput;
    try {
        lcmOutput = sdncLcmRestClient.sendRequest(lcmInput);
    } catch (Exception e) {
        logger.error("SDNCLcmRestClient sends request failure: ", e);
        throw new BadResponseException("Send request to SDNC failure.");
    }
    return lcmOutput;
}
Also used : BadResponseException(org.onap.so.client.exception.BadResponseException) PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException) BadResponseException(org.onap.so.client.exception.BadResponseException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with BadResponseException

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

the class SdncControllerDE method sendAsyncRequest.

private LcmOutput sendAsyncRequest(String operation, LcmInput lcmInput) throws BadResponseException {
    SDNCLcmClientBuilder sdncLcmClientBuilder = new SDNCLcmClientBuilder();
    SDNCLcmDmaapClient sdncLcmDmaapClient;
    try {
        sdncLcmDmaapClient = sdncLcmClientBuilder.newSDNCLcmDmaapClient();
    } catch (SDNCLcmClientBuilderException e) {
        logger.error("Create SDNCLcmDmaapClient error: ", e);
        throw new BadResponseException("Can not send request to SDNC.");
    }
    LcmDmaapRequest lcmDmaapRequest = SDNCLcmMessageBuilder.buildLcmDmaapRequest(operation, lcmInput);
    try {
        sdncLcmDmaapClient.sendRequest(lcmDmaapRequest);
    } catch (Exception e) {
        logger.error("SDNCLcmDmaapClient sends request failure: ", e);
        throw new BadResponseException("Send request to SDNC failure.");
    }
    long timeout = sdncLcmClientBuilder.getSDNCLcmProperties().getActionTimeout();
    long startTime = System.currentTimeMillis();
    while (true) {
        List<LcmDmaapResponse> lcmDmaapResponses = sdncLcmDmaapClient.getResponse();
        if (lcmDmaapResponses.size() > 0) {
            LcmOutput lcmOutput = selectLcmOutputFromDmaapResponses(lcmDmaapResponses, lcmInput);
            if (lcmOutput != null) {
                return lcmOutput;
            }
        }
        long stopTime = System.currentTimeMillis();
        if ((stopTime - startTime) > timeout) {
            String msg = "Timeout for SDNC LCM action " + lcmInput.getAction();
            logger.error(msg);
            throw new BadResponseException(msg);
        }
    }
}
Also used : BadResponseException(org.onap.so.client.exception.BadResponseException) PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException) BadResponseException(org.onap.so.client.exception.BadResponseException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 4 with BadResponseException

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

the class OofValidator method validateDemandsResponse.

/**
 * Validates the synchronous homing response from oof
 *
 * @throws BadResponseException when validation failed
 */
public void validateDemandsResponse(Map<?, ?> response) throws BadResponseException {
    logger.debug("Validating oofs synchronous response");
    if (!response.isEmpty()) {
        JSONObject jsonResponse = new JSONObject(response);
        if (jsonResponse.has("requestStatus")) {
            String status = jsonResponse.getString("requestStatus");
            if (status.equals("accepted")) {
                logger.debug("oofs synchronous response indicates accepted");
            } else {
                String message = jsonResponse.getString("statusMessage");
                if (isNotBlank(message)) {
                    logger.debug("oofs response indicates failed: {}", message);
                } else {
                    logger.debug("oofs response indicates failed: no status message provided");
                    message = "error message not provided";
                }
                throw new BadResponseException("oofs synchronous response indicates failed: {}", message);
            }
        } else {
            logger.debug("oofs synchronous response does not contain: request status");
            throw new BadResponseException("oofs synchronous response does not contain: request status");
        }
    } else {
        logger.debug("oofs synchronous response is empty");
        throw new BadResponseException("oofs synchronous response i is empty");
    }
}
Also used : JSONObject(org.json.JSONObject) BadResponseException(org.onap.so.client.exception.BadResponseException)

Example 5 with BadResponseException

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

the class NamingClient method postNameGenRequest.

public String postNameGenRequest(NameGenRequest request) throws BadResponseException, IOException {
    String targetUrl = env.getProperty(ENDPOINT);
    HttpHeaders headers = setHeaders(env.getProperty(AUTH));
    logger.info("Sending postNameGenRequest to url: {}", targetUrl);
    HttpEntity<NameGenRequest> requestEntity = new HttpEntity<>(request, headers);
    ResponseEntity<NameGenResponse> response;
    try {
        response = restTemplate.postForEntity(targetUrl, requestEntity, NameGenResponse.class);
    } catch (HttpStatusCodeException e) {
        throw new BadResponseException(namingClientResponseValidator.formatError(e));
    }
    return namingClientResponseValidator.validateNameGenResponse(response);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) NameGenResponse(org.onap.namingservice.model.NameGenResponse) HttpEntity(org.springframework.http.HttpEntity) BadResponseException(org.onap.so.client.exception.BadResponseException) NameGenRequest(org.onap.namingservice.model.NameGenRequest) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException)

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