Ejemplo n.º 1
0
def test_launch_tasks(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    offer_ids = [str(uuid.uuid4()) for _ in range(random.randint(1, 10))]
    tasks = [{
        'name': '1',
    }, {
        'name': '2',
    }]
    driver.launchTasks(offer_ids, tasks)
    driver._send.assert_called_once_with({
        'type': 'ACCEPT',
        'framework_id': {
            'value': ID
        },
        'accept': {
            'offer_ids': offer_ids,
            'operations': [{
                'type': 'LAUNCH',
                'launch': {
                    'task_infos': tasks,
                }
            }]
        }
    })
Ejemplo n.º 2
0
    def launch_tasks_for_offers(self, driver: MesosSchedulerDriver,
                                offers) -> List[TaskInfo]:
        """For each offer tries to launch all tasks that can fit in there.
        Declines offer if no fitting tasks found."""
        launched_tasks: List[TaskInfo] = []

        for offer in offers:
            with self.constraint_state_lock:
                try:
                    tasks, new_state = self.tasks_and_state_for_offer(
                        driver, offer, self.constraint_state)

                    if tasks is not None and len(tasks) > 0:
                        driver.launchTasks([offer.id], tasks)

                        for task in tasks:
                            self.task_store.add_task_if_doesnt_exist(
                                task["task_id"]["value"],
                                health=None,
                                mesos_task_state=TASK_STAGING,
                                offer=offer,
                                resources=task["resources"],
                            )
                        launched_tasks.extend(tasks)
                        self.constraint_state = new_state
                    else:
                        driver.declineOffer(offer.id)
                except ConstraintFailAllTasksError:
                    self.log(
                        "Offer failed constraints for every task, rejecting 60s"
                    )
                    filters = {"refuse_seconds": 60}
                    driver.declineOffer(offer.id, filters)
        return launched_tasks
Ejemplo n.º 3
0
def test_launch_tasks(mocker):
    ID = str(uuid.uuid4())
    sched = mocker.Mock()
    framework = {'id': {'value': ID}}
    master = mocker.Mock()
    driver = MesosSchedulerDriver(sched, framework, master)
    driver._send = mocker.Mock()
    offer_ids = [str(uuid.uuid4()) for _ in range(random.randint(1, 10))]
    tasks = [
        {
            'name': '1',
        },
        {
            'name': '2',
        }
    ]
    driver.launchTasks(offer_ids, tasks)
    driver._send.assert_called_once_with({
        'type': 'ACCEPT',
        'framework_id': {
            'value': ID
        },
        'accept': {
            'offer_ids': offer_ids,
            'operations': [{
                'type': 'LAUNCH',
                'launch': {
                    'task_infos': tasks,
                }
            }]
        }
    })