From 13d05bc8458758ee39cb829098241e89616717ee Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Wed, 9 Sep 2015 22:15:21 -0700 Subject: ONOS checkin based on commit tag e796610b1f721d02f9b0e213cf6f7790c10ecd60 Change-Id: Ife8810491034fe7becdba75dda20de4267bd15cd --- .../onos/apps/test/distributed-primitives/pom.xml | 70 +++++++++++++ .../DistributedPrimitivesTest.java | 57 +++++++++++ .../cli/CounterTestIncrementCommand.java | 100 +++++++++++++++++++ .../cli/SetTestAddCommand.java | 81 +++++++++++++++ .../cli/SetTestGetCommand.java | 108 ++++++++++++++++++++ .../cli/SetTestRemoveCommand.java | 109 +++++++++++++++++++++ .../cli/TransactionalMapTestGetCommand.java | 73 ++++++++++++++ .../cli/TransactionalMapTestPutCommand.java | 81 +++++++++++++++ .../distributedprimitives/cli/package-info.java | 20 ++++ .../distributedprimitives/package-info.java | 20 ++++ .../resources/OSGI-INF/blueprint/shell-config.xml | 39 ++++++++ 11 files changed, 758 insertions(+) create mode 100644 framework/src/onos/apps/test/distributed-primitives/pom.xml create mode 100644 framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/DistributedPrimitivesTest.java create mode 100644 framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/CounterTestIncrementCommand.java create mode 100644 framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestAddCommand.java create mode 100644 framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestGetCommand.java create mode 100644 framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestRemoveCommand.java create mode 100644 framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/TransactionalMapTestGetCommand.java create mode 100644 framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/TransactionalMapTestPutCommand.java create mode 100644 framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/package-info.java create mode 100644 framework/src/onos/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/package-info.java create mode 100644 framework/src/onos/apps/test/distributed-primitives/src/main/resources/OSGI-INF/blueprint/shell-config.xml (limited to 'framework/src/onos/apps/test/distributed-primitives') 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 @@ + + + + + 4.0.0 + + + org.onosproject + onos-apps-test + 1.3.0-SNAPSHOT + ../pom.xml + + + onos-app-distributed-primitives + bundle + + ONOS app to test distributed primitives + + + org.onosproject.distributedprimitives + + + + + + org.onosproject + onos-api + ${project.version} + test + tests + + + + org.onosproject + onos-cli + ${project.version} + + + org.onosproject + onos-core-dist + 1.3.0-SNAPSHOT + + + org.osgi + org.osgi.core + + + org.apache.karaf.shell + org.apache.karaf.shell.console + + + + + 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 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 set; + Set toAdd = new HashSet(); + + + Serializer serializer = Serializer.using( + new KryoNamespace.Builder().register(KryoNamespaces.BASIC).build()); + + + @Override + protected void execute() { + StorageService storageService = get(StorageService.class); + set = storageService.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 set; + Set toCheck = new HashSet(); + 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.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 set; + Set givenValues = new HashSet(); + Serializer serializer = Serializer.using( + new KryoNamespace.Builder().register(KryoNamespaces.BASIC).build()); + + + @Override + protected void execute() { + StorageService storageService = get(StorageService.class); + set = storageService.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 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 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit 1.2.3-korg