Search in sources :

Example 11 with YFlowResources

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");
    }
}
Also used : YFlow(org.openkilda.model.YFlow) YFlowResources(org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources) DeleteSpeakerCommandsRequest(org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)

Aggregations

YFlowResources (org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources)11 EndpointResources (org.openkilda.wfm.topology.flowhs.model.yflow.YFlowResources.EndpointResources)6 SwitchId (org.openkilda.model.SwitchId)3 YFlow (org.openkilda.model.YFlow)3 MeterId (org.openkilda.model.MeterId)2 ArrayList (java.util.ArrayList)1 DeleteSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)1 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)1 YFlowStatsInfoFactory (org.openkilda.messaging.info.stats.YFlowStatsInfoFactory)1 YFlowEndpointResources (org.openkilda.messaging.payload.yflow.YFlowEndpointResources)1 Flow (org.openkilda.model.Flow)1 FlowPath (org.openkilda.model.FlowPath)1 FlowStatus (org.openkilda.model.FlowStatus)1 ResourceAllocationException (org.openkilda.wfm.share.flow.resources.ResourceAllocationException)1 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)1 InsufficientDataException (org.openkilda.wfm.topology.flowhs.exception.InsufficientDataException)1