Ejemplo n.º 1
0
def ajax_status(taskid, host):
    """
    This route is an ajax call from the javascript on the '/status' route, it returns messages from workers.
    :param taskid: This is the celery task ID being used to communicate with the master worker.
    :param host: This is the host in question, as a string.
    :return: A json object that represents the state of the containers on this host.
    """
    State.hosts = {}
    State.host_uuid = {}
    try:
        ret_value = list(State.tasks[taskid].get(timeout=TIMEOUT))
        parsed = []
        for i in ret_value:
            q.update_state(i, parsed)
            if i[0] == host:
                containers = i[2]['containers']
                bids = i[2]['bid_running']
        # Attach the BID to each container
        for bid in bids:
            for c in containers:
                if bids[bid]['cid'] == c['Id']:
                    c['bid'] = bid
    except Exception as e:
        app.logger.error(str(e))
        ret_value = []
    del State.tasks[taskid]
    if len(ret_value) == 0:
        return jsonify(results={}), 500
    return jsonify(containers=containers, host=host)
Ejemplo n.º 2
0
def ajax_queue(taskid):
    """
    This route is an ajax call from the /queue page that populates a table via javascript.
    :param taskid: The TaskID of the celery task started in '/queue'
    :return: A json object that can be used to create a table on the client side HTML.
    """
    State.hosts = {}
    try:
        ret_value = list(State.tasks[taskid].get(timeout=TIMEOUT))
        parsed = []
        for i in ret_value:
            q.update_state(i, parsed)
    except Exception as e:
        app.logger.error(str(e))
        pass
    results = []
    records = list(models.Build.query.filter_by().order_by(models.Build.created).all())
    db.session.commit()
    for b in records:
        s = dict()
        s['created'] = formatting.pretty_date(b.created)
        s['id'] = b.bid
        s['description'] = b.options['description']
        s['url'] = b.options['url']
        s['state'] = b.state
        results.append(s)
    results.reverse()
    return jsonify(builds=results)
Ejemplo n.º 3
0
def ajax_ping(id):
    """
    This route is an ajax call from the javascript on the '/ping' route, it returns messages from workers in the queue.
    :param id: This is the celery task ID being used to communicate with the master worker.
    :return: A json object that represents the state of the cluster.
    """
    State.hosts = {}
    try:
        ret_value = list(State.tasks[id].get(timeout=TIMEOUT))
        parsed = []
        for i in ret_value:
            q.update_state(i, parsed)
    except Exception as e:
        app.logger.error(str(e))
        ret_value = []
    del State.tasks[id]
    if len(ret_value) == 0:
        return jsonify(results={}), 500
    return jsonify(results=parsed)