Search in sources :

Example 11 with StorageService

use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.

the class ConsistentMapTestCommand method doExecute.

@Override
protected void doExecute() {
    StorageService storageService = get(StorageService.class);
    map = storageService.<String, String>consistentMapBuilder().withName(name).withSerializer(Serializer.using(KryoNamespaces.BASIC)).withVersion(Version.version("1.0.0")).withCompatibilityFunction((value, version) -> version + ":" + value).build();
    if ("get".equals(operation)) {
        print(map.get(arg1));
    } else if ("put".equals(operation)) {
        print(map.put(arg1, arg2));
    } else if ("size".equals(operation)) {
        print("%d", map.size());
    } else if ("isEmpty".equals(operation)) {
        print("%b", map.isEmpty());
    } else if ("putIfAbsent".equals(operation)) {
        print(map.putIfAbsent(arg1, arg2));
    } else if ("putAndGet".equals(operation)) {
        print(map.putAndGet(arg1, arg2));
    } else if ("clear".equals(operation)) {
        map.clear();
    } else if ("remove".equals(operation)) {
        if (arg2 == null) {
            print(map.remove(arg1));
        } else {
            print("%b", map.remove(arg1, arg2));
        }
    } else if ("containsKey".equals(operation)) {
        print("%b", map.containsKey(arg1));
    } else if ("containsValue".equals(operation)) {
        print("%b", map.containsValue(arg1));
    } else if ("replace".equals(operation)) {
        if (arg3 == null) {
            print(map.replace(arg1, arg2));
        } else {
            print("%b", map.replace(arg1, arg2, arg3));
        }
    } else if ("compatiblePut".equals(operation)) {
        ConsistentMap<String, String> map = storageService.<String, String>consistentMapBuilder().withName(name).withSerializer(Serializer.using(KryoNamespaces.BASIC)).withCompatibilityFunction((value, version) -> version + ":" + value).withVersion(Version.version("2.0.0")).build();
        print(map.put(arg1, arg2));
    } else if ("compatibleGet".equals(operation)) {
        ConsistentMap<String, String> map = storageService.<String, String>consistentMapBuilder().withName(name).withSerializer(Serializer.using(KryoNamespaces.BASIC)).withCompatibilityFunction((value, version) -> version + ":" + value).withVersion(Version.version("2.0.0")).build();
        print(map.get(arg1));
    }
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Serializer(org.onosproject.store.service.Serializer) Versioned(org.onosproject.store.service.Versioned) StorageService(org.onosproject.store.service.StorageService) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Version(org.onosproject.core.Version) Argument(org.apache.karaf.shell.api.action.Argument) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) Command(org.apache.karaf.shell.api.action.Command) ConsistentMap(org.onosproject.store.service.ConsistentMap) StorageService(org.onosproject.store.service.StorageService)

Example 12 with StorageService

use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.

the class DocumentTreeTestCommand method doExecute.

@Override
protected void doExecute() {
    StorageService storageService = get(StorageService.class);
    tree = storageService.<String>getDocumentTree(name, Serializer.using(KryoNamespaces.BASIC)).asDocumentTree();
    tree.addListener(value -> {
        log.debug("Received event: {}", value);
    });
    if ("set".equals(operation)) {
        log.debug("set {} {}", DocumentPath.from(arg1), arg2);
        print(tree.set(DocumentPath.from(arg1), arg2));
    } else if ("get".equals(operation)) {
        log.debug("get {}", DocumentPath.from(arg1));
        print(tree.get(DocumentPath.from(arg1)));
    } else if ("remove".equals(operation)) {
        log.debug("removeNode {}", DocumentPath.from(arg1));
        print(tree.removeNode(DocumentPath.from(arg1)));
    } else if ("create".equals(operation)) {
        log.debug("create {} {}", DocumentPath.from(arg1), arg2);
        print("%b", tree.create(DocumentPath.from(arg1), arg2));
    } else if ("createRecursive".equals(operation)) {
        log.debug("createRecursive {} {}", DocumentPath.from(arg1), arg2);
        print("%b", tree.createRecursive(DocumentPath.from(arg1), arg2));
    }
}
Also used : StorageService(org.onosproject.store.service.StorageService)

Example 13 with StorageService

use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.

the class SetTestAddCommand method doExecute.

@Override
protected void doExecute() {
    StorageService storageService = get(StorageService.class);
    set = storageService.<String>setBuilder().withName(setName).withSerializer(serializer).build().asDistributedSet();
    // Add a single element to the set
    if (values.length == 1) {
        if (set.add(values[0])) {
            print("[%s] was added to the set %s", values[0], setName);
        } else {
            print("[%s] was already in set %s", values[0], setName);
        }
    } else if (values.length >= 1) {
        // Add multiple elements to a set
        if (set.addAll(Arrays.asList(values))) {
            print("%s was added to the set %s", Arrays.asList(values), setName);
        } else {
            print("%s was already in set %s", Arrays.asList(values), setName);
        }
    }
}
Also used : StorageService(org.onosproject.store.service.StorageService)

Example 14 with StorageService

use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.

the class TransactionalMapTestGetCommand method doExecute.

@Override
protected void doExecute() {
    StorageService storageService = get(StorageService.class);
    TransactionContext context;
    context = storageService.transactionContextBuilder().build();
    context.begin();
    try {
        map = context.getTransactionalMap(mapName, serializer);
        String response = map.get(key);
        context.commit();
        if (response == null) {
            print("Key %s not found.", key);
        } else {
            print("Key-value pair (%s, %s) found.", key, response);
        }
    } catch (Exception e) {
        context.abort();
        throw e;
    }
}
Also used : TransactionContext(org.onosproject.store.service.TransactionContext) StorageService(org.onosproject.store.service.StorageService)

Example 15 with StorageService

use of org.onosproject.store.service.StorageService in project onos by opennetworkinglab.

the class TransactionalMapTestPutCommand method doExecute.

@Override
protected void doExecute() {
    StorageService storageService = get(StorageService.class);
    TransactionContext context;
    context = storageService.transactionContextBuilder().build();
    context.begin();
    try {
        map = context.getTransactionalMap(mapName, serializer);
        for (int i = 1; i <= numKeys; i++) {
            String key = prefix + i;
            String response = map.put(key, value);
            if (response == null) {
                print("Created Key %s with value %s.", key, value);
            } else {
                print("Put %s into key %s. The old value was %s.", value, key, response);
            }
        }
        context.commit();
    } catch (Exception e) {
        context.abort();
        throw e;
    }
}
Also used : TransactionContext(org.onosproject.store.service.TransactionContext) 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