Exemple #1
0
def stop_task(constellation_name):
    """
    Stops the current running tasks on a constellation. If no simulation task
    is running.
    """
    try:
        log("stop_task %s" % (constellation_name))
        cs = ConstellationState(constellation_name)
        config = cs.get_value('configuration')
        constellation_plugin = get_plugin(config)

        task_id = cs.get_value('current_task')
        if task_id != '':
            task = cs.get_task(task_id)

            # you can only stop a running task
            if task['task_state'] == 'running':

                log('task_state stopping')
                cs.update_task_value(task_id, 'task_state', 'stopping')
                cs.update_task_value(task_id, 'stop_time',
                                     datetime.datetime.utcnow().isoformat())
                try:
                    log('calling stop task')
                    constellation_plugin.stop_task(constellation_name, task)
                except Exception, e:
                    tb = traceback.format_exc()
                    log('task error during stop')
                    log("traceback:  %s" % tb)
                else:
                    log('task stopped successfully')
                finally:
                    cs.update_task_value(task_id, 'task_state', 'stopped')
                    cs.set_value('current_task', '')
Exemple #2
0
def start_task(constellation_name, task_id):
    """
    Starts a simulation task on a constellation.
    Only one task can run at a time.
    """
    try:
        log("start_task %s/%s" % (constellation_name, task_id))
        cs = ConstellationState(constellation_name)
        config = cs.get_value('configuration')
        constellation_plugin = get_plugin(config)
        current_task = cs.get_value('current_task')
        if current_task == '':
            task = cs.get_task(task_id)
            task_state = task['task_state']
            if task_state == 'ready':
                cs.set_value('current_task', task_id)
                log('task_state starting')
                cs.update_task_value(task_id, 'task_message', '')
                cs.update_task_value(task_id, 'task_state', 'starting')
                cs.update_task_value(task_id, 'start_time',
                                     datetime.datetime.utcnow().isoformat())
                # no other task running, and task is ready
                try:
                    constellation_plugin.start_task(constellation_name, task)
                except Exception, e:
                    log("Start task error %s" % e)
                    tb = traceback.format_exc()
                    log("traceback:  %s" % tb)
                    cs.update_task_value(task_id, 'task_message',
                                         'Task failed to start: %s' % (e))
                    task = cs.get_task(task_id)
                    constellation_plugin.stop_task(constellation_name, task)
                    cs.update_task_value(task_id, 'task_state', 'stopped')
                    cs.set_value('current_task', '')
                    raise
                cs.update_task_value(task_id, 'task_state', 'running')
                log('task_state running')
            else:
                log("Task is not ready (%s)" % task_state)
        else: