use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class ValidateSubFlowsAction method perform.
@Override
protected void perform(State from, State to, Event event, YFlowValidationContext context, YFlowValidationFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
if (yFlow.getStatus() == FlowStatus.DOWN) {
throw new FlowProcessingException(ErrorType.UNPROCESSABLE_REQUEST, format("Could not validate y-flow: y-flow %s in in DOWN state", yFlowId));
}
log.debug("Start validating {} sub-flows of y-flow {}", yFlow.getSubFlows().size(), yFlowId);
stateMachine.clearValidatingSubFlows();
yFlow.getSubFlows().forEach(subFlow -> {
String subFlowId = subFlow.getSubFlowId();
stateMachine.addSubFlow(subFlowId);
stateMachine.addValidatingSubFlow(subFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, subFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(subFlowId);
flowValidationHubService.startFlowValidation(flowContext, subFlowId);
});
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class FlowRerouteService method startFlowRerouting.
private void startFlowRerouting(String key, FlowRerouteRequest reroute, CommandContext commandContext, String sharedBandwidthGroupId) {
String flowId = reroute.getFlowId();
log.debug("Handling flow reroute request with key {} and flow ID: {}", key, flowId);
try {
checkRequestsCollision(key, flowId);
} catch (Exception e) {
log.error(e.getMessage());
fsmRegister.getFsmByKey(key).ifPresent(fsm -> removeIfFinished(fsm, key));
return;
}
if (fsmRegister.hasRegisteredFsmWithFlowId(flowId)) {
carrier.sendRerouteResultStatus(flowId, new RerouteInProgressError(), commandContext.getCorrelationId());
return;
}
FlowRerouteFsm fsm = fsmFactory.newInstance(flowId, commandContext, eventListeners);
fsm.setSharedBandwidthGroupId(sharedBandwidthGroupId);
fsmRegister.registerFsm(key, fsm);
FlowRerouteContext context = FlowRerouteContext.builder().flowId(flowId).affectedIsl(reroute.getAffectedIsl()).forceReroute(reroute.isForce()).ignoreBandwidth(reroute.isIgnoreBandwidth()).effectivelyDown(reroute.isEffectivelyDown()).rerouteReason(reroute.getReason()).build();
fsmExecutor.fire(fsm, Event.NEXT, context);
removeIfFinished(fsm, key);
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class FlowRerouteServiceTest method shouldFailRerouteOnErrorDuringCompletingFlowPathInstallation.
@Test
public void shouldFailRerouteOnErrorDuringCompletingFlowPathInstallation() throws RecoverableException, UnroutableFlowException, UnknownKeyException {
Flow origin = makeFlow();
preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
FlowPathRepository repository = setupFlowPathRepositorySpy();
Set<PathId> originalPaths = origin.getPaths().stream().map(FlowPath::getPathId).collect(toSet());
doThrow(new RuntimeException(injectedErrorMessage)).when(repository).updateStatus(ArgumentMatchers.argThat(argument -> !originalPaths.contains(argument)), eq(FlowPathStatus.ACTIVE));
FlowRerouteService service = makeService();
FlowRerouteRequest request = new FlowRerouteRequest(origin.getFlowId(), false, false, false, Collections.emptySet(), null, false);
service.handleRequest(currentRequestKey, request, commandContext);
verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
verifyNorthboundSuccessResponse(carrier);
FlowSegmentRequest speakerRequest;
while ((speakerRequest = requests.poll()) != null) {
if (speakerRequest.isVerifyRequest()) {
service.handleAsyncResponse(currentRequestKey, buildResponseOnVerifyRequest(speakerRequest));
} else {
produceAsyncResponse(service, speakerRequest);
}
}
Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
verifyNoPathReplace(origin, result);
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class FlowValidationHubServiceTest method testMainPath.
@Test
public void testMainPath() throws DuplicateKeyException, UnknownKeyException {
FlowValidationHubCarrier carrier = new FlowValidationHubCarrier() {
@Override
public void sendSpeakerRequest(String flowId, CommandData commandData) {
assertTrue(commandData instanceof DumpRulesForFlowHsRequest || commandData instanceof DumpMetersForFlowHsRequest || commandData instanceof DumpGroupsForFlowHsRequest);
List<SwitchId> switchIds = Lists.newArrayList(TEST_SWITCH_ID_A, TEST_SWITCH_ID_B, TEST_SWITCH_ID_C, TEST_SWITCH_ID_E);
if (commandData instanceof DumpRulesForFlowHsRequest) {
assertTrue(switchIds.contains(((DumpRulesForFlowHsRequest) commandData).getSwitchId()));
} else if (commandData instanceof DumpMetersForFlowHsRequest) {
assertTrue(switchIds.contains(((DumpMetersForFlowHsRequest) commandData).getSwitchId()));
} else {
assertTrue(switchIds.contains(((DumpGroupsForFlowHsRequest) commandData).getSwitchId()));
}
}
@Override
public void sendNorthboundResponse(List<? extends InfoData> message) {
assertEquals(4, message.size());
try {
assertEquals(flowValidationService.validateFlow(TEST_FLOW_ID_A, getSwitchFlowEntriesWithTransitVlan(), getSwitchMeterEntries(), getSwitchGroupEntries()), message);
} catch (FlowNotFoundException | SwitchNotFoundException e) {
// tested in the FlowValidationServiceTest
}
}
@Override
public void sendNorthboundResponse(Message message) {
fail();
}
@Override
public void cancelTimeoutCallback(String key) {
assertEquals(TEST_KEY, key);
}
@Override
public void sendInactive() {
}
};
flowValidationHubService = new FlowValidationHubService(carrier, persistenceManager, flowResourcesManager, MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT);
buildTransitVlanFlow("");
flowValidationHubService.handleFlowValidationRequest(TEST_KEY, new CommandContext(), new FlowValidationRequest(TEST_FLOW_ID_A));
for (SwitchFlowEntries switchFlowEntries : getSwitchFlowEntriesWithTransitVlan()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchFlowEntries);
}
for (SwitchMeterEntries switchMeterEntries : getSwitchMeterEntries()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchMeterEntries);
}
for (SwitchGroupEntries switchGroupEntries : getSwitchGroupEntries()) {
flowValidationHubService.handleAsyncResponse(TEST_KEY, switchGroupEntries);
}
}
use of org.openkilda.wfm.CommandContext in project open-kilda by telstra.
the class YFlowDeleteServiceTest method shouldDeleteOnTimeoutDuringMeterRemoval.
@Test
public void shouldDeleteOnTimeoutDuringMeterRemoval() throws DuplicateKeyException {
// given
String yFlowId = "test_y_flow_11";
createYFlowViaTransit(yFlowId);
YFlowDeleteService service = makeYFlowDeleteService(0);
// when
service.handleRequest(yFlowId, new CommandContext(), new YFlowDeleteRequest(yFlowId));
verifyYFlowStatus(yFlowId, FlowStatus.IN_PROGRESS);
// and
handleSpeakerCommandsAndTimeoutRemove(service, yFlowId);
// then
verifyNorthboundSuccessResponse(yFlowDeleteHubCarrier, YFlowResponse.class);
verifyYFlowIsAbsent(yFlowId);
}
Aggregations