Search in sources :

Example 56 with CommandContext

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

the class FlowRerouteQueueBolt method sendRerouteRequest.

@Override
public void sendRerouteRequest(String correlationId, FlowRerouteRequest request) {
    log.info("Send reroute request {} with correlationId {}", request, correlationId);
    // emit without anchor to prevent a possible loop
    emit(STREAM_OPERATION_QUEUE_ID, new Values(request.getFlowId(), request, new CommandContext(correlationId)));
    registerCallback(correlationId);
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) Values(org.apache.storm.tuple.Values)

Example 57 with CommandContext

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

the class RerouteBolt method emitRerouteCommand.

/**
 * Emit reroute command for consumer.
 *
 * @param flowId flow id
 * @param flowThrottlingData flow throttling data
 */
@Override
public void emitRerouteCommand(String flowId, FlowThrottlingData flowThrottlingData) {
    String newCorrelationId = new CommandContext(flowThrottlingData.getCorrelationId()).fork(flowId).getCorrelationId();
    flowThrottlingData.setCorrelationId(newCorrelationId);
    emitWithContext(STREAM_REROUTE_REQUEST_ID, getCurrentTuple(), new Values(flowId, flowThrottlingData));
    log.warn("Flow {} reroute command message sent with correlationId {}, reason \"{}\"", flowId, flowThrottlingData.getCorrelationId(), flowThrottlingData.getReason());
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) Values(org.apache.storm.tuple.Values)

Example 58 with CommandContext

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

the class TimeWindowBolt method init.

@Override
protected void init() {
    super.init();
    // Imitate flush window event on bolt startup to prevent data loss when this bolt is restarted
    getOutput().emit(new Values(new CommandContext()));
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) Values(org.apache.storm.tuple.Values)

Example 59 with CommandContext

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

the class ResourcesAllocationAction method createSpeakerRequestFactories.

private void createSpeakerRequestFactories(FlowCreateFsm stateMachine, Flow flow) {
    final FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    final CommandContext commandContext = stateMachine.getCommandContext();
    List<FlowSegmentRequestFactory> requestFactories;
    // ingress
    requestFactories = stateMachine.getIngressCommands();
    SpeakerRequestBuildContext buildContext = buildBaseSpeakerContextForInstall(flow.getSrcSwitchId(), flow.getDestSwitchId());
    requestFactories.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, buildContext));
    // non ingress
    requestFactories = stateMachine.getNonIngressCommands();
    requestFactories.addAll(commandBuilder.buildAllExceptIngress(commandContext, flow));
    if (flow.isAllocateProtectedPath()) {
        requestFactories.addAll(commandBuilder.buildAllExceptIngress(commandContext, flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()));
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) CommandContext(org.openkilda.wfm.CommandContext) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) SpeakerRequestBuildContext(org.openkilda.wfm.share.model.SpeakerRequestBuildContext)

Example 60 with CommandContext

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

the class FlowCreateServiceTest method shouldRollbackIfEgressRuleNotInstalled.

@Test
public void shouldRollbackIfEgressRuleNotInstalled() throws Exception {
    when(pathComputer.getPath(any(Flow.class))).thenReturn(make3SwitchesPathPair());
    String key = "failed_flow_create";
    FlowRequest flowRequest = makeRequest().flowId("failed_flow_id").build();
    FlowCreateService service = makeService();
    service.handleRequest(key, new CommandContext(), flowRequest);
    Flow inProgress = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyFlowPathStatus(inProgress.getForwardPath(), FlowPathStatus.IN_PROGRESS, "forward");
    verifyFlowPathStatus(inProgress.getReversePath(), FlowPathStatus.IN_PROGRESS, "reverse");
    verifyNorthboundSuccessResponse(carrier);
    FlowSegmentRequest request;
    int installCommands = 0;
    int deleteCommands = 0;
    while ((request = requests.poll()) != null) {
        try {
            if (request.isVerifyRequest()) {
                service.handleAsyncResponse(key, buildResponseOnVerifyRequest(request));
            } else if (request.isInstallRequest()) {
                installCommands++;
                if (requests.size() > 1) {
                    handleResponse(service, key, request);
                } else {
                    handleErrorResponse(service, key, request, ErrorCode.UNKNOWN);
                }
            } else if (request.isRemoveRequest()) {
                deleteCommands++;
                handleResponse(service, key, request);
            }
        } catch (UnknownKeyException ex) {
        // skip
        }
    }
    assertEquals("All installed rules should be deleted", installCommands, deleteCommands);
    Flow result = verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.DOWN);
    // TODO(surabujin): do we really want to create flow without paths?
    Assert.assertNull(result.getForwardPath());
    Assert.assertNull(result.getReversePath());
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) Test(org.junit.Test)

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