use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class SetTestRemoveCommand method doExecute.
@Override
protected void doExecute() {
StorageService storageService = get(StorageService.class);
set = storageService.<String>setBuilder().withName(setName).withSerializer(serializer).build().asDistributedSet();
if (clear) {
set.clear();
print("Set %s cleared", setName);
return;
}
if (values == null) {
print("Error executing command: No value given");
return;
}
if (retain) {
// Keep only the given values
if (set.retainAll(Arrays.asList(values))) {
print("%s was pruned to contain only elements of set %s", setName, Arrays.asList(values));
} else {
print("%s was not changed by retaining only elements of the set %s", setName, Arrays.asList(values));
}
} else if (values.length == 1) {
// Remove a single element from the set
if (set.remove(values[0])) {
print("[%s] was removed from the set %s", values[0], setName);
} else {
print("[%s] was not in set %s", values[0], setName);
}
} else if (values.length > 1) {
// Remove multiple elements from a set
if (set.removeAll(Arrays.asList(values))) {
print("%s was removed from the set %s", Arrays.asList(values), setName);
} else {
print("No element of %s was in set %s", Arrays.asList(values), setName);
}
}
}
use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class WorkQueueTestCommand method doExecute.
@Override
protected void doExecute() {
StorageService storageService = get(StorageService.class);
Serializer serializer = Serializer.using(KryoNamespaces.BASIC);
queue = storageService.getWorkQueue(name, serializer);
if ("add".equals(operation)) {
if (value1 == null) {
print("Usage: add <value1>");
} else {
get(queue.addOne(value1));
print("Done");
}
} else if ("addMultiple".equals(operation)) {
if (value1 == null || value2 == null) {
print("Usage: addMultiple <value1> <value2>");
} else {
get(queue.addMultiple(Arrays.asList(value1, value2)));
print("Done");
}
} else if ("takeAndComplete".equals(operation)) {
int maxItems = value1 != null ? Integer.parseInt(value1) : 1;
Collection<Task<String>> tasks = get(queue.take(maxItems));
tasks.forEach(task -> get(queue.complete(task.taskId())));
print("Done");
} else if ("totalPending".equals(operation)) {
WorkQueueStats stats = get(queue.stats());
print("%d", stats.totalPending());
} else if ("totalInProgress".equals(operation)) {
WorkQueueStats stats = get(queue.stats());
print("%d", stats.totalInProgress());
} else if ("totalCompleted".equals(operation)) {
WorkQueueStats stats = get(queue.stats());
print("%d", stats.totalCompleted());
} else if ("destroy".equals(operation)) {
get(queue.destroy());
} else {
print("Invalid operation name. Valid operations names are:" + " [add, addMultiple takeAndComplete, totalPending, totalInProgress, totalCompleted, destroy]");
}
}
use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class CounterCommand method doExecute.
@Override
protected void doExecute() {
StorageService storageService = get(StorageService.class);
AtomicCounter counter = storageService.getAtomicCounter(name);
if (outputJson()) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode counterJsonNode = mapper.createObjectNode();
counterJsonNode.put("value", counter.get());
print("%s", counterJsonNode);
} else {
print("%d", counter.get());
}
}
use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class NodeMetricsManager method activate.
@Activate
public void activate(ComponentContext context) {
appId = coreService.registerApplication("org.onosproject.nodemetrics");
cfgService.registerProperties(getClass());
metricsExecutor = Executors.newSingleThreadScheduledExecutor(Tools.groupedThreads("nodemetrics/pollingStatics", "statistics-executor-%d", log));
localNodeId = clusterService.getLocalNode().id();
KryoNamespace.Builder serializer = KryoNamespace.newBuilder().register(KryoNamespaces.API).register(NodeMemoryUsage.class).register(NodeDiskUsage.class).register(NodeCpuUsage.class).register(Units.class);
memoryStore = storageService.<NodeId, NodeMemoryUsage>eventuallyConsistentMapBuilder().withSerializer(serializer).withTimestampProvider((nodeId, memory) -> clockService.getTimestamp()).withName("nodemetrics-memory").build();
diskStore = storageService.<NodeId, NodeDiskUsage>eventuallyConsistentMapBuilder().withSerializer(serializer).withTimestampProvider((nodeId, disk) -> clockService.getTimestamp()).withName("nodemetrics-disk").build();
cpuStore = storageService.<NodeId, NodeCpuUsage>eventuallyConsistentMapBuilder().withSerializer(serializer).withTimestampProvider((nodeId, cpu) -> clockService.getTimestamp()).withName("nodemetrics-cpu").build();
modified(context);
sigar = new Sigar();
pollMetrics();
}
use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.
the class AtomicValueTestCommand method doExecute.
@Override
protected void doExecute() {
StorageService storageService = get(StorageService.class);
atomicValue = storageService.<String>atomicValueBuilder().withName(name).withSerializer(Serializer.using(KryoNamespaces.BASIC)).build().asAtomicValue();
if ("get".equals(operation)) {
print("%s", atomicValue.get());
} else if ("set".equals(operation)) {
atomicValue.set("null".equals(value1) ? null : value1);
} else if ("compareAndSet".equals(operation)) {
print("%b", atomicValue.compareAndSet("null".equals(value1) ? null : value1, "null".equals(value2) ? null : value2));
} else if ("getAndSet".equals(operation)) {
print("%s", atomicValue.getAndSet(value1));
} else if ("destroy".equals(operation)) {
atomicValue.destroy();
} else {
print("Error, unknown operation %s", operation);
}
}
Aggregations