示例#1
0
def simple_app(environ, start_response):
    setup_testing_defaults(environ)

    status = '200 OK'
    headers = [('Content-type', 'text/html')]

    start_response(status, headers)

    return TMPL % create_table(util.get_hosts())
示例#2
0
    def statusUpdate(self, driver, update):
        """
        Called to tell us about the status of our task by Mesos.
        """
        tmp = update.data.split(':')
        if len(tmp) < 2:
            return
        host = tmp[0]
        ip_addr = tmp[1]

        if host not in self.running_tasks:
            util.add_to_hosts(host, ip_addr)
            util.add_to_cluster_conf(host)
            # We tell the master to only expose those shares it should
            # expose and not more - currently JOB_SLOTS = CPU offers.
            tmp = self.accepted_tasks[host]
            max_jobs = tmp[0]
            resource_tag = tmp[1]
            util.add_host_to_cluster(host.strip(), max_jobs, resource_tag)
            self.running_tasks[host] = ip_addr
        elif update.state == mesos_pb2.TASK_FINISHED:
            util.rm_host_from_cluster(host.strip())
            util.rm_from_cluster_conf(host)
            util.rm_from_hosts(host)
            self.accepted_tasks.pop(host)
            self.running_tasks.pop(host)
        elif update.state == mesos_pb2.TASK_LOST \
                or update.state == mesos_pb2.TASK_KILLED \
                or update.state == mesos_pb2.TASK_FAILED:
            driver.abort()
            self.accepted_tasks.pop(host)
            self.running_tasks.pop(host)

        # TODO: use proper logging!
        print('Current queue length (normal): {0}'.
              format(util.get_queue_length('normal')))
        print('Current queue length (priority): {0}'.
              format(util.get_queue_length('priority')))
        print('Current number of hosts: {0}'.
              format(str(len(util.get_hosts()) - 2)))

        sys.stdout.flush()
示例#3
0
    def statusUpdate(self, driver, update):
        """
        Called to tell us about the status of our task by Mesos.
        """
        tmp = update.data.split(':')
        if len(tmp) < 2:
            return
        host = tmp[0]
        ip_addr = tmp[1]

        if host not in self.running_tasks:
            util.add_to_hosts(host, ip_addr)
            util.add_to_cluster_conf(host)
            # We tell the master to only expose those shares it should
            # expose and not more - currently JOB_SLOTS = CPU offers.
            tmp = self.accepted_tasks[host]
            max_jobs = tmp[0]
            resource_tag = tmp[1]
            util.add_host_to_cluster(host.strip(), max_jobs, resource_tag)
            self.running_tasks[host] = ip_addr
        elif update.state == mesos_pb2.TASK_FINISHED:
            util.rm_host_from_cluster(host.strip())
            util.rm_from_cluster_conf(host)
            util.rm_from_hosts(host)
            self.accepted_tasks.pop(host)
            self.running_tasks.pop(host)
        elif update.state == mesos_pb2.TASK_LOST \
                or update.state == mesos_pb2.TASK_KILLED \
                or update.state == mesos_pb2.TASK_FAILED:
            driver.abort()
            self.accepted_tasks.pop(host)
            self.running_tasks.pop(host)

        # TODO: use proper logging!
        print('Current queue length (normal): {0}'.format(
            util.get_queue_length('normal')))
        print('Current queue length (priority): {0}'.format(
            util.get_queue_length('priority')))
        print('Current number of hosts: {0}'.format(
            str(len(util.get_hosts()) - 2)))

        sys.stdout.flush()