use of org.openkilda.model.PathId in project open-kilda by telstra.
the class SwapFlowPathsAction method swapPrimaryPaths.
private void swapPrimaryPaths(FlowUpdateFsm stateMachine) {
PathId newForward = stateMachine.getNewPrimaryForwardPath();
PathId newReverse = stateMachine.getNewPrimaryReversePath();
if (newForward != null && newReverse != null) {
transactionManager.doInTransaction(() -> {
Flow flow = getFlow(stateMachine.getFlowId());
FlowPath oldForward = flow.getForwardPath();
if (oldForward != null) {
stateMachine.setOldPrimaryForwardPath(oldForward.getPathId());
stateMachine.setOldPrimaryForwardPathStatus(oldForward.getStatus());
oldForward.setStatus(FlowPathStatus.IN_PROGRESS);
}
FlowPath oldReverse = flow.getReversePath();
if (oldReverse != null) {
stateMachine.setOldPrimaryReversePath(oldReverse.getPathId());
stateMachine.setOldPrimaryReversePathStatus(oldReverse.getStatus());
oldReverse.setStatus(FlowPathStatus.IN_PROGRESS);
}
if (oldForward != null || oldReverse != null) {
FlowEncapsulationType oldFlowEncapsulationType = stateMachine.getOriginalFlow().getFlowEncapsulationType();
FlowResources oldResources = getResources(oldForward != null ? oldForward : oldReverse, oldReverse != null ? oldReverse : oldForward, oldFlowEncapsulationType);
stateMachine.getOldResources().add(oldResources);
}
flow.setForwardPathId(newForward);
flow.setReversePathId(newReverse);
log.debug("Swapping the primary paths {}/{} with {}/{}", oldForward != null ? oldForward.getPathId() : null, oldReverse != null ? oldReverse.getPathId() : null, newForward, newReverse);
});
saveHistory(stateMachine, stateMachine.getFlowId(), newForward, newReverse);
}
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class CompleteFlowPathInstallationAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
PathId newPrimaryForward = stateMachine.getNewPrimaryForwardPath();
PathId newPrimaryReverse = stateMachine.getNewPrimaryReversePath();
FlowPathStatus primaryPathStatus;
if (stateMachine.isBackUpPrimaryPathComputationWayUsed()) {
primaryPathStatus = FlowPathStatus.DEGRADED;
} else {
primaryPathStatus = FlowPathStatus.ACTIVE;
}
log.debug("Completing installation of the flow primary path {} / {}", newPrimaryForward, newPrimaryReverse);
transactionManager.doInTransaction(() -> {
flowPathRepository.updateStatus(newPrimaryForward, primaryPathStatus);
flowPathRepository.updateStatus(newPrimaryReverse, primaryPathStatus);
});
stateMachine.saveActionToHistory("Flow paths were installed", format("The flow paths %s / %s were installed", newPrimaryForward, newPrimaryReverse));
if (stateMachine.getNewProtectedForwardPath() != null && stateMachine.getNewProtectedReversePath() != null) {
PathId newForward = stateMachine.getNewProtectedForwardPath();
PathId newReverse = stateMachine.getNewProtectedReversePath();
FlowPathStatus protectedPathStatus;
if (stateMachine.isBackUpProtectedPathComputationWayUsed()) {
protectedPathStatus = FlowPathStatus.DEGRADED;
} else {
protectedPathStatus = FlowPathStatus.ACTIVE;
}
log.debug("Completing installation of the flow protected path {} / {}", newForward, newReverse);
transactionManager.doInTransaction(() -> {
flowPathRepository.updateStatus(newForward, protectedPathStatus);
flowPathRepository.updateStatus(newReverse, protectedPathStatus);
});
stateMachine.saveActionToHistory("Flow paths were installed", format("The flow paths %s / %s were installed", newForward, newReverse));
}
}
use of org.openkilda.model.PathId 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.model.PathId in project open-kilda by telstra.
the class CompleteFlowPathRemovalAction method removeOldProtectedFlowPaths.
private void removeOldProtectedFlowPaths(Flow originalFlow, FlowUpdateFsm stateMachine) {
PathId oldProtectedForwardPathId = stateMachine.getOldProtectedForwardPath();
PathId oldProtectedReversePathId = stateMachine.getOldProtectedReversePath();
if (oldProtectedForwardPathId != null || oldProtectedReversePathId != null) {
FlowPath oldProtectedForward = flowPathRepository.remove(oldProtectedForwardPathId).orElse(null);
FlowPath oldProtectedReverse = flowPathRepository.remove(oldProtectedReversePathId).orElse(null);
FlowPathPair removedPaths = null;
if (oldProtectedForward != null) {
if (oldProtectedReverse != null) {
log.debug("Removed the flow paths {} / {}", oldProtectedForward, oldProtectedReverse);
removedPaths = new FlowPathPair(oldProtectedForward, oldProtectedReverse);
updateIslsForFlowPath(removedPaths.getForward(), removedPaths.getReverse());
} else {
log.debug("Removed the flow path {} (no reverse pair)", oldProtectedForward);
// TODO: History dumps require paired paths, fix it to support any (without opposite one).
removedPaths = new FlowPathPair(oldProtectedForward, oldProtectedForward);
updateIslsForFlowPath(removedPaths.getForward());
}
} else if (oldProtectedReverse != null) {
log.debug("Removed the flow path {} (no forward pair)", oldProtectedReverse);
// TODO: History dumps require paired paths, fix it to support any (without opposite one).
removedPaths = new FlowPathPair(oldProtectedReverse, oldProtectedReverse);
updateIslsForFlowPath(removedPaths.getReverse());
}
if (removedPaths != null) {
saveRemovalActionWithDumpToHistory(stateMachine, originalFlow, removedPaths);
}
}
}
use of org.openkilda.model.PathId in project open-kilda by telstra.
the class CompleteFlowPathRemovalAction method removeOldPrimaryFlowPaths.
private void removeOldPrimaryFlowPaths(Flow originalFlow, FlowUpdateFsm stateMachine) {
PathId oldPrimaryForwardPathId = stateMachine.getOldPrimaryForwardPath();
PathId oldPrimaryReversePathId = stateMachine.getOldPrimaryReversePath();
if (oldPrimaryForwardPathId != null || oldPrimaryReversePathId != null) {
FlowPath oldPrimaryForward = flowPathRepository.remove(oldPrimaryForwardPathId).orElse(null);
FlowPath oldPrimaryReverse = flowPathRepository.remove(oldPrimaryReversePathId).orElse(null);
FlowPathPair removedPaths = null;
if (oldPrimaryForward != null) {
if (oldPrimaryReverse != null) {
log.debug("Removed the flow paths {} / {}", oldPrimaryForward, oldPrimaryReverse);
removedPaths = new FlowPathPair(oldPrimaryForward, oldPrimaryReverse);
updateIslsForFlowPath(removedPaths.getForward(), removedPaths.getReverse());
} else {
log.debug("Removed the flow path {} (no reverse pair)", oldPrimaryForward);
// TODO: History dumps require paired paths, fix it to support any (without opposite one).
removedPaths = new FlowPathPair(oldPrimaryForward, oldPrimaryForward);
updateIslsForFlowPath(removedPaths.getForward());
}
} else if (oldPrimaryReverse != null) {
log.debug("Removed the flow path {} (no forward pair)", oldPrimaryReverse);
// TODO: History dumps require paired paths, fix it to support any (without opposite one).
removedPaths = new FlowPathPair(oldPrimaryReverse, oldPrimaryReverse);
updateIslsForFlowPath(removedPaths.getReverse());
}
if (removedPaths != null) {
saveRemovalActionWithDumpToHistory(stateMachine, originalFlow, removedPaths);
}
}
}
Aggregations