Search in sources :

Example 16 with YSubFlow

use of org.openkilda.model.YSubFlow in project open-kilda by telstra.

the class ValidateYFlowAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, YFlowRerouteContext context, YFlowRerouteFsm stateMachine) {
    boolean isOperationAllowed = featureTogglesRepository.getOrDefault().getModifyYFlowEnabled();
    if (!isOperationAllowed) {
        throw new FlowProcessingException(ErrorType.NOT_PERMITTED, "Y-flow reroute feature is disabled");
    }
    YFlowRerouteRequest request = context.getRerouteRequest();
    String yFlowId = request.getYFlowId();
    Set<IslEndpoint> affectedIsls = new HashSet<>(Optional.ofNullable(request.getAffectedIsl()).orElse(emptySet()));
    dashboardLogger.onYFlowReroute(yFlowId, affectedIsls, request.isForce());
    stateMachine.setAffectedIsls(affectedIsls);
    stateMachine.setRerouteReason(request.getReason());
    stateMachine.setForceReroute(request.isForce());
    stateMachine.setIgnoreBandwidth(request.isIgnoreBandwidth());
    YFlow yFlow = transactionManager.doInTransaction(() -> {
        YFlow result = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
        if (result.getStatus() == FlowStatus.IN_PROGRESS) {
            throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Y-flow %s is in progress now", yFlowId));
        }
        // Keep it, just in case we have to revert it.
        stateMachine.setOriginalYFlowStatus(result.getStatus());
        result.setStatus(FlowStatus.IN_PROGRESS);
        return result;
    });
    Collection<Flow> subFlows = yFlow.getSubFlows().stream().map(YSubFlow::getFlow).collect(Collectors.toList());
    Flow mainAffinitySubFlow = subFlows.stream().filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).findFirst().orElseThrow(() -> new FlowProcessingException(ErrorType.DATA_INVALID, format("Main affinity sub-flow of the y-flow %s not found", yFlowId)));
    stateMachine.setMainAffinityFlowId(mainAffinitySubFlow.getFlowId());
    boolean mainAffinitySubFlowIsAffected = isFlowAffected(mainAffinitySubFlow, affectedIsls);
    Set<String> affectedFlowIds = subFlows.stream().filter(flow -> mainAffinitySubFlowIsAffected || isFlowAffected(flow, affectedIsls)).map(Flow::getFlowId).collect(Collectors.toSet());
    stateMachine.setTargetSubFlowIds(affectedFlowIds);
    stateMachine.saveNewEventToHistory("Y-flow was validated successfully", FlowEventData.Event.REROUTE);
    return Optional.empty();
}
Also used : YFlow(org.openkilda.model.YFlow) IslEndpoint(org.openkilda.model.IslEndpoint) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) YFlowRerouteRequest(org.openkilda.messaging.command.yflow.YFlowRerouteRequest) HashSet(java.util.HashSet) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 17 with YSubFlow

use of org.openkilda.model.YSubFlow in project open-kilda by telstra.

the class RerouteQueueService method isRetryRequired.

private boolean isRetryRequired(String flowId, RerouteError rerouteError, boolean isYFlow) {
    if (rerouteError instanceof NoPathFoundError) {
        log.info("Received no path found error for flow {}", flowId);
        return true;
    } else if (rerouteError instanceof RerouteInProgressError) {
        log.info("Received reroute in progress error for flow {}", flowId);
        return true;
    } else if (rerouteError instanceof SpeakerRequestError) {
        if (isYFlow) {
            log.info("Received speaker request error for y-flow {}", flowId);
            YFlow yFlow = yFlowRepository.findById(flowId).orElse(null);
            if (yFlow == null) {
                log.error("Y-flow {} not found", flowId);
                return false;
            }
            Set<SwitchId> yFlowSwitchIds = yFlow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
            yFlowSwitchIds.add(yFlow.getSharedEndpoint().getSwitchId());
            boolean isRetryRequired = true;
            SpeakerRequestError ruleFailedError = (SpeakerRequestError) rerouteError;
            for (SwitchId switchId : yFlowSwitchIds) {
                isRetryRequired &= !ruleFailedError.getSwitches().contains(switchId);
            }
            return isRetryRequired;
        } else {
            log.info("Received speaker request error for flow {}", flowId);
            Flow flow = flowRepository.findById(flowId).orElse(null);
            if (flow == null) {
                log.error("Flow {} not found", flowId);
                return false;
            }
            SpeakerRequestError ruleFailedError = (SpeakerRequestError) rerouteError;
            return !ruleFailedError.getSwitches().contains(flow.getSrcSwitchId()) && !ruleFailedError.getSwitches().contains(flow.getDestSwitchId());
        }
    }
    return false;
}
Also used : YFlow(org.openkilda.model.YFlow) NoPathFoundError(org.openkilda.messaging.info.reroute.error.NoPathFoundError) SwitchId(org.openkilda.model.SwitchId) SpeakerRequestError(org.openkilda.messaging.info.reroute.error.SpeakerRequestError) RerouteInProgressError(org.openkilda.messaging.info.reroute.error.RerouteInProgressError) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 18 with YSubFlow

