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 {
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);
}
}
}
......
......@@ -40,12 +40,28 @@ public interface StorageAdminService {
/**
* 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
......
......@@ -349,6 +349,20 @@ public class DatabaseManager implements StorageService, StorageAdminService {
}
@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());
}
......