Search in sources :

Example 1 with SwitchStatus

use of org.openkilda.model.SwitchStatus in project open-kilda by telstra.

the class NetworkHistoryService method loadNetworkHistory.

// -- private --
private Collection<HistoryFacts> loadNetworkHistory() {
    RepositoryFactory repositoryFactory = persistenceManager.getRepositoryFactory();
    SwitchRepository switchRepository = repositoryFactory.createSwitchRepository();
    HashMap<SwitchId, HistoryFacts> switchById = new HashMap<>();
    for (Switch switchEntry : switchRepository.findAll()) {
        SwitchId switchId = switchEntry.getSwitchId();
        SwitchStatus switchStatus = switchEntry.getStatus();
        switchById.put(switchId, new HistoryFacts(switchId, switchStatus));
    }
    IslRepository islRepository = repositoryFactory.createIslRepository();
    for (Isl islEntry : islRepository.findAll()) {
        HistoryFacts history = switchById.get(islEntry.getSrcSwitchId());
        if (history == null) {
            log.error("Orphaned ISL relation - {}-{} (read race condition?)", islEntry.getSrcSwitchId(), islEntry.getSrcPort());
            continue;
        }
        islRepository.detach(islEntry);
        history.addLink(islEntry);
    }
    return switchById.values();
}
Also used : IslRepository(org.openkilda.persistence.repositories.IslRepository) Isl(org.openkilda.model.Isl) Switch(org.openkilda.model.Switch) HashMap(java.util.HashMap) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) SwitchId(org.openkilda.model.SwitchId) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) HistoryFacts(org.openkilda.wfm.topology.network.model.facts.HistoryFacts) SwitchStatus(org.openkilda.model.SwitchStatus)

Example 2 with SwitchStatus

use of org.openkilda.model.SwitchStatus in project open-kilda by telstra.

the class SwitchService method toSwitchInfo.

private void toSwitchInfo(final SwitchInfo switchInfo, final InventorySwitch inventorySwitch) {
    switchInfo.setSwitchId(inventorySwitch.getSwitchId());
    switchInfo.setCommonName(inventorySwitch.getCommonName());
    switchInfo.setName(inventorySwitch.getSwitchId());
    switchInfo.setDescription(inventorySwitch.getDescription());
    switchInfo.setUuid(inventorySwitch.getUuid());
    switchInfo.setInventorySwitch(true);
    SwitchDiscrepancy discrepancy = new SwitchDiscrepancy();
    discrepancy.setControllerDiscrepancy(true);
    discrepancy.setStatus(true);
    SwitchStatus switchState = new SwitchStatus();
    switchState.setControllerStatus(null);
    switchState.setInventoryStatus(inventorySwitch.getStatus());
    discrepancy.setStatusValue(switchState);
    switchInfo.setDiscrepancy(discrepancy);
    appendInventoryInfo(switchInfo, inventorySwitch);
}
Also used : SwitchDiscrepancy(org.openkilda.model.SwitchDiscrepancy) SwitchStatus(org.openkilda.model.SwitchStatus)

Example 3 with SwitchStatus

use of org.openkilda.model.SwitchStatus 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);
}
Also used : ArrayList(java.util.ArrayList) InventorySwitch(org.openkilda.integration.source.store.dto.InventorySwitch) SwitchDiscrepancy(org.openkilda.model.SwitchDiscrepancy) SwitchInfo(org.openkilda.model.SwitchInfo) SwitchStatus(org.openkilda.model.SwitchStatus)

Example 4 with SwitchStatus

use of org.openkilda.model.SwitchStatus 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 5 with SwitchStatus

use of org.openkilda.model.SwitchStatus in project open-kilda by telstra.

the class SwitchService method processInventorySwitch.

private SwitchInfo processInventorySwitch(SwitchInfo switchInfo, final InventorySwitch inventorySwitch) {
    if (switchInfo == null) {
        switchInfo = new SwitchInfo();
        toSwitchInfo(switchInfo, inventorySwitch);
    } else {
        appendInventoryInfo(switchInfo, inventorySwitch);
        SwitchDiscrepancy discrepancy = new SwitchDiscrepancy();
        discrepancy.setControllerDiscrepancy(false);
        if (!((switchInfo.getState()).equalsIgnoreCase(inventorySwitch.getStatus()))) {
            discrepancy.setStatus(true);
            discrepancy.setInventoryDiscrepancy(true);
            SwitchStatus switchState = new SwitchStatus();
            switchState.setControllerStatus(switchInfo.getState());
            switchState.setInventoryStatus(inventorySwitch.getStatus());
            discrepancy.setStatusValue(switchState);
            switchInfo.setDiscrepancy(discrepancy);
        }
        switchInfo.setInventorySwitch(true);
    }
    return switchInfo;
}
Also used : SwitchDiscrepancy(org.openkilda.model.SwitchDiscrepancy) SwitchInfo(org.openkilda.model.SwitchInfo) SwitchStatus(org.openkilda.model.SwitchStatus)

Aggregations

SwitchStatus (org.openkilda.model.SwitchStatus)5 SwitchDiscrepancy (org.openkilda.model.SwitchDiscrepancy)4 SwitchInfo (org.openkilda.model.SwitchInfo)3 InventorySwitch (org.openkilda.integration.source.store.dto.InventorySwitch)2 AccessDeniedException (java.nio.file.AccessDeniedException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IntegrationException (org.openkilda.integration.exception.IntegrationException)1 InvalidResponseException (org.openkilda.integration.exception.InvalidResponseException)1 StoreIntegrationException (org.openkilda.integration.exception.StoreIntegrationException)1 Isl (org.openkilda.model.Isl)1 Switch (org.openkilda.model.Switch)1 SwitchId (org.openkilda.model.SwitchId)1 IslRepository (org.openkilda.persistence.repositories.IslRepository)1 RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)1 SwitchRepository (org.openkilda.persistence.repositories.SwitchRepository)1 HistoryFacts (org.openkilda.wfm.topology.network.model.facts.HistoryFacts)1 RequestValidationException (org.usermanagement.exception.RequestValidationException)1 UserInfo (org.usermanagement.model.UserInfo)1