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)
def check_object_creation(req, object_name): """ Check to ensure that everything is alright about an object to be created. :param req: HTTP request object :param object_name: name of object to be created :raises HTTPRequestEntityTooLarge: the object is too large :raises HTTPLengthRequered: missing content-length header and not a chunked request :raises HTTPBadRequest: missing or bad content-type header, or bad metadata """ if req.content_length and req.content_length > MAX_FILE_SIZE: respbody='Your request is too large.' return jresponse('-1', respbody, req,413) if req.content_length is None and \ req.headers.get('transfer-encoding') != 'chunked': return jresponse('-1', 'length required', req,411) if len(object_name) > MAX_OBJECT_NAME_LENGTH: respbody='Object name length of %d longer than %d' % (len(object_name), MAX_OBJECT_NAME_LENGTH) return jresponse('-1', respbody, req,400) return None
def processStatData(request): param = json.loads(request.body) hostUuid = param.get('hostUuid') typeClass = param.get('class') attr = param.get('attr') if not GlobalQueue.get(hostUuid): return jresponse('0', 'restart', request, 200) GlobalQueue.get(hostUuid).get(typeClass).put(attr) # GlobalQueue.get(hostUuid).get('host').put(attr) return jresponse('0', '', request, 200)
def processStatData(request): param = json.loads(request.body) hostUuid = param.get('hostUuid') typeClass = param.get('class') attr = param.get('attr') if not GlobalQueue.get(hostUuid): return jresponse('0','restart',request,200) GlobalQueue.get(hostUuid).get(typeClass).put(attr) # GlobalQueue.get(hostUuid).get('host').put(attr) return jresponse('0','',request,200)
def __call__(self, env, start_response): req = Request(env) self.logger.txn_id = req.headers.get('x-trans-id', None) if not check_utf8(req.path_info): res = jresponse('-1', 'invalid utf8', req,412) else: try: res = handlerequest(req) except (Exception, Timeout): self.logger.exception(('ERROR __call__ error with %(method)s' ' %(path)s '), {'method': req.method, 'path': req.path}) res = jresponse('-1', 'InternalServerError', req,500) return res(env, start_response)
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 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 centerGetConfig(request): attrs = {} attrs.update({'auth': libGetAuth()}) attrs.update({'cache': libGetCache()}) attrs.update({'concurrency': libGetConCurrency()}) attrs.update({'proxy': libGetProxy()}) attrs.update({'storage': libGetStorage()}) return jresponse('0', json.dumps(attrs), request, 200)
def handlerequest(req): url = req.path print url if url not in url2view: return jresponse('-1','url error',req,404) if url.startswith('/cloudfs'): return url2view[url](req) else: return url2view[url](req)
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 centerSetConfig(request): param = json.loads(request.body) attrs = param.get('confAttrs') for classtype,confdict in attrs.items(): if classtype not in class2func: continue class2func[classtype](confdict) return jresponse('0','',request,200)
def centerGetConfig(request): attrs = {} attrs.update({'auth':libGetAuth()}) attrs.update({'cache':libGetCache()}) attrs.update({'concurrency':libGetConCurrency()}) attrs.update({'proxy':libGetProxy()}) attrs.update({'storage':libGetStorage()}) return jresponse('0',json.dumps(attrs),request,200)
def centerSetConfig(request): param = json.loads(request.body) attrs = param.get('confAttrs') for classtype, confdict in attrs.items(): if classtype not in class2func: continue class2func[classtype](confdict) 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 check_metadata(req, target_type): """ Check metadata sent in the request headers. :param req: request object :param target_type: str: one of: object, container, or account: indicates which type the target storage for the metadata is :raises HTTPBadRequest: bad metadata """ prefix = 'x-%s' % (target_type) meta_count = 0 meta_size = 0 for key, value in req.headers.iteritems(): if not key.lower().startswith(prefix): continue if not key: respbody='Metadata name cannot be empty' return jresponse('-1', respbody, req,400) meta_count += 1 meta_size += len(key) + len(value) if len(key) > MAX_META_NAME_LENGTH: respbody='Metadata name too long; max %d' % MAX_META_NAME_LENGTH return jresponse('-1', respbody, req,400) elif len(value) > MAX_META_VALUE_LENGTH: respbody='Metadata value too long; max %d' % MAX_META_VALUE_LENGTH return jresponse('-1', respbody, req,400) elif meta_count > MAX_META_COUNT: respbody='Too many metadata items; max %d' % MAX_META_COUNT return jresponse('-1', respbody, req,400) elif meta_size > MAX_META_OVERALL_SIZE: respbody='Total metadata too large; max %d' % MAX_META_OVERALL_SIZE return jresponse('-1', respbody, req,400) return None
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)
def centerPullExecutor(request): host_info = {'uuid': loadUuid(), 'name': socket.gethostname()} return jresponse('0', json.dumps(host_info), request, 200)
def centerPullExecutor(request): host_info = {'uuid':loadUuid(), 'name':socket.gethostname()} return jresponse('0',json.dumps(host_info),request,200)
def handlerequest(req): url = req.path if url not in url2view: return jresponse('-1', 'url error', req, 404) return url2view[url](req)
def handlerequest(req): url = req.path if url not in url2view: return jresponse('-1','url error',req,404) return url2view[url](req)