def test_run(self):
     event = Event()
     mock_driver = mock.Mock(spec=ExecutorDriver)
     event.set()
     executor_timeout = ExecutorTimeout(event, mock_driver, timeout=Amount(0, Time.SECONDS))
     executor_timeout.run()
     assert mock_driver.stop.call_count == 0
 def test_run(self):
   event = Event()
   mock_driver = mock.Mock(spec=ExecutorDriver)
   event.set()
   executor_timeout = ExecutorTimeout(event, mock_driver, timeout=Amount(0, Time.SECONDS))
   executor_timeout.run()
   assert mock_driver.stop.call_count == 0
Esempio n. 3
0
 def test_run(self):
   event = Event()
   mock_driver = mock.create_autospec(spec=ExecutorDriver, instance=True)
   event.set()
   executor_timeout = ExecutorTimeout(event, mock_driver, timeout=Amount(0, Time.SECONDS))
   executor_timeout.run()
   assert mock_driver.stop.call_count == 0
Esempio n. 4
0
 def test_run_timeout(self):
     event = Event()
     mock_driver = mock.create_autospec(spec=ExecutorDriver, instance=True)
     executor_timeout = ExecutorTimeout(event,
                                        mock_driver,
                                        timeout=Amount(0, Time.SECONDS))
     executor_timeout.run()
     mock_driver.stop.assert_called_once_with()
Esempio n. 5
0
 def test_run(self):
     event = Event()
     mock_driver = mock.create_autospec(spec=ExecutorDriver, instance=True)
     event.set()
     executor_timeout = ExecutorTimeout(event,
                                        mock_driver,
                                        timeout=Amount(0, Time.SECONDS))
     executor_timeout.run()
     assert mock_driver.stop.call_count == 0
Esempio n. 6
0
def test_waiting_executor():
  proxy_driver = ProxyDriver()
  with temporary_dir() as checkpoint_root:
    te = AuroraExecutor(
        runner_provider=make_provider(checkpoint_root),
        sandbox_provider=DefaultTestSandboxProvider())
    ExecutorTimeout(te.launched, proxy_driver, timeout=Amount(100, Time.MILLISECONDS)).start()
    proxy_driver.wait_stopped()
Esempio n. 7
0
    def main(args, options):
        if MesosExecutorDriver is None:
            app.error('Could not load MesosExecutorDriver!')

        # status providers:
        status_providers = [
            HealthCheckerProvider(),
            ResourceManagerProvider(checkpoint_root=options.checkpoint_root)
        ]

        if options.announcer_enable:
            if options.announcer_ensemble is None:
                app.error(
                    'Must specify --announcer-ensemble if the announcer is enabled.'
                )
            status_providers.append(
                DefaultAnnouncerCheckerProvider(
                    options.announcer_ensemble,
                    options.announcer_serverset_path))

        # Create executor stub
        if options.execute_as_user or options.nosetuid:
            # If nosetuid is set, execute_as_user is also None
            thermos_runner_provider = UserOverrideThermosTaskRunnerProvider(
                dump_runner_pex(), artifact_dir=os.path.abspath(CWD))
            thermos_runner_provider.set_role(None)

            thermos_executor = AuroraExecutor(
                runner_provider=thermos_runner_provider,
                status_providers=status_providers,
                sandbox_provider=UserOverrideDirectorySandboxProvider(
                    options.execute_as_user))
        else:
            thermos_runner_provider = DefaultThermosTaskRunnerProvider(
                dump_runner_pex(), artifact_dir=os.path.abspath(CWD))

            thermos_executor = AuroraExecutor(
                runner_provider=thermos_runner_provider,
                status_providers=status_providers)

        # Create driver stub
        driver = MesosExecutorDriver(thermos_executor)

        # This is an ephemeral executor -- shutdown if we receive no tasks within a certain
        # time period
        ExecutorTimeout(thermos_executor.launched, driver).start()

        # Start executor
        driver.run()

        log.info('MesosExecutorDriver.run() has finished.')
Esempio n. 8
0
def make_executor(proxy_driver,
                  checkpoint_root,
                  task,
                  ports={},
                  fast_status=False,
                  runner_class=ThermosTaskRunner,
                  status_providers=()):

    status_manager_class = FastStatusManager if fast_status else StatusManager
    runner_provider = make_provider(checkpoint_root, runner_class)
    te = FastThermosExecutor(
        runner_provider=runner_provider,
        status_manager_class=status_manager_class,
        sandbox_provider=DefaultTestSandboxProvider,
        status_providers=status_providers,
    )

    ExecutorTimeout(te.launched,
                    proxy_driver,
                    timeout=Amount(100, Time.MILLISECONDS)).start()
    task_description = make_task(task, assigned_ports=ports, instanceId=0)
    te.launchTask(proxy_driver, task_description)

    te.status_manager_started.wait()
    sampled_metrics = te.metrics.sample()
    assert 'kill_manager.enabled' in sampled_metrics
    for checker in te._chained_checker._status_checkers:  # hacky
        assert ('%s.enabled' % checker.name()) in sampled_metrics

    while len(proxy_driver.method_calls['sendStatusUpdate']) < 2:
        time.sleep(0.1)

    # make sure startup was kosher
    updates = proxy_driver.method_calls['sendStatusUpdate']
    assert len(updates) == 2
    status_updates = [arg_tuple[0][0] for arg_tuple in updates]
    assert status_updates[0].state == mesos_pb2.TASK_STARTING
    assert status_updates[1].state == mesos_pb2.TASK_RUNNING

    # wait for the runner to bind to a task
    while True:
        runner = TaskRunner.get(task_description.task_id.value,
                                checkpoint_root)
        if runner:
            break
        time.sleep(0.1)

    assert te.launched.is_set()
    return runner, te
