use of org.openkilda.wfm.error.FlowNotFoundException in project open-kilda by telstra.
the class ResourcesAllocationAction method allocateProtectedPath.
private void allocateProtectedPath(FlowCreateFsm stateMachine) throws UnroutableFlowException, RecoverableException, ResourceAllocationException, FlowNotFoundException {
String flowId = stateMachine.getFlowId();
Flow tmpFlow = getFlow(flowId);
if (!tmpFlow.isAllocateProtectedPath()) {
return;
}
tmpFlow.setDiverseGroupId(getFlowDiverseGroupFromContext(flowId).orElseThrow(() -> new FlowNotFoundException(flowId)));
GetPathsResult protectedPath = pathComputer.getPath(tmpFlow);
stateMachine.setBackUpProtectedPathComputationWayUsed(protectedPath.isBackUpPathComputationWayUsed());
boolean overlappingProtectedPathFound = flowPathBuilder.arePathsOverlapped(protectedPath.getForward(), tmpFlow.getForwardPath()) || flowPathBuilder.arePathsOverlapped(protectedPath.getReverse(), tmpFlow.getReversePath());
if (overlappingProtectedPathFound) {
log.info("Couldn't find non overlapping protected path. Result flow state: {}", tmpFlow);
throw new UnroutableFlowException("Couldn't find non overlapping protected path", tmpFlow.getFlowId());
}
log.debug("Creating the protected path {} for flow {}", protectedPath, tmpFlow);
transactionManager.doInTransaction(() -> {
Flow flow = getFlow(flowId);
FlowResources flowResources = resourcesManager.allocateFlowResources(flow);
final FlowSegmentCookieBuilder cookieBuilder = FlowSegmentCookie.builder().flowEffectiveId(flowResources.getUnmaskedCookie());
FlowPath forward = flowPathBuilder.buildFlowPath(flow, flowResources.getForward(), protectedPath.getForward(), cookieBuilder.direction(FlowPathDirection.FORWARD).build(), false, stateMachine.getSharedBandwidthGroupId());
forward.setStatus(FlowPathStatus.IN_PROGRESS);
flowPathRepository.add(forward);
flow.setProtectedForwardPath(forward);
FlowPath reverse = flowPathBuilder.buildFlowPath(flow, flowResources.getReverse(), protectedPath.getReverse(), cookieBuilder.direction(FlowPathDirection.REVERSE).build(), false, stateMachine.getSharedBandwidthGroupId());
reverse.setStatus(FlowPathStatus.IN_PROGRESS);
flowPathRepository.add(reverse);
flow.setProtectedReversePath(reverse);
updateIslsForFlowPath(forward.getPathId());
updateIslsForFlowPath(reverse.getPathId());
stateMachine.setProtectedForwardPathId(forward.getPathId());
stateMachine.setProtectedReversePathId(reverse.getPathId());
log.debug("Allocated resources for the flow {}: {}", flow.getFlowId(), flowResources);
stateMachine.getFlowResources().add(flowResources);
});
}
use of org.openkilda.wfm.error.FlowNotFoundException in project open-kilda by telstra.
the class ResourcesAllocationAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, FlowCreateContext context, FlowCreateFsm stateMachine) throws FlowProcessingException {
try {
String flowId = stateMachine.getFlowId();
log.debug("Allocation resources has been started");
stateMachine.setPathsBeenAllocated(false);
if (context != null && context.getTargetFlow() != null) {
createFlow(context.getTargetFlow());
} else if (!flowRepository.exists(flowId)) {
log.warn("Flow {} has been deleted while creation was in progress", flowId);
return Optional.empty();
}
createPaths(stateMachine);
log.debug("Resources allocated successfully for the flow {}", flowId);
stateMachine.setPathsBeenAllocated(true);
Flow resultFlow = getFlow(flowId);
createSpeakerRequestFactories(stateMachine, resultFlow);
saveHistory(stateMachine, resultFlow);
if (resultFlow.isOneSwitchFlow()) {
stateMachine.fire(Event.SKIP_NON_INGRESS_RULES_INSTALL);
} else {
stateMachine.fireNext(context);
}
// Notify about successful allocation.
stateMachine.notifyEventListeners(listener -> listener.onResourcesAllocated(flowId));
return Optional.of(buildResponseMessage(resultFlow, stateMachine.getCommandContext()));
} catch (UnroutableFlowException | RecoverableException e) {
throw new FlowProcessingException(ErrorType.NOT_FOUND, "Not enough bandwidth or no path found. " + e.getMessage(), e);
} catch (ResourceAllocationException e) {
throw new FlowProcessingException(ErrorType.INTERNAL_ERROR, "Failed to allocate flow resources. " + e.getMessage(), e);
} catch (FlowNotFoundException e) {
throw new FlowProcessingException(ErrorType.NOT_FOUND, "Couldn't find the diverse flow. " + e.getMessage(), e);
} catch (FlowAlreadyExistException e) {
if (!stateMachine.retryIfAllowed()) {
throw new FlowProcessingException(ErrorType.INTERNAL_ERROR, e.getMessage(), e);
} else {
// we have retried the operation, no need to respond.
log.debug(e.getMessage(), e);
return Optional.empty();
}
}
}
use of org.openkilda.wfm.error.FlowNotFoundException in project open-kilda by telstra.
the class FlowValidationFsm method receiveData.
protected void receiveData(State from, State to, Event event, Object context) {
Flow flow;
try {
flow = service.checkFlowStatusAndGetFlow(flowId);
} catch (FlowNotFoundException e) {
log.error("Flow {} not found when sending commands to SpeakerWorkerBolt", flowId, e);
sendException(e.getMessage(), "Receiving rules operation in FlowValidationFsm", ErrorType.NOT_FOUND);
return;
} catch (IllegalFlowStateException e) {
log.error("Could not validate flow: Flow {} is in DOWN state", flowId, e);
sendException("Could not validate flow", format("Could not validate flow: Flow %s is in DOWN state", flowId), ErrorType.UNPROCESSABLE_REQUEST);
return;
}
List<SwitchId> switchIds = service.getSwitchIdListByFlowId(flowId);
awaitingRules = switchIds.size();
log.debug("Send commands to get rules on the switches");
switchIds.forEach(switchId -> getCarrier().sendSpeakerRequest(flowId, new DumpRulesForFlowHsRequest(switchId)));
log.debug("Send commands to get meters on the termination switches");
awaitingMeters = TERMINATION_SWITCHES_COUNT;
getCarrier().sendSpeakerRequest(flowId, new DumpMetersForFlowHsRequest(flow.getSrcSwitchId()));
getCarrier().sendSpeakerRequest(flowId, new DumpMetersForFlowHsRequest(flow.getDestSwitchId()));
log.debug("Send commands to get groups on the termination switches");
awaitingGroups = TERMINATION_SWITCHES_COUNT;
getCarrier().sendSpeakerRequest(flowId, new DumpGroupsForFlowHsRequest(flow.getSrcSwitchId()));
getCarrier().sendSpeakerRequest(flowId, new DumpGroupsForFlowHsRequest(flow.getDestSwitchId()));
}
use of org.openkilda.wfm.error.FlowNotFoundException in project open-kilda by telstra.
the class FlowValidationService method validateFlow.
/**
* Validate flow.
*/
public List<FlowValidationResponse> validateFlow(String flowId, List<SwitchFlowEntries> switchFlowEntries, List<SwitchMeterEntries> switchMeterEntries, List<SwitchGroupEntries> switchGroupEntries) throws FlowNotFoundException, SwitchNotFoundException {
Map<SwitchId, List<SimpleSwitchRule>> switchRules = new HashMap<>();
int rulesCount = 0;
int metersCount = 0;
for (SwitchFlowEntries switchRulesEntries : switchFlowEntries) {
SwitchMeterEntries switchMeters = switchMeterEntries.stream().filter(meterEntries -> switchRulesEntries.getSwitchId().equals(meterEntries.getSwitchId())).findFirst().orElse(null);
SwitchGroupEntries switchGroup = switchGroupEntries.stream().filter(groupEntries -> switchRulesEntries.getSwitchId().equals(groupEntries.getSwitchId())).findFirst().orElse(null);
List<SimpleSwitchRule> simpleSwitchRules = simpleSwitchRuleConverter.convertSwitchFlowEntriesToSimpleSwitchRules(switchRulesEntries, switchMeters, switchGroup);
switchRules.put(switchRulesEntries.getSwitchId(), simpleSwitchRules);
rulesCount += Optional.ofNullable(switchRulesEntries.getFlowEntries()).map(List::size).orElse(0);
metersCount += Optional.ofNullable(switchMeters).map(SwitchMeterEntries::getMeterEntries).map(List::size).orElse(0);
}
Optional<Flow> foundFlow = flowRepository.findById(flowId);
if (!foundFlow.isPresent()) {
throw new FlowNotFoundException(flowId);
}
Flow flow = foundFlow.get();
if (flow.getForwardPath() == null) {
throw new InvalidPathException(flowId, "Forward path was not returned.");
}
if (flow.getReversePath() == null) {
throw new InvalidPathException(flowId, "Reverse path was not returned.");
}
List<FlowValidationResponse> flowValidationResponse = new ArrayList<>();
List<SimpleSwitchRule> forwardRules = getSimpleSwitchRules(flow, flow.getForwardPath(), flow.getReversePath());
flowValidationResponse.add(compare(switchRules, forwardRules, flowId, rulesCount, metersCount));
List<SimpleSwitchRule> reverseRules = getSimpleSwitchRules(flow, flow.getReversePath(), flow.getForwardPath());
flowValidationResponse.add(compare(switchRules, reverseRules, flowId, rulesCount, metersCount));
if (flow.getProtectedForwardPath() != null) {
List<SimpleSwitchRule> forwardProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath());
flowValidationResponse.add(compare(switchRules, forwardProtectedRules, flowId, rulesCount, metersCount));
}
if (flow.getProtectedReversePath() != null) {
List<SimpleSwitchRule> reverseProtectedRules = getSimpleSwitchRules(flow, flow.getProtectedReversePath(), flow.getProtectedForwardPath());
flowValidationResponse.add(compare(switchRules, reverseProtectedRules, flowId, rulesCount, metersCount));
}
return flowValidationResponse;
}
use of org.openkilda.wfm.error.FlowNotFoundException in project open-kilda by telstra.
the class YFlowReadService method getYFlowPaths.
/**
* Gets y-flow paths.
*/
public YFlowPathsResponse getYFlowPaths(@NonNull String yFlowId) throws FlowNotFoundException {
return transactionManager.doInTransaction(getReadOperationRetryPolicy(), () -> {
Set<YSubFlow> subFlows = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowNotFoundException(yFlowId)).getSubFlows();
Set<FlowPath> mainPaths = new HashSet<>();
Set<FlowPath> protectedPaths = new HashSet<>();
for (YSubFlow subFlow : subFlows) {
Flow flow = subFlow.getFlow();
mainPaths.add(flow.getForwardPath());
if (flow.isAllocateProtectedPath() && flow.getProtectedForwardPath() != null) {
protectedPaths.add(flow.getProtectedForwardPath());
}
}
List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(mainPaths);
PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
PathInfoData sharedProtectedPath;
// At least 2 paths required to calculate Y-point.
if (protectedPaths.size() < 2) {
sharedProtectedPath = new PathInfoData();
} else {
List<PathSegment> pathSegments = IntersectionComputer.calculatePathIntersectionFromSource(protectedPaths);
sharedProtectedPath = FlowPathMapper.INSTANCE.map(pathSegments);
}
List<SubFlowPathDto> subFlowPathDtos = mainPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
List<SubFlowPathDto> subFlowProtectedPathDtos = protectedPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
return new YFlowPathsResponse(sharedPath, subFlowPathDtos, sharedProtectedPath, subFlowProtectedPathDtos);
});
}
Aggregations