use of org.openkilda.messaging.command.flow.FlowPathSwapRequest in project open-kilda by telstra.
the class FlowServiceImpl method swapFlowPaths.
/**
* {@inheritDoc}
*/
@Override
public CompletableFuture<FlowResponsePayload> swapFlowPaths(String flowId) {
final String correlationId = RequestCorrelationId.getId();
logger.info("Swapping paths for flow : {}", flowId);
FlowPathSwapRequest payload = new FlowPathSwapRequest(flowId, true);
CommandMessage request = new CommandMessage(payload, System.currentTimeMillis(), correlationId, Destination.WFM);
return messagingChannel.sendAndGet(flowHsTopic, request).thenApply(FlowResponse.class::cast).thenApply(FlowResponse::getPayload).thenApply(flowMapper::toFlowResponseOutput);
}
use of org.openkilda.messaging.command.flow.FlowPathSwapRequest in project open-kilda by telstra.
the class OperationQueueBolt method handleInput.
@Override
protected void handleInput(Tuple tuple) throws PipelineException {
CommandContext context = pullContext(tuple);
MessageData data = pullValue(tuple, FIELD_ID_PAYLOAD, MessageData.class);
if (data instanceof FlowPathSwapRequest) {
FlowPathSwapRequest flowPathSwapRequest = (FlowPathSwapRequest) data;
service.addFirst(flowPathSwapRequest.getFlowId(), context.getCorrelationId(), flowPathSwapRequest);
} else if (data instanceof FlowRerouteRequest) {
FlowRerouteRequest flowRerouteRequest = (FlowRerouteRequest) data;
service.addLast(flowRerouteRequest.getFlowId(), context.getCorrelationId(), flowRerouteRequest);
} else if (data instanceof YFlowRerouteRequest) {
YFlowRerouteRequest yFlowRerouteRequest = (YFlowRerouteRequest) data;
service.addLast(yFlowRerouteRequest.getYFlowId(), context.getCorrelationId(), yFlowRerouteRequest);
} else if (data instanceof RerouteResultInfoData) {
RerouteResultInfoData rerouteResultInfoData = (RerouteResultInfoData) data;
service.operationCompleted(rerouteResultInfoData.getFlowId(), rerouteResultInfoData);
emitRerouteResponse(rerouteResultInfoData);
} else if (data instanceof PathSwapResult) {
PathSwapResult pathSwapResult = (PathSwapResult) data;
service.operationCompleted(pathSwapResult.getFlowId(), pathSwapResult);
} else {
unhandledInput(tuple);
}
}
use of org.openkilda.messaging.command.flow.FlowPathSwapRequest in project open-kilda by telstra.
the class RerouteBolt method emitPathSwapCommand.
/**
* Emit swap command for consumer.
*
* @param correlationId correlation id to pass through
* @param flowId flow
* @param reason initial reason of path swap
*/
@Override
public void emitPathSwapCommand(String correlationId, String flowId, String reason) {
CommandContext context = new CommandContext(correlationId).fork(UUID.randomUUID().toString());
emit(STREAM_OPERATION_QUEUE_ID, getCurrentTuple(), new Values(flowId, new FlowPathSwapRequest(flowId, false), context));
log.warn("Flow {} swap path command message sent with correlationId {}, reason \"{}\"", flowId, context.getCorrelationId(), reason);
}
use of org.openkilda.messaging.command.flow.FlowPathSwapRequest in project open-kilda by telstra.
the class FlowPathSwapServiceTest method shouldFailSwapOnUnsuccessfulYFlowRulesInstallation.
@Test
public void shouldFailSwapOnUnsuccessfulYFlowRulesInstallation() {
// given
Flow origin = dummyFactory.makeFlowWithProtectedPath(flowSource, flowDestination, singletonList(islSourceDest), singletonList(islSourceDestAlt));
createTestYFlowForSubFlow(origin);
// when
FlowPathSwapService service = makeService();
FlowPathSwapRequest request = new FlowPathSwapRequest(origin.getFlowId(), false);
service.handleRequest(dummyRequestKey, commandContext, request);
verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
int failCounter = 1;
SpeakerRequest speakerRequest;
while ((speakerRequest = requests.poll()) != null) {
SpeakerResponse commandResponse;
if (speakerRequest instanceof FlowSegmentRequest) {
commandResponse = buildSpeakerResponse((FlowSegmentRequest) speakerRequest);
} else {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
if (failCounter > 0) {
commandResponse = buildErrorYFlowSpeakerResponse(speakerCommandsRequest);
failCounter--;
} else {
commandResponse = buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest);
}
}
service.handleAsyncResponse(dummyRequestKey, commandResponse);
}
// then
Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
verifyPathNotSwapped(origin, result);
verifyNorthboundSuccessResponse(carrier);
}
use of org.openkilda.messaging.command.flow.FlowPathSwapRequest in project open-kilda by telstra.
the class FlowPathSwapServiceTest method shouldFailSwapOnTimeoutDuringYFlowRulesInstallation.
@Test
public void shouldFailSwapOnTimeoutDuringYFlowRulesInstallation() {
// given
Flow origin = dummyFactory.makeFlowWithProtectedPath(flowSource, flowDestination, singletonList(islSourceDest), singletonList(islSourceDestAlt));
createTestYFlowForSubFlow(origin);
// when
FlowPathSwapService service = makeService();
FlowPathSwapRequest request = new FlowPathSwapRequest(origin.getFlowId(), false);
service.handleRequest(dummyRequestKey, commandContext, request);
verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
int failCounter = 1;
SpeakerRequest speakerRequest;
while ((speakerRequest = requests.poll()) != null) {
if (speakerRequest instanceof FlowSegmentRequest) {
service.handleAsyncResponse(dummyRequestKey, buildSpeakerResponse((FlowSegmentRequest) speakerRequest));
} else {
if (failCounter > 0) {
service.handleTimeout(dummyRequestKey);
failCounter--;
} else {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) speakerRequest;
service.handleAsyncResponse(dummyRequestKey, buildSuccessfulYFlowSpeakerResponse(speakerCommandsRequest));
}
}
}
// then
Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
verifyPathNotSwapped(origin, result);
verifyNorthboundSuccessResponse(carrier);
}
Aggregations