Skip to content

Commit d11ac28

Browse files
authored
Walle API adapter replace specific devices (#18257)
(cherry-picked from 53455f3)
1 parent 9289583 commit d11ac28

File tree

5 files changed

+106
-19
lines changed

5 files changed

+106
-19
lines changed

ydb/core/cms/walle_api_handler.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class TWalleCrateTaskHandler : public TActorBootstrapped<TWalleCrateTaskHandler>
8080
auto &hosts = map["hosts"].GetArray();
8181
for (auto &host : hosts)
8282
*request->Record.AddHosts() = host.GetString();
83+
84+
auto &devices = map["devices"].GetArray();
85+
for (auto &device : devices)
86+
*request->Record.AddDevices() = device.GetString();
8387

8488
const auto &params = http.GetParams();
8589
if (params.contains("dry_run"))
@@ -109,9 +113,15 @@ class TWalleCrateTaskHandler : public TActorBootstrapped<TWalleCrateTaskHandler>
109113
NJson::TJsonValue hosts(NJson::JSON_ARRAY);
110114
for (auto &host : resp.GetHosts())
111115
hosts.AppendValue(host);
116+
117+
NJson::TJsonValue devices(NJson::JSON_ARRAY);
118+
for (auto &device : resp.GetDevices())
119+
devices.AppendValue(device);
120+
112121
NJson::TJsonValue map;
113122
map.InsertValue("id", resp.GetTaskId());
114123
map.InsertValue("hosts", hosts);
124+
map.InsertValue("devices", devices);
115125
map.InsertValue("status", status);
116126
map.InsertValue("message", resp.GetStatus().GetReason());
117127

@@ -147,12 +157,19 @@ class TWalleCrateTaskHandler : public TActorBootstrapped<TWalleCrateTaskHandler>
147157
void Reply(const TWalleListTasksResponse &resp, const TActorContext &ctx) {
148158
NJson::TJsonValue tasks(NJson::JSON_ARRAY);
149159
for (auto &task : resp.GetTasks()) {
160+
150161
NJson::TJsonValue hosts(NJson::JSON_ARRAY);
151162
for (auto &host : task.GetHosts())
152163
hosts.AppendValue(host);
164+
165+
NJson::TJsonValue devices(NJson::JSON_ARRAY);
166+
for (auto &device : task.GetDevices())
167+
devices.AppendValue(device);
168+
153169
NJson::TJsonValue map;
154170
map.InsertValue("id", task.GetTaskId());
155171
map.InsertValue("hosts", hosts);
172+
map.InsertValue("devices", devices);
156173
map.InsertValue("status", task.GetStatus());
157174

158175
tasks.AppendValue(map);
@@ -199,9 +216,15 @@ class TWalleCrateTaskHandler : public TActorBootstrapped<TWalleCrateTaskHandler>
199216
NJson::TJsonValue hosts(NJson::JSON_ARRAY);
200217
for (auto &host : resp.GetTask().GetHosts())
201218
hosts.AppendValue(host);
219+
220+
NJson::TJsonValue devices(NJson::JSON_ARRAY);
221+
for (auto &device : resp.GetTask().GetDevices())
222+
devices.AppendValue(device);
223+
202224
NJson::TJsonValue map;
203225
map.InsertValue("id", resp.GetTask().GetTaskId());
204226
map.InsertValue("hosts", hosts);
227+
map.InsertValue("devices", devices);
205228
map.InsertValue("status", status);
206229
map.InsertValue("message", resp.GetStatus().GetReason());
207230

ydb/core/cms/walle_check_task_adapter.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ class TWalleCheckTaskAdapter : public TActorBootstrapped<TWalleCheckTaskAdapter>
4141
if (State->ScheduledRequests.contains(task.RequestId)) {
4242
auto &req = State->ScheduledRequests.find(task.RequestId)->second;
4343

44-
for (auto &action : req.Request.GetActions())
44+
for (auto &action : req.Request.GetActions()) {
4545
*info.AddHosts() = action.GetHost();
46+
for (auto &device : action.GetDevices())
47+
*info.AddDevices() = device;
48+
}
4649

4750
TAutoPtr<TEvCms::TEvCheckRequest> event = new TEvCms::TEvCheckRequest;
4851
event->Record.SetUser(WALLE_CMS_USER);
@@ -53,8 +56,13 @@ class TWalleCheckTaskAdapter : public TActorBootstrapped<TWalleCheckTaskAdapter>
5356
Become(&TThis::StateWork, ctx, TDuration::Seconds(10), new TEvents::TEvWakeup());
5457
} else {
5558
for (auto &id : task.Permissions) {
56-
if (State->Permissions.contains(id))
57-
*info.AddHosts() = State->Permissions.find(id)->second.Action.GetHost();
59+
if (State->Permissions.contains(id)) {
60+
const auto &action = State->Permissions.find(id)->second.Action;
61+
*info.AddHosts() = action.GetHost();
62+
63+
for (auto &device : action.GetDevices())
64+
*info.AddDevices() = device;
65+
}
5866
}
5967

6068
if (!info.HostsSize()) {

ydb/core/cms/walle_create_task_adapter.cpp

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class TWalleCreateTaskAdapter : public TActorBootstrapped<TWalleCreateTaskAdapte
6565
resp->Record.MutableStatus()->SetReason(err);
6666
resp->Record.SetTaskId(rec.GetTaskId());
6767
resp->Record.MutableHosts()->CopyFrom(rec.GetHosts());
68+
resp->Record.MutableDevices()->CopyFrom(rec.GetDevices());
6869
ReplyAndDie(resp.Release(), ctx);
6970
}
7071

@@ -81,6 +82,7 @@ class TWalleCreateTaskAdapter : public TActorBootstrapped<TWalleCreateTaskAdapte
8182
Response->Record.MutableStatus()->CopyFrom(rec.GetStatus());
8283
Response->Record.SetTaskId(RequestEvent->Get()->Record.GetTaskId());
8384
Response->Record.MutableHosts()->CopyFrom(RequestEvent->Get()->Record.GetHosts());
85+
Response->Record.MutableDevices()->CopyFrom(RequestEvent->Get()->Record.GetDevices());
8486

8587
// In case of success or scheduled request we have to store
8688
// task information.
@@ -101,6 +103,52 @@ class TWalleCreateTaskAdapter : public TActorBootstrapped<TWalleCreateTaskAdapte
101103
ReplyAndDie(Response, ctx);
102104
}
103105

106+
void HandleReplaceDevicesAction(const TClusterInfoPtr &cluster,
107+
TAutoPtr<TEvCms::TEvPermissionRequest> &request,
108+
ui64 duration,
109+
const TActorContext &ctx) {
110+
auto &task = RequestEvent->Get()->Record;
111+
112+
if (task.DevicesSize() > 0) {
113+
// Replace specified devices on the specified host.
114+
if (task.HostsSize() != 1) {
115+
ReplyWithErrorAndDie(TStatus::WRONG_REQUEST, "Exactly one host must be specified if \"devices\" are set", ctx);
116+
return;
117+
}
118+
TString host = task.get_idx_hosts(0);
119+
auto &action = *request->Record.AddActions();
120+
action.SetHost(host);
121+
action.SetType(TAction::REPLACE_DEVICES);
122+
action.SetDuration(duration);
123+
124+
for (const auto& device : task.GetDevices())
125+
*action.AddDevices() = device;
126+
} else {
127+
// Replace all devices on all provided hosts.
128+
for (auto &host : task.GetHosts()) {
129+
auto &action = *request->Record.AddActions();
130+
action.SetHost(host);
131+
action.SetType(TAction::REPLACE_DEVICES);
132+
action.SetDuration(duration);
133+
for (const auto node : cluster->HostNodes(host)) {
134+
for (auto &pdiskId : node->PDisks)
135+
*action.AddDevices() = cluster->PDisk(pdiskId).GetDeviceName();
136+
}
137+
}
138+
}
139+
}
140+
141+
void HandleGenericAction(TAutoPtr<TEvCms::TEvPermissionRequest> &cmsRequest, TAction::EType actionType, ui64 duration) {
142+
auto &task = RequestEvent->Get()->Record;
143+
144+
for (auto &host : task.GetHosts()) {
145+
auto &action = *cmsRequest->Record.AddActions();
146+
action.SetHost(host);
147+
action.SetType(actionType);
148+
action.SetDuration(duration);
149+
}
150+
}
151+
104152
void Handle(TEvCms::TEvGetClusterInfoResponse::TPtr &ev, const TActorContext &ctx) {
105153
if (ev->Get()->Info->IsOutdated()) {
106154
ReplyWithErrorAndDie(TStatus::ERROR_TEMP, "Cannot collect cluster info", ctx);
@@ -135,23 +183,20 @@ class TWalleCreateTaskAdapter : public TActorBootstrapped<TWalleCreateTaskAdapte
135183
TAutoPtr<TEvCms::TEvWalleCreateTaskResponse> resp = new TEvCms::TEvWalleCreateTaskResponse;
136184
resp->Record.SetTaskId(task.GetTaskId());
137185
resp->Record.MutableHosts()->CopyFrom(task.GetHosts());
186+
resp->Record.MutableDevices()->CopyFrom(task.GetDevices());
138187
resp->Record.MutableStatus()->SetCode(TStatus::OK);
139188
ReplyAndDie(resp.Release(), ctx);
140189
return;
141190
} else {
142-
for (auto &host : task.GetHosts()) {
143-
auto &action = *request->Record.AddActions();
144-
action.SetHost(host);
145-
action.SetType(*it->second);
146-
// We always use infinite duration.
147-
// Wall-E MUST delete processed tasks.
148-
action.SetDuration(TDuration::Max().GetValue());
149-
if (action.GetType() == TAction::REPLACE_DEVICES) {
150-
for (const auto node : cluster->HostNodes(host)) {
151-
for (auto &pdiskId : node->PDisks)
152-
*action.AddDevices() = cluster->PDisk(pdiskId).GetDeviceName();
153-
}
154-
}
191+
// We always use infinite duration.
192+
// Wall-E MUST delete processed tasks.
193+
ui64 duration = TDuration::Max().GetValue();
194+
195+
TAction::EType actionType = *it->second;
196+
if (actionType == TAction::REPLACE_DEVICES) {
197+
HandleReplaceDevicesAction(cluster, request, duration, ctx);
198+
} else {
199+
HandleGenericAction(request, actionType, duration);
155200
}
156201
}
157202

ydb/core/cms/walle_list_tasks_adapter.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,21 @@ class TWalleListTasksAdapter : public TActorBootstrapped<TWalleListTasksAdapter>
3535
info.SetTaskId(task.TaskId);
3636
if (State->ScheduledRequests.contains(task.RequestId)) {
3737
auto &req = State->ScheduledRequests.find(task.RequestId)->second;
38-
for (auto &action : req.Request.GetActions())
38+
for (auto &action : req.Request.GetActions()) {
3939
*info.AddHosts() = action.GetHost();
40+
for (auto &device : action.GetDevices())
41+
*info.AddDevices() = device;
42+
}
4043
info.SetStatus("in-process");
4144
} else {
4245
for (auto &id : task.Permissions) {
43-
if (State->Permissions.contains(id))
44-
*info.AddHosts() = State->Permissions.find(id)->second.Action.GetHost();
46+
if (State->Permissions.contains(id)) {
47+
const auto &action = State->Permissions.find(id)->second.Action;
48+
*info.AddHosts() = action.GetHost();
49+
50+
for (auto &device : action.GetDevices())
51+
*info.AddDevices() = device;
52+
}
4553
}
4654
info.SetStatus("ok");
4755
}

ydb/core/protos/cms.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,14 @@ message TWalleCreateTaskRequest {
355355
optional string Action = 4;
356356
repeated string Hosts = 5;
357357
optional bool DryRun = 6;
358+
repeated string Devices = 7;
358359
}
359360

360361
message TWalleCreateTaskResponse {
361362
optional TStatus Status = 1;
362363
optional string TaskId = 2;
363364
repeated string Hosts = 3;
365+
repeated string Devices = 4;
364366
}
365367

366368
message TWalleListTasksRequest {
@@ -370,6 +372,7 @@ message TWalleTaskInfo {
370372
optional string TaskId = 1;
371373
repeated string Hosts = 2;
372374
optional string Status = 3;
375+
repeated string Devices = 4;
373376
}
374377

375378
message TWalleListTasksResponse {

0 commit comments

Comments
 (0)