Search in sources :

Example 1 with SwitchConnect

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

the class SwitchOperationsService method getSwitchConnections.

/**
 * Find and return the set of connections to the speakers for specific switch.
 */
public SwitchConnectionsResponse getSwitchConnections(SwitchId switchId) throws SwitchNotFoundException {
    Switch sw = switchRepository.findById(switchId).orElseThrow(() -> new SwitchNotFoundException(switchId));
    SwitchAvailabilityData.SwitchAvailabilityDataBuilder payload = SwitchAvailabilityData.builder();
    for (SwitchConnect entry : switchConnectRepository.findBySwitchId(switchId)) {
        payload.connection(SwitchMapper.INSTANCE.map(entry));
    }
    return new SwitchConnectionsResponse(sw.getSwitchId(), sw.getStatus(), payload.build());
}
Also used : Switch(org.openkilda.model.Switch) SwitchAvailabilityData(org.openkilda.messaging.model.SwitchAvailabilityData) SwitchConnect(org.openkilda.model.SwitchConnect) SwitchConnectionsResponse(org.openkilda.messaging.nbtopology.response.SwitchConnectionsResponse) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException)

Example 2 with SwitchConnect

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

the class SwitchFsm method persistSwitchConnections.

private void persistSwitchConnections(Switch sw, SwitchAvailabilityData availabilityData) {
    List<SwitchAvailabilityEntry> goal;
    if (availabilityData != null) {
        goal = availabilityData.getConnections();
    } else {
        log.warn("Got \"null\" instead of {} availability data (treating it as an empty connections set)", switchId);
        goal = Collections.emptyList();
    }
    Map<ConnectReference, SwitchConnect> extra = new HashMap<>();
    for (SwitchConnect entry : switchConnectRepository.findBySwitchId(switchId)) {
        extra.put(new ConnectReference(entry), entry);
    }
    for (SwitchAvailabilityEntry entry : goal) {
        ConnectReference ref = new ConnectReference(entry);
        persistSingleSwitchConnect(sw, entry, extra.remove(ref));
    }
    for (SwitchConnect connect : extra.values()) {
        switchConnectRepository.remove(connect);
    }
}
Also used : HashMap(java.util.HashMap) SwitchConnect(org.openkilda.model.SwitchConnect) SwitchAvailabilityEntry(org.openkilda.messaging.model.SwitchAvailabilityEntry)

Example 3 with SwitchConnect

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

the class SwitchFsm method persistSingleSwitchConnect.

private void persistSingleSwitchConnect(Switch sw, SwitchAvailabilityEntry goal, SwitchConnect current) {
    SwitchConnect target = current;
    if (target == null) {
        target = SwitchConnect.builder(lookupSpeakerCreateIfMissing(goal.getRegionName()), sw).mode(goal.getConnectMode()).build();
    }
    target.setMaster(goal.isMaster());
    target.setConnectedAt(goal.getConnectedAt());
    target.setSwitchAddress(goal.getSwitchAddress());
    target.setSpeakerAddress(goal.getSpeakerAddress());
    if (current == null) {
        switchConnectRepository.add(target);
    }
}
Also used : SwitchConnect(org.openkilda.model.SwitchConnect)

Aggregations

SwitchConnect (org.openkilda.model.SwitchConnect)3 HashMap (java.util.HashMap)1 SwitchAvailabilityData (org.openkilda.messaging.model.SwitchAvailabilityData)1 SwitchAvailabilityEntry (org.openkilda.messaging.model.SwitchAvailabilityEntry)1 SwitchConnectionsResponse (org.openkilda.messaging.nbtopology.response.SwitchConnectionsResponse)1 Switch (org.openkilda.model.Switch)1 SwitchNotFoundException (org.openkilda.wfm.error.SwitchNotFoundException)1