Esempio n. 9
0
def make_executor(
    proxy_driver,
    checkpoint_root,
    task,
    ports={},
    fast_status=False,
    runner_class=ThermosTaskRunner,
    status_providers=[HealthCheckerProvider()],
    assert_task_is_running=True,
    stop_timeout_in_secs=120):

  status_manager_class = FastStatusManager if fast_status else StatusManager
  runner_provider = make_provider(checkpoint_root, runner_class)
  te = FastThermosExecutor(
      runner_provider=runner_provider,
      status_manager_class=status_manager_class,
      sandbox_provider=DefaultTestSandboxProvider(),
      status_providers=status_providers,
      stop_timeout_in_secs=stop_timeout_in_secs
  )

  ExecutorTimeout(te.launched, proxy_driver, timeout=Amount(100, Time.MILLISECONDS)).start()
  task_description = make_task(task, assigned_ports=ports, instanceId=0)
  te.launchTask(proxy_driver, task_description)

  te.status_manager_started.wait()

  while len(proxy_driver.method_calls['sendStatusUpdate']) < 2:
    time.sleep(0.1)

  # make sure startup was kosher
  updates = proxy_driver.method_calls['sendStatusUpdate']
  assert len(updates) == 2
  status_updates = [arg_tuple[0][0] for arg_tuple in updates]
  assert status_updates[0].state == mesos_pb2.TASK_STARTING

  runner = None
  if assert_task_is_running:
    assert status_updates[1].state == mesos_pb2.TASK_RUNNING
    # wait for the runner to bind to a task
    while True:
      runner = TaskRunner.get(task_description.task_id.value, checkpoint_root)
      if runner:
        break
      time.sleep(0.1)

  assert te.launched.is_set()
  return runner, te
Esempio n. 10
0
    def main(args, options):
        if MesosExecutorDriver is None:
            app.error('Could not load MesosExecutorDriver!')

        thermos_executor = initialize(options)

        # Create driver stub
        driver = MesosExecutorDriver(thermos_executor)

        # This is an ephemeral executor -- shutdown if we receive no tasks within a certain
        # time period
        ExecutorTimeout(thermos_executor.launched, driver).start()

        # Start executor
        driver.run()

        log.info('MesosExecutorDriver.run() has finished.')
    def main(args, options):
        thermos_runner_provider = DefaultThermosTaskRunnerProvider(
            dump_runner_pex(),
            artifact_dir=os.path.realpath('.'),
        )

        # status providers:
        status_providers = [HealthCheckerProvider()]

        if options.announcer_enable:
            if options.announcer_ensemble is None:
                app.error(
                    'Must specify --announcer-ensemble if the announcer is enabled.'
                )
            status_providers.append(
                DefaultAnnouncerCheckerProvider(
                    options.announcer_ensemble,
                    options.announcer_serverset_path))

        # Create executor stub
        thermos_executor = AuroraExecutor(
            runner_provider=thermos_runner_provider,
            status_providers=status_providers,
        )

        # Create driver stub
        driver = MesosExecutorDriver(thermos_executor)

        # This is an ephemeral executor -- shutdown if we receive no tasks within a certain
        # time period
        ExecutorTimeout(thermos_executor.launched, driver).start()

        # Start executor
        driver.run()

        log.info('MesosExecutorDriver.run() has finished.')
    def main(args, options):
        if MesosExecutorDriver is None:
            app.error('Could not load MesosExecutorDriver!')

        thermos_executor = initialize(options)

        # Create driver stub
        driver = MesosExecutorDriver(thermos_executor)

        # This is an ephemeral executor -- shutdown if we receive no tasks within a certain
        # time period
        ExecutorTimeout(thermos_executor.launched, driver).start()

        # Start executor and wait until it is stopped.
        driver_thread = ExecutorDriverThread(driver)
        driver_thread.start()
        try:
            while driver_thread.isAlive():
                driver_thread.join(5)
        except (KeyboardInterrupt, SystemExit):
            driver.stop()
            raise

        log.info('MesosExecutorDriver.run() has finished.')
 def test_run_timeout(self):
     event = Event()
     mock_driver = mock.Mock(spec=ExecutorDriver)
     executor_timeout = ExecutorTimeout(event, mock_driver, timeout=Amount(0, Time.SECONDS))
     executor_timeout.run()
     mock_driver.stop.assert_called_once_with()
 def test_run_timeout(self):
   event = Event()
   mock_driver = mock.Mock(spec=ExecutorDriver)
   executor_timeout = ExecutorTimeout(event, mock_driver, timeout=Amount(0, Time.SECONDS))
   executor_timeout.run()
   mock_driver.stop.assert_called_once_with()
Esempio n. 15
0
 def test_run_timeout(self):
   event = Event()
   mock_driver = mock.create_autospec(spec=ExecutorDriver, instance=True)
   executor_timeout = ExecutorTimeout(event, mock_driver, timeout=Amount(0, Time.SECONDS))
   executor_timeout.run()
   mock_driver.stop.assert_called_once_with()