use of org.onosproject.portloadbalancer.api.PortLoadBalancer 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.PortLoadBalancer in project onos by opennetworkinglab.
the class PortLoadBalancerManager method activate.
@Activate
public void activate() {
appId = coreService.registerApplication(APP_NAME);
portLoadBalancerEventExecutor = Executors.newSingleThreadExecutor(groupedThreads("portloadbalancer-event", "%d", log));
portLoadBalancerProvExecutor = Executors.newSingleThreadExecutor(groupedThreads("portloadbalancer-prov", "%d", log));
deviceEventExecutor = Executors.newSingleThreadScheduledExecutor(groupedThreads("portloadbalancer-dev-event", "%d", log));
portLoadBalancerStoreListener = new PortLoadBalancerStoreListener();
portLoadBalancerNextStoreListener = new PortLoadBalancerNextStoreListener();
portLoadBalancerResStoreListener = new PortLoadBalancerResStoreListener();
KryoNamespace serializer = KryoNamespace.newBuilder().register(KryoNamespaces.API).register(PortLoadBalancer.class).register(PortLoadBalancerId.class).register(PortLoadBalancerMode.class).build();
portLoadBalancerStore = storageService.<PortLoadBalancerId, PortLoadBalancer>consistentMapBuilder().withName("onos-portloadbalancer-store").withRelaxedReadConsistency().withSerializer(Serializer.using(serializer)).build();
portLoadBalancerStore.addListener(portLoadBalancerStoreListener);
portLoadBalancerNextStore = storageService.<PortLoadBalancerId, Integer>consistentMapBuilder().withName("onos-portloadbalancer-next-store").withRelaxedReadConsistency().withSerializer(Serializer.using(serializer)).build();
portLoadBalancerNextStore.addListener(portLoadBalancerNextStoreListener);
portLoadBalancerResStore = storageService.<PortLoadBalancerId, ApplicationId>consistentMapBuilder().withName("onos-portloadbalancer-res-store").withRelaxedReadConsistency().withSerializer(Serializer.using(serializer)).build();
portLoadBalancerResStore.addListener(portLoadBalancerResStoreListener);
deviceService.addListener(deviceListener);
log.info("Started");
}
use of org.onosproject.portloadbalancer.api.PortLoadBalancer 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.PortLoadBalancer in project onos by opennetworkinglab.
the class PortLoadBalancerManager method reserve.
@Override
public boolean reserve(PortLoadBalancerId portLoadBalancerId, ApplicationId appId) {
// Check if the resource is available
ApplicationId reservation = Versioned.valueOrNull(portLoadBalancerResStore.get(portLoadBalancerId));
PortLoadBalancer portLoadBalancer = Versioned.valueOrNull(portLoadBalancerStore.get(portLoadBalancerId));
if (reservation == null && portLoadBalancer != null) {
log.debug("Reserving {} -> {} into port load balancer reservation store", portLoadBalancerId, appId);
return portLoadBalancerResStore.put(portLoadBalancerId, appId) == null;
} else if (reservation != null && reservation.equals(appId)) {
// App try to reserve the resource a second time
log.debug("Already reserved {} -> {} skip reservation", portLoadBalancerId, appId);
return true;
}
log.warn("Reservation failed {} -> {}", portLoadBalancerId, appId);
return false;
}
use of org.onosproject.portloadbalancer.api.PortLoadBalancer 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