aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/apps/test/distributed-primitives
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/apps/test/distributed-primitives')
-rw-r--r--framework/src/onos/apps/test/distributed-primitives/pom.xml70
-rw-r--r--framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/DistributedPrimitivesTest.java57
-rw-r--r--framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/CounterTestIncrementCommand.java100
-rw-r--r--framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestAddCommand.java81
-rw-r--r--framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestGetCommand.java108
-rw-r--r--framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestRemoveCommand.java109
-rw-r--r--framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/TransactionalMapTestGetCommand.java73
-rw-r--r--framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/TransactionalMapTestPutCommand.java81
-rw-r--r--framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/package-info.java20
-rw-r--r--framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/package-info.java20
-rw-r--r--framework/src/onos/apps/test/distributed-primitives/src/main/resources/OSGI-INF/blueprint/shell-config.xml39
11 files changed, 758 insertions, 0 deletions
diff --git a/framework/src/onos/apps/test/distributed-primitives/pom.xml b/framework/src/onos/apps/test/distributed-primitives/pom.xml
new file mode 100644
index 00000000..e0376ee7
--- /dev/null
+++ b/framework/src/onos/apps/test/distributed-primitives/pom.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2015 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-apps-test</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-app-distributed-primitives</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>ONOS app to test distributed primitives</description>
+
+ <properties>
+ <onos.app.name>org.onosproject.distributedprimitives</onos.app.name>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ <classifier>tests</classifier>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-cli</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-core-dist</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.console</artifactId>
+ </dependency>
+
+ </dependencies>
+
+</project>
diff --git a/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/DistributedPrimitivesTest.java b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/DistributedPrimitivesTest.java
new file mode 100644
index 00000000..f0892282
--- /dev/null
+++ b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/DistributedPrimitivesTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.distributedprimitives;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.slf4j.Logger;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+
+/**
+ * Simple application to test distributed primitives.
+ */
+@Component(immediate = true)
+public class DistributedPrimitivesTest {
+
+ private final Logger log = getLogger(getClass());
+
+ private static final String APP_NAME = "org.onosproject.distributedprimitives";
+ private ApplicationId appId;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+
+ @Activate
+ protected void activate() {
+
+ log.info("Distributed-Primitives-test app started");
+ appId = coreService.registerApplication(APP_NAME);
+ }
+
+ @Deactivate
+ protected void deactivate() {
+
+ log.info("Distributed-Primitives-test app Stopped");
+ }
+}
diff --git a/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/CounterTestIncrementCommand.java b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/CounterTestIncrementCommand.java
new file mode 100644
index 00000000..d8e8e0be
--- /dev/null
+++ b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/CounterTestIncrementCommand.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.distributedprimitives.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.store.service.AsyncAtomicCounter;
+import org.onosproject.store.service.StorageService;
+import org.slf4j.Logger;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * CLI command to increment a distributed counter.
+ */
+@Command(scope = "onos", name = "counter-test-increment",
+ description = "Increment a distributed counter")
+public class CounterTestIncrementCommand extends AbstractShellCommand {
+
+ private final Logger log = getLogger(getClass());
+
+ @Option(name = "-i", aliases = "--inMemory", description = "use in memory map?",
+ required = false, multiValued = false)
+ private boolean inMemory = false;
+
+ @Option(name = "-g", aliases = "--getFirst", description = "get the counter's value before adding",
+ required = false, multiValued = false)
+ private boolean getFirst = false;
+
+ @Argument(index = 0, name = "counter",
+ description = "Counter name",
+ required = true, multiValued = false)
+ String counter = null;
+
+ @Argument(index = 1, name = "delta",
+ description = "Long to add to the counter",
+ required = false, multiValued = false)
+ Long delta = null;
+
+ AsyncAtomicCounter atomicCounter;
+
+
+ @Override
+ protected void execute() {
+ StorageService storageService = get(StorageService.class);
+ if (inMemory) {
+ atomicCounter = storageService.atomicCounterBuilder()
+ .withName(counter)
+ .withPartitionsDisabled()
+ .buildAsyncCounter();
+ } else {
+ atomicCounter = storageService.atomicCounterBuilder()
+ .withName(counter)
+ .buildAsyncCounter();
+ }
+ CompletableFuture<Long> result;
+ if (delta != null) {
+ if (getFirst) {
+ result = atomicCounter.getAndAdd(delta);
+ } else {
+ result = atomicCounter.addAndGet(delta);
+ }
+ } else {
+ if (getFirst) {
+ result = atomicCounter.getAndIncrement();
+ } else {
+ result = atomicCounter.incrementAndGet();
+ }
+ }
+ try {
+ print("%s was updated to %d", counter, result.get(3, TimeUnit.SECONDS));
+ } catch (InterruptedException e) {
+ return;
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ } catch (TimeoutException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestAddCommand.java b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestAddCommand.java
new file mode 100644
index 00000000..0ccc2d3c
--- /dev/null
+++ b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestAddCommand.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.distributedprimitives.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.StorageService;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * CLI command to add elements to a distributed set.
+ */
+@Command(scope = "onos", name = "set-test-add",
+ description = "Add to a distributed set")
+public class SetTestAddCommand extends AbstractShellCommand {
+
+ @Argument(index = 0, name = "setName",
+ description = "set name",
+ required = true, multiValued = false)
+ String setName = null;
+
+ @Argument(index = 1, name = "values",
+ description = "Value(s) to add to the set",
+ required = true, multiValued = true)
+ String[] values = null;
+
+ Set<String> set;
+ Set<String> toAdd = new HashSet<String>();
+
+
+ Serializer serializer = Serializer.using(
+ new KryoNamespace.Builder().register(KryoNamespaces.BASIC).build());
+
+
+ @Override
+ protected void execute() {
+ StorageService storageService = get(StorageService.class);
+ set = storageService.<String>setBuilder()
+ .withName(setName)
+ .withSerializer(serializer)
+ .build();
+
+ // 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
+ for (String value : values) {
+ toAdd.add(value);
+ }
+ if (set.addAll(toAdd)) {
+ print("%s was added to the set %s", toAdd, setName);
+ } else {
+ print("%s was already in set %s", toAdd, setName);
+ }
+ }
+ }
+}
diff --git a/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestGetCommand.java b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestGetCommand.java
new file mode 100644
index 00000000..792eab90
--- /dev/null
+++ b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestGetCommand.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.distributedprimitives.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.StorageService;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * CLI command to get the elements in a distributed set.
+ */
+@Command(scope = "onos", name = "set-test-get",
+ description = "Get the elements in a distributed set")
+public class SetTestGetCommand extends AbstractShellCommand {
+
+ @Option(name = "-s", aliases = "--size", description = "Also show the size of the set?",
+ required = false, multiValued = false)
+ private boolean size = false;
+
+ @Argument(index = 0, name = "setName",
+ description = "set name",
+ required = true, multiValued = false)
+ String setName = null;
+
+ @Argument(index = 1, name = "values",
+ description = "Check if the set contains these value(s)",
+ required = false, multiValued = true)
+ String[] values = null;
+
+ Set<String> set;
+ Set<String> toCheck = new HashSet<String>();
+ String output = new String();
+
+ Serializer serializer = Serializer.using(
+ new KryoNamespace.Builder().register(KryoNamespaces.BASIC).build());
+
+
+ @Override
+ protected void execute() {
+ StorageService storageService = get(StorageService.class);
+ set = storageService.<String>setBuilder()
+ .withName(setName)
+ .withSerializer(serializer)
+ .build();
+
+ // Print the set size
+ if (size) {
+ print("There are %d items in set %s:", set.size(), setName);
+ } else {
+ print("Items in set %s:", setName);
+ }
+ // Print the set
+ if (set.isEmpty()) {
+ print("[]");
+ } else {
+ for (String e : set.toArray(new String[set.size()])) {
+ if (output.isEmpty()) {
+ output += e;
+ } else {
+ output += ", " + e;
+ }
+ }
+ print("[%s]", output);
+ }
+ // Check if given values are in the set
+ if (values == null) {
+ return;
+ } else if (values.length == 1) {
+ // contains
+ if (set.contains(values[0])) {
+ print("Set %s contains the value %s", setName, values[0]);
+ } else {
+ print("Set %s did not contain the value %s", setName, values[0]);
+ }
+ } else if (values.length > 1) {
+ //containsAll
+ for (String value : values) {
+ toCheck.add(value);
+ }
+ if (set.containsAll(toCheck)) {
+ print("Set %s contains the the subset %s", setName, toCheck);
+ } else {
+ print("Set %s did not contain the the subset %s", setName, toCheck);
+ }
+ }
+ }
+}
diff --git a/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestRemoveCommand.java b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestRemoveCommand.java
new file mode 100644
index 00000000..7e3a3e82
--- /dev/null
+++ b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestRemoveCommand.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.distributedprimitives.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onlab.util.KryoNamespace;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.StorageService;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * CLI command to remove elements from a distributed set.
+ */
+@Command(scope = "onos", name = "set-test-remove",
+ description = "Remove from a distributed set")
+public class SetTestRemoveCommand extends AbstractShellCommand {
+
+ @Option(name = "-r", aliases = "--retain",
+ description = "Only keep the given values in the set (if they already exist in the set)",
+ required = false, multiValued = false)
+ private boolean retain = false;
+
+ @Option(name = "-c", aliases = "--clear", description = "Clear the set of all values",
+ required = false, multiValued = false)
+ private boolean clear = false;
+
+ @Argument(index = 0, name = "setName",
+ description = "set name",
+ required = true, multiValued = false)
+ String setName = null;
+
+ @Argument(index = 1, name = "values",
+ description = "Value(s) to remove from the set",
+ required = false, multiValued = true)
+ String[] values = null;
+
+ Set<String> set;
+ Set<String> givenValues = new HashSet<String>();
+ Serializer serializer = Serializer.using(
+ new KryoNamespace.Builder().register(KryoNamespaces.BASIC).build());
+
+
+ @Override
+ protected void execute() {
+ StorageService storageService = get(StorageService.class);
+ set = storageService.<String>setBuilder()
+ .withName(setName)
+ .withSerializer(serializer)
+ .build();
+
+ 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
+ for (String value : values) {
+ givenValues.add(value);
+ }
+ if (set.retainAll(givenValues)) {
+ print("%s was pruned to contain only elements of set %s", setName, givenValues);
+ } else {
+ print("%s was not changed by retaining only elements of the set %s", setName, givenValues);
+ }
+ } 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
+ for (String value : values) {
+ givenValues.add(value);
+ }
+ if (set.removeAll(givenValues)) {
+ print("%s was removed from the set %s", givenValues, setName);
+ } else {
+ print("No element of %s was in set %s", givenValues, setName);
+ }
+ }
+ }
+}
diff --git a/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/TransactionalMapTestGetCommand.java b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/TransactionalMapTestGetCommand.java
new file mode 100644
index 00000000..e41ccc8d
--- /dev/null
+++ b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/TransactionalMapTestGetCommand.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.distributedprimitives.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.TransactionContext;
+import org.onosproject.store.service.TransactionalMap;
+
+/**
+ * CLI command to get a value associated with a specific key in a transactional map.
+ */
+@Command(scope = "onos", name = "transactional-map-test-get",
+ description = "Get a value associated with a specific key in a transactional map")
+public class TransactionalMapTestGetCommand extends AbstractShellCommand {
+
+ @Option(name = "-i", aliases = "--inMemory", description = "use in memory map?",
+ required = false, multiValued = false)
+ private boolean inMemory = false;
+
+ @Argument(index = 0, name = "key",
+ description = "Key to get the value of",
+ required = true, multiValued = false)
+ private String key = null;
+
+ TransactionalMap<String, String> map;
+ String mapName = "Test-Map";
+ Serializer serializer = Serializer.using(KryoNamespaces.BASIC);
+
+ @Override
+ protected void execute() {
+ StorageService storageService = get(StorageService.class);
+ TransactionContext context;
+ if (inMemory) {
+ context = storageService.transactionContextBuilder().withPartitionsDisabled().build();
+ } else {
+ 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;
+ }
+ }
+}
diff --git a/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/TransactionalMapTestPutCommand.java b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/TransactionalMapTestPutCommand.java
new file mode 100644
index 00000000..0e0e44a7
--- /dev/null
+++ b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/TransactionalMapTestPutCommand.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.distributedprimitives.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.Serializer;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.TransactionContext;
+import org.onosproject.store.service.TransactionalMap;
+
+/**
+ * CLI command to put a value into a transactional map.
+ */
+@Command(scope = "onos", name = "transactional-map-test-put",
+ description = "Put a value into a transactional map")
+public class TransactionalMapTestPutCommand extends AbstractShellCommand {
+
+ @Option(name = "-i", aliases = "--inMemory", description = "use in memory map?",
+ required = false, multiValued = false)
+ private boolean inMemory = false;
+
+ @Argument(index = 0, name = "numKeys",
+ description = "Number of keys to put the value into",
+ required = true, multiValued = false)
+ private int numKeys = 1;
+
+ @Argument(index = 1, name = "value",
+ description = "Value to map with the keys in the map",
+ required = true, multiValued = false)
+ private String value = null;
+
+ TransactionalMap<String, String> map;
+ String prefix = "Key";
+ String mapName = "Test-Map";
+ Serializer serializer = Serializer.using(KryoNamespaces.BASIC);
+
+ @Override
+ protected void execute() {
+ StorageService storageService = get(StorageService.class);
+ TransactionContext context;
+ if (inMemory) {
+ context = storageService.transactionContextBuilder().withPartitionsDisabled().build();
+ } else {
+ 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;
+ }
+ }
+}
diff --git a/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/package-info.java b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/package-info.java
new file mode 100644
index 00000000..53ed8056
--- /dev/null
+++ b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Distributed Primitives test command-line handlers.
+ */
+package org.onosproject.distributedprimitives.cli;
diff --git a/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/package-info.java b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/package-info.java
new file mode 100644
index 00000000..73c41818
--- /dev/null
+++ b/framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Sample application for use in various experiments with distributed primitives.
+ */
+package org.onosproject.distributedprimitives;
diff --git a/framework/src/onos/apps/test/distributed-primitives/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/framework/src/onos/apps/test/distributed-primitives/src/main/resources/OSGI-INF/blueprint/shell-config.xml
new file mode 100644
index 00000000..295171d7
--- /dev/null
+++ b/framework/src/onos/apps/test/distributed-primitives/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -0,0 +1,39 @@
+<!--
+ ~ Copyright 2015 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+ <command>
+ <action class="org.onosproject.distributedprimitives.cli.CounterTestIncrementCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.distributedprimitives.cli.SetTestAddCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.distributedprimitives.cli.SetTestGetCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.distributedprimitives.cli.SetTestRemoveCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.distributedprimitives.cli.TransactionalMapTestGetCommand"/>
+ </command>
+ <command>
+ <action class="org.onosproject.distributedprimitives.cli.TransactionalMapTestPutCommand"/>
+ </command>
+ </command-bundle>
+
+</blueprint>