Esempio n. 1
0
def compute_stampede_db_url():
    """
    If the requested endpoint requires connecting to a STAMPEDE database, then determine STAMPEDE DB URL and store it
    in g.stampede_db_url. Also, set g.m_wf_id to be the root workflow's uuid
    """
    if "/workflow" not in request.path or "m_wf_id" not in g:
        return

    md5sum = hashlib.md5()
    md5sum.update(g.master_db_url.encode("utf-8"))
    m_wf_id = g.m_wf_id

    def _get_cache_key(key_suffix):
        return "%s.%s" % (md5sum.hexdigest(), key_suffix)

    cache_key = _get_cache_key(m_wf_id)

    if cache.get(cache_key):
        log.debug("Cache Hit: compute_stampede_db_url %s" % cache_key)
        root_workflow = cache.get(cache_key)

    else:
        log.debug("Cache Miss: compute_stampede_db_url %s" % cache_key)
        queries = MasterWorkflowQueries(g.master_db_url)
        root_workflow = queries.get_root_workflow(m_wf_id)
        queries.close()

        cache.set(_get_cache_key(root_workflow.wf_id), root_workflow, timeout=600)
        cache.set(_get_cache_key(root_workflow.wf_uuid), root_workflow, timeout=600)

    g.url_m_wf_id = root_workflow.wf_id
    g.m_wf_id = root_workflow.wf_uuid
    g.stampede_db_url = root_workflow.db_url
Esempio n. 2
0
def compute_stampede_db_url():
    """
    If the requested endpoint requires connecting to a STAMPEDE database, then determine STAMPEDE DB URL and store it
    in g.stampede_db_url. Also, set g.m_wf_id to be the root workflow's uuid
    """
    if '/workflow' not in request.path or 'm_wf_id' not in g:
        return

    md5sum = hashlib.md5()
    md5sum.update(g.master_db_url)
    m_wf_id = g.m_wf_id

    def _get_cache_key(key_suffix):
        return '%s.%s' % (md5sum.hexdigest(), key_suffix)

    cache_key = _get_cache_key(m_wf_id)

    if cache.get(cache_key):
        log.debug('Cache Hit: compute_stampede_db_url %s' % cache_key)
        root_workflow = cache.get(cache_key)

    else:
        log.debug('Cache Miss: compute_stampede_db_url %s' % cache_key)
        queries = MasterWorkflowQueries(g.master_db_url)
        root_workflow = queries.get_root_workflow(m_wf_id)
        queries.close()

        cache.set(_get_cache_key(root_workflow.wf_id), root_workflow, timeout=600)
        cache.set(_get_cache_key(root_workflow.wf_uuid), root_workflow, timeout=600)

    g.url_m_wf_id = root_workflow.wf_id
    g.m_wf_id = root_workflow.wf_uuid
    g.stampede_db_url = root_workflow.db_url
Esempio n. 3
0
def get_root_workflow(username, m_wf_id):
    """
    Returns root level workflow identified by m_wf_id.

    :query boolean pretty-print: Return formatted JSON response.

    :statuscode 200: OK
    :statuscode 401: Authentication failure
    :statuscode 403: Authorization failure
    :statuscode 404: Not found

    :return type: Record
    :return resource: Root Workflow
    """
    queries = MasterWorkflowQueries(g.master_db_url)
    record = queries.get_root_workflow(m_wf_id)

    #
    # Generate JSON Response
    #
    response_json = jsonify(record)

    return make_response(response_json, 200, JSON_HEADER)
Esempio n. 4
0
def get_root_workflow(username, m_wf_id):
    """
    Returns root level workflow identified by m_wf_id.

    :query boolean pretty-print: Return formatted JSON response.

    :statuscode 200: OK
    :statuscode 401: Authentication failure
    :statuscode 403: Authorization failure
    :statuscode 404: Not found

    :return type: Record
    :return resource: Root Workflow
    """
    queries = MasterWorkflowQueries(g.master_db_url)
    record = queries.get_root_workflow(m_wf_id)

    #
    # Generate JSON Response
    #
    response_json = jsonify(record)

    return make_response(response_json, 200, JSON_HEADER)