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);
}
}
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;
}
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);
}
}
}
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");
}
}
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);
}
Aggregations