def test_fitsInTrue(self): subTasksPerChunk = 5 task = newTaskChunk(self.slave_id, subTasks=self.new_tasks(subTasksPerChunk)) self.add_resources(task, 10, 2) offer = mesos_pb2.Offer() self.add_resources(offer, 5, 2) self.assertFalse(steal_utils.fitsIn(task, offer))
def resourceOffers(self, driver, offers): print "Got %d resource offers" % len(offers) for offer in offers: tasks = [] print "Got resource offer %s" % offer.id.value while self.tasksLaunched < TOTAL_TASKS: tid = self.tasksLaunched task = mesos_pb2.TaskInfo() task.task_id.value = str(tid) task.name = "task %d" % tid cpus = task.resources.add() cpus.name = "cpus" cpus.type = mesos_pb2.Value.SCALAR cpus.scalar.value = TASK_CPUS mem = task.resources.add() mem.name = "mem" mem.type = mesos_pb2.Value.SCALAR mem.scalar.value = TASK_MEM if not steal_utils.fitsIn(task, offer): print "Offer isn't enough to run task. Ignoring." break self.tasksLaunched += 1 print "Adding subtask %d to chunk" % tid tasks.append(task) if len(tasks) > TOTAL_TASKS / 2: break if tasks: taskChunk = chunk_utils.newTaskChunk(offer.slave_id, executor=self.executor, subTasks=tasks) taskChunk.task_id.value = "chunk_id_{0}".format(self.tasksLaunched) taskChunk.name = "taskChunk" self.taskChunkId = taskChunk.task_id print "Accepting offer on %s to start task chunk" % offer.hostname driver.launchTasks(offer.id, [taskChunk]) else: print "Rejecting offer {0}".format(offer.id.value) driver.launchTasks(offer.id, [])