Search in sources :

Example 91 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class YFlowUpdateServiceTest method shouldFailOnUnsuccessfulMeterInstallation.

@Test
public void shouldFailOnUnsuccessfulMeterInstallation() throws RecoverableException, UnroutableFlowException, DuplicateKeyException {
    // given
    YFlowRequest request = createYFlow();
    request.setMaximumBandwidth(2000L);
    request.getSubFlows().get(0).setEndpoint(newFirstEndpoint);
    request.getSubFlows().get(1).setEndpoint(newSecondEndpoint);
    preparePathComputationForUpdate("test_flow_1", buildNewFirstSubFlowPathPair(), buildFirstSubFlowPathPair());
    preparePathComputationForUpdate("test_flow_2", buildNewSecondSubFlowPathPair(), buildSecondSubFlowPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP, SWITCH_TRANSIT);
    YFlowUpdateService service = makeYFlowUpdateService(0);
    // when
    service.handleRequest(request.getYFlowId(), new CommandContext(), request);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.IN_PROGRESS, FlowStatus.IN_PROGRESS, FlowStatus.UP);
    // and
    handleSpeakerCommandsAndFailInstall(service, request.getYFlowId(), "test_successful_yflow");
    // then
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.UP);
    YFlow flow = getYFlow(request.getYFlowId());
    assertEquals(1000L, flow.getMaximumBandwidth());
    Set<SwitchId> expectedEndpointSwitchIds = Stream.of(SWITCH_FIRST_EP, SWITCH_SECOND_EP).collect(Collectors.toSet());
    Set<SwitchId> actualEndpointSwitchIds = flow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
    assertEquals(expectedEndpointSwitchIds, actualEndpointSwitchIds);
}
Also used : YFlow(org.openkilda.model.YFlow) CommandContext(org.openkilda.wfm.CommandContext) SwitchId(org.openkilda.model.SwitchId) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Example 92 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class LoggerContextInitializerTest method shouldParseMessageAndExtractCorrelationId.

@Test
public void shouldParseMessageAndExtractCorrelationId() {
    // given
    Tuple tuple = mock(Tuple.class);
    when(tuple.getFields()).thenReturn(new Fields("message"));
    String correlationId = String.format("test-%s", UUID.randomUUID());
    InfoMessage message = new InfoMessage(new FlowsResponse(Collections.emptyList()), System.currentTimeMillis(), correlationId);
    when(tuple.getValueByField(eq("message"))).thenReturn(message);
    // when
    Optional<CommandContext> result = LoggerContextInitializer.extract(tuple);
    // then
    assertEquals(correlationId, result.get().getCorrelationId());
}
Also used : Fields(org.apache.storm.tuple.Fields) CommandContext(org.openkilda.wfm.CommandContext) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowsResponse(org.openkilda.messaging.info.flow.FlowsResponse) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Example 93 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class UpdateFlowPathsAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
    Flow f = transactionManager.doInTransaction(() -> {
        String flowId = stateMachine.getFlowId();
        Flow flow = getFlow(flowId);
        log.debug("Swapping primary and protected paths for flow {}", flowId);
        FlowPath oldPrimaryForward = flow.getForwardPath();
        FlowPath oldPrimaryReverse = flow.getReversePath();
        FlowPath newPrimaryForward = flow.getProtectedForwardPath();
        FlowPath newPrimaryReverse = flow.getProtectedReversePath();
        setMirrorPointsToNewPath(oldPrimaryForward.getPathId(), newPrimaryForward.getPathId());
        setMirrorPointsToNewPath(oldPrimaryReverse.getPathId(), newPrimaryReverse.getPathId());
        flow.setForwardPath(newPrimaryForward);
        flow.setReversePath(newPrimaryReverse);
        flow.setProtectedForwardPath(oldPrimaryForward);
        flow.setProtectedReversePath(oldPrimaryReverse);
        return flow;
    });
    stateMachine.setNewPrimaryForwardPath(f.getForwardPathId());
    stateMachine.setNewPrimaryReversePath(f.getReversePathId());
    stateMachine.setNewProtectedForwardPath(f.getProtectedForwardPathId());
    stateMachine.setNewProtectedReversePath(f.getProtectedReversePathId());
    stateMachine.saveActionToHistory("The flow paths were updated");
    CommandContext commandContext = stateMachine.getCommandContext();
    return Optional.of(buildResponseMessage(f, commandContext));
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

