Search in sources :

Example 1 with IntegrationException

use of org.openkilda.integration.exception.IntegrationException 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)

Example 2 with IntegrationException

use of org.openkilda.integration.exception.IntegrationException in project open-kilda by telstra.

the class SwitchService method getSwitches.

/**
 * get All SwitchList.
 *
 * @return SwitchRelationData the switch info
 * @throws IntegrationException the integration exception
 */
public List<SwitchInfo> getSwitches(boolean storeConfigurationStatus, boolean controller) throws IntegrationException {
    List<SwitchInfo> switchInfo = switchIntegrationService.getSwitches();
    if (switchInfo == null) {
        switchInfo = new ArrayList<SwitchInfo>();
    }
    if (!controller) {
        try {
            UserInfo userInfo = userService.getLoggedInUserInfo();
            if (userInfo.getPermissions().contains(IConstants.Permission.SW_SWITCH_INVENTORY)) {
                if (storeConfigurationStatus && storeService.getSwitchStoreConfig().getUrls().size() > 0) {
                    List<InventorySwitch> inventorySwitches = new ArrayList<InventorySwitch>();
                    inventorySwitches = switchStoreService.getSwitches();
                    processInventorySwitch(switchInfo, inventorySwitches);
                }
            }
        } catch (Exception ex) {
            LOGGER.error("Error occurred while retrieving switches from store", ex);
        }
    }
    return switchInfo;
}
Also used : ArrayList(java.util.ArrayList) InventorySwitch(org.openkilda.integration.source.store.dto.InventorySwitch) UserInfo(org.usermanagement.model.UserInfo) SwitchInfo(org.openkilda.model.SwitchInfo) 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)

Example 3 with IntegrationException

use of org.openkilda.integration.exception.IntegrationException in project open-kilda by telstra.

the class StatsIntegrationService method getStats.

public String getStats(final String startDate, final String endDate, final String downsample, final String switchId, final String port, final String flowId, final String srcSwitch, final String srcPort, final String dstSwitch, final String dstPort, StatsType statsType, final String metric) throws IntegrationException {
    LOGGER.info("Inside getStats: switchId: " + switchId);
    try {
        String payload = getOpenTsdbRequestBody(startDate, endDate, downsample, switchId, port, flowId, srcSwitch, srcPort, dstSwitch, dstPort, statsType, metric);
        LOGGER.info("Inside getStats: CorrelationId: : startDate: " + startDate + ": endDate: " + endDate + ": payload: " + payload);
        HttpResponse response = restClientManager.invoke(applicationProperties.getOpenTsdbQuery(), HttpMethod.POST, payload, "application/json", "");
        if (RestClientManager.isValidResponse(response)) {
            return IoUtil.toString(response.getEntity().getContent());
        }
    } catch (IOException ex) {
        LOGGER.error("Inside getStats Exception is: " + ex.getMessage());
        throw new IntegrationException(ex);
    }
    return null;
}
Also used : IntegrationException(org.openkilda.integration.exception.IntegrationException) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Example 4 with IntegrationException

use of org.openkilda.integration.exception.IntegrationException in project open-kilda by telstra.

the class SwitchIntegrationService method getSwitchPorts.

/**
 * Gets the switch ports.
 *
 * @return the switch ports
 * @throws IntegrationException
 */
public List<PortInfo> getSwitchPorts(final String switchId) throws IntegrationException {
    try {
        HttpResponse response = restClientManager.invoke(applicationProperties.getSwitchPorts(), HttpMethod.GET, "", "", "");
        if (RestClientManager.isValidResponse(response)) {
            String responseEntity = IoUtil.toString(response.getEntity().getContent());
            JSONObject jsonObject = JsonUtil.toObject(responseEntity, JSONObject.class);
            return PortConverter.toPortsInfo(jsonObject, switchId);
        }
    } catch (IOException exception) {
        LOGGER.error("Exception in getSwitchPorts " + exception.getMessage(), exception);
        throw new IntegrationException(exception);
    }
    return null;
}
Also used : JSONObject(org.json.simple.JSONObject) IntegrationException(org.openkilda.integration.exception.IntegrationException) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException)

Example 5 with IntegrationException

use of org.openkilda.integration.exception.IntegrationException in project open-kilda by telstra.

the class StatsIntegrationService method getStats.

/**
 * Gets the stats.
 *
 * @param startDate the start date
 * @param endDate the end date
 * @param downsample the downsample
 * @param switchId the switch id
 * @param port the port
 * @param flowId the flow id
 * @param srcSwitch the src switch
 * @param srcPort the src port
 * @param dstSwitch the dst switch
 * @param dstPort the dst port
 * @param statsType the stats type
 * @param metric the metric
 * @param direction the direction
 * @return the stats
 * @throws IntegrationException the integration exception
 */
public String getStats(final String startDate, final String endDate, final String downsample, final List<String> switchId, final String port, final String flowId, final String srcSwitch, final String srcPort, final String dstSwitch, final String dstPort, final StatsType statsType, final String metric, final String direction) throws IntegrationException {
    LOGGER.info("Inside getStats: switchId: " + switchId);
    try {
        String payload = getOpenTsdbRequestBody(startDate, endDate, downsample, switchId, port, flowId, srcSwitch, srcPort, dstSwitch, dstPort, statsType, metric, direction);
        LOGGER.info("Inside getStats: startDate: " + startDate + ": endDate: " + endDate + ": payload: " + payload);
        HttpResponse response = restClientManager.invoke(applicationProperties.getOpenTsdbBaseUrl() + IConstants.OpenTsDbUrl.OPEN_TSDB_QUERY, HttpMethod.POST, payload, "application/json", "");
        if (RestClientManager.isValidResponse(response)) {
            return IoUtil.toString(response.getEntity().getContent());
        }
    } catch (InvalidResponseException e) {
        LOGGER.error("Error occurred while getting stats", e);
        throw new InvalidResponseException(e.getCode(), e.getResponse());
    } catch (IOException e) {
        LOGGER.warn("Error occurred while getting stats", e);
        throw new IntegrationException(e);
    }
    return null;
}
Also used : IntegrationException(org.openkilda.integration.exception.IntegrationException) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException)

Aggregations

IntegrationException (org.openkilda.integration.exception.IntegrationException)5 IOException (java.io.IOException)3 HttpResponse (org.apache.http.HttpResponse)3 InvalidResponseException (org.openkilda.integration.exception.InvalidResponseException)3 AccessDeniedException (java.nio.file.AccessDeniedException)2 StoreIntegrationException (org.openkilda.integration.exception.StoreIntegrationException)2 InventorySwitch (org.openkilda.integration.source.store.dto.InventorySwitch)2 SwitchInfo (org.openkilda.model.SwitchInfo)2 RequestValidationException (org.usermanagement.exception.RequestValidationException)2 UserInfo (org.usermanagement.model.UserInfo)2 ArrayList (java.util.ArrayList)1 JSONObject (org.json.simple.JSONObject)1 SwitchDiscrepancy (org.openkilda.model.SwitchDiscrepancy)1 SwitchStatus (org.openkilda.model.SwitchStatus)1