aditjind_crate/
tasks.rs

1/*
2 * Licensed to Elasticsearch B.V. under one or more contributor
3 * license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright
5 * ownership. Elasticsearch B.V. licenses this file to you under
6 * the Apache License, Version 2.0 (the "License"); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *	http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20// -----------------------------------------------
21// This file is generated, Please do not edit it manually.
22// Run the following in the root of the repo to regenerate:
23//
24// cargo make generate-api
25// -----------------------------------------------
26
27//! Task Management APIs
28//!
29//! Manage tasks currently executing on one or more nodes in the cluster.
30
31#![cfg(feature = "experimental-apis")]
32#![doc = " \n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n        "]
33#![allow(unused_imports)]
34use crate::{
35    client::OpenSearch,
36    error::Error,
37    http::{
38        headers::{HeaderMap, HeaderName, HeaderValue, ACCEPT, CONTENT_TYPE},
39        request::{Body, JsonBody, NdBody, PARTS_ENCODED},
40        response::Response,
41        transport::Transport,
42        Method,
43    },
44    params::*,
45};
46use percent_encoding::percent_encode;
47use serde::Serialize;
48use std::{borrow::Cow, time::Duration};
49#[cfg(feature = "experimental-apis")]
50#[derive(Debug, Clone, PartialEq)]
51#[doc = "API parts for the Tasks Cancel API"]
52pub enum TasksCancelParts<'b> {
53    #[doc = "No parts"]
54    None,
55    #[doc = "TaskId"]
56    TaskId(&'b str),
57}
58#[cfg(feature = "experimental-apis")]
59impl<'b> TasksCancelParts<'b> {
60    #[doc = "Builds a relative URL path to the Tasks Cancel API"]
61    pub fn url(self) -> Cow<'static, str> {
62        match self {
63            TasksCancelParts::None => "/_tasks/_cancel".into(),
64            TasksCancelParts::TaskId(ref task_id) => {
65                let encoded_task_id: Cow<str> =
66                    percent_encode(task_id.as_bytes(), PARTS_ENCODED).into();
67                let mut p = String::with_capacity(16usize + encoded_task_id.len());
68                p.push_str("/_tasks/");
69                p.push_str(encoded_task_id.as_ref());
70                p.push_str("/_cancel");
71                p.into()
72            }
73        }
74    }
75}
76#[doc = "Builder for the [Tasks Cancel API](https://opensearch.org/docs/)\n\nCancels a task, if it can be cancelled through an API."]
77#[doc = "&nbsp;\n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n        "]
78#[cfg(feature = "experimental-apis")]
79#[derive(Clone, Debug)]
80pub struct TasksCancel<'a, 'b, B> {
81    transport: &'a Transport,
82    parts: TasksCancelParts<'b>,
83    actions: Option<&'b [&'b str]>,
84    body: Option<B>,
85    error_trace: Option<bool>,
86    filter_path: Option<&'b [&'b str]>,
87    headers: HeaderMap,
88    human: Option<bool>,
89    nodes: Option<&'b [&'b str]>,
90    parent_task_id: Option<&'b str>,
91    pretty: Option<bool>,
92    request_timeout: Option<Duration>,
93    source: Option<&'b str>,
94    wait_for_completion: Option<bool>,
95}
96#[cfg(feature = "experimental-apis")]
97impl<'a, 'b, B> TasksCancel<'a, 'b, B>
98where
99    B: Body,
100{
101    #[doc = "Creates a new instance of [TasksCancel] with the specified API parts"]
102    pub fn new(transport: &'a Transport, parts: TasksCancelParts<'b>) -> Self {
103        let headers = HeaderMap::new();
104        TasksCancel {
105            transport,
106            parts,
107            headers,
108            actions: None,
109            body: None,
110            error_trace: None,
111            filter_path: None,
112            human: None,
113            nodes: None,
114            parent_task_id: None,
115            pretty: None,
116            request_timeout: None,
117            source: None,
118            wait_for_completion: None,
119        }
120    }
121    #[doc = "A comma-separated list of actions that should be cancelled. Leave empty to cancel all."]
122    pub fn actions(mut self, actions: &'b [&'b str]) -> Self {
123        self.actions = Some(actions);
124        self
125    }
126    #[doc = "The body for the API call"]
127    pub fn body<T>(self, body: T) -> TasksCancel<'a, 'b, JsonBody<T>>
128    where
129        T: Serialize,
130    {
131        TasksCancel {
132            transport: self.transport,
133            parts: self.parts,
134            body: Some(body.into()),
135            actions: self.actions,
136            error_trace: self.error_trace,
137            filter_path: self.filter_path,
138            headers: self.headers,
139            human: self.human,
140            nodes: self.nodes,
141            parent_task_id: self.parent_task_id,
142            pretty: self.pretty,
143            request_timeout: self.request_timeout,
144            source: self.source,
145            wait_for_completion: self.wait_for_completion,
146        }
147    }
148    #[doc = "Include the stack trace of returned errors."]
149    pub fn error_trace(mut self, error_trace: bool) -> Self {
150        self.error_trace = Some(error_trace);
151        self
152    }
153    #[doc = "A comma-separated list of filters used to reduce the response."]
154    pub fn filter_path(mut self, filter_path: &'b [&'b str]) -> Self {
155        self.filter_path = Some(filter_path);
156        self
157    }
158    #[doc = "Adds a HTTP header"]
159    pub fn header(mut self, key: HeaderName, value: HeaderValue) -> Self {
160        self.headers.insert(key, value);
161        self
162    }
163    #[doc = "Return human readable values for statistics."]
164    pub fn human(mut self, human: bool) -> Self {
165        self.human = Some(human);
166        self
167    }
168    #[doc = "A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes"]
169    pub fn nodes(mut self, nodes: &'b [&'b str]) -> Self {
170        self.nodes = Some(nodes);
171        self
172    }
173    #[doc = "Cancel tasks with specified parent task id (node_id:task_number). Set to -1 to cancel all."]
174    pub fn parent_task_id(mut self, parent_task_id: &'b str) -> Self {
175        self.parent_task_id = Some(parent_task_id);
176        self
177    }
178    #[doc = "Pretty format the returned JSON response."]
179    pub fn pretty(mut self, pretty: bool) -> Self {
180        self.pretty = Some(pretty);
181        self
182    }
183    #[doc = "Sets a request timeout for this API call.\n\nThe timeout is applied from when the request starts connecting until the response body has finished."]
184    pub fn request_timeout(mut self, timeout: Duration) -> Self {
185        self.request_timeout = Some(timeout);
186        self
187    }
188    #[doc = "The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests."]
189    pub fn source(mut self, source: &'b str) -> Self {
190        self.source = Some(source);
191        self
192    }
193    #[doc = "Should the request block until the cancellation of the task and its descendant tasks is completed. Defaults to false"]
194    pub fn wait_for_completion(mut self, wait_for_completion: bool) -> Self {
195        self.wait_for_completion = Some(wait_for_completion);
196        self
197    }
198    #[doc = "Creates an asynchronous call to the Tasks Cancel API that can be awaited"]
199    pub async fn send(self) -> Result<Response, Error> {
200        let path = self.parts.url();
201        let method = Method::Post;
202        let headers = self.headers;
203        let timeout = self.request_timeout;
204        let query_string = {
205            #[serde_with::skip_serializing_none]
206            #[derive(Serialize)]
207            struct QueryParams<'b> {
208                #[serde(serialize_with = "crate::client::serialize_coll_qs")]
209                actions: Option<&'b [&'b str]>,
210                error_trace: Option<bool>,
211                #[serde(serialize_with = "crate::client::serialize_coll_qs")]
212                filter_path: Option<&'b [&'b str]>,
213                human: Option<bool>,
214                #[serde(serialize_with = "crate::client::serialize_coll_qs")]
215                nodes: Option<&'b [&'b str]>,
216                parent_task_id: Option<&'b str>,
217                pretty: Option<bool>,
218                source: Option<&'b str>,
219                wait_for_completion: Option<bool>,
220            }
221            let query_params = QueryParams {
222                actions: self.actions,
223                error_trace: self.error_trace,
224                filter_path: self.filter_path,
225                human: self.human,
226                nodes: self.nodes,
227                parent_task_id: self.parent_task_id,
228                pretty: self.pretty,
229                source: self.source,
230                wait_for_completion: self.wait_for_completion,
231            };
232            Some(query_params)
233        };
234        let body = self.body;
235        let response = self
236            .transport
237            .send(method, &path, headers, query_string.as_ref(), body, timeout)
238            .await?;
239        Ok(response)
240    }
241}
242#[cfg(feature = "experimental-apis")]
243#[derive(Debug, Clone, PartialEq)]
244#[doc = "API parts for the Tasks Get API"]
245pub enum TasksGetParts<'b> {
246    #[doc = "TaskId"]
247    TaskId(&'b str),
248}
249#[cfg(feature = "experimental-apis")]
250impl<'b> TasksGetParts<'b> {
251    #[doc = "Builds a relative URL path to the Tasks Get API"]
252    pub fn url(self) -> Cow<'static, str> {
253        match self {
254            TasksGetParts::TaskId(ref task_id) => {
255                let encoded_task_id: Cow<str> =
256                    percent_encode(task_id.as_bytes(), PARTS_ENCODED).into();
257                let mut p = String::with_capacity(8usize + encoded_task_id.len());
258                p.push_str("/_tasks/");
259                p.push_str(encoded_task_id.as_ref());
260                p.into()
261            }
262        }
263    }
264}
265#[doc = "Builder for the [Tasks Get API](https://opensearch.org/docs/)\n\nReturns information about a task."]
266#[doc = "&nbsp;\n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n        "]
267#[cfg(feature = "experimental-apis")]
268#[derive(Clone, Debug)]
269pub struct TasksGet<'a, 'b> {
270    transport: &'a Transport,
271    parts: TasksGetParts<'b>,
272    error_trace: Option<bool>,
273    filter_path: Option<&'b [&'b str]>,
274    headers: HeaderMap,
275    human: Option<bool>,
276    pretty: Option<bool>,
277    request_timeout: Option<Duration>,
278    source: Option<&'b str>,
279    timeout: Option<&'b str>,
280    wait_for_completion: Option<bool>,
281}
282#[cfg(feature = "experimental-apis")]
283impl<'a, 'b> TasksGet<'a, 'b> {
284    #[doc = "Creates a new instance of [TasksGet] with the specified API parts"]
285    pub fn new(transport: &'a Transport, parts: TasksGetParts<'b>) -> Self {
286        let headers = HeaderMap::new();
287        TasksGet {
288            transport,
289            parts,
290            headers,
291            error_trace: None,
292            filter_path: None,
293            human: None,
294            pretty: None,
295            request_timeout: None,
296            source: None,
297            timeout: None,
298            wait_for_completion: None,
299        }
300    }
301    #[doc = "Include the stack trace of returned errors."]
302    pub fn error_trace(mut self, error_trace: bool) -> Self {
303        self.error_trace = Some(error_trace);
304        self
305    }
306    #[doc = "A comma-separated list of filters used to reduce the response."]
307    pub fn filter_path(mut self, filter_path: &'b [&'b str]) -> Self {
308        self.filter_path = Some(filter_path);
309        self
310    }
311    #[doc = "Adds a HTTP header"]
312    pub fn header(mut self, key: HeaderName, value: HeaderValue) -> Self {
313        self.headers.insert(key, value);
314        self
315    }
316    #[doc = "Return human readable values for statistics."]
317    pub fn human(mut self, human: bool) -> Self {
318        self.human = Some(human);
319        self
320    }
321    #[doc = "Pretty format the returned JSON response."]
322    pub fn pretty(mut self, pretty: bool) -> Self {
323        self.pretty = Some(pretty);
324        self
325    }
326    #[doc = "Sets a request timeout for this API call.\n\nThe timeout is applied from when the request starts connecting until the response body has finished."]
327    pub fn request_timeout(mut self, timeout: Duration) -> Self {
328        self.request_timeout = Some(timeout);
329        self
330    }
331    #[doc = "The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests."]
332    pub fn source(mut self, source: &'b str) -> Self {
333        self.source = Some(source);
334        self
335    }
336    #[doc = "Explicit operation timeout"]
337    pub fn timeout(mut self, timeout: &'b str) -> Self {
338        self.timeout = Some(timeout);
339        self
340    }
341    #[doc = "Wait for the matching tasks to complete (default: false)"]
342    pub fn wait_for_completion(mut self, wait_for_completion: bool) -> Self {
343        self.wait_for_completion = Some(wait_for_completion);
344        self
345    }
346    #[doc = "Creates an asynchronous call to the Tasks Get API that can be awaited"]
347    pub async fn send(self) -> Result<Response, Error> {
348        let path = self.parts.url();
349        let method = Method::Get;
350        let headers = self.headers;
351        let timeout = self.request_timeout;
352        let query_string = {
353            #[serde_with::skip_serializing_none]
354            #[derive(Serialize)]
355            struct QueryParams<'b> {
356                error_trace: Option<bool>,
357                #[serde(serialize_with = "crate::client::serialize_coll_qs")]
358                filter_path: Option<&'b [&'b str]>,
359                human: Option<bool>,
360                pretty: Option<bool>,
361                source: Option<&'b str>,
362                timeout: Option<&'b str>,
363                wait_for_completion: Option<bool>,
364            }
365            let query_params = QueryParams {
366                error_trace: self.error_trace,
367                filter_path: self.filter_path,
368                human: self.human,
369                pretty: self.pretty,
370                source: self.source,
371                timeout: self.timeout,
372                wait_for_completion: self.wait_for_completion,
373            };
374            Some(query_params)
375        };
376        let body = Option::<()>::None;
377        let response = self
378            .transport
379            .send(method, &path, headers, query_string.as_ref(), body, timeout)
380            .await?;
381        Ok(response)
382    }
383}
384#[cfg(feature = "experimental-apis")]
385#[derive(Debug, Clone, PartialEq)]
386#[doc = "API parts for the Tasks List API"]
387pub enum TasksListParts {
388    #[doc = "No parts"]
389    None,
390}
391#[cfg(feature = "experimental-apis")]
392impl TasksListParts {
393    #[doc = "Builds a relative URL path to the Tasks List API"]
394    pub fn url(self) -> Cow<'static, str> {
395        match self {
396            TasksListParts::None => "/_tasks".into(),
397        }
398    }
399}
400#[doc = "Builder for the [Tasks List API](https://opensearch.org/docs/)\n\nReturns a list of tasks."]
401#[doc = "&nbsp;\n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n        "]
402#[cfg(feature = "experimental-apis")]
403#[derive(Clone, Debug)]
404pub struct TasksList<'a, 'b> {
405    transport: &'a Transport,
406    parts: TasksListParts,
407    actions: Option<&'b [&'b str]>,
408    detailed: Option<bool>,
409    error_trace: Option<bool>,
410    filter_path: Option<&'b [&'b str]>,
411    group_by: Option<GroupBy>,
412    headers: HeaderMap,
413    human: Option<bool>,
414    nodes: Option<&'b [&'b str]>,
415    parent_task_id: Option<&'b str>,
416    pretty: Option<bool>,
417    request_timeout: Option<Duration>,
418    source: Option<&'b str>,
419    timeout: Option<&'b str>,
420    wait_for_completion: Option<bool>,
421}
422#[cfg(feature = "experimental-apis")]
423impl<'a, 'b> TasksList<'a, 'b> {
424    #[doc = "Creates a new instance of [TasksList]"]
425    pub fn new(transport: &'a Transport) -> Self {
426        let headers = HeaderMap::new();
427        TasksList {
428            transport,
429            parts: TasksListParts::None,
430            headers,
431            actions: None,
432            detailed: None,
433            error_trace: None,
434            filter_path: None,
435            group_by: None,
436            human: None,
437            nodes: None,
438            parent_task_id: None,
439            pretty: None,
440            request_timeout: None,
441            source: None,
442            timeout: None,
443            wait_for_completion: None,
444        }
445    }
446    #[doc = "A comma-separated list of actions that should be returned. Leave empty to return all."]
447    pub fn actions(mut self, actions: &'b [&'b str]) -> Self {
448        self.actions = Some(actions);
449        self
450    }
451    #[doc = "Return detailed task information (default: false)"]
452    pub fn detailed(mut self, detailed: bool) -> Self {
453        self.detailed = Some(detailed);
454        self
455    }
456    #[doc = "Include the stack trace of returned errors."]
457    pub fn error_trace(mut self, error_trace: bool) -> Self {
458        self.error_trace = Some(error_trace);
459        self
460    }
461    #[doc = "A comma-separated list of filters used to reduce the response."]
462    pub fn filter_path(mut self, filter_path: &'b [&'b str]) -> Self {
463        self.filter_path = Some(filter_path);
464        self
465    }
466    #[doc = "Group tasks by nodes or parent/child relationships"]
467    pub fn group_by(mut self, group_by: GroupBy) -> Self {
468        self.group_by = Some(group_by);
469        self
470    }
471    #[doc = "Adds a HTTP header"]
472    pub fn header(mut self, key: HeaderName, value: HeaderValue) -> Self {
473        self.headers.insert(key, value);
474        self
475    }
476    #[doc = "Return human readable values for statistics."]
477    pub fn human(mut self, human: bool) -> Self {
478        self.human = Some(human);
479        self
480    }
481    #[doc = "A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes"]
482    pub fn nodes(mut self, nodes: &'b [&'b str]) -> Self {
483        self.nodes = Some(nodes);
484        self
485    }
486    #[doc = "Return tasks with specified parent task id (node_id:task_number). Set to -1 to return all."]
487    pub fn parent_task_id(mut self, parent_task_id: &'b str) -> Self {
488        self.parent_task_id = Some(parent_task_id);
489        self
490    }
491    #[doc = "Pretty format the returned JSON response."]
492    pub fn pretty(mut self, pretty: bool) -> Self {
493        self.pretty = Some(pretty);
494        self
495    }
496    #[doc = "Sets a request timeout for this API call.\n\nThe timeout is applied from when the request starts connecting until the response body has finished."]
497    pub fn request_timeout(mut self, timeout: Duration) -> Self {
498        self.request_timeout = Some(timeout);
499        self
500    }
501    #[doc = "The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests."]
502    pub fn source(mut self, source: &'b str) -> Self {
503        self.source = Some(source);
504        self
505    }
506    #[doc = "Explicit operation timeout"]
507    pub fn timeout(mut self, timeout: &'b str) -> Self {
508        self.timeout = Some(timeout);
509        self
510    }
511    #[doc = "Wait for the matching tasks to complete (default: false)"]
512    pub fn wait_for_completion(mut self, wait_for_completion: bool) -> Self {
513        self.wait_for_completion = Some(wait_for_completion);
514        self
515    }
516    #[doc = "Creates an asynchronous call to the Tasks List API that can be awaited"]
517    pub async fn send(self) -> Result<Response, Error> {
518        let path = self.parts.url();
519        let method = Method::Get;
520        let headers = self.headers;
521        let timeout = self.request_timeout;
522        let query_string = {
523            #[serde_with::skip_serializing_none]
524            #[derive(Serialize)]
525            struct QueryParams<'b> {
526                #[serde(serialize_with = "crate::client::serialize_coll_qs")]
527                actions: Option<&'b [&'b str]>,
528                detailed: Option<bool>,
529                error_trace: Option<bool>,
530                #[serde(serialize_with = "crate::client::serialize_coll_qs")]
531                filter_path: Option<&'b [&'b str]>,
532                group_by: Option<GroupBy>,
533                human: Option<bool>,
534                #[serde(serialize_with = "crate::client::serialize_coll_qs")]
535                nodes: Option<&'b [&'b str]>,
536                parent_task_id: Option<&'b str>,
537                pretty: Option<bool>,
538                source: Option<&'b str>,
539                timeout: Option<&'b str>,
540                wait_for_completion: Option<bool>,
541            }
542            let query_params = QueryParams {
543                actions: self.actions,
544                detailed: self.detailed,
545                error_trace: self.error_trace,
546                filter_path: self.filter_path,
547                group_by: self.group_by,
548                human: self.human,
549                nodes: self.nodes,
550                parent_task_id: self.parent_task_id,
551                pretty: self.pretty,
552                source: self.source,
553                timeout: self.timeout,
554                wait_for_completion: self.wait_for_completion,
555            };
556            Some(query_params)
557        };
558        let body = Option::<()>::None;
559        let response = self
560            .transport
561            .send(method, &path, headers, query_string.as_ref(), body, timeout)
562            .await?;
563        Ok(response)
564    }
565}
566#[doc = "Namespace client for Tasks APIs"]
567#[doc = "&nbsp;\n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n        "]
568#[cfg(feature = "experimental-apis")]
569pub struct Tasks<'a> {
570    transport: &'a Transport,
571}
572#[cfg(feature = "experimental-apis")]
573impl<'a> Tasks<'a> {
574    #[doc = "Creates a new instance of [Tasks]"]
575    pub fn new(transport: &'a Transport) -> Self {
576        Self { transport }
577    }
578    pub fn transport(&self) -> &Transport {
579        self.transport
580    }
581    #[doc = "[Tasks Cancel API](https://opensearch.org/docs/)\n\nCancels a task, if it can be cancelled through an API."]
582    #[doc = "&nbsp;\n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n        "]
583    #[cfg(feature = "experimental-apis")]
584    pub fn cancel<'b>(&'a self, parts: TasksCancelParts<'b>) -> TasksCancel<'a, 'b, ()> {
585        TasksCancel::new(self.transport(), parts)
586    }
587    #[doc = "[Tasks Get API](https://opensearch.org/docs/)\n\nReturns information about a task."]
588    #[doc = "&nbsp;\n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n        "]
589    #[cfg(feature = "experimental-apis")]
590    pub fn get<'b>(&'a self, parts: TasksGetParts<'b>) -> TasksGet<'a, 'b> {
591        TasksGet::new(self.transport(), parts)
592    }
593    #[doc = "[Tasks List API](https://opensearch.org/docs/)\n\nReturns a list of tasks."]
594    #[doc = "&nbsp;\n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n        "]
595    #[cfg(feature = "experimental-apis")]
596    pub fn list<'b>(&'a self) -> TasksList<'a, 'b> {
597        TasksList::new(self.transport())
598    }
599}
600#[cfg(feature = "experimental-apis")]
601impl OpenSearch {
602    #[doc = "Creates a namespace client for Tasks APIs"]
603    pub fn tasks(&self) -> Tasks {
604        Tasks::new(self.transport())
605    }
606}