use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class YFlowUpdateServiceTest method shouldFailOnUnsuccessfulMeterInstallation.
@Test
public void shouldFailOnUnsuccessfulMeterInstallation() throws RecoverableException, UnroutableFlowException, DuplicateKeyException {
// given
YFlowRequest request = createYFlow();
request.setMaximumBandwidth(2000L);
request.getSubFlows().get(0).setEndpoint(newFirstEndpoint);
request.getSubFlows().get(1).setEndpoint(newSecondEndpoint);
preparePathComputationForUpdate("test_flow_1", buildNewFirstSubFlowPathPair(), buildFirstSubFlowPathPair());
preparePathComputationForUpdate("test_flow_2", buildNewSecondSubFlowPathPair(), buildSecondSubFlowPathPair());
prepareYPointComputation(SWITCH_SHARED, SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP, SWITCH_TRANSIT);
YFlowUpdateService service = makeYFlowUpdateService(0);
// when
service.handleRequest(request.getYFlowId(), new CommandContext(), request);
verifyYFlowStatus(request.getYFlowId(), FlowStatus.IN_PROGRESS, FlowStatus.IN_PROGRESS, FlowStatus.UP);
// and
handleSpeakerCommandsAndFailInstall(service, request.getYFlowId(), "test_successful_yflow");
// then
verifyYFlowStatus(request.getYFlowId(), FlowStatus.UP);
YFlow flow = getYFlow(request.getYFlowId());
assertEquals(1000L, flow.getMaximumBandwidth());
Set<SwitchId> expectedEndpointSwitchIds = Stream.of(SWITCH_FIRST_EP, SWITCH_SECOND_EP).collect(Collectors.toSet());
Set<SwitchId> actualEndpointSwitchIds = flow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
assertEquals(expectedEndpointSwitchIds, actualEndpointSwitchIds);
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class LoggerContextInitializerTest method shouldParseMessageAndExtractCorrelationId.
@Test
public void shouldParseMessageAndExtractCorrelationId() {
// given
Tuple tuple = mock(Tuple.class);
when(tuple.getFields()).thenReturn(new Fields("message"));
String correlationId = String.format("test-%s", UUID.randomUUID());
InfoMessage message = new InfoMessage(new FlowsResponse(Collections.emptyList()), System.currentTimeMillis(), correlationId);
when(tuple.getValueByField(eq("message"))).thenReturn(message);
// when
Optional<CommandContext> result = LoggerContextInitializer.extract(tuple);
// then
assertEquals(correlationId, result.get().getCorrelationId());
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class UpdateFlowPathsAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowPathSwapContext context, FlowPathSwapFsm stateMachine) {
Flow f = transactionManager.doInTransaction(() -> {
String flowId = stateMachine.getFlowId();
Flow flow = getFlow(flowId);
log.debug("Swapping primary and protected paths for flow {}", flowId);
FlowPath oldPrimaryForward = flow.getForwardPath();
FlowPath oldPrimaryReverse = flow.getReversePath();
FlowPath newPrimaryForward = flow.getProtectedForwardPath();
FlowPath newPrimaryReverse = flow.getProtectedReversePath();
setMirrorPointsToNewPath(oldPrimaryForward.getPathId(), newPrimaryForward.getPathId());
setMirrorPointsToNewPath(oldPrimaryReverse.getPathId(), newPrimaryReverse.getPathId());
flow.setForwardPath(newPrimaryForward);
flow.setReversePath(newPrimaryReverse);
flow.setProtectedForwardPath(oldPrimaryForward);
flow.setProtectedReversePath(oldPrimaryReverse);
return flow;
});
stateMachine.setNewPrimaryForwardPath(f.getForwardPathId());
stateMachine.setNewPrimaryReversePath(f.getReversePathId());
stateMachine.setNewProtectedForwardPath(f.getProtectedForwardPathId());
stateMachine.setNewProtectedReversePath(f.getProtectedReversePathId());
stateMachine.saveActionToHistory("The flow paths were updated");
CommandContext commandContext = stateMachine.getCommandContext();
return Optional.of(buildResponseMessage(f, commandContext));
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class OnFinishedAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowSwapEndpointsContext context, FlowSwapEndpointsFsm stateMachine) {
log.info("Swap endpoints operation completed successfully.");
updateFlowsStatuses(stateMachine);
stateMachine.saveFlowActionToHistory(stateMachine.getFirstFlowId(), format("Swap endpoints with flow %s was successful", stateMachine.getSecondFlowId()));
stateMachine.saveFlowActionToHistory(stateMachine.getSecondFlowId(), format("Swap endpoints with flow %s was successful", stateMachine.getFirstFlowId()));
List<FlowResponse> flowResponses = stateMachine.getFlowResponses();
SwapFlowResponse response = stateMachine.getFirstFlowId().equals(flowResponses.get(0).getPayload().getFlowId()) ? new SwapFlowResponse(flowResponses.get(0), flowResponses.get(1)) : new SwapFlowResponse(flowResponses.get(1), flowResponses.get(0));
CommandContext commandContext = stateMachine.getCommandContext();
return Optional.of(new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId()));
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class PostResourceAllocationAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
Flow flow = getFlow(stateMachine.getFlowId());
PathId flowMirrorPathId = stateMachine.getMirrorPathId();
FlowMirrorPath flowMirrorPath = flowMirrorPathRepository.findById(flowMirrorPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror path %s not found", flowMirrorPathId)));
String direction = flowMirrorPath.getFlowMirrorPoints().getFlowPath().isForward() ? "forward" : "reverse";
FlowMirrorPointResponse response = FlowMirrorPointResponse.builder().flowId(flow.getFlowId()).mirrorPointId(flowMirrorPath.getPathId().getId()).mirrorPointDirection(direction).mirrorPointSwitchId(flowMirrorPath.getMirrorSwitchId()).sinkEndpoint(FlowEndpoint.builder().switchId(flowMirrorPath.getEgressSwitchId()).portNumber(flowMirrorPath.getEgressPort()).outerVlanId(flowMirrorPath.getEgressOuterVlan()).innerVlanId(flowMirrorPath.getEgressInnerVlan()).build()).build();
CommandContext commandContext = stateMachine.getCommandContext();
return Optional.of(new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId()));
}
Aggregations