(self, driver, offers)
| 46 | driver.updateFramework(framework, []) |
| 47 | |
| 48 | def resourceOffers(self, driver, offers): |
| 49 | for offer in offers: |
| 50 | tasks = [] |
| 51 | offerCpus = 0 |
| 52 | offerMem = 0 |
| 53 | for resource in offer.resources: |
| 54 | if resource.name == "cpus": |
| 55 | offerCpus += resource.scalar.value |
| 56 | elif resource.name == "mem": |
| 57 | offerMem += resource.scalar.value |
| 58 | |
| 59 | print "Received offer %s with cpus: %s and mem: %s" \ |
| 60 | % (offer.id.value, offerCpus, offerMem) |
| 61 | |
| 62 | remainingCpus = offerCpus |
| 63 | remainingMem = offerMem |
| 64 | |
| 65 | while self.tasksLaunched < TOTAL_TASKS and \ |
| 66 | remainingCpus >= TASK_CPUS and \ |
| 67 | remainingMem >= TASK_MEM: |
| 68 | tid = self.tasksLaunched |
| 69 | self.tasksLaunched += 1 |
| 70 | |
| 71 | print "Launching task %d using offer %s" \ |
| 72 | % (tid, offer.id.value) |
| 73 | |
| 74 | task = mesos_pb2.TaskInfo() |
| 75 | task.task_id.value = str(tid) |
| 76 | task.slave_id.value = offer.slave_id.value |
| 77 | task.name = "task %d" % tid |
| 78 | task.executor.MergeFrom(self.executor) |
| 79 | |
| 80 | cpus = task.resources.add() |
| 81 | cpus.name = "cpus" |
| 82 | cpus.type = mesos_pb2.Value.SCALAR |
| 83 | cpus.scalar.value = TASK_CPUS |
| 84 | |
| 85 | mem = task.resources.add() |
| 86 | mem.name = "mem" |
| 87 | mem.type = mesos_pb2.Value.SCALAR |
| 88 | mem.scalar.value = TASK_MEM |
| 89 | |
| 90 | tasks.append(task) |
| 91 | self.taskData[task.task_id.value] = ( |
| 92 | offer.slave_id, task.executor.executor_id) |
| 93 | |
| 94 | remainingCpus -= TASK_CPUS |
| 95 | remainingMem -= TASK_MEM |
| 96 | |
| 97 | operation = mesos_pb2.Offer.Operation() |
| 98 | operation.type = mesos_pb2.Offer.Operation.LAUNCH |
| 99 | operation.launch.task_infos.extend(tasks) |
| 100 | |
| 101 | driver.acceptOffers([offer.id], [operation]) |
| 102 | |
| 103 | def statusUpdate(self, driver, update): |
| 104 | print "Task %s is in state %s" % \ |
nothing calls this directly
no test coverage detected