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