Search in sources :

Example 1 with InvalidResponseException

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;
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) HttpResponse(org.apache.http.HttpResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException)

Example 2 with InvalidResponseException

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());
        }
    }
}
Also used : IOException(java.io.IOException) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException)

Example 3 with InvalidResponseException

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());
        }
    }
}
Also used : IOException(java.io.IOException) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException)

Example 4 with InvalidResponseException

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;
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) HttpResponse(org.apache.http.HttpResponse) LinkProps(org.openkilda.model.LinkProps) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException)

Example 5 with InvalidResponseException

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;
}
Also used : InventorySwitch(org.openkilda.integration.source.store.dto.InventorySwitch) SwitchDiscrepancy(org.openkilda.model.SwitchDiscrepancy) StoreIntegrationException(org.openkilda.integration.exception.StoreIntegrationException) UserInfo(org.usermanagement.model.UserInfo) SwitchInfo(org.openkilda.model.SwitchInfo) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException) SwitchStatus(org.openkilda.model.SwitchStatus) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException) IntegrationException(org.openkilda.integration.exception.IntegrationException) StoreIntegrationException(org.openkilda.integration.exception.StoreIntegrationException) RequestValidationException(org.usermanagement.exception.RequestValidationException) AccessDeniedException(java.nio.file.AccessDeniedException)

Aggregations

InvalidResponseException (org.openkilda.integration.exception.InvalidResponseException)10 HttpResponse (org.apache.http.HttpResponse)5 IOException (java.io.IOException)3 IntegrationException (org.openkilda.integration.exception.IntegrationException)3 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)3 AccessDeniedException (java.nio.file.AccessDeniedException)2 LinkProps (org.openkilda.model.LinkProps)2 SwitchInfo (org.openkilda.model.SwitchInfo)2 RequestValidationException (org.usermanagement.exception.RequestValidationException)2 UserInfo (org.usermanagement.model.UserInfo)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 StoreIntegrationException (org.openkilda.integration.exception.StoreIntegrationException)1 FlowV2 (org.openkilda.integration.model.FlowV2)1 InventoryFlow (org.openkilda.integration.source.store.dto.InventoryFlow)1 InventorySwitch (org.openkilda.integration.source.store.dto.InventorySwitch)1 FlowBandwidth (org.openkilda.model.FlowBandwidth)1 FlowDiscrepancy (org.openkilda.model.FlowDiscrepancy)1 FlowInfo (org.openkilda.model.FlowInfo)1 FlowState (org.openkilda.model.FlowState)1 SwitchDiscrepancy (org.openkilda.model.SwitchDiscrepancy)1