Search in sources :

Example 6 with SpeakerCommandResponse

use of org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse in project open-kilda by telstra.

the class YFlowDeleteService 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);
    YFlowDeleteFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    if (speakerResponse instanceof SpeakerFlowSegmentResponse) {
        SpeakerFlowSegmentResponse response = (SpeakerFlowSegmentResponse) speakerResponse;
        String flowId = response.getMetadata().getFlowId();
        if (fsm.getDeletingSubFlows().contains(flowId)) {
            flowDeleteService.handleAsyncResponseByFlowId(flowId, response);
        }
    } else if (speakerResponse instanceof SpeakerCommandResponse) {
        SpeakerCommandResponse response = (SpeakerCommandResponse) speakerResponse;
        YFlowDeleteContext context = YFlowDeleteContext.builder().speakerResponse(response).build();
        fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
    } else {
        log.debug("Received unexpected speaker response: {}", speakerResponse);
    }
    // After handling an event by FlowDelete services, we should propagate execution to the FSM.
    if (!fsm.isTerminated()) {
        fsmExecutor.fire(fsm, Event.NEXT);
    }
    removeIfFinished(fsm, key);
}
Also used : YFlowDeleteFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.delete.YFlowDeleteFsm) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) YFlowDeleteContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.delete.YFlowDeleteContext) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 7 with SpeakerCommandResponse

use of org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse in project open-kilda by telstra.

the class YFlowRerouteService 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);
    YFlowRerouteFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    if (speakerResponse instanceof SpeakerFlowSegmentResponse) {
        SpeakerFlowSegmentResponse response = (SpeakerFlowSegmentResponse) speakerResponse;
        String flowId = response.getMetadata().getFlowId();
        if (fsm.getReroutingSubFlows().contains(flowId)) {
            flowRerouteService.handleAsyncResponseByFlowId(flowId, response);
        }
    } else if (speakerResponse instanceof SpeakerCommandResponse) {
        SpeakerCommandResponse response = (SpeakerCommandResponse) speakerResponse;
        YFlowRerouteContext context = YFlowRerouteContext.builder().speakerResponse(response).build();
        fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
    } else {
        log.debug("Received unexpected speaker response: {}", speakerResponse);
    }
    // After handling an event by FlowReroute service, we should propagate execution to the FSM.
    if (!fsm.isTerminated()) {
        fsmExecutor.fire(fsm, Event.NEXT);
    }
    removeIfFinished(fsm, key);
}
Also used : YFlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteFsm) YFlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteContext) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 8 with SpeakerCommandResponse

use of org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse in project open-kilda by telstra.

the class YFlowUpdateService 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);
    YFlowUpdateFsm fsm = fsmRegister.getFsmByKey(key).orElseThrow(() -> new UnknownKeyException(key));
    if (speakerResponse instanceof SpeakerFlowSegmentResponse) {
        SpeakerFlowSegmentResponse response = (SpeakerFlowSegmentResponse) speakerResponse;
        String flowId = response.getMetadata().getFlowId();
        if (fsm.getUpdatingSubFlows().contains(flowId)) {
            flowUpdateService.handleAsyncResponseByFlowId(flowId, response);
        }
    } else if (speakerResponse instanceof SpeakerCommandResponse) {
        SpeakerCommandResponse response = (SpeakerCommandResponse) speakerResponse;
        YFlowUpdateContext context = YFlowUpdateContext.builder().speakerResponse(response).build();
        fsmExecutor.fire(fsm, Event.RESPONSE_RECEIVED, context);
    } else {
        log.debug("Received unexpected speaker response: {}", speakerResponse);
    }
    // After handling an event by FlowUpdate service, we should propagate execution to the FSM.
    if (!fsm.isTerminated()) {
        fsmExecutor.fire(fsm, Event.NEXT);
    }
    removeIfFinished(fsm, key);
}
Also used : YFlowUpdateFsm(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateFsm) YFlowUpdateContext(org.openkilda.wfm.topology.flowhs.fsm.yflow.update.YFlowUpdateContext) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) UnknownKeyException(org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)

Example 9 with SpeakerCommandResponse

use of org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse in project open-kilda by telstra.

the class SpeakerWorkerService method handleTimeout.

/**
 * Handles operation timeout.
 * @param key operation identifier.
 */
