use of org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources 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");
}
}
Aggregations