use of org.openkilda.model.Switch 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.Switch in project open-kilda by telstra.
the class SwitchOperationsService method deleteSwitch.
/**
* Delete switch.
*
* @param switchId ID of switch to be deleted
* @param force if True all switch relationships will be deleted too.
* If False switch will be deleted only if it has no relations.
* @return True if switch was deleted, False otherwise
* @throws SwitchNotFoundException if switch is not found
*/
public boolean deleteSwitch(SwitchId switchId, boolean force) throws SwitchNotFoundException {
transactionManager.doInTransaction(() -> {
Switch sw = switchRepository.findById(switchId).orElseThrow(() -> new SwitchNotFoundException(switchId));
switchPropertiesRepository.findBySwitchId(sw.getSwitchId()).ifPresent(sp -> switchPropertiesRepository.remove(sp));
portPropertiesRepository.getAllBySwitchId(sw.getSwitchId()).forEach(portPropertiesRepository::remove);
if (force) {
// remove() removes switch along with all relationships.
switchRepository.remove(sw);
} else {
// removeIfNoDependant() is used to be sure that we wouldn't delete switch
// if it has even one relationship.
switchRepository.removeIfNoDependant(sw);
}
});
return !switchRepository.exists(switchId);
}
use of org.openkilda.model.Switch in project open-kilda by telstra.
the class SwitchOperationsService method getSwitch.
/**
* Get switch by switch id.
*
* @param switchId switch id.
*/
public GetSwitchResponse getSwitch(SwitchId switchId) throws SwitchNotFoundException {
Switch sw = switchRepository.findById(switchId).orElseThrow(() -> new SwitchNotFoundException(switchId));
switchRepository.detach(sw);
return new GetSwitchResponse(sw);
}
use of org.openkilda.model.Switch in project open-kilda by telstra.
the class LinkOperationsServiceTest method createSwitchIfNotExist.
private Switch createSwitchIfNotExist(SwitchId switchId) {
return switchRepository.findById(switchId).orElseGet(() -> {
Switch sw = Switch.builder().switchId(switchId).status(SwitchStatus.ACTIVE).build();
switchRepository.add(sw);
return sw;
});
}
use of org.openkilda.model.Switch in project open-kilda by telstra.
the class SwitchOperationsServiceTest method shouldValidateSupportedEncapsulationTypeWhenUpdatingSwitchProperties.
@Test(expected = IllegalSwitchPropertiesException.class)
public void shouldValidateSupportedEncapsulationTypeWhenUpdatingSwitchProperties() {
Switch sw = Switch.builder().switchId(TEST_SWITCH_ID).status(SwitchStatus.ACTIVE).build();
switchRepository.add(sw);
createSwitchProperties(sw, Collections.singleton(FlowEncapsulationType.TRANSIT_VLAN), false, false, false);
switchOperationsService.updateSwitchProperties(TEST_SWITCH_ID, new SwitchPropertiesDto());
}
Aggregations