Search in sources :

Example 6 with SwitchNotFoundException

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);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) YFlowValidationFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm) CommandContext(org.openkilda.wfm.CommandContext) YFlowValidationContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationContext) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) Slf4j(lombok.extern.slf4j.Slf4j) NbTrackableAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.NbTrackableAction) YFlowDiscrepancyDto(org.openkilda.messaging.command.yflow.YFlowDiscrepancyDto) Event(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm.Event) Optional(java.util.Optional) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) YFlowValidationService(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationService) State(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm.State) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) CommandContext(org.openkilda.wfm.CommandContext) InfoMessage(org.openkilda.messaging.info.InfoMessage) YFlowDiscrepancyDto(org.openkilda.messaging.command.yflow.YFlowDiscrepancyDto) FlowValidationResponse(org.openkilda.messaging.info.flow.FlowValidationResponse) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse)

Example 7 with SwitchNotFoundException

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;
}
Also used : Switch(org.openkilda.model.Switch) PathDiscrepancyEntity(org.openkilda.messaging.info.flow.PathDiscrepancyEntity) ArrayList(java.util.ArrayList) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException)

Example 8 with SwitchNotFoundException

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;
    });
}
Also used : Switch(org.openkilda.model.Switch) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException)

Example 9 with SwitchNotFoundException

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));
}
Also used : IslEndpoint(org.openkilda.model.IslEndpoint) GetSwitchResponse(org.openkilda.messaging.nbtopology.response.GetSwitchResponse) CommandContext(org.openkilda.wfm.CommandContext) Values(org.apache.storm.tuple.Values) SwitchId(org.openkilda.model.SwitchId) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) Switch(org.openkilda.model.Switch) MessageException(org.openkilda.messaging.error.MessageException) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) FlowPath(org.openkilda.model.FlowPath) HashSet(java.util.HashSet)

