Ejemplo n.º 1
0
def task_priority(lassod, id, priority):
    """Set the priority of the specified tasks."""
    db = Session()
    task = db.query(Task).filter(Task.id==id).first()
    task.set_priority(priority)
    db.commit()
    db.close()
    return priority
Ejemplo n.º 2
0
def job_pause(lassod, *ids):
    """Pause all unfinished tasks associated with specified jobs. Return a list paused jobs."""
    db = Session()
    output = list()
    for job in db.query(Job).filter(Job.id.in_(ids)):
        job.pause()
        _job_update(job)
        output.append(job.id)
    db.commit()
    db.close()
    return output
Ejemplo n.º 3
0
def task_pause(lassod, *ids):
    """Pause specified tasks."""
    db = Session()
    output = list()
    tasks = db.query(Task).filter(Task.id.in_(ids)).all()
    for task in tasks:
        task.pause()
        output.append(task.status)
        _job_update(task.job)
    db.commit()
    db.close()
    return output
Ejemplo n.º 4
0
def task_stop(lassod, *ids):
    """Stop specified tasks. (Kill task if currently running)"""
    db = Session()
    output = []
    tasks = db.query(Task).filter(Task.id.in_(ids)).all()
    for task in tasks:
        task.stop()
        output.append(task.status)
        _job_update(task.job)
    db.commit()
    db.close()
    return output
Ejemplo n.º 5
0
def job_rename(lassod, id, name):
    """Rename specified job."""
    db = Session()
    job = db.query(Job).filter(Job.id==id).first()
    if job:
        job.name = name
        db.commit()
        db.close()
        return True
    else:
        db.close()
        return False
Ejemplo n.º 6
0
def job_priority(lassod, id, priority):
    """Change the priority of all tasks associated with job."""
    db = Session()
    job = db.query(Job).filter(Job.id==id).first()
    if job:
        for task in job.tasks:
            task.set_priority(priority)
        db.commit()
        db.close()
        return True
    else:
        db.close()
        return False
Ejemplo n.º 7
0
def lasso_submit_job(lassod, job_data):
    """Add job to the queue and return the job's id number."""
    gen = job_data.pop('generator')
    job = generator.__dict__[gen](**job_data)
    db = Session()
    db.add(job)
    log.debug('Adding job "%s" to queue.' % job.name)
    db.commit()
    job.queue()
    jobid = job.id
    log.debug('Added job "%s" to queue. [%d]' % (job.name, job.id))
    db.commit()
    db.close()
    return jobid
Ejemplo n.º 8
0
def job_queue(lassod, *ids):
    """Queue all unfinished tasks associated with specified jobs. Return a list 
    of tasks that are waiting."""
    print ids
    db = Session()
    output = list()
    for job in db.query(Job).filter(Job.id.in_(ids)):
        log.info("Adding job %d to queue." % job.id)
        job.queue()
        _job_update(job)
        output.append(job.id)
    db.commit()
    db.close()
    return output
Ejemplo n.º 9
0
def job_stop(lassod, *ids):
    """Stop the speciefed job, and currently running tasks of job. Mark all unfinished
    tasks as stopped. Return a list of stopped jobs."""
    db = Session()
    tasks = list()
    output = []
    for job in db.query(Job).filter(Job.id.in_(ids)):
        job.stop()
        _job_update(job)
        output.append(job.id)
    db.commit()
    lassod.info('Job "%s" was stopped. [%d]' % (job.name, job.id))
    db.close()
    return output
Ejemplo n.º 10
0
def task_kill(lassod, *ids):
    """Kill task by id number."""
    db = Session()
    output = list()
    tasks = db.query(Task).filter(Task.id.in_(ids)).all()
    for task in tasks:
        if task.running:
            cattle = db.query(Cattle).filter(Cattle.id==task.running).first()
            client = CattleClient(cattle.hostname)
            client.kill_task(task.id)
            output.append(True)
        else:
            output.append(False)
    db.close()
    return output
Ejemplo n.º 11
0
def job_adjust_priority(lassod, id, adjustment):
    """Adjust the priority of all task associated with job."""
    db = Session()
    job = db.query(Job).filter(Job.id==id).first()
    if job:
        for task in job.tasks:
            task.priority += adjustment
            if task.priority > 800:
                task.priority = 800
            elif task.priority < 200:
                task.priority = 200
        db.commit()
        db.close()
        return True
    else:
        db.close()
        return False
Ejemplo n.º 12
0
def cattle_status(lassod, *hostnames):
    """Get the status of the specified cattle. Return cattle state as a list of
    dictionaries containing a runtime report of cattle."""
    db = Session()
    output = []
    cattles = db.query(Cattle).filter(Cattle.hostname.in_(hostnames)).all()
    for cattle in cattles:
        metric = db.query(CattleMetrics).filter(CattleMetrics.cattle_id==cattle.id)
        metric = metric.order_by(desc(CattleMetrics.time)).first()
        report = dict()
        for key in CattleMetrics.keys:
            attr = getattr(metric, key)
            if attr is not None:
                if key == 'running':
                    report[key] = [int(task.id) for task in attr]
                else:
                    report[key] = str(attr)
        output.append(report)
    db.close()
    return output
Ejemplo n.º 13
0
    def __init__(self):
        #Get configuration 
        config = config_lasso()
        hostname = config.get('lasso', 'hostname')
        port = config.getint('lasso', 'port')
        WranglerServer.__init__(self, hostname, port, 'wrangler.lasso')

        #Setup Code Objects
        self.decorate_task_object()

        #Clean Up Database
        db = Session()
        tasks = db.query(Task).filter(Task.status==Task.QUEUED).all()
        for task in tasks:
            task.status = task.WAITING
        db.commit()
        db.close()

        #Initialize
        self.heard = dict()
        self.next_task_lock = thread.allocate_lock()
        self.queue = PriorityQueue()