aboutsummaryrefslogtreecommitdiffstats
path: root/vespaclient-java/src/main/java/com/yahoo/vespastat/BucketStatsPrinter.java
blob: 372527d917169387afc369900719b4eedbfa533b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespastat;

import com.yahoo.document.BucketId;
import com.yahoo.documentapi.messagebus.protocol.GetBucketListReply;

import java.io.PrintStream;
import java.util.List;

/**
 * The class is responsible for printing bucket information to a printstream.
 *
 * @author bjorncs
 */
public class BucketStatsPrinter {
    private final BucketStatsRetriever retriever;
    private final PrintStream out;

    public BucketStatsPrinter(
            BucketStatsRetriever retriever,
            PrintStream out) {
        this.retriever = retriever;
        this.out = out;
    }

    public void retrieveAndPrintBucketStats(ClientParameters.SelectionType type, String id, boolean dumpData, String bucketSpace) throws BucketStatsException {
        BucketId bucketId = retriever.getBucketIdForType(type, id);
        if (type == ClientParameters.SelectionType.GROUP || type == ClientParameters.SelectionType.USER) {
            out.printf("Generated 32-bit bucket id: %s\n", bucketId);
        }

        List<GetBucketListReply.BucketInfo> bucketList = retriever.retrieveBucketList(bucketId, bucketSpace);
        printBucketList(bucketList);

        if (dumpData) {
            for (GetBucketListReply.BucketInfo bucketInfo : bucketList) {
                BucketId bucket = bucketInfo.getBucketId();
                String bucketStats = retriever.retrieveBucketStats(type, id, bucket, bucketSpace);
                printBucketStats(bucket, bucketStats);
            }
        }
    }

    private void printBucketList(List<GetBucketListReply.BucketInfo> bucketList) {
        if (bucketList.isEmpty()) {
            out.println("No actual files were stored for this bucket.");
        } else {
            out.println("Bucket maps to the following actual files:");
            for (GetBucketListReply.BucketInfo bucketInfo : bucketList) {
                out.printf("\t%s\n", bucketInfo);
            }
        }
    }

    private void printBucketStats(BucketId bucket, String stats) {
        out.printf("\nDetails for %s:\n%s", bucket, stats);
    }

}