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