Example #1
0
def get_task_from_options(opts):
  tasks = ThermosConfigLoader.load_json(opts.thermos_json)
  if len(tasks.tasks()) == 0:
    app.error("No tasks specified!")
  if len(tasks.tasks()) > 1:
    app.error("Multiple tasks in config but no task name specified!")
  task = tasks.tasks()[0]
  if not task.task.check().ok():
    app.error(task.task.check().message())
  return task
Example #2
0
def get_task_from_options(opts):
    tasks = ThermosConfigLoader.load_json(opts.thermos_json)
    if len(tasks.tasks()) == 0:
        app.error("No tasks specified!")
    if len(tasks.tasks()) > 1:
        app.error("Multiple tasks in config but no task name specified!")
    task = tasks.tasks()[0]
    if not task.task.check().ok():
        app.error(task.task.check().message())
    return task
Example #3
0
 def get(cls, task_id, checkpoint_root):
   """
     Get a TaskRunner bound to the task_id in checkpoint_root.
   """
   path = TaskPath(root=checkpoint_root, task_id=task_id, state='active')
   task_json = path.getpath('task_path')
   task_checkpoint = path.getpath('runner_checkpoint')
   if not os.path.exists(task_json):
     return None
   task = ThermosConfigLoader.load_json(task_json)
   if task is None:
     return None
   if len(task.tasks()) == 0:
     return None
   try:
     checkpoint = CheckpointDispatcher.from_file(task_checkpoint)
     if checkpoint is None or checkpoint.header is None:
       return None
     return cls(task.tasks()[0].task(), checkpoint_root, checkpoint.header.sandbox,
                log_dir=checkpoint.header.log_dir, task_id=task_id,
                portmap=checkpoint.header.ports)
   except Exception as e:
     log.error('Failed to reconstitute checkpoint in TaskRunner.get: %s' % e, exc_info=True)
     return None
Example #4
0
def main(args):
  """
    Given .thermos configs, loads them and prints out information about them.
  """

  if len(args) == 0:
    app.help()

  for arg in args:
    print '\nparsing %s\n' % arg
    tc = ThermosConfigLoader.load(arg)

    for task_wrapper in tc.tasks():
      task = task_wrapper.task
      if not task.has_name():
        print 'Found unnamed task!  Skipping...'
        continue

      print 'Task: %s [check: %s]' % (task.name(), task.check())
      if not task.processes():
        print '  No processes.'
      else:
        print '  Processes:'
        for proc in task.processes():
          print '    %s' % proc

      ports = task_wrapper.ports()
      if not ports:
        print '  No unbound ports.'
      else:
        print '  Ports:'
        for port in ports:
          print '    %s' % port

      print 'raw:'
      pprint.pprint(json.loads(task_wrapper.to_json()))