use of org.onosproject.portloadbalancer.api.PortLoadBalancerId 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;
}
}
use of org.onosproject.portloadbalancer.api.PortLoadBalancerId in project onos by opennetworkinglab.
the class PortLoadBalancerRemoveCommand method doExecute.
@Override
protected void doExecute() {
DeviceId deviceId = DeviceId.deviceId(deviceIdStr);
int portLoadBalancerKey = Integer.parseInt(keyStr);
PortLoadBalancerAdminService portLoadBalancerAdminService = get(PortLoadBalancerAdminService.class);
PortLoadBalancerId portLoadBalancerId = new PortLoadBalancerId(deviceId, portLoadBalancerKey);
PortLoadBalancer portLoadBalancer = portLoadBalancerAdminService.remove(portLoadBalancerId);
print("Removal of %s %s", portLoadBalancerId, portLoadBalancer != null ? EXECUTED : FAILED);
}
use of org.onosproject.portloadbalancer.api.PortLoadBalancerId in project onos by opennetworkinglab.
the class PortLoadBalancerListCommand method doExecute.
@Override
public void doExecute() {
PortLoadBalancerService service = get(PortLoadBalancerService.class);
// Get port load balancers and reservations
Map<PortLoadBalancerId, PortLoadBalancer> portLoadBalancerStore = service.getPortLoadBalancers();
Map<PortLoadBalancerId, ApplicationId> portLoadBalancerResStore = service.getReservations();
// Print id -> ports, mode, reservation
portLoadBalancerStore.forEach((portLoadBalancerId, portLoadBalancer) -> print("%s -> %s, %s, %s", portLoadBalancerId, portLoadBalancer.ports(), portLoadBalancer.mode(), portLoadBalancerResStore.get(portLoadBalancerId) == null ? AVAILABLE : portLoadBalancerResStore.get(portLoadBalancerId).name()));
}
use of org.onosproject.portloadbalancer.api.PortLoadBalancerId in project onos by opennetworkinglab.
the class PortLoadBalancerAddCommand method doExecute.
@Override
protected void doExecute() {
DeviceId deviceId = DeviceId.deviceId(deviceIdStr);
int portLoadBalancerKey = Integer.parseInt(keyStr);
PortLoadBalancerMode mode = PortLoadBalancerMode.valueOf(modeStr.toUpperCase());
Set<PortNumber> ports = Sets.newHashSet(portsStr).stream().map(PortNumber::fromString).collect(Collectors.toSet());
PortLoadBalancerAdminService portLoadBalancerAdminService = get(PortLoadBalancerAdminService.class);
PortLoadBalancerId portLoadBalancerId = new PortLoadBalancerId(deviceId, portLoadBalancerKey);
PortLoadBalancer portLoadBalancer = portLoadBalancerAdminService.createOrUpdate(portLoadBalancerId, ports, mode);
print("%s of %s executed", portLoadBalancer == null ? CREATE : UPDATE, portLoadBalancerId);
}
Aggregations