def flaskAddExecutor(request):

    param = json.loads(request.body)
    hostip = param.get('hostip')
    atName = param.get('atName')
    conn = GLOBAL_USER_DB.get(atName)
    with getlock(conn) as mylock:
        attr = db_flask_ip2attr(conn, hostip)
    if attr:
        info = '%s %s %s' % (attr.get('inet'), attr.get('name'),
                             attr.get('uuid'))
        return jresponse('-1', 'executor ip already exists: ' + info, request,
                         200)
    resp = libPullExecutor(hostip, CONFIG_EXECUTOR_PORT)
    if -1 == resp['status']:
        return jresponse('-1', 'pull executor host info failed,check network',
                         request, 200)
    ei = resp.get('msg')
    ei = json.loads(ei)
    with getlock(conn) as mylock:
        attr = db_flask_uuid2attr(conn, ei.get('uuid'))
        if attr:
            info = '%s %s %s' % (attr.get('name'), attr.get('uuid'),
                                 attr.get('ip'))
            return jresponse('-1', 'executor uuid already exists: ' + info,
                             request, 200)
        db_flask_put_executor(conn, ei.get('name'), hostip, ei.get('uuid'))
    return jresponse('0', '', request, 200)
Example #2
0
def processStartUp(request):

    param = json.loads(request.body)
    
    hostUuid = param.get('hostUuid')
    if not GlobalDb.get(hostUuid):
        GlobalDb.put(hostUuid, getdb())
        
    db = GlobalDb.get(hostUuid)
    
    with getlock(db) as mylock:
        puth(db,hostUuid,param.get('hostClass'))
        hostid = uuid2hostid(db, hostUuid)
        putc(db, hostid, param.get('cpuClass'))
        putms(db, hostid, param.get('memClass'))
        putns(db, hostid, param.get('netClass'))
        putds(db, hostid, param.get('diskClass'))
    
    if not GlobalQueue.get(hostUuid):
        loadQueue(hostUuid, GlobalQueue)
        
    if not GlobalThread.get(hostUuid):
        loadThread(hostUuid, GlobalThread)
    
    return jresponse('0','ready',request,200)
Example #3
0
def processStartUp(request):

    param = json.loads(request.body)

    hostUuid = param.get('hostUuid')
    if not GlobalDb.get(hostUuid):
        GlobalDb.put(hostUuid, getdb())

    db = GlobalDb.get(hostUuid)

    with getlock(db) as mylock:
        puth(db, hostUuid, param.get('hostClass'))
        hostid = uuid2hostid(db, hostUuid)
        putc(db, hostid, param.get('cpuClass'))
        putms(db, hostid, param.get('memClass'))
        putns(db, hostid, param.get('netClass'))
        putds(db, hostid, param.get('diskClass'))

    if not GlobalQueue.get(hostUuid):
        loadQueue(hostUuid, GlobalQueue)

    if not GlobalThread.get(hostUuid):
        loadThread(hostUuid, GlobalThread)

    return jresponse('0', 'ready', request, 200)
def flaskDelExecutor(request):
    
    param = json.loads(request.body)
    hostUuid = param.get('hostUuid')
    atName = param.get('atName')
    conn = GLOBAL_USER_DB.get(atName)
    with getlock(conn) as mylock:
        db_flask_del_executor(conn, hostUuid)
        
    return jresponse('0','',request,200) 
def flaskDelExecutor(request):

    param = json.loads(request.body)
    hostUuid = param.get('hostUuid')
    atName = param.get('atName')
    conn = GLOBAL_USER_DB.get(atName)
    with getlock(conn) as mylock:
        db_flask_del_executor(conn, hostUuid)

    return jresponse('0', '', request, 200)
def flaskListExecutor(request):
    
    param = json.loads(request.body)
    atName = param.get('atName')
    conn = GLOBAL_USER_DB.get(atName)
    with getlock(conn) as mylock:
        attrs = db_flask_list_executor(conn)
        for attr in attrs:
            attr.pop('id')
            
    return jresponse('0',json.dumps(attrs),request,200) 
def flaskListExecutor(request):

    param = json.loads(request.body)
    atName = param.get('atName')
    conn = GLOBAL_USER_DB.get(atName)
    with getlock(conn) as mylock:
        attrs = db_flask_list_executor(conn)
        for attr in attrs:
            attr.pop('id')

    return jresponse('0', json.dumps(attrs), request, 200)
def flaskGetConfig(request):
    
    param = json.loads(request.body)
    hostUuid = param.get('hostUuid')
    atName = param.get('atName')
    conn = GLOBAL_USER_DB.get(atName)
    
    with getlock(conn) as mylock:
        attr = db_flask_uuid2attr(conn, hostUuid)
    http_host = attr.get('inet')
    resp = libGetExecutorConf(http_host,  CONFIG_EXECUTOR_PORT)
    return jresponse(resp['status'],json.dumps(resp['msg']),request,200) 
def flaskSetConfig(request):
    
    param = json.loads(request.body)
    attrs = param.get('confAttrs')
    hostUuid = param.get('hostUuid')
    atName = param.get('atName')
    conn = GLOBAL_USER_DB.get(atName)
    with getlock(conn) as mylock:
        attr = db_flask_uuid2attr(conn, hostUuid)
    http_host = attr.get('inet')
    libSetExecutorConf(http_host, CONFIG_EXECUTOR_PORT, attrs)
    return jresponse('0','',request,200) 
def flaskGetConfig(request):

    param = json.loads(request.body)
    hostUuid = param.get('hostUuid')
    atName = param.get('atName')
    conn = GLOBAL_USER_DB.get(atName)

    with getlock(conn) as mylock:
        attr = db_flask_uuid2attr(conn, hostUuid)
    http_host = attr.get('inet')
    resp = libGetExecutorConf(http_host, CONFIG_EXECUTOR_PORT)
    return jresponse(resp['status'], json.dumps(resp['msg']), request, 200)
def flaskSetConfig(request):

    param = json.loads(request.body)
    attrs = param.get('confAttrs')
    hostUuid = param.get('hostUuid')
    atName = param.get('atName')
    conn = GLOBAL_USER_DB.get(atName)
    with getlock(conn) as mylock:
        attr = db_flask_uuid2attr(conn, hostUuid)
    http_host = attr.get('inet')
    libSetExecutorConf(http_host, CONFIG_EXECUTOR_PORT, attrs)
    return jresponse('0', '', request, 200)
def flaskAddExecutor(request):
    
    param = json.loads(request.body)
    hostip = param.get('hostip')
    atName = param.get('atName')
    conn = GLOBAL_USER_DB.get(atName)
    with getlock(conn) as mylock:
        attr = db_flask_ip2attr(conn, hostip)
    if attr:
        info = '%s %s %s' % (attr.get('inet'),attr.get('name'),attr.get('uuid'))
        return jresponse('-1','executor ip already exists: '+info,request,200) 
    resp = libPullExecutor(hostip, CONFIG_EXECUTOR_PORT)
    if -1 == resp['status']:
        return jresponse('-1','pull executor host info failed,check network',request,200)
    ei = resp.get('msg')
    ei = json.loads(ei)
    with getlock(conn) as mylock:
        attr = db_flask_uuid2attr(conn, ei.get('uuid'))
        if attr:
            info = '%s %s %s' % (attr.get('name'),attr.get('uuid'),attr.get('ip'))
            return jresponse('-1','executor uuid already exists: '+info,request,200) 
        db_flask_put_executor(conn, ei.get('name'), hostip, ei.get('uuid'))
    return jresponse('0','',request,200)