def _sendRequest(self, method, url, params, body, headers, respons_body_type='json'): (resp_status, resp_body, resp_header) = self._getHttpResponse(method, url, params, body, headers) header = {} for key, value in resp_header.items(): header[key] = value requestId = Util.h_v_td(header, 'x-log-requestid', '') if resp_status==200: if respons_body_type=='json': exJson = self._loadJson(resp_status, resp_header, resp_body, requestId) exJson = Util.convert_unicode_to_str(exJson) return exJson, header else: return resp_body, header exJson = self._loadJson(resp_status, resp_header, resp_body, requestId) exJson = Util.convert_unicode_to_str(exJson) if 'errorCode' in exJson and 'errorMessage' in exJson: raise LogException(exJson['errorCode'], exJson['errorMessage'], requestId, resp_status, resp_header, resp_body) else: exJson = '. Return json is ' + str(exJson) if exJson else '.' raise LogException('LogRequestError', 'Request is failed. Http code is ' + str(resp_status) + exJson, requestId, resp_status, resp_header, resp_body)
def _sendRequest(self, method, url, params, body, headers, respons_body_type = 'json'): (status, respText, respHeader) = self._getHttpResponse(method, url, params, body, headers) header = {} for key, value in respHeader.items(): header[key] = value requestId = header['x-log-requestid'] if 'x-log-requestid' in header else '' exJson = None header = Util.convert_unicode_to_str(header) if status == 200 : if respons_body_type == 'json' : exJson = self._loadJson(respText, requestId) #exJson = Util.convert_unicode_to_str(exJson) return (exJson, header) else : return (respText, header) exJson = self._loadJson(respText.encode('utf-8'), requestId) exJson = Util.convert_unicode_to_str(exJson) if 'errorCode' in exJson and 'errorMessage' in exJson: raise LogException(exJson['errorCode'], exJson['errorMessage'], requestId) else: exJson = '. Return json is '+str(exJson) if exJson else '.' raise LogException('LogRequestError', 'Request is failed. Http code is '+str(status)+exJson, requestId)
def __init__(self, resp, header): LogResponse.__init__(self, header) self.next_cursor = Util.convert_unicode_to_str(header["x-log-cursor"]) self.log_count = int(header["x-log-count"]) self.loggroup_list = LogGroupList() self._parse_loggroup_list(resp) self.loggroup_list_json = None
def __init__(self, resp, header): LogResponse.__init__(self, header) self.next_cursor = Util.convert_unicode_to_str(header["x-log-cursor"]) self.log_count = int(header["x-log-count"]) self.loggroup_list = LogGroupList() self._parse_loggroup_list(resp) self.loggroup_list_json = None
def _sendRequest(self, method, url, params, body, headers, respons_body_type='json'): (status, respText, respHeader) = self._getHttpResponse(method, url, params, body, headers) header = {} for key, value in respHeader.items(): header[key] = value requestId = header[ 'x-log-requestid'] if 'x-log-requestid' in header else '' exJson = None header = Util.convert_unicode_to_str(header) if status == 200: if respons_body_type == 'json': exJson = self._loadJson(respText, requestId) #exJson = Util.convert_unicode_to_str(exJson) return (exJson, header) else: return (respText, header) exJson = self._loadJson(respText.encode('utf-8'), requestId) exJson = Util.convert_unicode_to_str(exJson) if 'errorCode' in exJson and 'errorMessage' in exJson: raise LogException(exJson['errorCode'], exJson['errorMessage'], requestId) else: exJson = '. Return json is ' + str(exJson) if exJson else '.' raise LogException( 'LogRequestError', 'Request is failed. Http code is ' + str(status) + exJson, requestId)
def from_dict(cls, dict_data): schema_list = Util.convert_unicode_to_str( json.loads(dict_data.get("schema"))).get("schema") schema_instance_list = [] if schema_list: for schema in schema_list: schema_instance_list.append( ResourceSchemaItem(column=schema.get("column"), schema_type=schema.get("type"), ext_info=schema.get("ext_info"))) resource = Resource() resource.set_resource_name(dict_data.get("name")) resource.set_description(dict_data.get('description')) resource.set_resource_type(dict_data.get("type")) resource.set_ext_info(dict_data.get("extInfo")) resource.set_acl(json.loads(dict_data.get("acl"))) resource.set_schema_list(schema_instance_list) resource.set_create_time(dict_data.get("create_time")) resource.set_last_modify_time(dict_data.get("last_modify_time")) return resource
def maker(json_str): args_list, option_arg_pos = _parse_method(cls.__init__) if hasattr(cls, 'from_json'): # there's a from json method, try to use it try: j = json.loads(json_str) extjson = Util.convert_unicode_to_str(j) if option_arg_pos == 0: obj = cls() new_obj = obj.from_json(extjson) if new_obj is None: return obj # expecting it's updated else: return new_obj # expecting return a new obj else: # expect the from_json is static method. return cls.from_json(extjson) except Exception as ex: logger.warn("fail to load input via method from_json, try to call constructor for cls: " + str(cls) + "\n\tex:" + str(ex)) method_type = _parse_method_params_from_doc(cls.__doc__) j = json.loads(json_str) # verify if all mandantory args exists for i, arg in enumerate(args_list): if i >= option_arg_pos: break if arg not in j: raise ValueError("args:{0} is missed".format(arg)) # verify if all inputs exists in parameters for k in j: if k not in args_list: raise ValueError("args:{0} is unexpected".format(k)) # convert all values to expected type converted_args = _convert_args(j, method_type) return cls(**converted_args)
def maker(json_str): args_list, option_arg_pos = _parse_method(cls.__init__) if json_str.startswith('file://'): with open(json_str[7:], "r") as f: json_str = f.read() if option_arg_pos == 0 and hasattr(cls, 'from_json'): # there's a from json method, try to use it try: j = json.loads(json_str) extjson = Util.convert_unicode_to_str(j) obj = cls() obj.from_json(extjson) return obj except Exception as ex: print("** fail to load input via method from_json, try to call constructor for cls: " + str(cls) + "\nex:" + str(ex)) method_type = _parse_method_params_from_doc(cls.__doc__) j = json.loads(json_str) # verify if all mandantory args exists for i, arg in enumerate(args_list): if i >= option_arg_pos: break if arg not in j: raise ValueError("args:{0} is missed".format(arg)) # verify if all inputs exists in parameters for k in j: if k not in args_list: raise ValueError("args:{0} is unexpected".format(k)) # convert all values to expected type converted_args = _convert_args(j, method_type) return cls(**converted_args)
def __init__(self, resp, header): LogResponse.__init__(self, header) self.logstore_name = Util.convert_unicode_to_str(resp["logstoreName"]) self.ttl = int(resp["ttl"]) self.shard_count = int(resp["shardCount"])
def __init__(self, resp, header): LogResponse.__init__(self, header) self.shards = Util.convert_unicode_to_str(resp)
def __init__(self, resp, header): LogResponse.__init__(self, header) self.cursor = Util.convert_unicode_to_str(resp["cursor"])
def __init__(self, resp, header): LogResponse.__init__(self, header) self.count = int(resp["count"]) self.total = int(resp["total"]) self.machine_groups = Util.convert_unicode_to_str(resp["machinegroups"])
def __init__(self, resp, header): LogResponse.__init__(self, header) self.cursor = Util.convert_unicode_to_str(resp["cursor"])
def __init__(self, resp, header): LogResponse.__init__(self, header) self.logstore_name = Util.convert_unicode_to_str(resp["logstoreName"]) self.ttl = int(resp["ttl"]) self.shard_count = int(resp["shardCount"])
def __init__(self, resp, header): LogResponse.__init__(self, header) self.count = int(resp["count"]) self.logstores = Util.convert_unicode_to_str(resp["logstores"])
def __init__(self, resp, header): LogResponse.__init__(self, header) self.shards = Util.convert_unicode_to_str(resp)
def __init__(self, resp, header): LogResponse.__init__(self, header) self.count = int(resp["count"]) self.logstores = Util.convert_unicode_to_str(resp["logstores"])
def __init__(self, resp, header): LogResponse.__init__(self, header) self.count = int(resp["count"]) self.count = int(resp["total"]) self.logtail_configs = Util.convert_unicode_to_str(resp["configs"])
def __init__(self, resp, header): LogResponse.__init__(self, header) self.count = int(resp["count"]) self.count = int(resp["total"]) self.logtail_configs = Util.convert_unicode_to_str(resp["configs"])