use of org.openkilda.wfm.error.SwitchNotFoundException in project open-kilda by telstra.
the class CompleteYFlowValidationAction method performWithResponse.
@Override
public Optional<Message> performWithResponse(State from, State to, Event event, YFlowValidationContext context, YFlowValidationFsm stateMachine) throws FlowNotFoundException, SwitchNotFoundException {
YFlowDiscrepancyDto resourcesValidationResult = validationService.validateYFlowResources(stateMachine.getYFlowId(), stateMachine.getReceivedRules(), stateMachine.getReceivedMeters());
YFlowValidationResponse result = new YFlowValidationResponse();
result.setYFlowValidationResult(resourcesValidationResult);
result.setSubFlowValidationResults(stateMachine.getSubFlowValidationResults());
boolean notAsExpected = !resourcesValidationResult.isAsExpected() || stateMachine.getSubFlowValidationResults().stream().map(FlowValidationResponse::getAsExpected).anyMatch(n -> !n);
result.setAsExpected(!notAsExpected);
CommandContext commandContext = stateMachine.getCommandContext();
InfoMessage message = new InfoMessage(result, commandContext.getCreateTime(), commandContext.getCorrelationId());
return Optional.of(message);
}
use of org.openkilda.wfm.error.SwitchNotFoundException in project open-kilda by telstra.
the class SimpleSwitchRuleComparator method getRuleDiscrepancies.
private List<PathDiscrepancyEntity> getRuleDiscrepancies(SimpleSwitchRule expected, SimpleSwitchRule matched) throws SwitchNotFoundException {
List<PathDiscrepancyEntity> discrepancies = new ArrayList<>();
if (matched.getCookie() != expected.getCookie()) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "cookie", String.valueOf(expected.getCookie()), String.valueOf(matched.getCookie())));
}
if (matched.getInPort() != expected.getInPort()) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "inPort", String.valueOf(expected.getInPort()), String.valueOf(matched.getInPort())));
}
if (matched.getInVlan() != expected.getInVlan()) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "inVlan", String.valueOf(expected.getInVlan()), String.valueOf(matched.getInVlan())));
}
if (matched.getTunnelId() != expected.getTunnelId()) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "tunnelId", String.valueOf(expected.getTunnelId()), String.valueOf(matched.getTunnelId())));
}
if (matched.getOutPort() != expected.getOutPort()) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "outPort", String.valueOf(expected.getOutPort()), String.valueOf(matched.getOutPort())));
}
if (!Objects.equals(matched.getOutVlan(), expected.getOutVlan())) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "outVlan", String.valueOf(expected.getOutVlan()), String.valueOf(matched.getOutVlan())));
}
// meters on OF_12 switches are not supported, so skip them.
if ((matched.getVersion() == null || matched.getVersion().compareTo("OF_12") > 0) && !(matched.getMeterId() == null && expected.getMeterId() == null)) {
if (!Objects.equals(matched.getMeterId(), expected.getMeterId())) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "meterId", String.valueOf(expected.getMeterId()), String.valueOf(matched.getMeterId())));
} else {
Switch sw = switchRepository.findById(expected.getSwitchId()).orElseThrow(() -> new SwitchNotFoundException(expected.getSwitchId()));
boolean isESwitch = Switch.isNoviflowESwitch(sw.getOfDescriptionManufacturer(), sw.getOfDescriptionHardware());
if (!equalsRate(matched.getMeterRate(), expected.getMeterRate(), isESwitch)) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "meterRate", String.valueOf(expected.getMeterRate()), String.valueOf(matched.getMeterRate())));
}
if (!equalsBurstSize(matched.getMeterBurstSize(), expected.getMeterBurstSize(), isESwitch)) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "meterBurstSize", String.valueOf(expected.getMeterBurstSize()), String.valueOf(matched.getMeterBurstSize())));
}
if (!Arrays.equals(matched.getMeterFlags(), expected.getMeterFlags())) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "meterFlags", Arrays.toString(expected.getMeterFlags()), Arrays.toString(matched.getMeterFlags())));
}
}
}
if (matched.getGroupId() != expected.getGroupId()) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "groupId", String.valueOf(expected.getGroupId()), String.valueOf(matched.getGroupId())));
}
if (!Objects.equals(matched.getGroupBuckets(), expected.getGroupBuckets())) {
discrepancies.add(new PathDiscrepancyEntity(expected.toString(), "groupBuckets", String.valueOf(expected.getGroupBuckets()), String.valueOf(matched.getGroupBuckets())));
}
return discrepancies;
}
use of org.openkilda.wfm.error.SwitchNotFoundException in project open-kilda by telstra.
the class SwitchOperationsService method patchSwitch.
/**
* Patch switch.
*/
public Switch patchSwitch(SwitchId switchId, SwitchPatch data) throws SwitchNotFoundException {
return transactionManager.doInTransaction(() -> {
Switch foundSwitch = switchRepository.findById(switchId).orElseThrow(() -> new SwitchNotFoundException(switchId));
Optional.ofNullable(data.getPop()).ifPresent(pop -> foundSwitch.setPop(!"".equals(pop) ? pop : null));
Optional.ofNullable(data.getLocation()).ifPresent(location -> {
Optional.ofNullable(location.getLatitude()).ifPresent(foundSwitch::setLatitude);
Optional.ofNullable(location.getLongitude()).ifPresent(foundSwitch::setLongitude);
Optional.ofNullable(location.getStreet()).ifPresent(foundSwitch::setStreet);
Optional.ofNullable(location.getCity()).ifPresent(foundSwitch::setCity);
Optional.ofNullable(location.getCountry()).ifPresent(foundSwitch::setCountry);
});
switchRepository.detach(foundSwitch);
return foundSwitch;
});
}
use of org.openkilda.wfm.error.SwitchNotFoundException in project open-kilda by telstra.
the class SwitchOperationsBolt method updateSwitchUnderMaintenanceFlag.
private List<GetSwitchResponse> updateSwitchUnderMaintenanceFlag(UpdateSwitchUnderMaintenanceRequest request, Tuple tuple) {
SwitchId switchId = request.getSwitchId();
boolean underMaintenance = request.isUnderMaintenance();
boolean evacuate = request.isEvacuate();
Switch sw;
try {
sw = switchOperationsService.updateSwitchUnderMaintenanceFlag(switchId, underMaintenance);
} catch (SwitchNotFoundException e) {
throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "Switch was not found.");
}
if (underMaintenance && evacuate) {
Collection<FlowPath> paths = flowOperationsService.getFlowPathsForSwitch(switchId);
Set<IslEndpoint> affectedIslEndpoint = new HashSet<>(switchOperationsService.getSwitchIslEndpoints(switchId));
String reason = format("evacuated due to switch maintenance %s", switchId);
for (FlowRerouteRequest reroute : flowOperationsService.makeRerouteRequests(paths, affectedIslEndpoint, reason)) {
CommandContext forkedContext = getCommandContext().fork(reroute.getFlowId());
getOutput().emit(StreamType.REROUTE.toString(), tuple, new Values(reroute, forkedContext.getCorrelationId()));
}
}
return Collections.singletonList(new GetSwitchResponse(sw));
}
use of org.openkilda.wfm.error.SwitchNotFoundException in project open-kilda by telstra.
the class SwitchOperationsBolt method getSwitchConnectedDevices.
private SwitchConnectedDevicesResponse getSwitchConnectedDevices(GetSwitchConnectedDevicesRequest request) {
Collection<SwitchConnectedDevice> devices;
try {
devices = switchOperationsService.getSwitchConnectedDevices(request.getSwitchId());
} catch (SwitchNotFoundException e) {
throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "Could not get connected devices for non existent switch");
}
Map<Integer, List<SwitchConnectedDevice>> deviceByPort = devices.stream().filter(device -> request.getSince().isBefore(device.getTimeLastSeen()) || request.getSince().equals(device.getTimeLastSeen())).collect(Collectors.groupingBy(SwitchConnectedDevice::getPortNumber, Collectors.toList()));
List<SwitchPortConnectedDevicesDto> ports = new ArrayList<>();
for (Entry<Integer, List<SwitchConnectedDevice>> entry : deviceByPort.entrySet()) {
List<SwitchConnectedDeviceDto> lldpDevices = new ArrayList<>();
List<SwitchConnectedDeviceDto> arpDevices = new ArrayList<>();
for (SwitchConnectedDevice device : entry.getValue()) {
if (device.getType() == LLDP) {
lldpDevices.add(ConnectedDeviceMapper.INSTANCE.map(device));
} else if (device.getType() == ARP) {
arpDevices.add(ConnectedDeviceMapper.INSTANCE.map(device));
}
}
lldpDevices.sort(Comparator.comparing(o -> Instant.parse(o.getTimeLastSeen())));
arpDevices.sort(Comparator.comparing(o -> Instant.parse(o.getTimeLastSeen())));
ports.add(new SwitchPortConnectedDevicesDto(entry.getKey(), lldpDevices, arpDevices));
}
return new SwitchConnectedDevicesResponse(ports);
}
Aggregations