-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdistbench_node_manager.h
120 lines (95 loc) · 4.21 KB
/
distbench_node_manager.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
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
// Copyright 2023 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_NODE_MANAGER_H_
#define DISTBENCH_DISTBENCH_NODE_MANAGER_H_
#include "absl/status/statusor.h"
#include "distbench.grpc.pb.h"
#include "distbench_engine.h"
namespace distbench {
struct NodeManagerOpts {
int preassigned_node_id = -1;
std::string test_sequencer_service_address;
std::string default_data_plane_device;
std::string control_plane_device;
int* port;
std::vector<Attribute> attributes;
// This can be used to configure the service address that this node manager
// will advertise, in case the default does not work (E.g. DNS is unable to
// resolve the hostname). This is passed to gRPC unmodified, so it must be
// a valid "target" (I.e. it must include a protocol, host and port).
std::string service_address;
};
class NodeManager final : public DistBenchNodeManager::Service {
public:
~NodeManager() override;
absl::Status Initialize(const NodeManagerOpts& opts);
const NodeManagerOpts& GetOpts() { return opts_; }
void Shutdown();
void Wait();
const std::string& service_address() { return opts_.service_address; }
NodeManager();
grpc::Status ConfigureNode(grpc::ServerContext* context,
const NodeServiceConfig* request,
ServiceEndpointMap* response) override;
grpc::Status IntroducePeers(grpc::ServerContext* context,
const ServiceEndpointMap* request,
IntroducePeersResult* response) override;
grpc::Status RunTraffic(grpc::ServerContext* context,
const RunTrafficRequest* request,
RunTrafficResponse* response) override;
grpc::Status GetTrafficResult(grpc::ServerContext* context,
const GetTrafficResultRequest* request,
GetTrafficResultResponse* response) override;
grpc::Status CancelTraffic(grpc::ServerContext* context,
const CancelTrafficRequest* request,
CancelTrafficResult* response) override;
void CancelTraffic(absl::Status status);
grpc::Status ShutdownNode(grpc::ServerContext* context,
const ShutdownNodeRequest* request,
ShutdownNodeResult* response) override;
absl::StatusOr<ProtocolDriverOptions> ResolveProtocolDriverAlias(
const std::string& protocol_name);
private:
void ClearServices() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
struct ServiceOpts {
std::string_view service_name;
std::string_view service_type;
GridIndex service_index;
int* port;
std::string_view protocol;
std::string_view netdev_name;
};
absl::StatusOr<ProtocolDriverOptions> GetProtocolDriverOptionsFor(
const ServiceOpts& service_opts) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
absl::Status AllocService(const ServiceOpts& service_opts)
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
std::string NodeAlias() ABSL_LOCKS_EXCLUDED(config_mutex_) {
absl::MutexLock m(&config_mutex_);
return config_.node_alias();
}
absl::Mutex mutex_;
DistributedSystemDescription traffic_config_ ABSL_GUARDED_BY(mutex_);
ServiceEndpointMap peers_ ABSL_GUARDED_BY(mutex_);
std::map<std::string, std::unique_ptr<DistBenchEngine>> service_engines_
ABSL_GUARDED_BY(mutex_);
std::unique_ptr<grpc::Server> grpc_server_;
NodeManagerOpts opts_;
NodeRegistration registration_info_;
SafeNotification shutdown_requested_;
absl::Mutex config_mutex_;
NodeConfig config_ ABSL_GUARDED_BY(config_mutex_);
struct rusage rusage_start_test_;
};
} // namespace distbench
#endif // DISTBENCH_DISTBENCH_NODE_MANAGER_H_