Example #1
0
def submit_task(input_data):
    status = 0  # mark it can not submit
    task_name = input_data['task_name']
    try:
        result = es_group_result.get(index=group_index_name,
                                     doc_type=group_index_type,
                                     id=task_name)['_source']
    except:
        status = 1

    if status != 0 and 'uid_file' not in input_data:
        input_data['status'] = 0  # mark the task not compute
        count = len(input_data['uid_list'])
        input_data['count'] = count
        input_data['task_type'] = 'analysis'
        input_data['submit_user'] = '******'
        input_data['detect_type'] = ''
        input_data['detect_process'] = ''
        add_es_dict = {'task_information': input_data, 'query_condition': ''}
        es_group_result.index(index=group_index_name,
                              doc_type=group_index_type,
                              id=task_name,
                              body=input_data)
        r.lpush(group_analysis_queue_name, json.dumps(input_data))

    return status
Example #2
0
def save_compute2es(input_dict):
    add_dict = {}
    status = True
    add_dict = dict(add_dict, **input_dict['task_information'])
    task_name = input_dict['task_information']['task_name']
    uid_list = input_dict['task_information']['uid_list']
    submit_user = input_dict['task_information']['submit_user']
    task_id = submit_user + '-' + task_name
    if isinstance(uid_list, list):
        count = len(input_dict['task_information']['uid_list'])
    else:
        count = len(json.loads(input_dict['task_information']['uid_list']))
    add_dict['count'] = count
    if 'query_condition' not in input_dict:
        input_dict['query_condition'] = {}
    if isinstance(input_dict['query_condition'], str):
        add_dict['query_condition'] = input_dict['query_condition']
    else:
        add_dict['query_condition'] = json.dumps(input_dict['query_condition'])
    try:
        es_group_result.index(index=group_index_name,
                              doc_type=group_index_type,
                              id=task_id,
                              body=add_dict)
        print 'success add compute task es'
    except:
        status = False

    return status
def save_compute2es(input_dict):
    add_dict = {}
    status = True
    add_dict = dict(add_dict, **input_dict['task_information'])
    task_name = input_dict['task_information']['task_name']
    uid_list = input_dict['task_information']['uid_list']
    submit_user = input_dict['task_information']['submit_user']
    task_id = input_dict['task_information']['task_id']
    if isinstance(uid_list, list):
        count = len(input_dict['task_information']['uid_list'])
    else:
        count = len(json.loads(input_dict['task_information']['uid_list']))
    add_dict['count'] = count
    if 'query_condition' not in input_dict:
        input_dict['query_condition'] = {}
    if isinstance(input_dict['query_condition'], str):
        add_dict['query_condition'] = input_dict['query_condition']
    else:
        add_dict['query_condition'] = json.dumps(input_dict['query_condition'])
    try:
        es_group_result.index(index=group_index_name, doc_type=group_index_type, id=task_id, body=add_dict)
        print 'success add compute task es'
    except:
        status = False

    return status
