use of org.openkilda.wfm.share.flow.resources.FlowResources in project open-kilda by telstra.
the class SwapFlowPathsAction method swapPrimaryPaths.
private void swapPrimaryPaths(FlowRerouteFsm 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) {
FlowResources oldResources = getResources(flow, oldForward != null ? oldForward : oldReverse, oldReverse != null ? oldReverse : oldForward);
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.wfm.share.flow.resources.FlowResources in project open-kilda by telstra.
the class AllocatePrimaryResourcesAction 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 paths for flows {}", flowIds);
List<PathId> pathIdsToReuse = new ArrayList<>(flowPathRepository.findActualPathIdsByFlowIds(flowIds));
pathIdsToReuse.addAll(stateMachine.getRejectedPaths());
Flow tmpFlow = getFlow(flowId);
FlowPathPair oldPaths = new FlowPathPair(tmpFlow.getForwardPath(), tmpFlow.getReversePath());
PathId newForwardPathId = resourcesManager.generatePathId(flowId);
PathId newReversePathId = resourcesManager.generatePathId(flowId);
log.debug("Finding a new primary path for flow {}", flowId);
GetPathsResult allocatedPaths = allocatePathPair(tmpFlow, newForwardPathId, newReversePathId, false, pathIdsToReuse, oldPaths, true, stateMachine.getSharedBandwidthGroupId(), path -> true);
if (allocatedPaths == null) {
throw new ResourceAllocationException("Unable to allocate a path");
}
log.debug("New primary paths have been allocated: {}", allocatedPaths);
stateMachine.setBackUpPrimaryPathComputationWayUsed(allocatedPaths.isBackUpPathComputationWayUsed());
stateMachine.setNewPrimaryForwardPath(newForwardPathId);
stateMachine.setNewPrimaryReversePath(newReversePathId);
log.debug("Allocating resources for a new primary path of flow {}", flowId);
FlowResources flowResources = allocateFlowResources(tmpFlow, newForwardPathId, newReversePathId);
stateMachine.setNewPrimaryResources(flowResources);
FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, false, stateMachine.getSharedBandwidthGroupId());
log.debug("New primary path has been created: {}", createdPaths);
setMirrorPointsToNewPath(oldPaths.getForwardPathId(), newForwardPathId);
setMirrorPointsToNewPath(oldPaths.getReversePathId(), newReversePathId);
saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlow, "primary", createdPaths);
}
use of org.openkilda.wfm.share.flow.resources.FlowResources in project open-kilda by telstra.
the class SwapFlowPathsAction method swapProtectedPaths.
private void swapProtectedPaths(FlowUpdateFsm stateMachine) {
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) {
FlowEncapsulationType oldFlowEncapsulationType = stateMachine.getOriginalFlow().getFlowEncapsulationType();
FlowResources oldProtectedResources = getResources(oldForward != null ? oldForward : oldReverse, oldReverse != null ? oldReverse : oldForward, oldFlowEncapsulationType);
stateMachine.getOldResources().add(oldProtectedResources);
}
PathId newForward = stateMachine.getNewProtectedForwardPath();
PathId newReverse = stateMachine.getNewProtectedReversePath();
flow.setProtectedForwardPathId(newForward);
flow.setProtectedReversePathId(newReverse);
if (newForward != null && newReverse != null) {
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);
}
});
}
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, FlowRerouteContext context, FlowRerouteFsm 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.
@TimedExecution("fsm.resource_allocation_protected")
@Override
protected void allocate(FlowRerouteFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
String flowId = stateMachine.getFlowId();
Flow tmpFlowCopy = getFlow(flowId);
// Detach the entity to avoid propagation to the database.
flowRepository.detach(tmpFlowCopy);
if (stateMachine.getNewEncapsulationType() != null) {
// This is for PCE to use proper (updated) encapsulation type.
tmpFlowCopy.setEncapsulationType(stateMachine.getNewEncapsulationType());
}
FlowPathPair oldPaths = new FlowPathPair(tmpFlowCopy.getProtectedForwardPath(), tmpFlowCopy.getProtectedReversePath());
FlowPath primaryForward = tmpFlowCopy.getPath(stateMachine.getNewPrimaryForwardPath()).orElse(tmpFlowCopy.getForwardPath());
FlowPath primaryReverse = tmpFlowCopy.getPath(stateMachine.getNewPrimaryReversePath()).orElse(tmpFlowCopy.getReversePath());
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);
List<PathId> pathsToReuse = Lists.newArrayList(tmpFlowCopy.getProtectedForwardPathId(), tmpFlowCopy.getProtectedReversePathId());
pathsToReuse.addAll(stateMachine.getRejectedPaths());
log.debug("Finding a new protected path for flow {}", flowId);
GetPathsResult allocatedPaths = allocatePathPair(tmpFlowCopy, newForwardPathId, newReversePathId, stateMachine.isIgnoreBandwidth(), pathsToReuse, oldPaths, stateMachine.isRecreateIfSamePath(), stateMachine.getSharedBandwidthGroupId(), testNonOverlappingPath);
if (allocatedPaths != null) {
stateMachine.setBackUpProtectedPathComputationWayUsed(allocatedPaths.isBackUpPathComputationWayUsed());
if (!testNonOverlappingPath.test(allocatedPaths)) {
stateMachine.saveActionToHistory("Couldn't find non overlapping protected path. Skipped creating it");
stateMachine.fireNoPathFound("Couldn't find non overlapping protected path");
} else {
log.debug("New protected paths have been allocated: {}", allocatedPaths);
stateMachine.setNewProtectedForwardPath(newForwardPathId);
stateMachine.setNewProtectedReversePath(newReversePathId);
log.debug("Allocating resources for a new protected path of flow {}", flowId);
FlowResources flowResources = allocateFlowResources(tmpFlowCopy, newForwardPathId, newReversePathId);
stateMachine.setNewProtectedResources(flowResources);
FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, stateMachine.isIgnoreBandwidth(), stateMachine.getSharedBandwidthGroupId());
log.debug("New protected paths have been created: {}", createdPaths);
saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlowCopy, "protected", createdPaths);
}
} else {
stateMachine.saveActionToHistory("Found the same protected path. Skipped creating of it");
}
}
Aggregations