use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class RemoveYFlowResourcesAction method perform.
@Override
protected void perform(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
stateMachine.clearPendingAndRetriedAndFailedCommands();
String yFlowId = stateMachine.getYFlowId();
YFlow yFlow = getYFlow(yFlowId);
Collection<DeleteSpeakerCommandsRequest> commands = buildYFlowDeleteCommands(yFlow, stateMachine.getCommandContext());
if (commands.isEmpty()) {
stateMachine.saveActionToHistory("No need to remove y-flow meters");
stateMachine.fire(Event.ALL_YFLOW_METERS_REMOVED);
} else {
// emitting
commands.forEach(command -> {
stateMachine.getCarrier().sendSpeakerRequest(command);
stateMachine.addDeleteSpeakerCommand(command.getCommandId(), command);
stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
});
stateMachine.saveActionToHistory("Commands for removing y-flow rules have been sent");
}
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class RemoveYFlowResourcesAction method perform.
@Override
protected void perform(State from, State to, Event event, YFlowDeleteContext context, YFlowDeleteFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
YFlow yFlow = getYFlow(yFlowId);
YFlowResources oldResources;
// This could be a retry.
if (stateMachine.getOldResources() != null) {
oldResources = stateMachine.getOldResources();
} else {
oldResources = new YFlowResources();
stateMachine.setOldResources(oldResources);
}
if (oldResources.getSharedEndpointResources() == null) {
oldResources.setSharedEndpointResources(EndpointResources.builder().endpoint(yFlow.getSharedEndpoint().getSwitchId()).meterId(yFlow.getSharedEndpointMeterId()).build());
}
if (oldResources.getMainPathYPointResources() == null) {
oldResources.setMainPathYPointResources(EndpointResources.builder().endpoint(yFlow.getYPoint()).meterId(yFlow.getMeterId()).build());
}
if (yFlow.isAllocateProtectedPath() && oldResources.getProtectedPathYPointResources() == null) {
oldResources.setProtectedPathYPointResources(EndpointResources.builder().endpoint(yFlow.getProtectedPathYPoint()).meterId(yFlow.getProtectedPathMeterId()).build());
}
stateMachine.clearPendingAndRetriedAndFailedCommands();
Collection<DeleteSpeakerCommandsRequest> commands = stateMachine.getDeleteOldYFlowCommands();
if (commands.isEmpty()) {
stateMachine.saveActionToHistory("No need to remove y-flow meters");
stateMachine.fire(Event.ALL_YFLOW_METERS_REMOVED);
} else {
// emitting
commands.forEach(command -> {
stateMachine.getCarrier().sendSpeakerRequest(command);
stateMachine.addDeleteSpeakerCommand(command.getCommandId(), command);
stateMachine.addPendingCommand(command.getCommandId(), command.getSwitchId());
});
stateMachine.saveActionToHistory("Commands for removing y-flow rules have been sent");
}
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class ValidateYFlowAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, YFlowDeleteContext context, YFlowDeleteFsm stateMachine) {
String yFlowId = stateMachine.getYFlowId();
dashboardLogger.onYFlowDelete(yFlowId);
boolean isOperationAllowed = featureTogglesRepository.getOrDefault().getModifyYFlowEnabled();
if (!isOperationAllowed) {
throw new FlowProcessingException(ErrorType.NOT_PERMITTED, "Y-flow delete feature is disabled");
}
YFlow result = transactionManager.doInTransaction(() -> {
YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
if (yFlow.getStatus() == FlowStatus.IN_PROGRESS) {
throw new FlowProcessingException(ErrorType.REQUEST_INVALID, format("Y-flow %s is in progress now", yFlowId));
}
// Keep it, just in case we have to revert it.
stateMachine.setOriginalYFlowStatus(yFlow.getStatus());
yFlow.setStatus(FlowStatus.IN_PROGRESS);
return yFlow;
});
stateMachine.saveNewEventToHistory("Y-flow was validated successfully", FlowEventData.Event.DELETE);
return Optional.of(buildResponseMessage(result, stateMachine.getCommandContext()));
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class RuleManagerImpl method buildRulesForYFlow.
@Override
public List<SpeakerData> buildRulesForYFlow(List<FlowPath> flowPaths, DataAdapter adapter) {
if (flowPaths == null) {
return Collections.emptyList();
}
FlowPath flowPathForIngress = null;
FlowPath altFlowPathForIngress = null;
FlowPath flowPathForTransit = null;
FlowPath altFlowPathForTransit = null;
for (FlowPath flowPath : flowPaths) {
YFlow yFlow = adapter.getYFlow(flowPath.getPathId());
if (yFlow == null) {
break;
}
SwitchId sharedSwitchId = yFlow.getSharedEndpoint().getSwitchId();
if (sharedSwitchId.equals(flowPath.getSrcSwitchId())) {
if (flowPathForIngress == null) {
flowPathForIngress = flowPath;
} else if (altFlowPathForIngress == null) {
altFlowPathForIngress = flowPath;
}
} else {
if (flowPathForTransit == null) {
flowPathForTransit = flowPath;
} else if (altFlowPathForTransit == null) {
altFlowPathForTransit = flowPath;
}
}
}
if (flowPathForIngress == null || altFlowPathForIngress == null || flowPathForTransit == null || altFlowPathForTransit == null) {
return Collections.emptyList();
}
List<SpeakerData> result = new ArrayList<>(buildIngressYFlowCommands(flowPathForIngress, altFlowPathForIngress, adapter));
result.addAll(buildTransitYFlowCommands(flowPathForTransit, altFlowPathForTransit, adapter));
return result;
}
use of org.openkilda.model.YFlow in project open-kilda by telstra.
the class RuleManagerImpl method buildYFlowRulesForSwitch.
private List<SpeakerData> buildYFlowRulesForSwitch(SwitchId switchId, DataAdapter adapter) {
List<SpeakerData> result = new ArrayList<>();
Set<YFlow> yFlows = new HashSet<>();
Map<String, List<FlowPath>> yFlowIdsWithFlowPaths = new HashMap<>();
for (FlowPath flowPath : adapter.getFlowPaths().values()) {
YFlow yFlow = adapter.getYFlow(flowPath.getPathId());
if (yFlow != null) {
yFlows.add(yFlow);
yFlowIdsWithFlowPaths.computeIfAbsent(yFlow.getYFlowId(), fp -> new ArrayList<>()).add(flowPath);
}
}
yFlows.stream().filter(yFlow -> switchId.equals(yFlow.getSharedEndpoint().getSwitchId()) || switchId.equals(yFlow.getYPoint()) || switchId.equals(yFlow.getProtectedPathYPoint())).forEach(yFlow -> result.addAll(buildRulesForYFlow(yFlowIdsWithFlowPaths.get(yFlow.getYFlowId()), adapter)));
return result;
}
Aggregations