use of org.openkilda.wfm.share.flow.resources.FlowResources in project open-kilda by telstra.
the class HandleNotRevertedResourceAllocationAction method perform.
@Override
public void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
FlowResources newPrimaryResources = stateMachine.getNewPrimaryResources();
if (newPrimaryResources != null) {
stateMachine.saveErrorToHistory("Failed to revert resource allocation", format("Failed to revert resource allocation: %s", newPrimaryResources));
}
FlowResources newProtectedResources = stateMachine.getNewProtectedResources();
if (newProtectedResources != null) {
stateMachine.saveErrorToHistory("Failed to revert resource allocation", format("Failed to revert resource allocation: %s", newProtectedResources));
}
}
use of org.openkilda.wfm.share.flow.resources.FlowResources in project open-kilda by telstra.
the class AllocateProtectedResourcesAction method allocate.
@Override
protected void allocate(FlowUpdateFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
String flowId = stateMachine.getFlowId();
Set<String> flowIds = Sets.newHashSet(flowId);
if (stateMachine.getBulkUpdateFlowIds() != null) {
flowIds.addAll(stateMachine.getBulkUpdateFlowIds());
}
log.debug("Finding protected path ids for flows {}", flowIds);
List<PathId> pathIdsToReuse = new ArrayList<>(flowPathRepository.findActualPathIdsByFlowIds(flowIds));
pathIdsToReuse.addAll(stateMachine.getRejectedPaths());
Flow tmpFlow = getFlow(flowId);
FlowPathPair oldPaths = new FlowPathPair(tmpFlow.getProtectedForwardPath(), tmpFlow.getProtectedReversePath());
FlowPath primaryForward = getFlowPath(tmpFlow, stateMachine.getNewPrimaryForwardPath());
FlowPath primaryReverse = getFlowPath(tmpFlow, stateMachine.getNewPrimaryReversePath());
Predicate<GetPathsResult> testNonOverlappingPath = path -> (primaryForward == null || !flowPathBuilder.arePathsOverlapped(path.getForward(), primaryForward)) && (primaryReverse == null || !flowPathBuilder.arePathsOverlapped(path.getReverse(), primaryReverse));
PathId newForwardPathId = resourcesManager.generatePathId(flowId);
PathId newReversePathId = resourcesManager.generatePathId(flowId);
log.debug("Finding a new protected path for flow {}", flowId);
GetPathsResult allocatedPaths = allocatePathPair(tmpFlow, newForwardPathId, newReversePathId, false, pathIdsToReuse, oldPaths, true, stateMachine.getSharedBandwidthGroupId(), testNonOverlappingPath);
if (allocatedPaths == null) {
throw new ResourceAllocationException("Unable to allocate a path");
}
if (!testNonOverlappingPath.test(allocatedPaths)) {
stateMachine.saveActionToHistory("Couldn't find non overlapping protected path");
} else {
log.debug("New protected paths have been allocated: {}", allocatedPaths);
stateMachine.setNewProtectedForwardPath(newForwardPathId);
stateMachine.setNewProtectedReversePath(newReversePathId);
stateMachine.setBackUpProtectedPathComputationWayUsed(allocatedPaths.isBackUpPathComputationWayUsed());
log.debug("Allocating resources for a new protected path of flow {}", flowId);
FlowResources flowResources = allocateFlowResources(tmpFlow, newForwardPathId, newReversePathId);
stateMachine.setNewProtectedResources(flowResources);
FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, false, stateMachine.getSharedBandwidthGroupId());
log.debug("New protected path has been created: {}", createdPaths);
saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlow, "protected", createdPaths);
}
}
use of org.openkilda.wfm.share.flow.resources.FlowResources in project open-kilda by telstra.
the class BaseResourceAllocationAction method allocateFlowResources.
@SneakyThrows
protected FlowResources allocateFlowResources(Flow flow, PathId forwardPathId, PathId reversePathId) throws ResourceAllocationException {
RetryPolicy<FlowResources> resourceAllocationRetryPolicy = transactionManager.<FlowResources>getDefaultRetryPolicy().handle(ResourceAllocationException.class).handle(ConstraintViolationException.class).onRetry(e -> log.warn("Failure in resource allocation. Retrying #{}...", e.getAttemptCount(), e.getLastFailure())).onRetriesExceeded(e -> log.warn("Failure in resource allocation. No more retries", e.getFailure())).withMaxRetries(resourceAllocationRetriesLimit);
FlowResources flowResources = transactionManager.doInTransaction(resourceAllocationRetryPolicy, () -> resourcesManager.allocateFlowResources(flow, forwardPathId, reversePathId));
log.debug("Resources have been allocated: {}", flowResources);
return flowResources;
}
use of org.openkilda.wfm.share.flow.resources.FlowResources in project open-kilda by telstra.
the class ResourcesAllocationAction method allocateMainPath.
private void allocateMainPath(FlowCreateFsm stateMachine) throws UnroutableFlowException, RecoverableException, ResourceAllocationException {
GetPathsResult paths = pathComputer.getPath(getFlow(stateMachine.getFlowId()));
stateMachine.setBackUpPrimaryPathComputationWayUsed(paths.isBackUpPathComputationWayUsed());
log.debug("Creating the primary path {} for flow {}", paths, stateMachine.getFlowId());
transactionManager.doInTransaction(() -> {
Flow flow = getFlow(stateMachine.getFlowId());
FlowResources flowResources = resourcesManager.allocateFlowResources(flow);
final FlowSegmentCookieBuilder cookieBuilder = FlowSegmentCookie.builder().flowEffectiveId(flowResources.getUnmaskedCookie());
updateSwitchRelatedFlowProperties(flow);
FlowPath forward = flowPathBuilder.buildFlowPath(flow, flowResources.getForward(), paths.getForward(), cookieBuilder.direction(FlowPathDirection.FORWARD).build(), false, stateMachine.getSharedBandwidthGroupId());
forward.setStatus(FlowPathStatus.IN_PROGRESS);
flowPathRepository.add(forward);
flow.setForwardPath(forward);
FlowPath reverse = flowPathBuilder.buildFlowPath(flow, flowResources.getReverse(), paths.getReverse(), cookieBuilder.direction(FlowPathDirection.REVERSE).build(), false, stateMachine.getSharedBandwidthGroupId());
reverse.setStatus(FlowPathStatus.IN_PROGRESS);
flowPathRepository.add(reverse);
flow.setReversePath(reverse);
updateIslsForFlowPath(forward.getPathId());
updateIslsForFlowPath(reverse.getPathId());
stateMachine.setForwardPathId(forward.getPathId());
stateMachine.setReversePathId(reverse.getPathId());
log.debug("Allocated resources for the flow {}: {}", flow.getFlowId(), flowResources);
stateMachine.getFlowResources().add(flowResources);
});
}
use of org.openkilda.wfm.share.flow.resources.FlowResources in project open-kilda by telstra.
the class SwapFlowPathsAction method swapProtectedPaths.
private void swapProtectedPaths(FlowRerouteFsm stateMachine) {
PathId newForward = stateMachine.getNewProtectedForwardPath();
PathId newReverse = stateMachine.getNewProtectedReversePath();
if (newForward != null && newReverse != null) {
transactionManager.doInTransaction(() -> {
Flow flow = getFlow(stateMachine.getFlowId());
FlowPath oldForward = flow.getProtectedForwardPath();
if (oldForward != null) {
stateMachine.setOldProtectedForwardPath(oldForward.getPathId());
stateMachine.setOldProtectedForwardPathStatus(oldForward.getStatus());
oldForward.setStatus(FlowPathStatus.IN_PROGRESS);
}
FlowPath oldReverse = flow.getProtectedReversePath();
if (oldReverse != null) {
stateMachine.setOldProtectedReversePath(oldReverse.getPathId());
stateMachine.setOldProtectedReversePathStatus(oldReverse.getStatus());
oldReverse.setStatus(FlowPathStatus.IN_PROGRESS);
}
if (oldForward != null || oldReverse != null) {
FlowResources oldResources = getResources(flow, oldForward != null ? oldForward : oldReverse, oldReverse != null ? oldReverse : oldForward);
stateMachine.getOldResources().add(oldResources);
}
flow.setProtectedForwardPathId(newForward);
flow.setProtectedReversePathId(newReverse);
log.debug("Swapping the protected paths {}/{} with {}/{}", oldForward != null ? oldForward.getPathId() : null, oldReverse != null ? oldReverse.getPathId() : null, newForward, newReverse);
});
saveHistory(stateMachine, stateMachine.getFlowId(), newForward, newReverse);
}
}
Aggregations