Example 94 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class OnFinishedAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowSwapEndpointsContext context, FlowSwapEndpointsFsm stateMachine) {
    log.info("Swap endpoints operation completed successfully.");
    updateFlowsStatuses(stateMachine);
    stateMachine.saveFlowActionToHistory(stateMachine.getFirstFlowId(), format("Swap endpoints with flow %s was successful", stateMachine.getSecondFlowId()));
    stateMachine.saveFlowActionToHistory(stateMachine.getSecondFlowId(), format("Swap endpoints with flow %s was successful", stateMachine.getFirstFlowId()));
    List<FlowResponse> flowResponses = stateMachine.getFlowResponses();
    SwapFlowResponse response = stateMachine.getFirstFlowId().equals(flowResponses.get(0).getPayload().getFlowId()) ? new SwapFlowResponse(flowResponses.get(0), flowResponses.get(1)) : new SwapFlowResponse(flowResponses.get(1), flowResponses.get(0));
    CommandContext commandContext = stateMachine.getCommandContext();
    return Optional.of(new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId()));
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowResponse(org.openkilda.messaging.info.flow.FlowResponse) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse) SwapFlowResponse(org.openkilda.messaging.info.flow.SwapFlowResponse)

Example 95 with CommandContext

use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.

the class PostResourceAllocationAction method performWithResponse.

@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
    Flow flow = getFlow(stateMachine.getFlowId());
    PathId flowMirrorPathId = stateMachine.getMirrorPathId();
    FlowMirrorPath flowMirrorPath = flowMirrorPathRepository.findById(flowMirrorPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror path %s not found", flowMirrorPathId)));
    String direction = flowMirrorPath.getFlowMirrorPoints().getFlowPath().isForward() ? "forward" : "reverse";
    FlowMirrorPointResponse response = FlowMirrorPointResponse.builder().flowId(flow.getFlowId()).mirrorPointId(flowMirrorPath.getPathId().getId()).mirrorPointDirection(direction).mirrorPointSwitchId(flowMirrorPath.getMirrorSwitchId()).sinkEndpoint(FlowEndpoint.builder().switchId(flowMirrorPath.getEgressSwitchId()).portNumber(flowMirrorPath.getEgressPort()).outerVlanId(flowMirrorPath.getEgressOuterVlan()).innerVlanId(flowMirrorPath.getEgressInnerVlan()).build()).build();
    CommandContext commandContext = stateMachine.getCommandContext();
    return Optional.of(new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId()));
}
Also used : PathId(org.openkilda.model.PathId) FlowMirrorPointResponse(org.openkilda.messaging.info.flow.FlowMirrorPointResponse) CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Flow(org.openkilda.model.Flow)

Aggregations

CommandContext (org.openkilda.wfm.CommandContext)95 Test (org.junit.Test)28 Values (org.apache.storm.tuple.Values)27 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)15 Flow (org.openkilda.model.Flow)15 AbstractYFlowTest (org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)14 Tuple (org.apache.storm.tuple.Tuple)12 SwitchId (org.openkilda.model.SwitchId)11 YFlow (org.openkilda.model.YFlow)11 BaseSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)9 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)9 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)9 InfoMessage (org.openkilda.messaging.info.InfoMessage)9 TupleImpl (org.apache.storm.tuple.TupleImpl)8 FlowPath (org.openkilda.model.FlowPath)8 ArrayList (java.util.ArrayList)7 FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)7 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)7 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)7 List (java.util.List)6