Esempio n. 1
0
File: main.py Progetto: mpark/mesos
    def list(self, argv):
        """
        List the agents in a cluster by checking the /slaves endpoint.
        """
        # pylint: disable=unused-argument
        try:
            master = self.config.master()
        except Exception as exception:
            raise CLIException("Unable to get leading master address: {error}"
                               .format(error=exception))

        try:
            agents = http.get_json(master, "slaves")["slaves"]
        except Exception as exception:
            raise CLIException("Could not open '/slaves'"
                               " endpoint at '{addr}': {error}"
                               .format(addr=master, error=exception))

        if not agents:
            print("The cluster does not have any agents.")
            return

        try:
            table = Table(["Agent ID", "Hostname", "Active"])
            for agent in agents:
                table.add_row([agent["id"],
                               agent["hostname"],
                               str(agent["active"])])
        except Exception as exception:
            raise CLIException("Unable to build table of agents: {error}"
                               .format(error=exception))

        print(str(table))
Esempio n. 2
0
    def list(self, argv):
        """
        List the tasks running in a cluster by checking the /tasks endpoint.
        """
        # pylint: disable=unused-argument
        try:
            master = self.config.master()
        except Exception as exception:
            raise CLIException(
                "Unable to get leading master address: {error}".format(
                    error=exception))

        try:
            tasks = http.get_json(master, "tasks")["tasks"]
        except Exception as exception:
            raise CLIException("Could not open '/tasks'"
                               " endpoint at '{addr}': {error}".format(
                                   addr=master, error=exception))

        if len(tasks) == 0:
            print "There are no tasks running in the cluster."
            return

        try:
            table = Table(["Task ID", "Framework ID", "Executor ID"])
            for task in tasks:
                table.add_row(
                    [task["id"], task["framework_id"], task["executor_id"]])
        except Exception as exception:
            raise CLIException(
                "Unable to build table of tasks: {error}".format(
                    error=exception))

        print str(table)
Esempio n. 3
0
    def list(self, argv):
        """
        List the tasks running in a cluster by checking the /tasks endpoint.
        """
        # pylint: disable=unused-argument
        try:
            master = self.config.master()
        except Exception as exception:
            raise CLIException(
                "Unable to get leading master address: {error}".format(
                    error=exception))

        try:
            tasks = get_tasks(master)
        except Exception as exception:
            raise CLIException("Unable to get tasks from leading"
                               " master '{master}': {error}".format(
                                   master=master, error=exception))

        if not tasks:
            print("There are no tasks running in the cluster.")
            return

        try:
            table = Table(["Task ID", "Framework ID", "Executor ID"])
            for task in tasks:
                table.add_row(
                    [task["id"], task["framework_id"], task["executor_id"]])
        except Exception as exception:
            raise CLIException(
                "Unable to build table of tasks: {error}".format(
                    error=exception))

        print(str(table))
Esempio n. 4
0
    def list(self, argv):
        """
        List the agents in a cluster by checking the /slaves endpoint.
        """
        # pylint: disable=unused-argument
        try:
            master = self.config.master()
        except Exception as exception:
            raise CLIException(
                "Unable to get leading master address: {error}".format(
                    error=exception))

        try:
            agents = http.get_json(master, "slaves")["slaves"]
        except Exception as exception:
            raise CLIException("Could not open '/slaves'"
                               " endpoint at '{addr}': {error}".format(
                                   addr=master, error=exception))

        if not agents:
            print("The cluster does not have any agents.")
            return

        try:
            table = Table(["Agent ID", "Hostname", "Active"])
            for agent in agents:
                table.add_row(
                    [agent["id"], agent["hostname"],
                     str(agent["active"])])
        except Exception as exception:
            raise CLIException(
                "Unable to build table of agents: {error}".format(
                    error=exception))

        print(str(table))
