use of org.openkilda.topology.domain.Switch in project open-kilda by telstra.
the class IslServiceImpl method discoverLink.
/**
* {@inheritDoc}
*/
@Override
public void discoverLink(final IslInfoData data) {
logger.debug("Isl discover: isl={}", data);
PathNode sourceNode = data.getPath().get(0);
PathNode destinationNode = data.getPath().get(1);
Isl isl = islRepository.findIsl(sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo());
logger.debug("Isl relationship found: {}", isl);
if (isl == null) {
Switch sourceSwitch = switchRepository.findByName(sourceNode.getSwitchId());
Switch destinationSwitch = switchRepository.findByName(destinationNode.getSwitchId());
if (sourceSwitch == null || destinationSwitch == null) {
logger.error("Could not find switch: source={}, destination={}", sourceSwitch, destinationSwitch);
return;
}
isl = new Isl(sourceSwitch, destinationSwitch, sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo(), data.getLatency(), data.getSpeed(), 0L);
// TODO: replace queries on Spring auto generated
// islRepository.save(isl);
logger.debug("Isl relationship create: isl={}", isl);
islRepository.creteIsl(sourceSwitch.getName(), destinationSwitch.getName(), sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo(), data.getLatency(), data.getSpeed(), 0L);
} else {
islRepository.updateLatency(sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo(), data.getLatency());
logger.debug("Isl relationship update: latency={}", data.getLatency());
}
}
use of org.openkilda.topology.domain.Switch in project open-kilda by telstra.
the class IslServiceImpl method dropLink.
/**
* {@inheritDoc}
*/
@Override
public void dropLink(final IslInfoData data) {
logger.debug("Isl drop: isl={}", data);
PathNode sourceNode = data.getPath().get(0);
PathNode destinationNode = data.getPath().get(1);
Switch sourceSwitch = switchRepository.findByName(sourceNode.getSwitchId());
Switch destinationSwitch = switchRepository.findByName(destinationNode.getSwitchId());
if (sourceSwitch == null || destinationSwitch == null) {
logger.error("Could not find switch: source={}, destination={}", sourceSwitch, destinationSwitch);
return;
}
Isl isl = islRepository.findIsl(sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo());
logger.debug("Isl relationship found: {}", isl);
if (isl == null) {
throw new MessageException(ErrorType.NOT_FOUND, System.currentTimeMillis());
}
// TODO: replace queries on Spring auto generated
// islRepository.delete(isl);
islRepository.deleteIsl(sourceNode.getSwitchId(), sourceNode.getPortNo(), destinationNode.getSwitchId(), destinationNode.getPortNo());
logger.debug("Isl delete relationship: isl={}", isl);
}
use of org.openkilda.topology.domain.Switch in project open-kilda by telstra.
the class SwitchServiceImpl method add.
/**
* {@inheritDoc}
*/
@Override
public Switch add(final SwitchInfoData data) {
String name = data.getSwitchId();
String state = SwitchStateType.INACTIVE.toString().toLowerCase();
logger.debug("Switch adding: switch-id={}", name);
Switch sw = switchRepository.findByName(name);
if (sw != null) {
throw new MessageException(ErrorType.ALREADY_EXISTS, System.currentTimeMillis());
}
sw = new Switch(name, state, data.getAddress(), data.getHostname(), data.getDescription());
sw.setLabels(state, data.getDescription());
switchRepository.save(sw);
return sw;
}
use of org.openkilda.topology.domain.Switch in project open-kilda by telstra.
the class SwitchServiceImpl method remove.
/**
* {@inheritDoc}
*/
@Override
public Switch remove(final SwitchInfoData data) {
String name = data.getSwitchId();
logger.debug("Switch removing: switch-id={}", name);
Switch sw = switchRepository.findByName(name);
if (sw == null) {
throw new MessageException(ErrorType.NOT_FOUND, System.currentTimeMillis());
}
switchRepository.delete(sw);
return sw;
}
use of org.openkilda.topology.domain.Switch in project open-kilda by telstra.
the class SwitchServiceImplTest method add.
@Test
@Transactional
public void add() throws Exception {
SwitchInfoData data = new SwitchInfoData(switchId, SwitchEventType.ADDED, address, name, description);
Switch sw = switchService.add(data);
assertEquals(sw.getName(), switchId);
assertEquals(sw.getState(), SwitchStateType.INACTIVE.toString().toLowerCase());
}
Aggregations