Search in sources :

Example 1 with PortLoadBalancerData

use of org.onosproject.portloadbalancer.api.PortLoadBalancerData in project onos by opennetworkinglab.

the class PortLoadBalancerManager method onErrorHandler.

private void onErrorHandler(NextObjective nextObjective, PortLoadBalancerId portLoadBalancerId) {
    // There was a failure
    PortLoadBalancerData portLoadBalancerData = new PortLoadBalancerData(portLoadBalancerId);
    // send FAILED event;
    switch(nextObjective.op()) {
        case ADD:
            // If ADD is failing apps do not know the next id; let's update the store
            portLoadBalancerNextStore.remove(portLoadBalancerId);
            portLoadBalancerResStore.remove(portLoadBalancerId);
            portLoadBalancerStore.remove(portLoadBalancerId);
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
            break;
        case ADD_TO_EXISTING:
            // If ADD_TO_EXISTING is failing let's remove the failed ports
            Collection<PortNumber> addedPorts = nextObjective.next().stream().flatMap(t -> t.allInstructions().stream()).filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).collect(Collectors.toList());
            portLoadBalancerStore.compute(portLoadBalancerId, (key, value) -> {
                if (value != null && value.ports() != null && !value.ports().isEmpty()) {
                    value.ports().removeAll(addedPorts);
                }
                return value;
            });
            portLoadBalancerData.setNextId(nextObjective.id());
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
            break;
        case REMOVE_FROM_EXISTING:
            // If REMOVE_TO_EXISTING is failing let's re-add the failed ports
            Collection<PortNumber> removedPorts = nextObjective.next().stream().flatMap(t -> t.allInstructions().stream()).filter(i -> i.type() == Instruction.Type.OUTPUT).map(i -> ((Instructions.OutputInstruction) i).port()).collect(Collectors.toList());
            portLoadBalancerStore.compute(portLoadBalancerId, (key, value) -> {
                if (value != null && value.ports() != null) {
                    value.ports().addAll(removedPorts);
                }
                return value;
            });
            portLoadBalancerData.setNextId(nextObjective.id());
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
            break;
        case VERIFY:
        case REMOVE:
            // If ADD/REMOVE_TO_EXISTING, REMOVE and VERIFY are failing let's send
            // also the info about the next id
            portLoadBalancerData.setNextId(nextObjective.id());
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.FAILED, portLoadBalancerData, portLoadBalancerData));
            break;
        default:
            break;
    }
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MastershipService(org.onosproject.mastership.MastershipService) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) ImmutableMap(com.google.common.collect.ImmutableMap) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) PortLoadBalancerId(org.onosproject.portloadbalancer.api.PortLoadBalancerId) Versioned(org.onosproject.store.service.Versioned) PortLoadBalancerData(org.onosproject.portloadbalancer.api.PortLoadBalancerData) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DeviceEvent(org.onosproject.net.device.DeviceEvent) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) PortLoadBalancer(org.onosproject.portloadbalancer.api.PortLoadBalancer) PortLoadBalancerMode(org.onosproject.portloadbalancer.api.PortLoadBalancerMode) DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) PortLoadBalancerAdminService(org.onosproject.portloadbalancer.api.PortLoadBalancerAdminService) PortLoadBalancerService(org.onosproject.portloadbalancer.api.PortLoadBalancerService) KryoNamespace(org.onlab.util.KryoNamespace) MapEventListener(org.onosproject.store.service.MapEventListener) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DeviceListener(org.onosproject.net.device.DeviceListener) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) PortLoadBalancerEvent(org.onosproject.portloadbalancer.api.PortLoadBalancerEvent) Instruction(org.onosproject.net.flow.instructions.Instruction) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) PortLoadBalancerListener(org.onosproject.portloadbalancer.api.PortLoadBalancerListener) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) PortLoadBalancerData(org.onosproject.portloadbalancer.api.PortLoadBalancerData) PortLoadBalancerEvent(org.onosproject.portloadbalancer.api.PortLoadBalancerEvent) PortNumber(org.onosproject.net.PortNumber)

Example 2 with PortLoadBalancerData

use of org.onosproject.portloadbalancer.api.PortLoadBalancerData in project onos by opennetworkinglab.

the class PortLoadBalancerManager method onSuccessHandler.

private void onSuccessHandler(NextObjective nextObjective, PortLoadBalancerId portLoadBalancerId) {
    // Operation done
    PortLoadBalancerData oldPortLoadBalancerData = new PortLoadBalancerData(portLoadBalancerId);
    PortLoadBalancerData newPortLoadBalancerData = new PortLoadBalancerData(portLoadBalancerId);
    // Other operations will not lead to a generation of an event
    switch(nextObjective.op()) {
        case ADD:
            newPortLoadBalancerData.setNextId(nextObjective.id());
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.INSTALLED, newPortLoadBalancerData, oldPortLoadBalancerData));
            break;
        case REMOVE:
            oldPortLoadBalancerData.setNextId(nextObjective.id());
            post(new PortLoadBalancerEvent(PortLoadBalancerEvent.Type.UNINSTALLED, newPortLoadBalancerData, oldPortLoadBalancerData));
            break;
        default:
            break;
    }
}
Also used : PortLoadBalancerData(org.onosproject.portloadbalancer.api.PortLoadBalancerData) PortLoadBalancerEvent(org.onosproject.portloadbalancer.api.PortLoadBalancerEvent)

Aggregations

PortLoadBalancerData (org.onosproject.portloadbalancer.api.PortLoadBalancerData)2 PortLoadBalancerEvent (org.onosproject.portloadbalancer.api.PortLoadBalancerEvent)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Collectors (java.util.stream.Collectors)1 KryoNamespace (org.onlab.util.KryoNamespace)1 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)1 ClusterService (org.onosproject.cluster.ClusterService)1 LeadershipService (org.onosproject.cluster.LeadershipService)1 NodeId (org.onosproject.cluster.NodeId)1 ApplicationId (org.onosproject.core.ApplicationId)1 CoreService (org.onosproject.core.CoreService)1 MastershipService (org.onosproject.mastership.MastershipService)1 DeviceId (org.onosproject.net.DeviceId)1 PortNumber (org.onosproject.net.PortNumber)1