Search in sources :

Example 26 with UnknownKeyException

use of org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException in project open-kilda by telstra.

the class FlowCreateServiceTest method shouldNotRetryForever.

@Test
public void shouldNotRetryForever() throws Exception {
    String key = "retries_non_ingress_installation";
    FlowRequest flowRequest = makeRequest().flowId("dummy_flow_id").build();
    int retriesLimit = 10;
    FlowCreateService service = makeService(retriesLimit);
    preparePathComputation(flowRequest.getFlowId(), make2SwitchesPathPair());
    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;
    Map<UUID, Integer> remainingRetries = new HashMap<>();
    while ((request = requests.poll()) != null) {
        UUID commandId = request.getCommandId();
        Integer remaining = remainingRetries.getOrDefault(commandId, retriesLimit + 1);
        Assert.assertTrue(0 < remaining);
        try {
            if (request instanceof EgressFlowSegmentInstallRequest) {
                remainingRetries.put(commandId, remaining - 1);
                handleErrorResponse(service, key, request, ErrorCode.SWITCH_UNAVAILABLE);
            } else if (request.isVerifyRequest()) {
                service.handleAsyncResponse(key, buildResponseOnVerifyRequest(request));
            } else {
                handleResponse(service, key, request);
            }
        } catch (UnknownKeyException ex) {
        // skip
        }
    }
    verifyFlowStatus(flowRequest.getFlowId(), FlowStatus.DOWN);
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) HashMap(java.util.HashMap) EgressFlowSegmentInstallRequest(org.openkilda.floodlight.api.request.EgressFlowSegmentInstallRequest) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException) UUID(java.util.UUID) Test(org.junit.Test)

Example 27 with UnknownKeyException

use of org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException in project open-kilda by telstra.

the class YFlowDeleteService method handleTimeout.

/**
 * Handles timeout case.
 *
 * @param key command identifier.
 */
public void handleTimeout(@NonNull String key) throws UnknownKeyException {
    log.debug("Handling timeout for {}", key);
    YFlowDeleteFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    // Propagate timeout event to all sub-flow processing FSMs.
    fsm.getDeletingSubFlows().forEach(flowId -> {
        try {
            flowDeleteService.handleTimeoutByFlowId(flowId);
        } catch (UnknownKeyException e) {
            log.error("Failed to handle a timeout event by FlowDeleteService for {}.", flowId);
        }
    });
    fsmExecutor.fire(fsm, Event.TIMEOUT);
    removeIfFinished(fsm, key);
}
Also used : YFlowDeleteFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.delete.YFlowDeleteFsm) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 28 with UnknownKeyException

use of org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException in project open-kilda by telstra.

the class YFlowUpdateService method handleTimeout.

/**
 * Handles timeout case.
 *
 * @param key command identifier.
 */
public void handleTimeout(@NonNull String key) throws UnknownKeyException {
    log.debug("Handling timeout for {}", key);
    YFlowUpdateFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    // Propagate timeout event to all sub-flow processing FSMs.
    fsm.getUpdatingSubFlows().forEach(flowId -> {
        try {
            flowUpdateService.handleTimeoutByFlowId(flowId);
        } catch (UnknownKeyException e) {
            log.error("Failed to handle a timeout event by FlowUpdateService for {}.", flowId);
        }
    });
    fsmExecutor.fire(fsm, Event.TIMEOUT);
    removeIfFinished(fsm, key);
}
Also used : YFlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateFsm) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 29 with UnknownKeyException

use of org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException in project open-kilda by telstra.

the class YFlowValidationHubService method handleTimeout.

/**
 * Handles timeout case.
 *
 * @param key command identifier.
 */
public void handleTimeout(@NonNull String key) throws UnknownKeyException {
    log.debug("Handling timeout for {}", key);
    YFlowValidationFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    // Propagate timeout event to all sub-flow processing FSMs.
    fsm.getValidatingSubFlows().forEach(flowId -> {
        try {
            flowValidationService.handleTimeoutByFlowId(flowId);
        } catch (UnknownKeyException e) {
            log.error("Failed to handle a timeout event by FlowUpdateService for {}.", flowId);
        }
    });
    fsmExecutor.fire(fsm, Event.TIMEOUT);
    removeIfFinished(fsm, key);
}
Also used : YFlowValidationFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationFsm) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 30 with UnknownKeyException

use of org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException in project open-kilda by telstra.

the class YFlowCreateService method handleAsyncResponse.

/**
 * Handles async response from worker.
 *
 * @param key command identifier.
 */
public void handleAsyncResponse(@NonNull String key, @NonNull SpeakerResponse speakerResponse) throws UnknownKeyException {
    log.debug("Received flow command response: {}", speakerResponse);
    YFlowCreateFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    if (speakerResponse instanceof SpeakerFlowSegmentResponse) {
        SpeakerFlowSegmentResponse response = (SpeakerFlowSegmentResponse) speakerResponse;
        String flowId = response.getMetadata().getFlowId();
        if (fsm.getCreatingSubFlows().contains(flowId)) {
            flowCreateService.handleAsyncResponseByFlowId(flowId, response);
        } else if (fsm.getDeletingSubFlows().contains(flowId)) {
            flowDeleteService.handleAsyncResponseByFlowId(flowId, response);
        }
    } else if (speakerResponse instanceof SpeakerCommandResponse) {
        SpeakerCommandResponse response = (SpeakerCommandResponse) speakerResponse;
        YFlowCreateContext context = YFlowCreateContext.builder().speakerResponse(response).build();
        fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
    } else {
        log.debug("Received unexpected speaker response: {}", speakerResponse);
    }
    // After handling an event by FlowCreate or FlowDelete services, we should propagate execution to the FSM.
    if (!fsm.isTerminated()) {
        fsmExecutor.fire(fsm, Event.NEXT);
    }
    removeIfFinished(fsm, key);
}
Also used : YFlowCreateContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.create.YFlowCreateContext) YFlowCreateFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.create.YFlowCreateFsm) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Aggregations

UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)49 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)9 SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)9 Flow (org.openkilda.model.Flow)7 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)6 Test (org.junit.Test)5 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)5 SpeakerCommandResponse (org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse)4 FlowRequest (org.openkilda.messaging.command.flow.FlowRequest)4 FlowEndpoint (org.openkilda.model.FlowEndpoint)4 CommandContext (org.openkilda.wfm.CommandContext)4 ErrorData (org.openkilda.messaging.error.ErrorData)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 UUID (java.util.UUID)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Matchers.hasProperty (org.hamcrest.Matchers.hasProperty)2 Assert (org.junit.Assert)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2