use of org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException in project open-kilda by telstra.
the class FlowUpdateService method startFlowUpdating.
private void startFlowUpdating(String key, CommandContext commandContext, RequestedFlow request, boolean doNotRevert, Set<String> bulkUpdateFlowIds, String sharedBandwidthGroupId) throws DuplicateKeyException {
String flowId = request.getFlowId();
log.debug("Handling flow update request with key {} and flow ID: {}", key, request.getFlowId());
if (fsmRegister.hasRegisteredFsmWithKey(key)) {
throw new DuplicateKeyException(key, "There's another active FSM with the same key");
}
if (fsmRegister.hasRegisteredFsmWithFlowId(flowId)) {
sendErrorResponseToNorthbound(ErrorType.REQUEST_INVALID, "Could not update flow", format("Flow %s is updating now", flowId), commandContext);
log.error("Attempt to create a FSM with key {}, while there's another active FSM for the same flowId {}.", key, flowId);
return;
}
FlowUpdateFsm fsm = fsmFactory.newInstance(request.getFlowId(), commandContext, eventListeners);
fsm.setSharedBandwidthGroupId(sharedBandwidthGroupId);
fsmRegister.registerFsm(key, fsm);
if (request.getFlowEncapsulationType() == null) {
request.setFlowEncapsulationType(kildaConfigurationRepository.getOrDefault().getFlowEncapsulationType());
}
FlowUpdateContext context = FlowUpdateContext.builder().targetFlow(request).doNotRevert(doNotRevert).bulkUpdateFlowIds(bulkUpdateFlowIds).build();
fsmExecutor.fire(fsm, Event.NEXT, context);
removeIfFinished(fsm, key);
}
use of org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException in project open-kilda by telstra.
the class FlowCreateService method startFlowCreation.
private void startFlowCreation(String key, CommandContext commandContext, RequestedFlow requestedFlow, String sharedBandwidthGroupId) throws DuplicateKeyException {
String flowId = requestedFlow.getFlowId();
log.debug("Handling flow create request with key {} and flow ID: {}", key, flowId);
if (fsmRegister.hasRegisteredFsmWithKey(key)) {
throw new DuplicateKeyException(key, "There's another active FSM with the same key");
}
if (fsmRegister.hasRegisteredFsmWithFlowId(flowId)) {
sendErrorResponseToNorthbound(ErrorType.ALREADY_EXISTS, "Could not create flow", format("Flow %s is already creating now", flowId), commandContext);
throw new DuplicateKeyException(key, "There's another active FSM for the same flowId " + flowId);
}
FlowCreateFsm fsm = fsmFactory.newInstance(commandContext, flowId, eventListeners);
fsm.setSharedBandwidthGroupId(sharedBandwidthGroupId);
fsmRegister.registerFsm(key, fsm);
if (requestedFlow.getFlowEncapsulationType() == null) {
requestedFlow.setFlowEncapsulationType(kildaConfigurationRepository.getOrDefault().getFlowEncapsulationType());
}
if (requestedFlow.getPathComputationStrategy() == null) {
requestedFlow.setPathComputationStrategy(kildaConfigurationRepository.getOrDefault().getPathComputationStrategy());
}
FlowCreateContext context = FlowCreateContext.builder().targetFlow(requestedFlow).build();
fsm.start(context);
fsmExecutor.fire(fsm, Event.NEXT, context);
removeIfFinished(fsm, key);
}
use of org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException in project open-kilda by telstra.
the class FlowDeleteService method startFlowDeletion.
private void startFlowDeletion(String key, CommandContext commandContext, String flowId) throws DuplicateKeyException {
log.debug("Handling flow deletion request with key {} and flow ID: {}", key, flowId);
if (fsmRegister.hasRegisteredFsmWithKey(key)) {
throw new DuplicateKeyException(key, "There's another active FSM with the same key");
}
if (fsmRegister.hasRegisteredFsmWithFlowId(flowId)) {
sendErrorResponseToNorthbound(ErrorType.REQUEST_INVALID, "Could not delete flow", format("Flow %s is already deleting now", flowId), commandContext);
throw new DuplicateKeyException(key, "There's another active FSM for the same flowId " + flowId);
}
FlowDeleteFsm fsm = fsmFactory.newInstance(commandContext, flowId, eventListeners);
fsmRegister.registerFsm(key, fsm);
fsm.start();
fsmExecutor.fire(fsm, Event.NEXT, FlowDeleteContext.builder().build());
removeIfFinished(fsm, key);
}
use of org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException in project open-kilda by telstra.
the class FlowUpdateServiceTest method shouldFailUpdateOnErrorDuringCompletingFlowPathInstallation.
@Test
public void shouldFailUpdateOnErrorDuringCompletingFlowPathInstallation() throws RecoverableException, UnroutableFlowException, DuplicateKeyException, UnknownKeyException {
Flow origin = makeFlow();
preparePathComputation(origin.getFlowId(), make3SwitchesPathPair());
FlowRequest request = makeRequest().flowId(origin.getFlowId()).build();
FlowPathRepository repository = setupFlowPathRepositorySpy();
Set<PathId> originalPaths = origin.getPaths().stream().map(FlowPath::getPathId).collect(Collectors.toSet());
doThrow(new RuntimeException(injectedErrorMessage)).when(repository).updateStatus(ArgumentMatchers.argThat(argument -> !originalPaths.contains(argument)), eq(FlowPathStatus.ACTIVE));
FlowUpdateService service = makeService();
service.handleUpdateRequest(dummyRequestKey, commandContext, request);
verifyFlowStatus(origin.getFlowId(), FlowStatus.IN_PROGRESS);
verifyNorthboundSuccessResponse(carrier);
FlowSegmentRequest speakerRequest;
while ((speakerRequest = requests.poll()) != null) {
if (speakerRequest.isVerifyRequest()) {
service.handleAsyncResponse(dummyRequestKey, buildResponseOnVerifyRequest(speakerRequest));
} else {
service.handleAsyncResponse(dummyRequestKey, SpeakerFlowSegmentResponse.builder().messageContext(speakerRequest.getMessageContext()).commandId(speakerRequest.getCommandId()).metadata(speakerRequest.getMetadata()).switchId(speakerRequest.getSwitchId()).success(true).build());
}
}
Flow result = verifyFlowStatus(origin.getFlowId(), FlowStatus.UP);
verifyNoPathReplace(origin, result);
}
use of org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException in project open-kilda by telstra.
the class YFlowDeleteHubBolt method onRequest.
@Override
protected void onRequest(Tuple input) throws PipelineException {
currentKey = pullKey(input);
YFlowDeleteRequest payload = pullValue(input, FIELD_ID_PAYLOAD, YFlowDeleteRequest.class);
try {
yFlowDeleteService.handleRequest(currentKey, getCommandContext(), payload);
} catch (DuplicateKeyException e) {
log.error("Failed to handle a request with key {}. {}", currentKey, e.getMessage());
}
}
Aggregations