Search in sources :

Example 26 with FlowRerouteRequest

use of org.openkilda.messaging.command.flow.FlowRerouteRequest in project open-kilda by telstra.

the class FlowRerouteServiceTest method shouldFailRerouteFlowOnResourcesAllocationConstraint.

@Test
public void shouldFailRerouteFlowOnResourcesAllocationConstraint() throws RecoverableException, UnroutableFlowException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
    FlowPathRepository repository = setupFlowPathRepositorySpy();
    doThrow(new RuntimeException(injectedErrorMessage)).when(repository).add(any(FlowPath.class));
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    testExpectedFailure(dummyRequestKey, request, commandContext, origin, FlowStatus.UP, ErrorType.INTERNAL_ERROR);
}
Also used : FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 27 with FlowRerouteRequest

use of org.openkilda.messaging.command.flow.FlowRerouteRequest in project open-kilda by telstra.

the class FlowRerouteServiceTest method shouldFailRerouteFlowIfRecoverableException.

@Test
public void shouldFailRerouteFlowIfRecoverableException() throws RecoverableException, UnroutableFlowException {
    Flow origin = makeFlow();
    preparePathComputation(origin.getFlowId(), new RecoverableException(injectedErrorMessage));
    FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
    testExpectedFailure(dummyRequestKey, request, commandContext, origin, FlowStatus.UP, ErrorType.INTERNAL_ERROR);
    verify(pathComputer, times(PATH_ALLOCATION_RETRIES_LIMIT + 1)).getPath(makeFlowArgumentMatch(origin.getFlowId()), any());
}
Also used : FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) RecoverableException(org.openkilda.pce.exception.RecoverableException) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 28 with FlowRerouteRequest

use of org.openkilda.messaging.command.flow.FlowRerouteRequest in project open-kilda by telstra.

the class FlowServiceImpl method rerouteFlow.

/**
 * {@inheritDoc}
 */
@Override
public FlowPathPayload rerouteFlow(String flowId, String correlationId) {
    Flow flow = new Flow();
    flow.setFlowId(flowId);
    FlowRerouteRequest data = new FlowRerouteRequest(flow, FlowOperation.UPDATE);
    CommandMessage command = new CommandMessage(data, System.currentTimeMillis(), correlationId, Destination.WFM);
    messageConsumer.clear();
    messageProducer.send(topic, command);
    Message message = (Message) messageConsumer.poll(correlationId);
    logger.debug("Got response {}", message);
    FlowPathResponse response = (FlowPathResponse) validateInfoMessage(command, message, correlationId);
    return Converter.buildFlowPathPayloadByFlowPath(flowId, response.getPayload());
}
Also used : FlowPathResponse(org.openkilda.messaging.info.flow.FlowPathResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) Flow(org.openkilda.messaging.model.Flow) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 29 with FlowRerouteRequest

use of org.openkilda.messaging.command.flow.FlowRerouteRequest in project open-kilda by telstra.

the class MessageEncoder method handleInput.

@Override
protected void handleInput(Tuple input) throws Exception {
    MessageData payload = pullPayload(input);
    try {
        CommandContext commandContext = pullContext(input);
        Message message = wrap(commandContext, payload);
        if (payload instanceof FlowRerouteRequest) {
            getOutput().emit(input.getSourceStreamId(), input, new Values(message));
        } else if (payload instanceof SwitchValidateRequest) {
            getOutput().emit(input.getSourceStreamId(), input, new Values(commandContext.getCorrelationId(), message));
        } else if (payload instanceof ErrorData) {
            getOutput().emit(StreamType.ERROR.toString(), input, new Values(null, message));
        }
    } catch (IllegalArgumentException e) {
        log.error(e.getMessage());
        unhandledInput(input);
    }
}
Also used : CommandContext(org.openkilda.wfm.CommandContext) Message(org.openkilda.messaging.Message) MessageData(org.openkilda.messaging.MessageData) Values(org.apache.storm.tuple.Values) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) SwitchValidateRequest(org.openkilda.messaging.command.switches.SwitchValidateRequest) ErrorData(org.openkilda.messaging.error.ErrorData)

Example 30 with FlowRerouteRequest

use of org.openkilda.messaging.command.flow.FlowRerouteRequest in project open-kilda by telstra.

the class SwitchOperationsBolt method updateSwitchUnderMaintenanceFlag.

private List<GetSwitchResponse> updateSwitchUnderMaintenanceFlag(UpdateSwitchUnderMaintenanceRequest request, Tuple tuple) {
    SwitchId switchId = request.getSwitchId();
    boolean underMaintenance = request.isUnderMaintenance();
    boolean evacuate = request.isEvacuate();
    Switch sw;
    try {
        sw = switchOperationsService.updateSwitchUnderMaintenanceFlag(switchId, underMaintenance);
    } catch (SwitchNotFoundException e) {
        throw new MessageException(ErrorType.NOT_FOUND, e.getMessage(), "Switch was not found.");
    }
    if (underMaintenance && evacuate) {
        Collection<FlowPath> paths = flowOperationsService.getFlowPathsForSwitch(switchId);
        Set<IslEndpoint> affectedIslEndpoint = new HashSet<>(switchOperationsService.getSwitchIslEndpoints(switchId));
        String reason = format("evacuated due to switch maintenance %s", switchId);
        for (FlowRerouteRequest reroute : flowOperationsService.makeRerouteRequests(paths, affectedIslEndpoint, reason)) {
            CommandContext forkedContext = getCommandContext().fork(reroute.getFlowId());
            getOutput().emit(StreamType.REROUTE.toString(), tuple, new Values(reroute, forkedContext.getCorrelationId()));
        }
    }
    return Collections.singletonList(new GetSwitchResponse(sw));
}
Also used : IslEndpoint(org.openkilda.model.IslEndpoint) GetSwitchResponse(org.openkilda.messaging.nbtopology.response.GetSwitchResponse) CommandContext(org.openkilda.wfm.CommandContext) Values(org.apache.storm.tuple.Values) SwitchId(org.openkilda.model.SwitchId) SwitchNotFoundException(org.openkilda.wfm.error.SwitchNotFoundException) Switch(org.openkilda.model.Switch) MessageException(org.openkilda.messaging.error.MessageException) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) FlowPath(org.openkilda.model.FlowPath) HashSet(java.util.HashSet)

Aggregations

FlowRerouteRequest (org.openkilda.messaging.command.flow.FlowRerouteRequest)49 Test (org.junit.Test)27 Flow (org.openkilda.model.Flow)23 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)14 Values (org.apache.storm.tuple.Values)10 YFlowRerouteRequest (org.openkilda.messaging.command.yflow.YFlowRerouteRequest)9 CommandMessage (org.openkilda.messaging.command.CommandMessage)8 IslEndpoint (org.openkilda.model.IslEndpoint)8 CommandContext (org.openkilda.wfm.CommandContext)7 FlowPath (org.openkilda.model.FlowPath)6 FlowThrottlingData (org.openkilda.wfm.topology.reroute.model.FlowThrottlingData)5 RerouteResultInfoData (org.openkilda.messaging.info.reroute.RerouteResultInfoData)4 GetPathsResult (org.openkilda.pce.GetPathsResult)4 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)4 HashSet (java.util.HashSet)3 RerouteQueue (org.openkilda.wfm.topology.reroute.model.RerouteQueue)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Ignore (org.junit.Ignore)2 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)2