thomasmueller commented on a change in pull request #498:
URL: https://github.com/apache/jackrabbit-oak/pull/498#discussion_r811307939
##########
File path:
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/inventory/IndexPrinter.java
##########
@@ -71,147 +70,107 @@ public IndexPrinter(IndexInfoService indexInfoService,
AsyncIndexInfoService asy
@Override
public void print(PrintWriter pw, Format format, boolean isZip) {
-
- if (format == Format.JSON) {
- JsopBuilder json = new JsopBuilder();
- startJsonObject(json);
- printAsyncIndexInfo(pw, json, format);
- printIndexInfo(pw, json, format);
- endJsonObject(json);
- pw.print(JsopBuilder.prettyPrint(json.toString()));
- } else {
- //TODO Highlight if failing
- printAsyncIndexInfo(pw, null, format);
- printIndexInfo(pw, null, format);
- }
+ PrinterOutput po = format == Format.JSON ? new JsonPrinterOutput() :
new TextPrinterOutput();
+ asyncLanesInfo(po);
+ indexInfo(po);
+ pw.print(po.output());
}
- private void printAsyncIndexInfo(PrintWriter pw, JsopBuilder json, Format
format) {
+ private void asyncLanesInfo(PrinterOutput po) {
List<String> asyncLanes =
ImmutableList.copyOf(asyncIndexInfoService.getAsyncLanes());
- String title = "Async Indexers State";
- printTitle(pw, title, format);
- addJsonKey(json, title);
- startJsonObject(json);
- keyValue("Number of async indexer lanes ", asyncLanes.size(), pw,
json, format);
- printWithNewLine(pw, "", format);
+ po.startSection("Async Indexers State", true);
+ po.text("Number of async indexer lanes", asyncLanes.size());
for (String lane : asyncLanes) {
- printWithNewLine(pw, lane, format);
- addJsonKey(json, lane);
+ po.startSection(lane, false);
AsyncIndexInfo info = asyncIndexInfoService.getInfo(lane);
- startJsonObject(json);
if (info != null) {
- keyValue(" Last indexed to ",
formatTime(info.getLastIndexedTo()), pw, json, format);
+ po.text("Last indexed to",
formatTime(info.getLastIndexedTo()));
IndexStatsMBean stats = info.getStatsMBean();
if (stats != null) {
- keyValue(" Status ", stats.getStatus(),
pw, json, format);
- keyValue(" Failing ", stats.isFailing(),
pw, json, format);
- keyValue(" Paused ", stats.isPaused(), pw,
json, format);
+ po.text("Status", stats.getStatus());
+ po.text("Failing", stats.isFailing());
+ po.text("Paused", stats.isPaused());
if (stats.isFailing()) {
- keyValue(" Failing since ",
stats.getFailingSince(), pw, json, format);
- keyValue(" Latest error ",
stats.getLatestError(), pw, json, format);
+ po.text("Failing since", stats.getFailingSince());
+ po.text("Latest error", stats.getLatestError());
}
}
- printWithNewLine(pw, "", format);
}
- endJsonObject(json);
+ po.endSection();
}
- endJsonObject(json);
+ po.endSection();
}
- private static void printTitle(PrintWriter pw, String title, Format
format) {
- if (format == Format.TEXT) {
- pw.println(title);
- pw.println(Strings.repeat("=", title.length()));
- pw.println();
- }
- }
+ private void indexInfo(PrinterOutput po) {
+ Map<String, List<IndexInfo>> indexesByType =
StreamSupport.stream(indexInfoService.getAllIndexInfo().spliterator(), false)
+ .collect(Collectors.groupingBy(IndexInfo::getType));
- private static void printWithNewLine(PrintWriter pw, String printLine,
Format format) {
- if (format == Format.TEXT) {
- pw.println(printLine);
- }
- }
+ po.text("Total number of indexes",
indexesByType.values().stream().mapToInt(List::size).sum());
- private void printIndexInfo(PrintWriter pw, JsopBuilder json, Format
format) {
- ListMultimap<String, IndexInfo> infos = ArrayListMultimap.create();
- for (IndexInfo info : indexInfoService.getAllIndexInfo()) {
- infos.put(info.getType(), info);
- }
-
- keyValue("Total number of indexes ", infos.size(), pw, json, format);
-
- for (String type : infos.keySet()){
- List<IndexInfo> typedInfo = infos.get(type);
- String title = String.format("%s(%d)", type, typedInfo.size());
- printTitle(pw, title, format);
- addJsonKey(json, type);
- startJsonObject(json);
+ for (String type : indexesByType.keySet()){
+ List<IndexInfo> typedInfo = indexesByType.get(type);
+ po.startSection(type, true);
+ po.text("Number of " + type + " indexes", typedInfo.size());
for (IndexInfo info : typedInfo){
- printIndexInfo(pw, json, info, format);
+ indexInfo(po, info);
}
- endJsonObject(json);
+ po.endSection();
}
}
+ private void indexInfo(PrinterOutput po, IndexInfo info) {
+ po.startSection(info.getIndexPath(), false);
- private static void printIndexInfo(PrintWriter pw, JsopBuilder json,
IndexInfo info, Format format) {
- if (format == Format.TEXT) {
- pw.println(info.getIndexPath());
- }
- addJsonKey(json, info.getIndexPath());
- startJsonObject(json);
-
- keyValue(" Type ", info.getType(), pw, json,
format);
+ po.text("Type", info.getType());
if (info.getAsyncLaneName() != null) {
- keyValue(" Async ", true, pw, json, format);
- keyValue(" Async lane name ", info.getAsyncLaneName(),
pw, json, format);
+ po.text("Async", true);
+ po.text("Async lane name", info.getAsyncLaneName());
}
if (info.getIndexedUpToTime() > 0){
- keyValue(" Last indexed up to ",
formatTime(info.getIndexedUpToTime()), pw, json, format);
+ po.text("Last indexed up to",
formatTime(info.getIndexedUpToTime()));
}
if (info.getLastUpdatedTime() > 0){
- keyValue(" Last updated time ",
formatTime(info.getLastUpdatedTime()), pw, json, format);
+ po.text("Last updated time",
formatTime(info.getLastUpdatedTime()));
}
if (info.getCreationTimestamp() > 0){
- keyValue(" Creation time ",
formatTime(info.getCreationTimestamp()), pw, json, format);
+ po.text("Creation time", formatTime(info.getCreationTimestamp()));
}
if (info.getReindexCompletionTimestamp() > 0){
- keyValue(" Reindex completion time ",
formatTime(info.getReindexCompletionTimestamp()), pw, json, format);
+ po.text("Reindex completion time ",
formatTime(info.getReindexCompletionTimestamp()));
Review comment:
Please remove the trailing space here as well.
##########
File path:
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/inventory/IndexPrinter.java
##########
@@ -71,147 +70,107 @@ public IndexPrinter(IndexInfoService indexInfoService,
AsyncIndexInfoService asy
@Override
public void print(PrintWriter pw, Format format, boolean isZip) {
-
- if (format == Format.JSON) {
- JsopBuilder json = new JsopBuilder();
- startJsonObject(json);
- printAsyncIndexInfo(pw, json, format);
- printIndexInfo(pw, json, format);
- endJsonObject(json);
- pw.print(JsopBuilder.prettyPrint(json.toString()));
- } else {
- //TODO Highlight if failing
- printAsyncIndexInfo(pw, null, format);
- printIndexInfo(pw, null, format);
- }
+ PrinterOutput po = format == Format.JSON ? new JsonPrinterOutput() :
new TextPrinterOutput();
+ asyncLanesInfo(po);
+ indexInfo(po);
+ pw.print(po.output());
}
- private void printAsyncIndexInfo(PrintWriter pw, JsopBuilder json, Format
format) {
+ private void asyncLanesInfo(PrinterOutput po) {
List<String> asyncLanes =
ImmutableList.copyOf(asyncIndexInfoService.getAsyncLanes());
- String title = "Async Indexers State";
- printTitle(pw, title, format);
- addJsonKey(json, title);
- startJsonObject(json);
- keyValue("Number of async indexer lanes ", asyncLanes.size(), pw,
json, format);
- printWithNewLine(pw, "", format);
+ po.startSection("Async Indexers State", true);
+ po.text("Number of async indexer lanes", asyncLanes.size());
for (String lane : asyncLanes) {
- printWithNewLine(pw, lane, format);
- addJsonKey(json, lane);
+ po.startSection(lane, false);
AsyncIndexInfo info = asyncIndexInfoService.getInfo(lane);
- startJsonObject(json);
if (info != null) {
- keyValue(" Last indexed to ",
formatTime(info.getLastIndexedTo()), pw, json, format);
+ po.text("Last indexed to",
formatTime(info.getLastIndexedTo()));
IndexStatsMBean stats = info.getStatsMBean();
if (stats != null) {
- keyValue(" Status ", stats.getStatus(),
pw, json, format);
- keyValue(" Failing ", stats.isFailing(),
pw, json, format);
- keyValue(" Paused ", stats.isPaused(), pw,
json, format);
+ po.text("Status", stats.getStatus());
+ po.text("Failing", stats.isFailing());
+ po.text("Paused", stats.isPaused());
if (stats.isFailing()) {
- keyValue(" Failing since ",
stats.getFailingSince(), pw, json, format);
- keyValue(" Latest error ",
stats.getLatestError(), pw, json, format);
+ po.text("Failing since", stats.getFailingSince());
+ po.text("Latest error", stats.getLatestError());
}
}
- printWithNewLine(pw, "", format);
}
- endJsonObject(json);
+ po.endSection();
}
- endJsonObject(json);
+ po.endSection();
}
- private static void printTitle(PrintWriter pw, String title, Format
format) {
- if (format == Format.TEXT) {
- pw.println(title);
- pw.println(Strings.repeat("=", title.length()));
- pw.println();
- }
- }
+ private void indexInfo(PrinterOutput po) {
+ Map<String, List<IndexInfo>> indexesByType =
StreamSupport.stream(indexInfoService.getAllIndexInfo().spliterator(), false)
+ .collect(Collectors.groupingBy(IndexInfo::getType));
- private static void printWithNewLine(PrintWriter pw, String printLine,
Format format) {
- if (format == Format.TEXT) {
- pw.println(printLine);
- }
- }
+ po.text("Total number of indexes",
indexesByType.values().stream().mapToInt(List::size).sum());
- private void printIndexInfo(PrintWriter pw, JsopBuilder json, Format
format) {
- ListMultimap<String, IndexInfo> infos = ArrayListMultimap.create();
- for (IndexInfo info : indexInfoService.getAllIndexInfo()) {
- infos.put(info.getType(), info);
- }
-
- keyValue("Total number of indexes ", infos.size(), pw, json, format);
-
- for (String type : infos.keySet()){
- List<IndexInfo> typedInfo = infos.get(type);
- String title = String.format("%s(%d)", type, typedInfo.size());
- printTitle(pw, title, format);
- addJsonKey(json, type);
- startJsonObject(json);
+ for (String type : indexesByType.keySet()){
+ List<IndexInfo> typedInfo = indexesByType.get(type);
+ po.startSection(type, true);
+ po.text("Number of " + type + " indexes", typedInfo.size());
for (IndexInfo info : typedInfo){
- printIndexInfo(pw, json, info, format);
+ indexInfo(po, info);
}
- endJsonObject(json);
+ po.endSection();
}
}
+ private void indexInfo(PrinterOutput po, IndexInfo info) {
+ po.startSection(info.getIndexPath(), false);
- private static void printIndexInfo(PrintWriter pw, JsopBuilder json,
IndexInfo info, Format format) {
- if (format == Format.TEXT) {
- pw.println(info.getIndexPath());
- }
- addJsonKey(json, info.getIndexPath());
- startJsonObject(json);
-
- keyValue(" Type ", info.getType(), pw, json,
format);
+ po.text("Type", info.getType());
if (info.getAsyncLaneName() != null) {
- keyValue(" Async ", true, pw, json, format);
- keyValue(" Async lane name ", info.getAsyncLaneName(),
pw, json, format);
+ po.text("Async", true);
+ po.text("Async lane name", info.getAsyncLaneName());
}
if (info.getIndexedUpToTime() > 0){
- keyValue(" Last indexed up to ",
formatTime(info.getIndexedUpToTime()), pw, json, format);
+ po.text("Last indexed up to",
formatTime(info.getIndexedUpToTime()));
}
if (info.getLastUpdatedTime() > 0){
- keyValue(" Last updated time ",
formatTime(info.getLastUpdatedTime()), pw, json, format);
+ po.text("Last updated time",
formatTime(info.getLastUpdatedTime()));
}
if (info.getCreationTimestamp() > 0){
- keyValue(" Creation time ",
formatTime(info.getCreationTimestamp()), pw, json, format);
+ po.text("Creation time", formatTime(info.getCreationTimestamp()));
}
if (info.getReindexCompletionTimestamp() > 0){
- keyValue(" Reindex completion time ",
formatTime(info.getReindexCompletionTimestamp()), pw, json, format);
+ po.text("Reindex completion time ",
formatTime(info.getReindexCompletionTimestamp()));
}
if (info.getSizeInBytes() >= 0){
- keyValue(" Size ",
IOUtils.humanReadableByteCount(info.getSizeInBytes()), pw, json, format);
- keyValue(" Size (in Bytes) ", info.getSizeInBytes(),
pw, json, format);
+ po.text("Size",
IOUtils.humanReadableByteCount(info.getSizeInBytes()));
+ po.text("Size (in Bytes)", info.getSizeInBytes());
Review comment:
"Bytes" should be lower case in my view
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]