public void handleTimeout(@NonNull String key) throws PipelineException {
    SpeakerRequest failedRequest = keyToRequest.remove(key);
    if (failedRequest instanceof FlowSegmentRequest) {
        FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) failedRequest;
        SpeakerFlowSegmentResponse response = FlowErrorResponse.errorBuilder().commandId(flowSegmentRequest.getCommandId()).switchId(flowSegmentRequest.getSwitchId()).metadata(flowSegmentRequest.getMetadata()).errorCode(ErrorCode.OPERATION_TIMED_OUT).messageContext(flowSegmentRequest.getMessageContext()).build();
        carrier.sendResponse(key, response);
    } else if (failedRequest instanceof BaseSpeakerCommandsRequest) {
        BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) failedRequest;
        SpeakerCommandResponse response = SpeakerCommandResponse.builder().commandId(speakerCommandsRequest.getCommandId()).switchId(speakerCommandsRequest.getSwitchId()).messageContext(speakerCommandsRequest.getMessageContext()).success(false).failedCommandIds(speakerCommandsRequest.getCommands().stream().map(command -> {
            if (command instanceof FlowCommand) {
                return ((FlowCommand) command).getData();
            }
            if (command instanceof MeterCommand) {
                return ((MeterCommand) command).getData();
            }
            return ((GroupCommand) command).getData();
        }).collect(Collectors.toMap(SpeakerData::getUuid, error -> "Operation is timed out"))).build();
        carrier.sendResponse(key, response);
    }
}
Also used : GroupCommand(org.openkilda.floodlight.api.request.rulemanager.GroupCommand) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) FlowCommand(org.openkilda.floodlight.api.request.rulemanager.FlowCommand) MeterCommand(org.openkilda.floodlight.api.request.rulemanager.MeterCommand) SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) SpeakerRequest(org.openkilda.floodlight.api.request.SpeakerRequest) BaseSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.BaseSpeakerCommandsRequest) SpeakerData(org.openkilda.rulemanager.SpeakerData)

Example 10 with SpeakerCommandResponse

use of org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse in project open-kilda by telstra.

the class OnReceivedValidateResponseAction method perform.

@Override
public void perform(State from, State to, Event event, YFlowUpdateContext context, YFlowUpdateFsm stateMachine) {
    SpeakerCommandResponse response = context.getSpeakerResponse();
    UUID commandId = response.getCommandId();
    if (!stateMachine.hasPendingCommand(commandId)) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    if (response.isSuccess()) {
        stateMachine.removePendingCommand(commandId);
        stateMachine.saveActionToHistory("Rule was validated", format("The rule was validated successfully: switch %s", response.getSwitchId()));
    } else {
    // We use validation directly in floodlight after installing the rules, so it's not necessary to do it here.
    }
    if (stateMachine.getPendingCommands().isEmpty()) {
        if (stateMachine.getFailedValidationResponses().isEmpty()) {
            log.debug("Rules have been validated for y-flow {}", stateMachine.getYFlowId());
            stateMachine.fire(Event.YPOINT_METERS_VALIDATED);
        } else {
            String errorMessage = format("Received error response(s) for %d validation commands", stateMachine.getFailedValidationResponses().size());
            stateMachine.saveErrorToHistory(errorMessage);
            stateMachine.fireError(errorMessage);
        }
    }
}
Also used : SpeakerCommandResponse(org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse) UUID(java.util.UUID)

Aggregations

SpeakerCommandResponse (org.openkilda.floodlight.api.response.rulemanager.SpeakerCommandResponse)17 UUID (java.util.UUID)12 String.format (java.lang.String.format)9 Set (java.util.Set)9 Slf4j (lombok.extern.slf4j.Slf4j)9 FlowCommand (org.openkilda.floodlight.api.request.rulemanager.FlowCommand)8 GroupCommand (org.openkilda.floodlight.api.request.rulemanager.GroupCommand)8 MeterCommand (org.openkilda.floodlight.api.request.rulemanager.MeterCommand)8 List (java.util.List)7 Optional (java.util.Optional)7 Collectors (java.util.stream.Collectors)7 OfCommand (org.openkilda.floodlight.api.request.rulemanager.OfCommand)7 SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)7 HistoryRecordingAction (org.openkilda.wfm.topology.flowhs.fsm.common.actions.HistoryRecordingAction)7 DeleteSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)4 UnknownKeyException (org.openkilda.wfm.topology.flowhs.exception.UnknownKeyException)4 InstallSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest)3 YFlowCreateContext (org.openkilda.wfm.topology.flowhs.fsm.yflow.create.YFlowCreateContext)3 YFlowCreateFsm (org.openkilda.wfm.topology.flowhs.fsm.yflow.create.YFlowCreateFsm)3 YFlowRerouteContext (org.openkilda.wfm.topology.flowhs.fsm.yflow.reroute.YFlowRerouteContext)3