Search in sources :

Example 26 with CommandContext

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

the class LoggerContextInitializerTest method shouldParseJsonAndExtractCorrelationId.

@Test
public void shouldParseJsonAndExtractCorrelationId() throws JsonProcessingException {
    // 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);
    ObjectMapper mapper = new ObjectMapper();
    when(tuple.getValueByField(eq("message"))).thenReturn(mapper.writeValueAsString(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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 27 with CommandContext

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

the class YFlowCreateServiceTest method processRequestAndSpeakerCommands.

private void processRequestAndSpeakerCommands(YFlowRequest yFlowRequest) throws DuplicateKeyException {
    YFlowCreateService service = makeYFlowCreateService(0);
    service.handleRequest(yFlowRequest.getYFlowId(), new CommandContext(), yFlowRequest);
    verifyYFlowAndSubFlowStatus(yFlowRequest.getYFlowId(), FlowStatus.IN_PROGRESS);
    handleSpeakerRequests(speakerRequest -> {
        SpeakerResponse commandResponse;
        if (speakerRequest instanceof FlowSegmentRequest) {
            FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) speakerRequest;
            commandResponse = buildSuccessfulSpeakerResponse(flowSegmentRequest);
        } else {
            BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
            commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
        }
        handleAsyncResponse(service, yFlowRequest.getYFlowId(), commandResponse);
    });
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) BaseSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)

Example 28 with CommandContext

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

the class YFlowCreateServiceTest method shouldFailOnUnsuccessfulValidation.

@Ignore("TODO: implement meter validation")
@Test
public void shouldFailOnUnsuccessfulValidation() throws RecoverableException, UnroutableFlowException, DuplicateKeyException {
    // given
    YFlowRequest request = buildYFlowRequest("test_failed_yflow", "test_flow_1", "test_flow_2").build();
    preparePathComputation("test_flow_1", buildFirstSubFlowPathPair());
    preparePathComputation("test_flow_2", buildSecondSubFlowPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_FIRST_EP, SWITCH_SECOND_EP, SWITCH_TRANSIT);
    YFlowCreateService service = makeYFlowCreateService(0);
    // when
    service.handleRequest(request.getYFlowId(), new CommandContext(), request);
    verifyYFlowAndSubFlowStatus(request.getYFlowId(), FlowStatus.IN_PROGRESS);
    // and
    handleSpeakerCommandsAndFailVerify(service, request.getYFlowId(), request.getYFlowId());
    // then
    verifyNoSpeakerInteraction(yFlowCreateHubCarrier);
    verifyYFlowIsAbsent(request.getYFlowId());
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Example 29 with CommandContext

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

the class YFlowCreateServiceTest method shouldFailOnTimeoutDuringMeterInstallation.

@Test
public void shouldFailOnTimeoutDuringMeterInstallation() throws RecoverableException, UnroutableFlowException, DuplicateKeyException {
    // given
    YFlowRequest request = buildYFlowRequest("test_failed_yflow", "test_flow_1", "test_flow_2").build();
    preparePathComputation("test_flow_1", buildFirstSubFlowPathPair());
    preparePathComputation("test_flow_2", buildSecondSubFlowPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_FIRST_EP, SWITCH_SECOND_EP, SWITCH_TRANSIT);
    YFlowCreateService service = makeYFlowCreateService(0);
    // when
    service.handleRequest(request.getYFlowId(), new CommandContext(), request);
    verifyYFlowAndSubFlowStatus(request.getYFlowId(), FlowStatus.IN_PROGRESS);
    // and
    handleSpeakerCommandsAndTimeoutInstall(service, request.getYFlowId());
    // then
    verifyYFlowIsAbsent(request.getYFlowId());
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Example 30 with CommandContext

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

the class YFlowUpdateServiceTest method processUpdateRequestAndSpeakerCommands.

private void processUpdateRequestAndSpeakerCommands(YFlowPartialUpdateRequest request) throws DuplicateKeyException {
    YFlowUpdateService service = makeYFlowUpdateService(0);
    service.handlePartialUpdateRequest(request.getYFlowId(), new CommandContext(), request);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.IN_PROGRESS);
    handleSpeakerRequests(speakerRequest -> {
        SpeakerResponse commandResponse;
        if (speakerRequest instanceof FlowSegmentRequest) {
            FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) speakerRequest;
            commandResponse = buildSuccessfulSpeakerResponse(flowSegmentRequest);
        } else {
            BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
            commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
        }
        handleAsyncResponse(service, request.getYFlowId(), commandResponse);
    });
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) SpeakerResponse(org.openkilda.floodlight.api.response.SpeakerResponse) BaseSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest)

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