Exemplo n.º 1
0
    def __init__(self, statusCode, body):
        DisResponse.__init__(self, statusCode, body)
        if type(body) == dict:
            if sys.version_info.major == 2 or sys.version_info.major < 3:
                self.body = {}
                self.body['next_partition_cursor'] = body[
                    "next_partition_cursor"]
                for i in range(len(body["records"])):
                    tempData = body["records"][i]["data"].encode('utf-8')
                    body["records"][i]["data"] = base64.b64decode(tempData)
                self.body['records'] = [{
                    'data':
                    i.get('data'),
                    'sequence_number':
                    i.get('sequence_number')
                } for i in body["records"]]

            else:
                for i in range(len(body["records"])):
                    tempData = body["records"][i]["data"].encode('utf-8')
                    try:
                        body["records"][i]["data"] = base64.b64decode(
                            tempData).decode('utf-8').replace('\ufeff', '')
                    except:
                        pass
                self.body['records'] = [{
                    'data':
                    i.get('data'),
                    'sequence_number':
                    i.get('sequence_number')
                } for i in body["records"]]

        else:
            from src.com.dis.models import send_records_pb2
            target = send_records_pb2.GetRecordsResult()
            target.ParseFromString(body)
            self.body = {}
            self.body['next_partition_cursor'] = target.nextShardIterator
            import re
            p1 = re.compile(r'data:.*\n')
            p = re.compile(r'sequenceNumber:.*\n')
            datas = []
            for i in p1.findall(str(target.records)):
                datas.append((i.replace('\\', '').replace('"', '').strip()))
            sequenceNumber = []
            for i in p.findall(str(target.records)):
                sequenceNumber.append((i.replace('\\',
                                                 '').replace('"', '').strip()))
            ddd = list(zip(datas, sequenceNumber))
            records = [{
                'sequence_number':
                i[1].split('sequenceNumber:')[-1].strip(),
                'data':
                i[0].split('data:', 1)[-1].strip()
            } for i in ddd]
            self.body['records'] = records

        self.nextPartitionCursor = self.body["next_partition_cursor"]
        self.recordResult = self.body["records"]
        self.recordCount = len(self.body["records"])
Exemplo n.º 2
0
    def __init__(self,status_code, body,total_number):
        app_list=[]
        if 'apps' in body.keys():
            for i in body.get('apps'):
                app_list.append(i.get('app_name'))
            body.setdefault('apps_list', app_list)
            body.setdefault('total_number', total_number)

            import copy
            new_body=copy.deepcopy(body)
            if 'apps' in new_body.keys():
                del new_body['apps']
            if 'hasMoreApp' in new_body.keys():
                del new_body['hasMoreApp']

            new_body.setdefault('appinfo_list',body.get('apps'))
            new_body.setdefault('has_more_app',body.get('hasMoreApp'))

        else:
            import copy
            new_body = copy.deepcopy(body)
            if 'hasMoreApp' in new_body.keys():
                del new_body['hasMoreApp']
            new_body.setdefault('has_more_app', body.get('hasMoreApp'))

        DisResponse.__init__(self, status_code, new_body)
Exemplo n.º 3
0
    def __init__(self, statusCode, body):
        DisResponse.__init__(self, statusCode, body)
        if type(body) != dict:
            from src.com.dis.models import send_records_pb2
            target = send_records_pb2.PutRecordsResult()
            target.ParseFromString(body)
            records = []
            self.body = {}
            records.extend([{
                'partition_id': target.records[i].shardId,
                'sequence_number': target.records[i].sequenceNumber,
                'error_message': target.records[i].errorMessage,
                'error_code': target.records[i].errorCode
            } for i in range(len(target.records))])

            for i in records:
                if 'DIS' not in i['error_code']:
                    del i['error_code']
                    del i['error_message']

            self.body['records'] = records
            self.body['failed_record_count'] = target.failedRecordCount
        else:
            self.body = body

        self.failedRecordCount = self.body["failed_record_count"]
        self.recordResult = self.body["records"]
Exemplo n.º 4
0
 def __init__(self, statusCode, body):
     DisResponse.__init__(self, statusCode, body)
     self.streamName = body["stream_name"]
     self.createTime = body["create_time"]
     self.lastModifiedTime = body["last_modified_time"]
     self.retentionPeriod = body["retention_period"]
     self.status = body["status"]
     self.streamType = body["stream_type"]
     self.partitions = body["partitions"]
     self.currentPartitionCount = len(self.partitions)
     self.hasMorePartitions = body["has_more_partitions"]
Exemplo n.º 5
0
 def __init__(self, statusCode, body):
     DisResponse.__init__(self, statusCode, body)
     self.partitions = body['partitions']
     self.streamName = body["stream_name"]
     self.createTime = body["create_time"]
     self.lastModifiedTime = body["last_modified_time"]
     self.retentionPeriod = body["retention_period"]
     self.status = body["status"]
     self.streamType = body["stream_type"]
     self.partitions = body["partitions"]
     self.currentPartitionCount = len(self.partitions)
     self.hasMorePartitions = body["has_more_partitions"]
     for i in self.partitions:
         self.hash_range = i.get('hash_range')
         self.sequence_number_range =i.get('sequence_number_range')
         self.partition_id = i.get('partition_id')
Exemplo n.º 6
0
 def __init__(self, status_code, body):
     DisResponse.__init__(self, status_code, body)
Exemplo n.º 7
0
 def __init__(self, status_code, body):
     DisResponse.__init__(self, status_code, body)   
     # self.seqNumber = body["sequence_number"]
     self.seqNumber=body.get("sequence_number")
     self.metaData=body.get("metaData",'')
Exemplo n.º 8
0
 def __init__(self, statusCode, body):
     DisResponse.__init__(self, statusCode, body)
     self.cursor = body["partition_cursor"]
Exemplo n.º 9
0
 def __init__(self, statusCode, body):
     DisResponse.__init__(self, statusCode, body)
     self.total = body["total_number"]
     self.streams = body["stream_names"]
     self.count = len(self.streams)
     self.hasMoreStream = body["has_more_streams"]
Exemplo n.º 10
0
 def __init__(self, statusCode, body):
     DisResponse.__init__(self, statusCode, body)
     self.body = body
Exemplo n.º 11
0
 def __init__(self, statusCode, body):
     DisResponse.__init__(self, statusCode, body)
     self.has_more_tasks = body['has_more_tasks']
     self.total_number = body['total_number']
     self.details = body['details']