Esempio n. 5
0
    def list(self, argv):
        """
        List the tasks running in a cluster by checking the /tasks endpoint.
        """
        # pylint: disable=unused-argument
        try:
            master = self.config.master()
        except Exception as exception:
            raise CLIException("Unable to get leading master address: {error}"
                               .format(error=exception))

        try:
            tasks = http.get_json(master, "tasks")["tasks"]
        except Exception as exception:
            raise CLIException("Could not open '/tasks'"
                               " endpoint at '{addr}': {error}"
                               .format(addr=master, error=exception))

        if len(tasks) == 0:
            print "There are no tasks running in the cluster."
            return

        try:
            table = Table(["Task ID", "Framework ID", "Executor ID"])
            for task in tasks:
                table.add_row([task["id"],
                               task["framework_id"],
                               task["executor_id"]])
        except Exception as exception:
            raise CLIException("Unable to build table of tasks: {error}"
                               .format(error=exception))

        print str(table)
Esempio n. 6
0
    def list(self, argv):
        """
        Show a list of running frameworks
        """

        try:
            master = self.config.master()
        except Exception as exception:
            raise CLIException(
                "Unable to get leading master address: {error}".format(
                    error=exception))

        data = get_frameworks(master, self.config)
        table = Table(["ID", "Active", "Hostname", "Name"])
        for framework in data:
            if (not argv["--all"] and not framework["active"]):
                continue

            active = "False"
            if framework["active"]:
                active = "True"

            table.add_row([
                framework["id"], active, framework["hostname"],
                framework["name"]
            ])

        print(str(table))
Esempio n. 7
0
    def plugins(self, argv):
        """
        Parse and load the builtin plugins and the ones in the configuration
        file. If this method is called using 'mesos config plugins', it
        displays the plugins that can be used.
        """
        # pylint: disable=unused-argument
        plugins_table = Table(["NAME", "DESCRIPTION"])

        # Load the plugins
        loaded_plugins = cli.util.import_modules(settings.PLUGINS, "plugins")
        for plugin in loaded_plugins:
            plugins_table.add_row([
                cli.util.get_module(loaded_plugins, plugin).PLUGIN_NAME,
                cli.util.get_module(loaded_plugins, plugin).SHORT_HELP
            ])
        sys.stdout.write("{}\n".format(plugins_table))
Esempio n. 8
0
    def test_list(self):
        """
        Basic test for the task `list()` sub-command.
        """
        # Launch a master, agent, and task.
        master = Master()
        master.launch()

        agent = Agent()
        agent.launch()

        task = Task({"command": "sleep 1000"})
        task.launch()

        try:
            wait_for_task(master, task.name, "TASK_RUNNING")
        except Exception as exception:
            raise CLIException("Error waiting for task '{name}' to"
                               " reach state '{state}': {error}".format(
                                   name=task.name,
                                   state="TASK_RUNNING",
                                   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), 1)

        # 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": False})
        table = Table.parse(output)

        # Verify there are two rows in the table
        # and that they are formatted as expected,
        # with the proper task info in them.
        self.assertEqual(table.dimensions()[0], 2)
        self.assertEqual(table.dimensions()[1], 4)
        self.assertEqual("ID", table[0][0])
        self.assertEqual("State", table[0][1])
        self.assertEqual("Framework ID", table[0][2])
        self.assertEqual("Executor ID", table[0][3])
        self.assertEqual(tasks[0]["id"], table[1][0])
        self.assertEqual(tasks[0]["statuses"][-1]["state"], table[1][1])
        self.assertEqual(tasks[0]["framework_id"], table[1][2])
        self.assertEqual(tasks[0]["executor_id"], table[1][3])

        # Kill the task, agent, and master.
        task.kill()
        agent.kill()
        master.kill()
Esempio n. 9
0
    def test_list(self):
        """
        Basic test for the task `list()` sub-command.
        """
        # Launch a master, agent, and task.
        master = Master()
        master.launch()

        agent = Agent()
        agent.launch()

        task = Task({"command": "sleep 1000"})
        task.launch()

        try:
            wait_for_task(master, task.name, "TASK_RUNNING")
        except Exception as exception:
            raise CLIException(
                "Error waiting for task '{name}' to"
                " reach state '{state}': {error}"
                .format(name=task.name, state="TASK_RUNNING", 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), 1)

        # 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": False})
        table = Table.parse(output)

        # Verify there are two rows in the table
        # and that they are formatted as expected,
        # with the proper task info in them.
        self.assertEqual(table.dimensions()[0], 2)
        self.assertEqual(table.dimensions()[1], 4)
        self.assertEqual("ID", table[0][0])
        self.assertEqual("State", table[0][1])
        self.assertEqual("Framework ID", table[0][2])
        self.assertEqual("Executor ID", table[0][3])
        self.assertEqual(tasks[0]["id"], table[1][0])
        self.assertEqual(tasks[0]["statuses"][-1]["state"], table[1][1])
        self.assertEqual(tasks[0]["framework_id"], table[1][2])
        self.assertEqual(tasks[0]["executor_id"], table[1][3])

        # Kill the task, agent, and master.
        task.kill()
        agent.kill()
        master.kill()
