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);
}
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());
}
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());
}
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);
}
}
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));
}
Aggregations