use of org.openkilda.model.YSubFlow in project open-kilda by telstra.

the class AbstractYFlowTest method verifyAffinity.

protected void verifyAffinity(String yFlowId) {
    YFlow flow = getYFlow(yFlowId);
    Set<String> affinityGroups = flow.getSubFlows().stream().map(YSubFlow::getFlow).map(Flow::getAffinityGroupId).collect(Collectors.toSet());
    assertEquals(1, affinityGroups.size());
    String affinityGroupId = affinityGroups.iterator().next();
    Set<String> subFlowIds = flow.getSubFlows().stream().map(YSubFlow::getSubFlowId).collect(Collectors.toSet());
    assertTrue(subFlowIds.contains(affinityGroupId));
}
Also used : YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 19 with YSubFlow

use of org.openkilda.model.YSubFlow in project open-kilda by telstra.

the class TestYSubFlowBuilder method build.

/**
 * Build {@link YSubFlow} instance.
 */
public YSubFlow build() {
    checkArgument(endpoint != null, "YSubFlow endpoint must be defined");
    YSubFlow subFlow = YSubFlow.builder().yFlow(yFlow).flow(flow).sharedEndpointVlan(sharedEndpointVlan).sharedEndpointInnerVlan(sharedEndpointInnerVlan).endpointSwitchId(endpoint.getSwitchId()).endpointPort(endpoint.getPortNumber()).endpointVlan(endpoint.getOuterVlanId()).endpointInnerVlan(endpoint.getInnerVlanId()).build();
    subFlow.setTimeCreate(timeCreate);
    subFlow.setTimeModify(timeModify);
    return subFlow;
}
Also used : YSubFlow(org.openkilda.model.YSubFlow)

Example 20 with YSubFlow

use of org.openkilda.model.YSubFlow in project open-kilda by telstra.

the class UpdateFlowAction method getOrCreateDiverseFlowGroupId.

private String getOrCreateDiverseFlowGroupId(String diverseFlowId) throws FlowProcessingException {
    log.debug("Getting flow diverse group for flow with id {}", diverseFlowId);
    String flowId = yFlowRepository.findById(diverseFlowId).map(Stream::of).orElseGet(Stream::empty).map(YFlow::getSubFlows).flatMap(Collection::stream).map(YSubFlow::getFlow).filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).map(Flow::getFlowId).findFirst().orElse(diverseFlowId);
    return flowRepository.getOrCreateDiverseFlowGroupId(flowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow %s not found", flowId)));
}
Also used : YFlow(org.openkilda.model.YFlow) Message(org.openkilda.messaging.Message) HistoryMapper(org.openkilda.wfm.share.mappers.HistoryMapper) NbTrackableWithHistorySupportAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.NbTrackableWithHistorySupportAction) Flow(org.openkilda.model.Flow) EndpointUpdate(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.EndpointUpdate) Objects(org.apache.storm.shade.com.google.common.base.Objects) YFlow(org.openkilda.model.YFlow) DumpType(org.openkilda.wfm.share.history.model.FlowDumpData.DumpType) PersistenceManager(org.openkilda.persistence.PersistenceManager) DetectConnectedDevices(org.openkilda.model.DetectConnectedDevices) Switch(org.openkilda.model.Switch) YSubFlow(org.openkilda.model.YSubFlow) ErrorType(org.openkilda.messaging.error.ErrorType) FlowLoopOperation(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.FlowLoopOperation) Collection(java.util.Collection) FlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm) State(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.State) RequestedFlowMapper(org.openkilda.wfm.topology.flowhs.mapper.RequestedFlowMapper) String.format(java.lang.String.format) Event(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateFsm.Event) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) FlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.update.FlowUpdateContext) FlowDumpData(org.openkilda.wfm.share.history.model.FlowDumpData) Optional(java.util.Optional) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) Stream(java.util.stream.Stream) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow)

Aggregations

YSubFlow (org.openkilda.model.YSubFlow)26 YFlow (org.openkilda.model.YFlow)24 Flow (org.openkilda.model.Flow)18 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)11 SwitchId (org.openkilda.model.SwitchId)7 ArrayList (java.util.ArrayList)6 FlowEndpoint (org.openkilda.model.FlowEndpoint)6 FlowPath (org.openkilda.model.FlowPath)5 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 List (java.util.List)4 ErrorType (org.openkilda.messaging.error.ErrorType)4 PathSegment (org.openkilda.model.PathSegment)4 PersistenceManager (org.openkilda.persistence.PersistenceManager)4 CommandContext (org.openkilda.wfm.CommandContext)4 Collectors (java.util.stream.Collectors)3 Slf4j (lombok.extern.slf4j.Slf4j)3 SubFlowDto (org.openkilda.messaging.command.yflow.SubFlowDto)3 SubFlowSharedEndpointEncapsulation (org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation)3 String.format (java.lang.String.format)2