Fixed bug ONOS-1676.
- Added comments and updated counters command display.
- Modified Json output for counters command.
- Fixed indentation and wrapped long code lines
Change-Id: I4ccc7f67071ea587ee0b12e2f59582f5e5ca760f
Change-Id: Id6cdeda344dd429e3a9f9ab7f027b45e7d6f293a
Change-Id: I6b90a868cedfa405f8deabb1cee6988ba6c1f96e
Change-Id: I93710bd69e266779220c5d1a240e6a06090da55c
diff --git a/cli/src/main/java/org/onosproject/cli/net/CountersListCommand.java b/cli/src/main/java/org/onosproject/cli/net/CountersListCommand.java
index 9706e0e..7a22965 100644
--- a/cli/src/main/java/org/onosproject/cli/net/CountersListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/CountersListCommand.java
@@ -64,14 +64,44 @@
return jsonCounters;
}
+ /**
+ * Converts info for counters from different databases into a JSON object.
+ *
+ * @param partitionedDbCounters counters info
+ * @param inMemoryDbCounters counters info
+ */
+ private JsonNode jsonAllCounters(Map<String, Long> partitionedDbCounters,
+ Map<String, Long> inMemoryDbCounters) {
+ ObjectMapper mapper = new ObjectMapper();
+ ArrayNode jsonCounters = mapper.createArrayNode();
+
+ // Create a JSON node for partitioned database counter
+ ObjectNode jsonPartitionedDatabaseCounters = mapper.createObjectNode();
+ jsonPartitionedDatabaseCounters.put("partitionedDatabaseCounters",
+ partitionedDbCounters.toString());
+ jsonCounters.add(jsonPartitionedDatabaseCounters);
+ // Create a JSON node for in-memory database counter
+ ObjectNode jsonInMemoryDatabseCounters = mapper.createObjectNode();
+ jsonInMemoryDatabseCounters.put("inMemoryDatabaseCounters",
+ inMemoryDbCounters.toString());
+ jsonCounters.add(jsonInMemoryDatabseCounters);
+
+ return jsonCounters;
+ }
+
+
@Override
protected void execute() {
StorageAdminService storageAdminService = get(StorageAdminService.class);
- Map<String, Long> counters = storageAdminService.getCounters();
+ Map<String, Long> partitionedDatabaseCounters = storageAdminService.getPartitionedDatabaseCounters();
+ Map<String, Long> inMemoryDatabaseCounters = storageAdminService.getInMemoryDatabaseCounters();
if (outputJson()) {
- print("%s", json(counters));
+ print("%s", jsonAllCounters(partitionedDatabaseCounters, inMemoryDatabaseCounters));
} else {
- displayCounters(counters);
+ print("Partitioned database counters:");
+ displayCounters(partitionedDatabaseCounters);
+ print("In-memory database counters:");
+ displayCounters(inMemoryDatabaseCounters);
}
}
}
diff --git a/core/api/src/main/java/org/onosproject/store/service/StorageAdminService.java b/core/api/src/main/java/org/onosproject/store/service/StorageAdminService.java
index 204e35b..2259104 100644
--- a/core/api/src/main/java/org/onosproject/store/service/StorageAdminService.java
+++ b/core/api/src/main/java/org/onosproject/store/service/StorageAdminService.java
@@ -40,12 +40,28 @@
/**
* Returns information about all the atomic counters in the system.
+ * If 2 counters belonging to 2 different databases have the same name,
+ * then only one counter from one database is returned.
*
* @return mapping from counter name to that counter's next value
*/
Map<String, Long> getCounters();
/**
+ * Returns information about all the atomic partitioned database counters in the system.
+ *
+ * @return mapping from counter name to that counter's next value
+ */
+ Map<String, Long> getPartitionedDatabaseCounters();
+
+ /**
+ * Returns information about all the atomic in-memory database counters in the system.
+ *
+ * @return mapping from counter name to that counter's next value
+ */
+ Map<String, Long> getInMemoryDatabaseCounters();
+
+ /**
* Returns all the transactions in the system.
*
* @return collection of transactions
diff --git a/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DatabaseManager.java b/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DatabaseManager.java
index 390a444..181490e 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DatabaseManager.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DatabaseManager.java
@@ -349,6 +349,20 @@
}
@Override
+ public Map<String, Long> getPartitionedDatabaseCounters() {
+ Map<String, Long> counters = Maps.newHashMap();
+ counters.putAll(complete(partitionedDatabase.counters()));
+ return counters;
+ }
+
+ @Override
+ public Map<String, Long> getInMemoryDatabaseCounters() {
+ Map<String, Long> counters = Maps.newHashMap();
+ counters.putAll(complete(inMemoryDatabase.counters()));
+ return counters;
+ }
+
+ @Override
public Collection<Transaction> getTransactions() {
return complete(transactionManager.getTransactions());
}