Search in sources :

Example 56 with YFlow

use of org.openkilda.model.YFlow 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)

Example 57 with YFlow

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

the class InstallYFlowResourcesAction method perform.

@Override
protected void perform(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
    stateMachine.clearPendingAndRetriedAndFailedCommands();
    String yFlowId = stateMachine.getYFlowId();
    YFlow yFlow = getYFlow(yFlowId);
    Collection<InstallSpeakerCommandsRequest> commands = buildYFlowInstallCommands(yFlow, stateMachine.getCommandContext());
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to install y-flow meters");
        stateMachine.fire(Event.ALL_YFLOW_METERS_INSTALLED);
    } else {
        // emitting
        commands.forEach(command -> {
            stateMachine.getCarrier().sendSpeakerRequest(command);
            stateMachine.addInstallSpeakerCommand(command.getCommandId(), command);
            stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
        });
        stateMachine.saveActionToHistory("Commands for installing y-flow rules have been sent");
    }
}
Also used : YFlow(org.openkilda.model.YFlow) InstallSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest)

Example 58 with YFlow

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

the class OnSubFlowAllocatedAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
    String subFlowId = context.getSubFlowId();
    if (!stateMachine.isCreatingSubFlow(subFlowId)) {
        throw new IllegalStateException("Received an event for non-pending sub-flow " + subFlowId);
    }
    String yFlowId = stateMachine.getYFlowId();
    stateMachine.saveActionToHistory("Creating a sub-flow", format("Allocated resources for sub-flow %s of y-flow %s", subFlowId, yFlowId));
    stateMachine.addAllocatedSubFlow(subFlowId);
    SubFlowDto subFlowDto = stateMachine.getTargetFlow().getSubFlows().stream().filter(f -> f.getFlowId().equals(subFlowId)).findAny().orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Can't find definition of created sub-flow %s", subFlowId)));
    SubFlowSharedEndpointEncapsulation sharedEndpoint = subFlowDto.getSharedEndpoint();
    FlowEndpoint endpoint = subFlowDto.getEndpoint();
    log.debug("Start creating sub-flow references from {} to y-flow {}", subFlowId, stateMachine.getYFlowId());
    YFlow result = transactionManager.doInTransaction(() -> {
        YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Y-flow %s not found", yFlowId)));
        Flow flow = flowRepository.findById(subFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Flow %s not found", subFlowId)));
        YSubFlow subFlow = YSubFlow.builder().yFlow(yFlow).flow(flow).sharedEndpointVlan(sharedEndpoint.getVlanId()).sharedEndpointInnerVlan(sharedEndpoint.getInnerVlanId()).endpointSwitchId(endpoint.getSwitchId()).endpointPort(endpoint.getPortNumber()).endpointVlan(endpoint.getOuterVlanId()).endpointInnerVlan(endpoint.getInnerVlanId()).build();
        yFlow.addSubFlow(subFlow);
        return yFlow;
    });
    if (subFlowId.equals(stateMachine.getMainAffinityFlowId())) {
        stateMachine.getRequestedFlows().forEach(requestedFlow -> {
            String requestedFlowId = requestedFlow.getFlowId();
            if (!requestedFlowId.equals(subFlowId)) {
                stateMachine.addSubFlow(requestedFlowId);
                stateMachine.addCreatingSubFlow(requestedFlowId);
                stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, requestedFlowId));
                CommandContext flowContext = stateMachine.getCommandContext().fork(requestedFlowId);
                requestedFlow.setAffinityFlowId(stateMachine.getMainAffinityFlowId());
                flowCreateService.startFlowCreation(flowContext, requestedFlow, yFlowId);
            }
        });
    }
    if (stateMachine.getAllocatedSubFlows().size() == stateMachine.getSubFlows().size()) {
        return Optional.of(buildResponseMessage(result, stateMachine.getCommandContext()));
    } else {
        return Optional.empty();
    }
}
Also used : YFlow(org.openkilda.model.YFlow) FlowEndpoint(org.openkilda.model.FlowEndpoint) CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) SubFlowSharedEndpointEncapsulation(org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation) SubFlowDto(org.openkilda.messaging.command.yflow.SubFlowDto) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 59 with YFlow

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

the class OnSubFlowAllocatedAction method convertToYFlowDto.

private YFlowDto convertToYFlowDto(YFlow yFlow) {
    Flow mainAffinityFlow = yFlow.getSubFlows().stream().map(YSubFlow::getFlow).filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).findFirst().orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, "Main affinity flow not found"));
    Collection<Flow> diverseWithFlow = getDiverseWithFlow(mainAffinityFlow);
    Set<String> diverseFlows = diverseWithFlow.stream().filter(flow -> flow.getYFlowId() == null).map(Flow::getFlowId).collect(Collectors.toSet());
    Set<String> diverseYFlows = diverseWithFlow.stream().map(Flow::getYFlowId).filter(Objects::nonNull).collect(Collectors.toSet());
    return YFlowMapper.INSTANCE.toYFlowDto(yFlow, diverseFlows, diverseYFlows);
}
Also used : FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 60 with YFlow

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

the class CompleteYFlowInstallationAction method perform.

@Override
protected void perform(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
    String yFlowId = stateMachine.getYFlowId();
    FlowStatus flowStatus = transactionManager.doInTransaction(() -> {
        YFlow yFlow = getYFlow(yFlowId);
        yFlow.recalculateStatus();
        return yFlow.getStatus();
    });
    dashboardLogger.onYFlowStatusUpdate(yFlowId, flowStatus);
    stateMachine.saveActionToHistory(format("The y-flow status was set to %s", flowStatus));
}
Also used : YFlow(org.openkilda.model.YFlow) FlowStatus(org.openkilda.model.FlowStatus)

Aggregations

YFlow (org.openkilda.model.YFlow)74 Flow (org.openkilda.model.Flow)30 SwitchId (org.openkilda.model.SwitchId)29 YSubFlow (org.openkilda.model.YSubFlow)26 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)19 Test (org.junit.Test)12 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)12 ArrayList (java.util.ArrayList)11 FlowStatus (org.openkilda.model.FlowStatus)10 CommandContext (org.openkilda.wfm.CommandContext)10 AbstractYFlowTest (org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)10 FlowPath (org.openkilda.model.FlowPath)9 FlowEndpoint (org.openkilda.model.FlowEndpoint)8 InstallSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest)6 Switch (org.openkilda.model.Switch)6 HashSet (java.util.HashSet)5 DeleteSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)5 SharedEndpoint (org.openkilda.model.YFlow.SharedEndpoint)5 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4