Esempio n. 10
0
    def list(self, argv):
        """
        List the tasks running in a cluster by checking the /tasks endpoint.
        """
        # pylint: disable=unused-argument
        try:
            master = self.config.master()
        except Exception as exception:
            raise CLIException(
                "Unable to get leading master address: {error}".format(
                    error=exception))

        try:
            tasks = get_tasks(master, self.config)
        except Exception as exception:
            raise CLIException("Unable to get tasks from leading"
                               " master '{master}': {error}".format(
                                   master=master, error=exception))

        if not tasks:
            print("There are no tasks running in the cluster.")
            return

        try:
            table = Table(["ID", "State", "Framework ID", "Executor ID"])
            for task in tasks:
                task_state = "UNKNOWN"
                if task["statuses"]:
                    task_state = task["statuses"][-1]["state"]

                if not argv["--all"] and task_state != "TASK_RUNNING":
                    continue

                table.add_row([
                    task["id"], task_state, task["framework_id"],
                    task["executor_id"]
                ])
        except Exception as exception:
            raise CLIException(
                "Unable to build table of tasks: {error}".format(
                    error=exception))

        print(str(table))
Esempio n. 11
0
    def list(self, argv):
        """
        List the tasks running in a cluster by checking the /tasks endpoint.
        """
        # pylint: disable=unused-argument
        try:
            master = self.config.master()
        except Exception as exception:
            raise CLIException("Unable to get leading master address: {error}"
                               .format(error=exception))

        try:
            tasks = get_tasks(master)
        except Exception as exception:
            raise CLIException("Unable to get tasks from leading"
                               " master '{master}': {error}"
                               .format(master=master, error=exception))

        if not tasks:
            print("There are no tasks running in the cluster.")
            return

        try:
            table = Table(["ID", "State", "Framework ID", "Executor ID"])
            for task in tasks:
                task_state = "UNKNOWN"
                if task["statuses"]:
                    task_state = task["statuses"][-1]["state"]

                if not argv["--all"] and task_state != "TASK_RUNNING":
                    continue

                table.add_row([task["id"],
                               task_state,
                               task["framework_id"],
                               task["executor_id"]])
        except Exception as exception:
            raise CLIException("Unable to build table of tasks: {error}"
                               .format(error=exception))

        print(str(table))
Esempio n. 12
0
File: task.py Progetto: zuker/mesos
    def test_list(self):
        """
        Basic test for the task `list()` sub-command.
        """
        # Launch a master, agent, and task.
        master = Master()
        master.launch()

        agent = Agent()
        agent.launch()

        task = Task({"command": "sleep 1000"})
        task.launch()

        # Open the master's `/tasks` endpoint and read the
        # task information ourselves.
        tasks = http.get_json(master.addr, 'tasks')["tasks"]

        self.assertEqual(type(tasks), list)
        self.assertEqual(len(tasks), 1)

        # 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, {})
        table = Table.parse(output)

        # Verify there are two rows in the table
        # and that they are formatted as expected,
        # with the proper task info in them.
        self.assertEqual(table.dimensions()[0], 2)
        self.assertEqual(table.dimensions()[1], 3)
        self.assertEqual("Task ID", table[0][0])
        self.assertEqual("Framework ID", table[0][1])
        self.assertEqual("Executor ID", table[0][2])
        self.assertEqual(tasks[0]["id"], table[1][0])
        self.assertEqual(tasks[0]["framework_id"], table[1][1])
        self.assertEqual(tasks[0]["executor_id"], table[1][2])

        # Kill the task, agent, and master.
        task.kill()
        agent.kill()
        master.kill()
