use of org.openkilda.wfm.error.SwitchPropertiesNotFoundException in project open-kilda by telstra.
the class SwitchOperationsService method updateSwitchProperties.
/**
* Update switch properties.
*
* @param switchId target switch id
* @param switchPropertiesDto switch properties
* @throws IllegalSwitchPropertiesException if switch properties are incorrect
* @throws SwitchPropertiesNotFoundException if switch properties is not found by switch id
*/
public SwitchPropertiesDto updateSwitchProperties(SwitchId switchId, SwitchPropertiesDto switchPropertiesDto) {
if (isEmpty(switchPropertiesDto.getSupportedTransitEncapsulation())) {
throw new IllegalSwitchPropertiesException("Supported transit encapsulations should not be null or empty");
}
SwitchProperties update = SwitchPropertiesMapper.INSTANCE.map(switchPropertiesDto);
UpdateSwitchPropertiesResult result = transactionManager.doInTransaction(() -> {
SwitchProperties switchProperties = switchPropertiesRepository.findBySwitchId(switchId).orElseThrow(() -> new SwitchPropertiesNotFoundException(switchId));
final SwitchProperties oldProperties = new SwitchProperties(switchProperties);
validateSwitchProperties(switchId, update);
// must be called before updating of switchProperties object
final boolean isSwitchSyncNeeded = isSwitchSyncNeeded(switchProperties, update);
switchProperties.setMultiTable(update.isMultiTable());
switchProperties.setSwitchLldp(update.isSwitchLldp());
switchProperties.setSwitchArp(update.isSwitchArp());
switchProperties.setSupportedTransitEncapsulation(update.getSupportedTransitEncapsulation());
switchProperties.setServer42FlowRtt(update.isServer42FlowRtt());
switchProperties.setServer42IslRtt(update.getServer42IslRtt());
switchProperties.setServer42Port(update.getServer42Port());
switchProperties.setServer42Vlan(update.getServer42Vlan());
switchProperties.setServer42MacAddress(update.getServer42MacAddress());
log.info("Updating {} switch properties from {} to {}. Is switch sync needed: {}", switchId, oldProperties, switchProperties, isSwitchSyncNeeded);
return new UpdateSwitchPropertiesResult(SwitchPropertiesMapper.INSTANCE.map(switchProperties), isSwitchSyncNeeded);
});
if (result.isSwitchSyncRequired()) {
carrier.requestSwitchSync(switchId);
}
if (switchPropertiesDto.isServer42FlowRtt()) {
carrier.enableServer42FlowRttOnSwitch(switchId);
} else {
carrier.disableServer42FlowRttOnSwitch(switchId);
}
if (switchPropertiesDto.getServer42IslRtt() != SwitchPropertiesDto.RttState.DISABLED) {
carrier.enableServer42IslRttOnSwitch(switchId);
} else {
carrier.disableServer42IslRttOnSwitch(switchId);
}
return result.switchPropertiesDto;
}
use of org.openkilda.wfm.error.SwitchPropertiesNotFoundException in project open-kilda by telstra.
the class PathsService method getPaths.
/**
* Get paths.
*/
public List<PathsInfoData> getPaths(SwitchId srcSwitchId, SwitchId dstSwitchId, FlowEncapsulationType requestEncapsulationType, PathComputationStrategy requestPathComputationStrategy, Duration maxLatency, Duration maxLatencyTier2) throws RecoverableException, SwitchNotFoundException, UnroutableFlowException {
if (Objects.equals(srcSwitchId, dstSwitchId)) {
throw new IllegalArgumentException(String.format("Source and destination switch IDs are equal: '%s'", srcSwitchId));
}
if (!switchRepository.exists(srcSwitchId)) {
throw new SwitchNotFoundException(srcSwitchId);
}
if (!switchRepository.exists(dstSwitchId)) {
throw new SwitchNotFoundException(dstSwitchId);
}
KildaConfiguration kildaConfiguration = kildaConfigurationRepository.getOrDefault();
FlowEncapsulationType flowEncapsulationType = Optional.ofNullable(requestEncapsulationType).orElse(kildaConfiguration.getFlowEncapsulationType());
SwitchProperties srcProperties = switchPropertiesRepository.findBySwitchId(srcSwitchId).orElseThrow(() -> new SwitchPropertiesNotFoundException(srcSwitchId));
if (!srcProperties.getSupportedTransitEncapsulation().contains(flowEncapsulationType)) {
throw new IllegalArgumentException(String.format("Switch %s doesn't support %s encapslation type. Choose " + "one of the supported encapsulation types %s or update switch properties and add needed " + "encapsulation type.", srcSwitchId, flowEncapsulationType, srcProperties.getSupportedTransitEncapsulation()));
}
SwitchProperties dstProperties = switchPropertiesRepository.findBySwitchId(dstSwitchId).orElseThrow(() -> new SwitchPropertiesNotFoundException(dstSwitchId));
if (!dstProperties.getSupportedTransitEncapsulation().contains(flowEncapsulationType)) {
throw new IllegalArgumentException(String.format("Switch %s doesn't support %s encapslation type. Choose " + "one of the supported encapsulation types %s or update switch properties and add needed " + "encapsulation type.", dstSwitchId, requestEncapsulationType, dstProperties.getSupportedTransitEncapsulation()));
}
PathComputationStrategy pathComputationStrategy = Optional.ofNullable(requestPathComputationStrategy).orElse(kildaConfiguration.getPathComputationStrategy());
List<Path> flowPaths = pathComputer.getNPaths(srcSwitchId, dstSwitchId, MAX_PATH_COUNT, flowEncapsulationType, pathComputationStrategy, maxLatency, maxLatencyTier2);
return flowPaths.stream().map(PathMapper.INSTANCE::map).map(path -> PathsInfoData.builder().path(path).build()).collect(Collectors.toList());
}
Aggregations