Example 10 with SwitchNotFoundException

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);
}
Also used : OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) GetPortPropertiesRequest(org.openkilda.messaging.nbtopology.request.GetPortPropertiesRequest) KeyProvider(org.openkilda.wfm.share.utils.KeyProvider) FlowPath(org.openkilda.model.FlowPath) FlowOperationsService(org.openkilda.wfm.topology.nbworker.services.FlowOperationsService) DeactivateSwitchInfoData(org.openkilda.messaging.info.event.DeactivateSwitchInfoData) StreamType(org.openkilda.wfm.topology.nbworker.StreamType) SwitchLagPortResponse(org.openkilda.messaging.nbtopology.response.SwitchLagPortResponse) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) LLDP(org.openkilda.model.ConnectedDeviceType.LLDP) MessageException(org.openkilda.messaging.error.MessageException) GetSwitchesRequest(org.openkilda.messaging.nbtopology.request.GetSwitchesRequest) ILinkOperationsServiceCarrier(org.openkilda.wfm.topology.nbworker.services.ILinkOperationsServiceCarrier) Map(java.util.Map) SwitchPatchRequest(org.openkilda.messaging.nbtopology.request.SwitchPatchRequest) DeleteSwitchResponse(org.openkilda.messaging.nbtopology.response.DeleteSwitchResponse) LagPortMapper(org.openkilda.wfm.share.mappers.LagPortMapper) PortMapper(org.openkilda.wfm.share.mappers.PortMapper) GetSwitchRequest(org.openkilda.messaging.nbtopology.request.GetSwitchRequest) SwitchPropertiesDto(org.openkilda.messaging.model.SwitchPropertiesDto) IslEndpoint(org.openkilda.model.IslEndpoint) IllegalSwitchStateException(org.openkilda.wfm.error.IllegalSwitchStateException) ActivateFlowMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.flowrtt.ActivateFlowMonitoringOnSwitchInfoData) DeactivateIslMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.islrtt.DeactivateIslMonitoringOnSwitchInfoData) IllegalSwitchPropertiesException(org.openkilda.wfm.error.IllegalSwitchPropertiesException) GetSwitchResponse(org.openkilda.messaging.nbtopology.response.GetSwitchResponse) Collection(java.util.Collection) Set(java.util.Set) InfoData(org.openkilda.messaging.info.InfoData) CommandContext(org.openkilda.wfm.CommandContext) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) Fields(org.apache.storm.tuple.Fields) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) SwitchOperationsService(org.openkilda.wfm.topology.nbworker.services.SwitchOperationsService) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) List(java.util.List) PortProperties(org.openkilda.model.PortProperties) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution) PortPropertiesPayload(org.openkilda.messaging.payload.switches.PortPropertiesPayload) Entry(java.util.Map.Entry) UpdateSwitchPropertiesRequest(org.openkilda.messaging.nbtopology.request.UpdateSwitchPropertiesRequest) BaseRequest(org.openkilda.messaging.nbtopology.request.BaseRequest) GetSwitchConnectedDevicesRequest(org.openkilda.messaging.nbtopology.request.GetSwitchConnectedDevicesRequest) ActivateIslMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.islrtt.ActivateIslMonitoringOnSwitchInfoData) GetSwitchPropertiesRequest(org.openkilda.messaging.nbtopology.request.GetSwitchPropertiesRequest) SwitchPortConnectedDevicesDto(org.openkilda.messaging.nbtopology.response.SwitchPortConnectedDevicesDto) GetSwitchLagPortsRequest(org.openkilda.messaging.nbtopology.request.GetSwitchLagPortsRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwitchValidateRequest(org.openkilda.messaging.command.switches.SwitchValidateRequest) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) SwitchConnectionsResponse(org.openkilda.messaging.nbtopology.response.SwitchConnectionsResponse) SwitchConnectedDeviceDto(org.openkilda.messaging.nbtopology.response.SwitchConnectedDeviceDto) PersistenceManager(org.openkilda.persistence.PersistenceManager) DeactivateFlowMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.flowrtt.DeactivateFlowMonitoringOnSwitchInfoData) UpdateSwitchUnderMaintenanceRequest(org.openkilda.messaging.nbtopology.request.UpdateSwitchUnderMaintenanceRequest) Switch(org.openkilda.model.Switch) ConnectedDeviceMapper(org.openkilda.wfm.share.mappers.ConnectedDeviceMapper) ErrorType(org.openkilda.messaging.error.ErrorType) DeleteSwitchRequest(org.openkilda.messaging.nbtopology.request.DeleteSwitchRequest) Endpoint(org.openkilda.wfm.share.model.Endpoint) SwitchOperationsServiceCarrier(org.openkilda.wfm.topology.nbworker.services.SwitchOperationsServiceCarrier) ARP(org.openkilda.model.ConnectedDeviceType.ARP) SwitchPropertiesResponse(org.openkilda.messaging.nbtopology.response.SwitchPropertiesResponse) SwitchConnectionsRequest(org.openkilda.messaging.nbtopology.request.SwitchConnectionsRequest) GetAllSwitchPropertiesRequest(org.openkilda.messaging.nbtopology.request.GetAllSwitchPropertiesRequest) SwitchConnectedDevicesResponse(org.openkilda.messaging.nbtopology.response.SwitchConnectedDevicesResponse) SwitchId(org.openkilda.model.SwitchId) SwitchPropertiesNotFoundException(org.openkilda.wfm.error.SwitchPropertiesNotFoundException) Comparator(java.util.Comparator) Collections(java.util.Collections) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice) ArrayList(java.util.ArrayList) SwitchPortConnectedDevicesDto(org.openkilda.messaging.nbtopology.response.SwitchPortConnectedDevicesDto) SwitchConnectedDeviceDto(org.openkilda.messaging.nbtopology.response.SwitchConnectedDeviceDto) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) MessageException(org.openkilda.messaging.error.MessageException) List(java.util.List) ArrayList(java.util.ArrayList) SwitchConnectedDevice(org.openkilda.model.SwitchConnectedDevice) SwitchConnectedDevicesResponse(org.openkilda.messaging.nbtopology.response.SwitchConnectedDevicesResponse)

Aggregations

SwitchNotFoundException (org.openkilda.wfm.error.SwitchNotFoundException)12 Switch (org.openkilda.model.Switch)7 SwitchId (org.openkilda.model.SwitchId)6 MessageException (org.openkilda.messaging.error.MessageException)4 CommandContext (org.openkilda.wfm.CommandContext)4 List (java.util.List)3 Values (org.apache.storm.tuple.Values)3 GetSwitchResponse (org.openkilda.messaging.nbtopology.response.GetSwitchResponse)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Message (org.openkilda.messaging.Message)2 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)2 InfoData (org.openkilda.messaging.info.InfoData)2 DeactivateSwitchInfoData (org.openkilda.messaging.info.event.DeactivateSwitchInfoData)2 FlowPath (org.openkilda.model.FlowPath)2 IslEndpoint (org.openkilda.model.IslEndpoint)2 SwitchPropertiesNotFoundException (org.openkilda.wfm.error.SwitchPropertiesNotFoundException)2