Search in sources :

Example 6 with StorageService

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);
        }
    }
}
Also used : StorageService(org.onosproject.store.service.StorageService)

Example 7 with StorageService

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]");
    }
}
Also used : Task(org.onosproject.store.service.Task) WorkQueueStats(org.onosproject.store.service.WorkQueueStats) StorageService(org.onosproject.store.service.StorageService) Serializer(org.onosproject.store.service.Serializer)

Example 8 with StorageService

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());
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AtomicCounter(org.onosproject.store.service.AtomicCounter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StorageService(org.onosproject.store.service.StorageService)

Example 9 with StorageService

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();
}
Also used : METRIC_POLL_FREQUENCY_SECONDS(org.onosproject.nodemetrics.impl.OsgiPropertyConstants.METRIC_POLL_FREQUENCY_SECONDS) ScheduledFuture(java.util.concurrent.ScheduledFuture) Tools(org.onlab.util.Tools) Mem(org.hyperic.sigar.Mem) CoreService(org.onosproject.core.CoreService) ComponentContext(org.osgi.service.component.ComponentContext) LoggerFactory(org.slf4j.LoggerFactory) Tools.getIntegerProperty(org.onlab.util.Tools.getIntegerProperty) KryoNamespace(org.onlab.util.KryoNamespace) METRIC_POLL_FREQUENCY_SECONDS_DEFAULT(org.onosproject.nodemetrics.impl.OsgiPropertyConstants.METRIC_POLL_FREQUENCY_SECONDS_DEFAULT) CpuPerc(org.hyperic.sigar.CpuPerc) NodeCpuUsage(org.onosproject.nodemetrics.NodeCpuUsage) Component(org.osgi.service.component.annotations.Component) StorageService(org.onosproject.store.service.StorageService) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NodeDiskUsage(org.onosproject.nodemetrics.NodeDiskUsage) Activate(org.osgi.service.component.annotations.Activate) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) NodeId(org.onosproject.cluster.NodeId) SigarException(org.hyperic.sigar.SigarException) NodeMemoryUsage(org.onosproject.nodemetrics.NodeMemoryUsage) Logger(org.slf4j.Logger) FileSystemUsage(org.hyperic.sigar.FileSystemUsage) NodeMetricsService(org.onosproject.nodemetrics.NodeMetricsService) Deactivate(org.osgi.service.component.annotations.Deactivate) LogicalClockService(org.onosproject.store.service.LogicalClockService) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Modified(org.osgi.service.component.annotations.Modified) ClusterService(org.onosproject.cluster.ClusterService) Units(org.onosproject.nodemetrics.Units) Reference(org.osgi.service.component.annotations.Reference) Sigar(org.hyperic.sigar.Sigar) Dictionary(java.util.Dictionary) Sigar(org.hyperic.sigar.Sigar) NodeCpuUsage(org.onosproject.nodemetrics.NodeCpuUsage) NodeMemoryUsage(org.onosproject.nodemetrics.NodeMemoryUsage) KryoNamespace(org.onlab.util.KryoNamespace) Activate(org.osgi.service.component.annotations.Activate)

Example 10 with StorageService

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);
    }
}
Also used : StorageService(org.onosproject.store.service.StorageService)

Aggregations

StorageService (org.onosproject.store.service.StorageService)16 Activate (org.osgi.service.component.annotations.Activate)4 Component (org.osgi.service.component.annotations.Component)4 Deactivate (org.osgi.service.component.annotations.Deactivate)4 Reference (org.osgi.service.component.annotations.Reference)4 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)4 Logger (org.slf4j.Logger)4 Collection (java.util.Collection)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 KryoNamespace (org.onlab.util.KryoNamespace)3 ClusterService (org.onosproject.cluster.ClusterService)3 KryoNamespaces (org.onosproject.store.serializers.KryoNamespaces)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 ImmutableList (com.google.common.collect.ImmutableList)2 Dictionary (java.util.Dictionary)2 Map (java.util.Map)2 Objects (java.util.Objects)2 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)2 NodeId (org.onosproject.cluster.NodeId)2