You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by kl...@apache.org on 2018/11/26 13:56:00 UTC

[mesos] branch master updated: Added '--all' flag to 'mesos task list'.

This is an automated email from the ASF dual-hosted git repository.

klueska pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git


The following commit(s) were added to refs/heads/master by this push:
     new 8c6e0e5  Added '--all' flag to 'mesos task list'.
8c6e0e5 is described below

commit 8c6e0e570e970a1fa6e1b3085373c6b84cb4a81d
Author: Armand Grillet <ag...@mesosphere.io>
AuthorDate: Mon Nov 26 08:55:03 2018 -0500

    Added '--all' flag to 'mesos task list'.
    
    With this option, the command is able to show all the tasks that have
    ever been run. This makes the command's behavior closer to the one of
    'docker ps -a'.
    
    Review: https://reviews.apache.org/r/69395/
---
 src/python/cli_new/lib/cli/plugins/task/main.py |  6 ++-
 src/python/cli_new/lib/cli/tests/task.py        | 66 ++++++++++++++++++++++++-
 2 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/src/python/cli_new/lib/cli/plugins/task/main.py b/src/python/cli_new/lib/cli/plugins/task/main.py
index 0ce21b3..00167f8 100644
--- a/src/python/cli_new/lib/cli/plugins/task/main.py
+++ b/src/python/cli_new/lib/cli/plugins/task/main.py
@@ -60,7 +60,9 @@ class Task(PluginBase):
         },
         "list": {
             "arguments": [],
-            "flags": {},
+            "flags": {
+                "-a --all": "list all tasks, not only running [default: False]"
+            },
             "short_help": "List all running tasks in a Mesos cluster",
             "long_help": "List all running tasks in a Mesos cluster"
         }
@@ -126,7 +128,7 @@ class Task(PluginBase):
                 if task["statuses"]:
                     task_state = task["statuses"][-1]["state"]
 
-                if task_state != "TASK_RUNNING":
+                if not argv["--all"] and task_state != "TASK_RUNNING":
                     continue
 
                 table.add_row([task["id"],
diff --git a/src/python/cli_new/lib/cli/tests/task.py b/src/python/cli_new/lib/cli/tests/task.py
index 69ed823..b846ee8 100644
--- a/src/python/cli_new/lib/cli/tests/task.py
+++ b/src/python/cli_new/lib/cli/tests/task.py
@@ -223,7 +223,7 @@ class TestTaskPlugin(CLITestCase):
         # and parse its output as a table.
         test_config = config.Config(None)
         plugin = TaskPlugin(None, test_config)
-        output = capture_output(plugin.list, {})
+        output = capture_output(plugin.list, {"--all": False})
         table = Table.parse(output)
 
         # Verify there are two rows in the table
@@ -244,3 +244,67 @@ class TestTaskPlugin(CLITestCase):
         task.kill()
         agent.kill()
         master.kill()
+
+    def test_list_all(self):
+        """
+        Basic test for the task `list()` sub-command with flag `--all`.
+        """
+        # Launch a master, agent, and two tasks.
+        master = Master()
+        master.launch()
+
+        agent = Agent()
+        agent.launch()
+
+        task1 = Task({"command": "true"})
+        task1.launch()
+        task1_state = "TASK_FINISHED"
+
+        try:
+            wait_for_task(master, task1.name, task1_state)
+        except Exception as exception:
+            raise CLIException(
+                "Error waiting for task '{name}' to"
+                " reach state '{state}': {error}"
+                .format(name=task1.name, state=task1_state, error=exception))
+
+        task2 = Task({"command": "sleep 1000"})
+        task2.launch()
+        task2_state = "TASK_RUNNING"
+
+        try:
+            wait_for_task(master, task2.name, task2_state)
+        except Exception as exception:
+            raise CLIException(
+                "Error waiting for task '{name}' to"
+                " reach state '{state}': {error}"
+                .format(name=task2.name, state=task2_state, error=exception))
+
+        try:
+            tasks = http.get_json(master.addr, "tasks")["tasks"]
+        except Exception as exception:
+            raise CLIException(
+                "Could not get tasks from '/{endpoint}' on master: {error}"
+                .format(endpoint="tasks", error=exception))
+
+        self.assertEqual(type(tasks), list)
+        self.assertEqual(len(tasks), 2)
+
+        # Invoke the task plugin `list()` command
+        # and parse its output as a table.
+        test_config = config.Config(None)
+        plugin = TaskPlugin(None, test_config)
+        output = capture_output(plugin.list, {"--all": True})
+        table = Table.parse(output)
+
+        # Verify that there are two rows in the table, one for the running task
+        # and one for the finished task. We do verify the information in the
+        # table as this is already covered in the test `test_list`.
+        self.assertEqual(table.dimensions()[0], 3)
+        self.assertEqual(table.dimensions()[1], 4)
+
+        # Kill the task1, task2, agent, and master.
+        task1.kill()
+        task2.kill()
+        agent.kill()
+        master.kill()