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