aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storageapi/message/state.cpp
blob: 5a50167f58453f5499ed118c1e85ecca8869cabc (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "state.h"
#include <vespa/storageapi/messageapi/storagemessage.h>
#include <vespa/vdslib/state/clusterstate.h>
#include <ostream>

namespace storage {
namespace api {

IMPLEMENT_COMMAND(GetNodeStateCommand, GetNodeStateReply)
IMPLEMENT_REPLY(GetNodeStateReply)
IMPLEMENT_COMMAND(SetSystemStateCommand, SetSystemStateReply)
IMPLEMENT_REPLY(SetSystemStateReply)
IMPLEMENT_COMMAND(ActivateClusterStateVersionCommand, ActivateClusterStateVersionReply)
IMPLEMENT_REPLY(ActivateClusterStateVersionReply)

GetNodeStateCommand::GetNodeStateCommand(lib::NodeState::UP expectedState)
    : StorageCommand(MessageType::GETNODESTATE),
      _expectedState(std::move(expectedState))
{
}

void
GetNodeStateCommand::print(std::ostream& out, bool verbose,
                           const std::string& indent) const
{
    out << "GetNodeStateCommand(";
    if (_expectedState.get() != 0) {
        out << "Expected state: " << *_expectedState;
    }
    out << ")";
    if (verbose) {
        out << " : ";
        StorageCommand::print(out, verbose, indent);
    }
}

GetNodeStateReply::GetNodeStateReply(const GetNodeStateCommand& cmd)
    : StorageReply(cmd),
      _state()
{
}

GetNodeStateReply::GetNodeStateReply(const GetNodeStateCommand& cmd,
                                     const lib::NodeState& state)
    : StorageReply(cmd),
      _state(new lib::NodeState(state))
{
}

void
GetNodeStateReply::print(std::ostream& out, bool verbose,
                         const std::string& indent) const
{
    out << "GetNodeStateReply(";
    if (_state.get()) {
        out << "State: " << *_state;
    }
    out << ")";
    if (verbose) {
        out << " : ";
        StorageReply::print(out, verbose, indent);
    }
}

SetSystemStateCommand::SetSystemStateCommand(const lib::ClusterStateBundle& state)
    : StorageCommand(MessageType::SETSYSTEMSTATE),
      _state(state)
{
}

SetSystemStateCommand::SetSystemStateCommand(const lib::ClusterState& state)
    : StorageCommand(MessageType::SETSYSTEMSTATE),
      _state(state)
{
}

void
SetSystemStateCommand::print(std::ostream& out, bool verbose,
                             const std::string& indent) const
{
    out << "SetSystemStateCommand(" << *_state.getBaselineClusterState() << ")";
    if (verbose) {
        out << " : ";
        StorageCommand::print(out, verbose, indent);
    }
}

SetSystemStateReply::SetSystemStateReply(const SetSystemStateCommand& cmd)
    : StorageReply(cmd),
      _state(cmd.getClusterStateBundle())
{
}

void
SetSystemStateReply::print(std::ostream& out, bool verbose,
                           const std::string& indent) const
{
    out << "SetSystemStateReply()";
    if (verbose) {
        out << " : ";
        StorageReply::print(out, verbose, indent);
    }
}

ActivateClusterStateVersionCommand::ActivateClusterStateVersionCommand(uint32_t version)
    : StorageCommand(MessageType::ACTIVATE_CLUSTER_STATE_VERSION),
      _version(version)
{
}

void ActivateClusterStateVersionCommand::print(std::ostream& out, bool verbose,
                                               const std::string& indent) const
{
    out << "ActivateClusterStateVersionCommand(" << _version << ")";
    if (verbose) {
        out << " : ";
        StorageCommand::print(out, verbose, indent);
    }
}

ActivateClusterStateVersionReply::ActivateClusterStateVersionReply(const ActivateClusterStateVersionCommand& cmd)
    : StorageReply(cmd),
      _activateVersion(cmd.version()),
      _actualVersion(0) // Must be set explicitly
{
}

void ActivateClusterStateVersionReply::print(std::ostream& out, bool verbose,
                                             const std::string& indent) const
{
    out << "ActivateClusterStateVersionReply(activate " << _activateVersion
        << ", actual " << _actualVersion << ")";
    if (verbose) {
        out << " : ";
        StorageReply::print(out, verbose, indent);
    }
}

} // api
} // storage