aboutsummaryrefslogtreecommitdiffstats
path: root/vespaclient-java/src/main/java/com/yahoo/vespastat/Main.java
blob: 2349630df62f101bf9c7b02eae1e5dfcf8882682 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespastat;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Main application class
 *
 * @author bjorncs
 */
public class Main {

    private Main() {
    }

    public static void main(String[] args) {
        Logger.getLogger("").setLevel(Level.WARNING);
        CommandLineOptions options = new CommandLineOptions();
        try {
            ClientParameters params = options.parseCommandLineArguments(args);
            if (params.help) {
                options.printHelp();
                return;
            }
            BucketStatsRetriever retriever = new BucketStatsRetriever(
                    new DocumentAccessFactory(),
                    params.route,
                    createShutdownHookRegistrar());
            BucketStatsPrinter printer = new BucketStatsPrinter(retriever, System.out);
            printer.retrieveAndPrintBucketStats(params.selectionType, params.id, params.dumpData, params.bucketSpace);
        } catch (IllegalArgumentException e) {
            System.err.printf("Failed to parse command line arguments: %s.\n", e.getMessage());
        } catch (BucketStatsException e) {
            System.err.println(e.getMessage());
        }
    }

    private static BucketStatsRetriever.ShutdownHookRegistrar createShutdownHookRegistrar() {
        return runnable -> Runtime.getRuntime().addShutdownHook(new Thread(runnable));
    }

}