forked from google/distbench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
distbench_test_sequencer.h
95 lines (75 loc) · 3.22 KB
/
distbench_test_sequencer.h
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
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef DISTBENCH_DISTBENCH_TEST_SEQUENCER_H_
#define DISTBENCH_DISTBENCH_TEST_SEQUENCER_H_
#include <set>
#include "distbench.grpc.pb.h"
#include "absl/status/statusor.h"
#include "absl/synchronization/notification.h"
namespace distbench {
struct RegisteredNode {
NodeRegistration registration;
std::unique_ptr<DistBenchNodeManager::Stub> stub;
std::string node_alias;
bool idle = true;
};
struct TestSequencerOpts {
int* port;
};
class TestSequencer final : public DistBenchTestSequencer::Service {
public:
~TestSequencer() override;
void Initialize(const TestSequencerOpts& opts);
const TestSequencerOpts& GetOpts() { return opts_; }
void Shutdown();
void Wait();
const std::string& service_address() { return service_address_; }
grpc::Status RegisterNode(grpc::ServerContext* context,
const NodeRegistration* request,
NodeConfig* response) override;
grpc::Status RunTestSequence(grpc::ServerContext* context,
const TestSequence* request,
TestSequenceResults* response) override;
private:
grpc::Status DoRunTestSequence(grpc::ServerContext* context,
const TestSequence* request,
TestSequenceResults* response);
absl::StatusOr<TestResult> DoRunTest(
grpc::ServerContext* context,
const DistributedSystemDescription& test);
absl::StatusOr<std::map<std::string, std::set<std::string>>> PlaceServices(
const DistributedSystemDescription& test);
absl::StatusOr<ServiceEndpointMap> ConfigureNodes(
const std::map<std::string, std::set<std::string>>& node_service_map,
const DistributedSystemDescription& test);
absl::Status IntroducePeers(
const std::map<std::string, std::set<std::string>>& node_service_map,
ServiceEndpointMap service_map);
absl::StatusOr<ServiceLogs> RunTraffic(
const std::map<std::string, std::set<std::string>>& node_service_map);
void CancelTraffic() ABSL_LOCKS_EXCLUDED(mutex_);
absl::Mutex mutex_;
std::vector<RegisteredNode> registered_nodes_ ABSL_GUARDED_BY(mutex_);
std::map<std::string, int> node_alias_id_map_ ABSL_GUARDED_BY(mutex_);
std::map<std::string, int> node_registration_id_map_ ABSL_GUARDED_BY(mutex_);
grpc::ServerContext* running_test_sequence_context_ ABSL_GUARDED_BY(mutex_)
= nullptr;
std::shared_ptr<absl::Notification> running_test_notification_
ABSL_GUARDED_BY(mutex_);
std::unique_ptr<grpc::Server> grpc_server_;
std::string service_address_;
TestSequencerOpts opts_;
};
} // namespace distbench
#endif // DISTBENCH_DISTBENCH_TEST_SEQUENCER_H_