2021-08-06 12:59:39 +05:30
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
#
|
|
|
|
|
# The OpenSearch Contributors require contributions made to
|
|
|
|
|
# this file be licensed under the Apache-2.0 license or a
|
|
|
|
|
# compatible open source license.
|
|
|
|
|
#
|
|
|
|
|
# Modifications Copyright OpenSearch Contributors. See
|
|
|
|
|
# GitHub history for details.
|
|
|
|
|
#
|
2020-07-02 13:15:25 -05:00
|
|
|
# Licensed to Elasticsearch B.V. under one or more contributor
|
|
|
|
|
# license agreements. See the NOTICE file distributed with
|
|
|
|
|
# this work for additional information regarding copyright
|
|
|
|
|
# ownership. Elasticsearch B.V. licenses this file to you 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
|
|
|
|
|
#
|
|
|
|
|
# http://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.
|
2020-04-23 11:22:08 -05:00
|
|
|
|
2020-03-13 16:20:54 -05:00
|
|
|
import warnings
|
2021-01-13 14:21:04 -06:00
|
|
|
|
|
|
|
|
from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params
|
2016-03-22 21:04:07 +01:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
|
2016-03-22 21:04:07 +01:00
|
|
|
class TasksClient(NamespacedClient):
|
2019-05-10 09:16:33 -06:00
|
|
|
@query_params(
|
|
|
|
|
"actions",
|
|
|
|
|
"detailed",
|
|
|
|
|
"group_by",
|
|
|
|
|
"nodes",
|
|
|
|
|
"parent_task_id",
|
|
|
|
|
"timeout",
|
2019-12-17 22:31:35 +01:00
|
|
|
"wait_for_completion",
|
2019-05-10 09:16:33 -06:00
|
|
|
)
|
2020-03-11 16:33:15 -05:00
|
|
|
def list(self, params=None, headers=None):
|
2016-03-22 21:04:07 +01:00
|
|
|
"""
|
2019-12-17 22:31:35 +01:00
|
|
|
Returns a list of tasks.
|
2020-10-20 13:02:15 -05:00
|
|
|
|
2016-03-22 21:04:07 +01:00
|
|
|
|
2020-12-08 13:18:08 -06:00
|
|
|
.. warning::
|
|
|
|
|
|
|
|
|
|
This API is **experimental** so may include breaking changes
|
|
|
|
|
or be removed in a future version
|
|
|
|
|
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg actions: A comma-separated list of actions that should be
|
|
|
|
|
returned. Leave empty to return all.
|
2016-03-22 21:04:07 +01:00
|
|
|
:arg detailed: Return detailed task information (default: false)
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg group_by: Group tasks by nodes or parent/child
|
2020-02-21 12:23:01 -06:00
|
|
|
relationships Valid choices: nodes, parents, none Default: nodes
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg nodes: 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
|
2017-10-26 14:51:37 +02:00
|
|
|
:arg parent_task_id: Return tasks with specified parent task id
|
2016-05-17 14:12:39 +02:00
|
|
|
(node_id:task_number). Set to -1 to return all.
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg timeout: Explicit operation timeout
|
|
|
|
|
:arg wait_for_completion: Wait for the matching tasks to
|
|
|
|
|
complete (default: false)
|
2016-03-22 21:04:07 +01:00
|
|
|
"""
|
2020-03-11 16:33:15 -05:00
|
|
|
return self.transport.perform_request(
|
|
|
|
|
"GET", "/_tasks", params=params, headers=headers
|
|
|
|
|
)
|
2016-03-22 21:04:07 +01:00
|
|
|
|
2020-04-23 11:20:33 -05:00
|
|
|
@query_params("actions", "nodes", "parent_task_id", "wait_for_completion")
|
2020-03-11 16:33:15 -05:00
|
|
|
def cancel(self, task_id=None, params=None, headers=None):
|
2016-03-22 21:04:07 +01:00
|
|
|
"""
|
2019-12-17 22:31:35 +01:00
|
|
|
Cancels a task, if it can be cancelled through an API.
|
2020-10-20 13:02:15 -05:00
|
|
|
|
2016-03-22 21:04:07 +01:00
|
|
|
|
2020-12-08 13:18:08 -06:00
|
|
|
.. warning::
|
|
|
|
|
|
|
|
|
|
This API is **experimental** so may include breaking changes
|
|
|
|
|
or be removed in a future version
|
|
|
|
|
|
2016-05-17 14:12:39 +02:00
|
|
|
:arg task_id: Cancel the task with specified task id
|
|
|
|
|
(node_id:task_number)
|
2016-03-22 21:04:07 +01:00
|
|
|
:arg actions: A comma-separated list of actions that should be
|
|
|
|
|
cancelled. Leave empty to cancel all.
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg nodes: 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
|
2017-10-26 14:51:37 +02:00
|
|
|
:arg parent_task_id: Cancel tasks with specified parent task id
|
2016-05-17 14:12:39 +02:00
|
|
|
(node_id:task_number). Set to -1 to cancel all.
|
2020-04-23 11:20:33 -05:00
|
|
|
:arg wait_for_completion: Should the request block until the
|
|
|
|
|
cancellation of the task and its descendant tasks is completed. Defaults
|
|
|
|
|
to false
|
2016-03-22 21:04:07 +01:00
|
|
|
"""
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
2020-03-11 16:33:15 -05:00
|
|
|
"POST",
|
|
|
|
|
_make_path("_tasks", task_id, "_cancel"),
|
|
|
|
|
params=params,
|
|
|
|
|
headers=headers,
|
2019-05-10 09:16:33 -06:00
|
|
|
)
|
2016-03-22 21:04:07 +01:00
|
|
|
|
2019-12-17 22:31:35 +01:00
|
|
|
@query_params("timeout", "wait_for_completion")
|
2020-03-13 16:20:54 -05:00
|
|
|
def get(self, task_id=None, params=None, headers=None):
|
2016-06-28 16:38:32 +02:00
|
|
|
"""
|
2019-12-17 22:31:35 +01:00
|
|
|
Returns information about a task.
|
2020-10-20 13:02:15 -05:00
|
|
|
|
2016-06-28 16:38:32 +02:00
|
|
|
|
2020-12-08 13:18:08 -06:00
|
|
|
.. warning::
|
|
|
|
|
|
|
|
|
|
This API is **experimental** so may include breaking changes
|
|
|
|
|
or be removed in a future version
|
|
|
|
|
|
2019-12-17 22:31:35 +01:00
|
|
|
:arg task_id: Return the task with specified id
|
|
|
|
|
(node_id:task_number)
|
|
|
|
|
:arg timeout: Explicit operation timeout
|
|
|
|
|
:arg wait_for_completion: Wait for the matching tasks to
|
|
|
|
|
complete (default: false)
|
2016-06-28 16:38:32 +02:00
|
|
|
"""
|
2019-12-17 22:31:35 +01:00
|
|
|
if task_id in SKIP_IN_PATH:
|
2020-03-13 16:20:54 -05:00
|
|
|
warnings.warn(
|
|
|
|
|
"Calling client.tasks.get() without a task_id is deprecated "
|
|
|
|
|
"and will be removed in v8.0. Use client.tasks.list() instead.",
|
2020-04-01 09:16:38 -05:00
|
|
|
category=DeprecationWarning,
|
|
|
|
|
stacklevel=3,
|
2020-03-13 16:20:54 -05:00
|
|
|
)
|
2019-12-17 22:31:35 +01:00
|
|
|
|
2019-05-10 09:16:33 -06:00
|
|
|
return self.transport.perform_request(
|
2020-03-11 16:33:15 -05:00
|
|
|
"GET", _make_path("_tasks", task_id), params=params, headers=headers
|
2019-05-10 09:16:33 -06:00
|
|
|
)
|