Esempio n. 1
0
def mesos_job_from_assigned_task(assigned_task):
  """Deserialize a MesosJob pystachio struct from an AssignedTask."""
  thermos_task = assigned_task.task.executorConfig.data
  try:
    json_blob = json.loads(thermos_task)
  except (TypeError, ValueError):
    return None
  if 'instance' in json_blob:
    # This is a MesosTaskInstance so we cannot get a MesosJob from this assigned_task
    return None
  return MesosJob.json_loads(thermos_task)
Esempio n. 2
0
def mesos_job_from_assigned_task(assigned_task):
    """Deserialize a MesosJob pystachio struct from an AssignedTask."""
    thermos_task = assigned_task.task.executorConfig.data
    try:
        json_blob = json.loads(thermos_task)
    except (TypeError, ValueError):
        return None
    if 'instance' in json_blob:
        # This is a MesosTaskInstance so we cannot get a MesosJob from this assigned_task
        return None
    return MesosJob.json_loads(thermos_task)
Esempio n. 3
0
def mesos_task_instance_from_assigned_task(assigned_task):
    """Deserialize MesosTaskInstance from an AssignedTask thrift."""
    thermos_task = assigned_task.task.executorConfig.data

    if not thermos_task:
        raise ValueError('Task did not have a thermos config!')

    try:
        json_blob = json.loads(thermos_task)
    except (TypeError, ValueError) as e:
        raise ValueError('Could not deserialize thermos config: %s' % e)

    # As part of the transition for MESOS-2133, we can send either a MesosTaskInstance
    # or we can be sending a MesosJob.  So handle both possible cases.  Once everyone
    # is using MesosJob, then we can begin to leverage additional information that
    # becomes available such as cluster.
    if 'instance' in json_blob:
        return MesosTaskInstance.json_loads(thermos_task)

    # This is a MesosJob
    mti, refs = task_instance_from_job(MesosJob.json_loads(thermos_task),
                                       assigned_task.instanceId)
    for ref in refs:
        # If the ref is {{thermos.task_id}} or a subscope of
        # {{thermos.ports}}, it currently gets bound by the Thermos Runner,
        # so we must leave them unbound.
        #
        # {{thermos.user}} is a legacy binding which we can safely ignore.
        #
        # TODO(wickman) These should be rewritten by the mesos client to use
        # %%style%% replacements in order to allow us to better type-check configs
        # client-side.
        if ref == Ref.from_address('thermos.task_id'):
            continue
        if Ref.subscope(Ref.from_address('thermos.ports'), ref):
            continue
        if ref == Ref.from_address('thermos.user'):
            continue
        raise ValueError('Unexpected unbound refs: %s' %
                         ' '.join(map(str, refs)))
    return mti
Esempio n. 4
0
def mesos_task_instance_from_assigned_task(assigned_task):
  """Deserialize MesosTaskInstance from an AssignedTask thrift."""
  thermos_task = assigned_task.task.executorConfig.data

  if not thermos_task:
    raise ValueError('Task did not have a thermos config!')

  try:
    json_blob = json.loads(thermos_task)
  except (TypeError, ValueError) as e:
    raise ValueError('Could not deserialize thermos config: %s' % e)

  # As part of the transition for MESOS-2133, we can send either a MesosTaskInstance
  # or we can be sending a MesosJob.  So handle both possible cases.  Once everyone
  # is using MesosJob, then we can begin to leverage additional information that
  # becomes available such as cluster.
  if 'instance' in json_blob:
    return MesosTaskInstance.json_loads(thermos_task)

  # This is a MesosJob
  mti, refs = task_instance_from_job(MesosJob.json_loads(thermos_task), assigned_task.instanceId)
  for ref in refs:
    # If the ref is {{thermos.task_id}} or a subscope of
    # {{thermos.ports}}, it currently gets bound by the Thermos Runner,
    # so we must leave them unbound.
    #
    # {{thermos.user}} is a legacy binding which we can safely ignore.
    #
    # TODO(wickman) These should be rewritten by the mesos client to use
    # %%style%% replacements in order to allow us to better type-check configs
    # client-side.
    if ref == Ref.from_address('thermos.task_id'):
      continue
    if Ref.subscope(Ref.from_address('thermos.ports'), ref):
      continue
    if ref == Ref.from_address('thermos.user'):
      continue
    raise ValueError('Unexpected unbound refs: %s' % ' '.join(map(str, refs)))
  return mti
Esempio n. 5
0
HELLO_WORLD_TASK_ID = 'hello_world-001'
HELLO_WORLD = BASE_TASK(name='hello_world',
                        processes=[
                            Process(name='hello_world_{{thermos.task_id}}',
                                    cmdline='echo hello world')
                        ])
HELLO_WORLD_MTI = BASE_MTI(task=HELLO_WORLD)

SLEEP60 = BASE_TASK(processes=[Process(name='sleep60', cmdline='sleep 60')])
SLEEP2 = BASE_TASK(processes=[Process(name='sleep2', cmdline='sleep 2')])
SLEEP60_MTI = BASE_MTI(task=SLEEP60)

MESOS_JOB = MesosJob(
    name='does_not_matter',
    instances=1,
    role=getpass.getuser(),
)


def make_provider(checkpoint_root, runner_class=ThermosTaskRunner):
    return DefaultThermosTaskRunnerProvider(
        pex_location=os.path.join('dist', 'thermos_runner.pex'),
        checkpoint_root=checkpoint_root,
        task_runner_class=runner_class,
    )


def make_executor(proxy_driver,
                  checkpoint_root,
                  task,