use of org.openkilda.integration.source.store.dto.InventorySwitch in project open-kilda by telstra.
the class SwitchService method processInventorySwitch.
/**
* Process inventory switch.
*
* @param switches the switch.
*
* @param inventorySwitches the inventory switch.
*/
private void processInventorySwitch(final List<SwitchInfo> switches, final List<InventorySwitch> inventorySwitches) {
List<SwitchInfo> discrepancySwitch = new ArrayList<SwitchInfo>();
for (InventorySwitch inventorySwitch : inventorySwitches) {
int index = -1;
for (SwitchInfo switchInfo : switches) {
if (switchInfo.getSwitchId().equalsIgnoreCase((inventorySwitch.getSwitchId()))) {
index = switches.indexOf(switchInfo);
break;
}
}
if (index >= 0) {
SwitchInfo switchObj = switches.get(index);
appendInventoryInfo(switchObj, inventorySwitch);
SwitchDiscrepancy discrepancy = new SwitchDiscrepancy();
discrepancy.setControllerDiscrepancy(false);
if (!((switchObj.getState()).equalsIgnoreCase(inventorySwitch.getStatus()))) {
discrepancy.setStatus(true);
discrepancy.setInventoryDiscrepancy(true);
SwitchStatus switchState = new SwitchStatus();
switchState.setControllerStatus(switchObj.getState());
switchState.setInventoryStatus(inventorySwitch.getStatus());
discrepancy.setStatusValue(switchState);
switchObj.setDiscrepancy(discrepancy);
}
switchObj.setInventorySwitch(true);
} else {
SwitchInfo switchInfoObj = new SwitchInfo();
toSwitchInfo(switchInfoObj, inventorySwitch);
discrepancySwitch.add(switchInfoObj);
}
}
for (SwitchInfo switchInfo : switches) {
boolean flag = false;
for (InventorySwitch inventorySwitch : inventorySwitches) {
if (switchInfo.getSwitchId().equalsIgnoreCase((inventorySwitch.getSwitchId()))) {
flag = true;
break;
}
}
if (!flag) {
SwitchDiscrepancy discrepancy = new SwitchDiscrepancy();
discrepancy.setInventoryDiscrepancy(true);
discrepancy.setControllerDiscrepancy(false);
discrepancy.setStatus(true);
SwitchStatus switchState = new SwitchStatus();
switchState.setControllerStatus(switchInfo.getState());
switchState.setInventoryStatus(null);
discrepancy.setStatusValue(switchState);
switchInfo.setDiscrepancy(discrepancy);
}
switchInfo.setControllerSwitch(true);
}
switches.addAll(discrepancySwitch);
}
use of org.openkilda.integration.source.store.dto.InventorySwitch 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.source.store.dto.InventorySwitch 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;
}
Aggregations