Kaouther Abrougui
Committed by Gerrit Code Review

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
...@@ -64,14 +64,44 @@ public class CountersListCommand extends AbstractShellCommand { ...@@ -64,14 +64,44 @@ public class CountersListCommand extends AbstractShellCommand {
64 return jsonCounters; 64 return jsonCounters;
65 } 65 }
66 66
67 + /**
68 + * Converts info for counters from different databases into a JSON object.
69 + *
70 + * @param partitionedDbCounters counters info
71 + * @param inMemoryDbCounters counters info
72 + */
73 + private JsonNode jsonAllCounters(Map<String, Long> partitionedDbCounters,
74 + Map<String, Long> inMemoryDbCounters) {
75 + ObjectMapper mapper = new ObjectMapper();
76 + ArrayNode jsonCounters = mapper.createArrayNode();
77 +
78 + // Create a JSON node for partitioned database counter
79 + ObjectNode jsonPartitionedDatabaseCounters = mapper.createObjectNode();
80 + jsonPartitionedDatabaseCounters.put("partitionedDatabaseCounters",
81 + partitionedDbCounters.toString());
82 + jsonCounters.add(jsonPartitionedDatabaseCounters);
83 + // Create a JSON node for in-memory database counter
84 + ObjectNode jsonInMemoryDatabseCounters = mapper.createObjectNode();
85 + jsonInMemoryDatabseCounters.put("inMemoryDatabaseCounters",
86 + inMemoryDbCounters.toString());
87 + jsonCounters.add(jsonInMemoryDatabseCounters);
88 +
89 + return jsonCounters;
90 + }
91 +
92 +
67 @Override 93 @Override
68 protected void execute() { 94 protected void execute() {
69 StorageAdminService storageAdminService = get(StorageAdminService.class); 95 StorageAdminService storageAdminService = get(StorageAdminService.class);
70 - Map<String, Long> counters = storageAdminService.getCounters(); 96 + Map<String, Long> partitionedDatabaseCounters = storageAdminService.getPartitionedDatabaseCounters();
97 + Map<String, Long> inMemoryDatabaseCounters = storageAdminService.getInMemoryDatabaseCounters();
71 if (outputJson()) { 98 if (outputJson()) {
72 - print("%s", json(counters)); 99 + print("%s", jsonAllCounters(partitionedDatabaseCounters, inMemoryDatabaseCounters));
73 } else { 100 } else {
74 - displayCounters(counters); 101 + print("Partitioned database counters:");
102 + displayCounters(partitionedDatabaseCounters);
103 + print("In-memory database counters:");
104 + displayCounters(inMemoryDatabaseCounters);
75 } 105 }
76 } 106 }
77 } 107 }
......
...@@ -40,12 +40,28 @@ public interface StorageAdminService { ...@@ -40,12 +40,28 @@ public interface StorageAdminService {
40 40
41 /** 41 /**
42 * Returns information about all the atomic counters in the system. 42 * Returns information about all the atomic counters in the system.
43 + * If 2 counters belonging to 2 different databases have the same name,
44 + * then only one counter from one database is returned.
43 * 45 *
44 * @return mapping from counter name to that counter's next value 46 * @return mapping from counter name to that counter's next value
45 */ 47 */
46 Map<String, Long> getCounters(); 48 Map<String, Long> getCounters();
47 49
48 /** 50 /**
51 + * Returns information about all the atomic partitioned database counters in the system.
52 + *
53 + * @return mapping from counter name to that counter's next value
54 + */
55 + Map<String, Long> getPartitionedDatabaseCounters();
56 +
57 + /**
58 + * Returns information about all the atomic in-memory database counters in the system.
59 + *
60 + * @return mapping from counter name to that counter's next value
61 + */
62 + Map<String, Long> getInMemoryDatabaseCounters();
63 +
64 + /**
49 * Returns all the transactions in the system. 65 * Returns all the transactions in the system.
50 * 66 *
51 * @return collection of transactions 67 * @return collection of transactions
......
...@@ -349,6 +349,20 @@ public class DatabaseManager implements StorageService, StorageAdminService { ...@@ -349,6 +349,20 @@ public class DatabaseManager implements StorageService, StorageAdminService {
349 } 349 }
350 350
351 @Override 351 @Override
352 + public Map<String, Long> getPartitionedDatabaseCounters() {
353 + Map<String, Long> counters = Maps.newHashMap();
354 + counters.putAll(complete(partitionedDatabase.counters()));
355 + return counters;
356 + }
357 +
358 + @Override
359 + public Map<String, Long> getInMemoryDatabaseCounters() {
360 + Map<String, Long> counters = Maps.newHashMap();
361 + counters.putAll(complete(inMemoryDatabase.counters()));
362 + return counters;
363 + }
364 +
365 + @Override
352 public Collection<Transaction> getTransactions() { 366 public Collection<Transaction> getTransactions() {
353 return complete(transactionManager.getTransactions()); 367 return complete(transactionManager.getTransactions());
354 } 368 }
......