aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storageapi/message/stat.cpp
blob: 3b97f4f554116359d337c415732de329c85a1aa5 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "stat.h"
#include <ostream>

namespace storage::api {

IMPLEMENT_COMMAND(StatBucketCommand, StatBucketReply)
IMPLEMENT_REPLY(StatBucketReply)
IMPLEMENT_COMMAND(GetBucketListCommand, GetBucketListReply)
IMPLEMENT_REPLY(GetBucketListReply)

StatBucketCommand::StatBucketCommand(const document::Bucket& bucket,
                                     vespalib::stringref documentSelection)
    : BucketCommand(MessageType::STATBUCKET, bucket),
      _docSelection(documentSelection)
{
}

StatBucketCommand::~StatBucketCommand() = default;

void
StatBucketCommand::print(std::ostream& out, bool verbose,
                         const std::string& indent) const
{
    out << "StatBucketCommand(" << getBucketId()
        << ", selection: " << _docSelection << ")";
    if (verbose) {
        out << " : ";
        BucketCommand::print(out, verbose, indent);
    }
}

StatBucketReply::StatBucketReply(const StatBucketCommand& cmd,
                                 vespalib::stringref results)
    : BucketReply(cmd),
      _results(results)
{
}

void
StatBucketReply::print(std::ostream& out, bool verbose,
                       const std::string& indent) const
{
    out << "StatBucketReply(" << getBucketId();
    if (verbose) {
        out << ", result: " << _results << ") : ";
        BucketReply::print(out, verbose, indent);
    } else {
        vespalib::string::size_type pos = _results.find('\n');
        vespalib::string overview;
        if (pos != vespalib::string::npos) {
            overview = _results.substr(0, pos) + " ...";
        } else {
            overview = _results;
        }
        out << ", result: " << overview << ")";
    }
}

GetBucketListCommand::GetBucketListCommand(const document::Bucket &bucket)
    : BucketCommand(MessageType::GETBUCKETLIST, bucket)
{
}

void
GetBucketListCommand::print(std::ostream& out, bool verbose,
                            const std::string& indent) const
{
    out << "GetBucketList(" << getBucketId() << ")";
    if (verbose) {
        out << " : ";
        BucketCommand::print(out, verbose, indent);
    }
}

GetBucketListReply::GetBucketListReply(const GetBucketListCommand& cmd)
    : BucketReply(cmd),
      _buckets()
{}

GetBucketListReply::~GetBucketListReply() {}

void
GetBucketListReply::print(std::ostream& out, bool verbose,
                          const std::string& indent) const
{
    out << "GetBucketListReply(" << getBucketId() << ", Info on "
        << _buckets.size() << " buckets)";
    if (verbose) {
        out << " : ";
        BucketReply::print(out, verbose, indent);
    }
}

std::ostream&
operator<<(std::ostream& out, const GetBucketListReply::BucketInfo& instance)
{
    out << "BucketInfo(" << instance._bucket << ": "
        << instance._bucketInformation << ")";
    return out;
}

}