Example #4
0
def submit_task(input_data):
    print 'aaaaaaaaaaaaaaa'
    print input_data
    status = 0 # mark it can not submit
    task_name = input_data['task_name']
    submit_user = input_data['submit_user']
    task_id = submit_user + '-' + task_name
    #identify the compute task is not more than limit
    try:
        task_max_count = input_data['task_max_count']
    except:
        task_max_count = 0
    query_body = {
    'query':{
        'filtered':{
            'filter':{
                'bool':{
                    'must':[
                        {'term': {'submit_user': submit_user}},
                        {'term': {'status': 0}}
                        ]
                    }
                }
            }
        }
    }
    print es_group_result,group_index_name,group_index_type
    exist_compute_result = es_group_result.search(index=group_index_name, doc_type=group_index_type, body=query_body)['hits']['hits']
    exist_compute_count = len(exist_compute_result)
    if exist_compute_count >= task_max_count:
        return 'more than limit'
    #identify the task name is valid
    try:
        result = es_group_result.get(index=group_index_name, doc_type=group_index_type, id=task_id)['_source']
    except:
        status = 1
    if status != 0 and 'uid_file' not in input_data:
        input_data['status'] = 0 # mark the task not compute
        count = len(input_data['uid_list'])
        input_data['count'] = count
        input_data['task_type'] = 'analysis'
        input_data['submit_user'] = submit_user
        input_data['detect_type'] = ''
        input_data['detect_process'] = ''
        input_data['task_id'] = task_id
        add_es_dict = {'task_information': input_data, 'query_condition':''}
        # print es_group_result,group_index_name,group_index_type
        # print r
        # print '**********************8'
        es_group_result.index(index=group_index_name, doc_type=group_index_type, id=task_id, body=input_data)
        #print es_group_result,group_index_name,group_index_type
        r.lpush(group_analysis_queue_name, json.dumps(input_data))
        #print status
    print status
    return status
Example #5
0
def save_detect2es(input_dict):
    add_dict = {}
    status = True
    add_dict = dict(add_dict, **input_dict['task_information'])
    task_name = input_dict['task_information']['task_name']
    add_dict['query_condition'] = json.dumps(input_dict['query_condition'])
    try:
        es_group_result.index(index=group_index_name, doc_type=group_index_type, id=task_name, body=add_dict)
        print 'success add detect task to es'
    except:
        status = False
    
    return status
def submit_task(input_data):
    status = 0 # mark it can not submit
    task_name = input_data['task_name']
    submit_user = input_data['submit_user']
    task_id = submit_user + '-' + task_name
    #identify the compute task is not more than limit
    try:
        task_max_count = input_data['task_max_count']
    except:
        task_max_count = 0
    query_body = {
    'query':{
        'filtered':{
            'filter':{
                'bool':{
                    'must':[
                        {'term': {'submit_user': submit_user}},
                        {'term': {'status': 0}}
                        ]
                    }
                }
            }
        }
    }
    exist_compute_result = es_group_result.search(index=group_index_name, doc_type=group_index_type, body=query_body)['hits']['hits']
    exist_compute_count = len(exist_compute_result)
    if exist_compute_count >= task_max_count:
        return 'more than limit'
    #identify the task name is valid
    try:
        result = es_group_result.get(index=group_index_name, doc_type=group_index_type, id=task_id)['_source']
    except:
        status = 1
    
    if status != 0 and 'uid_file' not in input_data:
        input_data['status'] = 0 # mark the task not compute
        count = len(input_data['uid_list'])
        input_data['count'] = count
        input_data['task_type'] = 'analysis'
        input_data['submit_user'] = submit_user
        input_data['detect_type'] = ''
        input_data['detect_process'] = ''
        add_es_dict = {'task_information': input_data, 'query_condition':''}
        es_group_result.index(index=group_index_name, doc_type=group_index_type, id=task_id, body=input_data)
        r.lpush(group_analysis_queue_name, json.dumps(input_data))
    
    return status
Example #7
0
def submit_task(input_data):
    status = 0 # mark it can not submit
    task_name = input_data['task_name']
    try:
        result = es_group_result.get(index=group_index_name, doc_type=group_index_type, id=task_name)['_source']
    except:
        status = 1
    
    if status != 0 and 'uid_file' not in input_data:
        input_data['status'] = 0 # mark the task not compute
        count = len(input_data['uid_list'])
        input_data['count'] = count
        input_data['task_type'] = 'analysis'
        input_data['submit_user'] = '******'
        input_data['detect_type'] = ''
        input_data['detect_process'] = ''
        add_es_dict = {'task_information': input_data, 'query_condition':''}
        es_group_result.index(index=group_index_name, doc_type=group_index_type, id=task_name, body=input_data)
        r.lpush(group_analysis_queue_name, json.dumps(input_data))
    
    return status