use of org.openkilda.integration.exception.InvalidResponseException in project open-kilda by telstra.
the class FlowsIntegrationService method getFlowHistoryById.
/**
* Gets the flow history by id.
*
* @param flowId the flow id
* @return the flow history by id
*/
public List<FlowHistory> getFlowHistoryById(final String flowId, String timeFrom, String timeTo) throws IntegrationException {
try {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(applicationProperties.getNbBaseUrl() + IConstants.NorthBoundUrl.GET_FLOW_HISTORY.replace("{flow_id}", UriUtils.encodePath(flowId, "UTF-8")));
builder = setFlowTimestamp(timeFrom, timeTo, builder);
String fullUri = builder.build().toUriString();
HttpResponse response = restClientManager.invoke(fullUri, HttpMethod.GET, "", "", applicationService.getAuthHeader());
if (RestClientManager.isValidResponse(response)) {
return restClientManager.getResponseList(response, FlowHistory.class);
}
return null;
} catch (InvalidResponseException e) {
LOGGER.error("Error occurred while retriving flow history with id: " + flowId, e);
throw new InvalidResponseException(e.getCode(), e.getResponse());
} catch (UnsupportedEncodingException e) {
LOGGER.error("Error occurred while retriving flow history with id: " + flowId, e);
e.printStackTrace();
}
return null;
}
use of org.openkilda.integration.exception.InvalidResponseException in project open-kilda by telstra.
the class RestClientManager method isValidResponse.
/**
* Checks if is valid response.
*
* @param response the response
* @return true, if is valid response
*/
public static boolean isValidResponse(final HttpResponse response) {
LOGGER.debug("[isValidResponse] Response Code " + response.getStatusLine().getStatusCode());
boolean isValid = response.getStatusLine().getStatusCode() >= HttpStatus.OK.value() && response.getStatusLine().getStatusCode() < HttpStatus.MULTIPLE_CHOICES.value() && response.getEntity() != null;
if (isValid) {
return true;
} else {
try {
String content = IoUtil.toString(response.getEntity().getContent());
LOGGER.warn("Found invalid Response. Status Code: " + response.getStatusLine().getStatusCode() + ", content: " + content);
throw new InvalidResponseException(response.getStatusLine().getStatusCode(), content);
} catch (IOException exception) {
LOGGER.warn("Error occurred while vaildating response", exception);
throw new InvalidResponseException(HttpError.INTERNAL_ERROR.getCode(), HttpError.INTERNAL_ERROR.getMessage());
}
}
}
use of org.openkilda.integration.exception.InvalidResponseException in project open-kilda by telstra.
the class RestClientManager method isDeleteBfdValidResponse.
/**
* Checks if is delete link bfd valid response.
*
* @param response the response
* @return true, if is valid response
*/
public static boolean isDeleteBfdValidResponse(final HttpResponse response) {
LOGGER.debug("[isValidResponse] Response Code " + response.getStatusLine().getStatusCode());
boolean isValid = response.getStatusLine().getStatusCode() >= HttpStatus.OK.value() && response.getStatusLine().getStatusCode() < HttpStatus.MULTIPLE_CHOICES.value();
if (isValid) {
return true;
} else {
try {
String content = IoUtil.toString(response.getEntity().getContent());
LOGGER.warn("Found invalid Response. Status Code: " + response.getStatusLine().getStatusCode() + ", content: " + content);
throw new InvalidResponseException(response.getStatusLine().getStatusCode(), content);
} catch (IOException exception) {
LOGGER.warn("Error occurred while vaildating response", exception);
throw new InvalidResponseException(HttpError.INTERNAL_ERROR.getCode(), HttpError.INTERNAL_ERROR.getMessage());
}
}
}
use of org.openkilda.integration.exception.InvalidResponseException in project open-kilda by telstra.
the class SwitchIntegrationService method getIslLinkProps.
/**
* Gets the isl link cost.
*
* @return the isl link cost
*/
public List<LinkProps> getIslLinkProps(final LinkProps keys) {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(applicationProperties.getNbBaseUrl() + IConstants.NorthBoundUrl.GET_LINK_PROPS);
builder = setLinkProps(keys, builder);
String fullUri = builder.build().toUriString();
HttpResponse response = restClientManager.invoke(fullUri, HttpMethod.GET, "", "", applicationService.getAuthHeader());
try {
if (RestClientManager.isValidResponse(response)) {
List<LinkProps> linkPropsResponses = restClientManager.getResponseList(response, LinkProps.class);
if (!CollectionUtil.isEmpty(linkPropsResponses)) {
return linkPropsResponses;
}
}
} catch (InvalidResponseException e) {
LOGGER.warn("Error occurred while getting isl link props ", e);
return null;
}
return null;
}
use of org.openkilda.integration.exception.InvalidResponseException in project open-kilda by telstra.
the class SwitchService method getSwitch.
/**
* get All SwitchList.
*
* @return SwitchRelationData the switch info
* @throws IntegrationException the integration exception
*/
public SwitchInfo getSwitch(final String switchId, boolean controller) throws IntegrationException {
SwitchInfo switchInfo = null;
try {
switchInfo = switchIntegrationService.getSwitchesById(switchId);
} catch (InvalidResponseException ex) {
LOGGER.error("Error occurred while retrieving switches from controller", ex);
}
if (!controller) {
try {
UserInfo userInfo = userService.getLoggedInUserInfo();
if (userInfo.getPermissions().contains(IConstants.Permission.SW_SWITCH_INVENTORY)) {
if (storeService.getSwitchStoreConfig().getUrls().size() > 0) {
InventorySwitch inventorySwitch = switchStoreService.getSwitch(switchId);
if (inventorySwitch.getSwitchId() != null) {
switchInfo = processInventorySwitch(switchInfo, inventorySwitch);
} else {
SwitchDiscrepancy discrepancy = new SwitchDiscrepancy();
discrepancy.setControllerDiscrepancy(false);
discrepancy.setStatus(true);
discrepancy.setInventoryDiscrepancy(true);
SwitchStatus switchState = new SwitchStatus();
switchState.setControllerStatus(switchInfo.getState());
discrepancy.setStatusValue(switchState);
switchInfo.setDiscrepancy(discrepancy);
}
}
}
} catch (Exception ex) {
LOGGER.error("Error occurred while retrieving switches from store", ex);
throw new StoreIntegrationException("Error occurred while retrieving switches from store");
}
}
return switchInfo;
}
Aggregations