Exemple #1
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 TaskInfoError('Task did not have a thermos config!')

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

  # TODO(wickman) Determine if there are any serialized MesosTaskInstances in the wild;
  # kill this code if not.
  if 'instance' in json_blob:
    return MesosTaskInstance.json_loads(thermos_task)

  # This is a MesosJob
  task_instance = task_instance_from_job(
      MesosJob.json_loads(thermos_task), assigned_task.instanceId)

  try:
    ThermosTaskValidator.assert_valid_task(task_instance.task())
    ThermosTaskValidator.assert_all_refs_bound(task_instance)
  except ThermosTaskValidator.InvalidTaskError as e:
    raise UnexpectedUnboundRefsError('Got invalid task: %s' % e)

  task_instance, _ = task_instance.interpolate()
  return task_instance
Exemple #2
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 TaskInfoError('Task did not have a thermos config!')

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

    # TODO(wickman) Determine if there are any serialized MesosTaskInstances in the wild;
    # kill this code if not.
    if 'instance' in json_blob:
        return MesosTaskInstance.json_loads(thermos_task)

    # This is a MesosJob
    task_instance = task_instance_from_job(MesosJob.json_loads(thermos_task),
                                           assigned_task.instanceId,
                                           assigned_task.slaveHost)

    try:
        ThermosTaskValidator.assert_valid_task(task_instance.task())
        ThermosTaskValidator.assert_all_refs_bound(task_instance)
    except ThermosTaskValidator.InvalidTaskError as e:
        raise UnexpectedUnboundRefsError('Got invalid task: %s' % e)

    task_instance, _ = task_instance.interpolate()
    return task_instance
Exemple #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)
  unbound_refs = []
  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
    else:
      unbound_refs.append(ref)

  if len(unbound_refs) != 0:
    raise ValueError('Unexpected unbound refs: %s' % ' '.join(map(str, unbound_refs)))

  return mti
def test_task_instance_from_job():
  instance = task_instance_from_job(Job(health_check_config=HealthCheckConfig(interval_secs=30)), 0)
  assert instance is not None
def test_task_instance_from_job():
  instance = task_instance_from_job(Job(health_check_interval_secs=30), 0)
  assert instance is not None
Exemple #6
0
def test_mesos_hostname_in_task():
  hw = HELLO_WORLD(task=Task(name="{{mesos.hostname}}"))
  instance = task_instance_from_job(hw, 0, 'test_host')
  assert str(instance.task().name()) == 'test_host'
Exemple #7
0
def test_mesos_hostname_in_task():
  hw = HELLO_WORLD(task=Task(name="{{mesos.hostname}}"))
  instance = task_instance_from_job(hw, 0, 'test_host')
  assert str(instance.task().name()) == 'test_host'
def test_task_instance_from_job():
    instance = task_instance_from_job(Job(health_check_interval_secs=30), 0)
    assert instance is not None