@@ -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
0 commit comments