Esempio n. 13
0
File: task.py Progetto: mpark/mesos
    def test_list(self):
        """
        Basic test for the task `list()` sub-command.
        """
        # Launch a master, agent, and task.
        master = Master()
        master.launch()

        agent = Agent()
        agent.launch()

        task = Task({"command": "sleep 1000"})
        task.launch()

        # Open the master's `/tasks` endpoint and read the
        # task information ourselves.
        tasks = http.get_json(master.addr, 'tasks')["tasks"]

        self.assertEqual(type(tasks), list)
        self.assertEqual(len(tasks), 1)

        # 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, {})
        table = Table.parse(output)

        # Verify there are two rows in the table
        # and that they are formatted as expected,
        # with the proper task info in them.
        self.assertEqual(table.dimensions()[0], 2)
        self.assertEqual(table.dimensions()[1], 3)
        self.assertEqual("Task ID", table[0][0])
        self.assertEqual("Framework ID", table[0][1])
        self.assertEqual("Executor ID", table[0][2])
        self.assertEqual(tasks[0]["id"], table[1][0])
        self.assertEqual(tasks[0]["framework_id"], table[1][1])
        self.assertEqual(tasks[0]["executor_id"], table[1][2])

        # Kill the task, agent, and master.
        task.kill()
        agent.kill()
        master.kill()
Esempio n. 14
0
    def test_list(self):
        """
        Basic test for the agent `list()` sub-command.
        """
        # Launch a master and agent.
        master = Master()
        master.launch()

        agent = Agent()
        agent.launch()

        # Open the master's `/slaves` endpoint and read the
        # agents' information ourselves.
        agents = http.get_json(master.addr, 'slaves',
                               config.Config(None))["slaves"]

        self.assertEqual(type(agents), list)
        self.assertEqual(len(agents), 1)

        # Invoke the agent plugin `list()` command
        # and parse its output as a table.
        test_config = config.Config(None)
        plugin = AgentPlugin(None, test_config)
        output = capture_output(plugin.list, {})
        table = Table.parse(output)

        # Verify there are two rows in the table
        # and that they are formatted as expected,
        # with the proper agent info in them.
        self.assertEqual(table.dimensions()[0], 2)
        self.assertEqual(table.dimensions()[1], 3)
        self.assertEqual("Agent ID", table[0][0])
        self.assertEqual("Hostname", table[0][1])
        self.assertEqual("Active", table[0][2])
        self.assertEqual(agents[0]["id"], table[1][0])
        self.assertEqual(agents[0]["hostname"], table[1][1])
        self.assertEqual(str(agents[0]["active"]), table[1][2])

        # Kill the agent and master.
        agent.kill()
        master.kill()
Esempio n. 15
0
    def test_list(self):
        """
        Basic test for the agent `list()` sub-command.
        """
        # Launch a master and agent.
        master = Master()
        master.launch()

        agent = Agent()
        agent.launch()

        # Open the master's `/slaves` endpoint and read the
        # agents' information ourselves.
        agents = http.get_json(master.addr, 'slaves')["slaves"]

        self.assertEqual(type(agents), list)
        self.assertEqual(len(agents), 1)

        # Invoke the agent plugin `list()` command
        # and parse its output as a table.
        test_config = config.Config(None)
        plugin = AgentPlugin(None, test_config)
        output = capture_output(plugin.list, {})
        table = Table.parse(output)

        # Verify there are two rows in the table
        # and that they are formatted as expected,
        # with the proper agent info in them.
        self.assertEqual(table.dimensions()[0], 2)
        self.assertEqual(table.dimensions()[1], 3)
        self.assertEqual("Agent ID", table[0][0])
        self.assertEqual("Hostname", table[0][1])
        self.assertEqual("Active", table[0][2])
        self.assertEqual(agents[0]["id"], table[1][0])
        self.assertEqual(agents[0]["hostname"], table[1][1])
        self.assertEqual(str(agents[0]["active"]), table[1][2])

        # Kill the agent and master.
        agent.kill()
        master.kill()
Esempio n. 16
0
    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, None, "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()
Esempio n. 17
0
    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()