Ejemplo n.º 1
0
    def resourceOffers(self, driver, offers):
        """
        Apache Mesos invokes this to inform us about offers. We can accept
        or decline...
        """
        # TODO: let's become smarter and grab only what we need in \
        #       future. - match pending jobs in queues to offers from mesos.
        # TODO: candidate: https://github.com/Netflix/Fenzo
        for offer in offers:
            # not going to run openlava twice on same hosts.
            if str(offer.hostname) in self.accepted_tasks:
                # TODO: could tune number of job slots available on that host.
                # TODO: work with filters
                driver.declineOffer(offer.id)

            # if prio queue > 10 exclusively assign offers to prio queue.
            if util.get_queue_length(queue='priority') > 10:
                operation = self._grab_offer(offer, 'exl_prio')
                driver.acceptOffers([offer.id], [operation])
                continue
            if util.get_queue_length(queue='normal') > 10:
                operation = self._grab_offer(offer, None)
                driver.acceptOffers([offer.id], [operation])
                continue

            # otherwise let's decline.
            driver.declineOffer(offer.id)
Ejemplo n.º 2
0
    def resourceOffers(self, driver, offers):
        """
        Apache Mesos invokes this to inform us about offers. We can accept
        or decline...
        """
        # TODO: let's become smarter and grab only what we need in \
        #       future. - match pending jobs in queues to offers from mesos.
        # TODO: candidate: https://github.com/Netflix/Fenzo
        for offer in offers:
            # not going to run openlava twice on same hosts.
            if str(offer.hostname) in self.accepted_tasks:
                # TODO: could tune number of job slots available on that host.
                # TODO: work with filters
                driver.declineOffer(offer.id)

            # if prio queue > 10 exclusively assign offers to prio queue.
            if util.get_queue_length(queue='priority') > 10:
                operation = self._grab_offer(offer, 'exl_prio')
                driver.acceptOffers([offer.id], [operation])
                continue
            if util.get_queue_length(queue='normal') > 10:
                operation = self._grab_offer(offer, None)
                driver.acceptOffers([offer.id], [operation])
                continue

            # otherwise let's decline.
            driver.declineOffer(offer.id)
Ejemplo n.º 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()
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
 def resourceOffers(self, driver, offers):
     """
     Apache Mesos invokes this to inform us about offers. We can accept
     or decline...
     """
     # TODO: let's become smarter and grab only what we need in
     # future. - match pending jobs in queues to offers from mesos.
     # TODO: candidate: https://github.com/Netflix/Fenzo
     for offer in offers:
         if util.get_queue_length() > 10:
             operation = self._grab_offer(offer)
             driver.acceptOffers([offer.id], [operation])
         else:
             # TODO: work with filters
             driver.declineOffer(offer.id)
Ejemplo n.º 6
0
 def resourceOffers(self, driver, offers):
     """
     Apache Mesos invokes this to inform us about offers. We can accept
     or decline...
     """
     # TODO: let's become smarter and grab only what we need in
     # future. - match pending jobs in queues to offers from mesos.
     # TODO: candidate: https://github.com/Netflix/Fenzo
     for offer in offers:
         if util.get_queue_length() > 10:
             operation = self._grab_offer(offer)
             driver.acceptOffers([offer.id], [operation])
         else:
             # TODO: work with filters
             driver.declineOffer(offer.id)