def state_from_tr_bson(cls, doc): r""" >>> from common.typed_uuids import DatasetUUID, MessageUUID, PeerUUID >>> # No optional arguments >>> Transaction.state_from_tr_bson({ ... 'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), ... 'state': {'dataset_uuid': ... UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')}, ... 'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), ... 'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), ... 'type': 'BACKUP', ... 'ts': datetime(2012, 9, 26, 14, 29, 48, 877434) ... }) # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE BackupTransactionState_Node(tr_start_time=....datetime(2012, 9, 26, 14, 29, 48, 877434), tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), dataset_uuid=DatasetUUID('cf9a54b1-1239-48de-9b25-d7fa927db125')) >>> # All optional arguments >>> Transaction.state_from_tr_bson({ ... 'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), ... 'state': {'dataset_uuid': ... UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')}, ... 'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), ... 'parent': UUID('a096cf37-dc4f-4d0e-9488-da50443c8c40'), ... 'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), ... 'wake_up_ts': datetime(2012, 10, 3, 12, 31, 8, 279807), ... 'type': 'BACKUP', ... 'ts': datetime(2012, 9, 26, 14, 29, 48, 877434) ... }) # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE BackupTransactionState_Node(tr_start_time=....datetime(2012, 9, 26, 14, 29, 48, 877434), tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), dataset_uuid=DatasetUUID('cf9a54b1-1239-48de-9b25-d7fa927db125')) @type: NodeTransactionState """ assert cls.validate_schema(doc), repr(doc) state_class = \ transaction_states.TRANSACTION_STATE_CLASS_BY_NAME[doc['type']] assert state_class.validate_schema(doc['state']), repr(doc) return state_class.from_bson(doc['state'])( tr_start_time=doc['ts'], tr_uuid=TransactionUUID.safe_cast_uuid(doc['uuid']), tr_src_uuid=PeerUUID.safe_cast_uuid(doc['src']), tr_dst_uuid=PeerUUID.safe_cast_uuid(doc['dst']))
def _init_from_body(self, body): # N2H assert 'files' in body, \ repr(body) if 'dataset' in body: self.dataset = \ AbstractBasicDatasetInfo.from_json(body['dataset'])() if 'ugroup' in body: self.ugroup = UserGroup.from_json(body['ugroup'])() self.sync = bool(int(body['sync'])) _files_pre = {LocalPhysicalFileState.from_json( json.loads(file_key))(): blocks for file_key, blocks in body['files'].iteritems()} self.files = {file: [Chunk.Block.from_json(ser_block, file)() for ser_block in blocks] for file, blocks in _files_pre.iteritems()} if 'want_restore' in body: self.wr_uuid = TransactionUUID(body['want_restore'])
def from_bson(cls, doc): r""" >>> from common.typed_uuids import DatasetUUID, MessageUUID, PeerUUID >>> # No optional arguments >>> Transaction.from_bson({ ... 'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), ... 'state': {'dataset_uuid': ... UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')}, ... 'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), ... 'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), ... 'type': 'BACKUP', ... 'ts': datetime(2012, 9, 26, 14, 29, 48, 877434) ... })() # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE Transaction(_id=None, type_='BACKUP', uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), src=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), dst=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), ts=datetime.datetime(2012, 9, 26, 14, 29, 48, 877434), state=BackupTransactionState_Node(tr_start_time=....datetime(2012, 9, 26, 14, 29, 48, 877434), tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), dataset_uuid=DatasetUUID('cf9a54b1-...-d7fa927db125'))) >>> # All optional arguments >>> Transaction.from_bson({ ... 'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), ... 'state': {'dataset_uuid': ... UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')}, ... 'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), ... 'parent': UUID('a096cf37-dc4f-4d0e-9488-da50443c8c40'), ... 'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), ... 'wake_up_ts': datetime(2012, 10, 3, 12, 31, 8, 279807), ... 'type': 'BACKUP', ... 'ts': datetime(2012, 9, 26, 14, 29, 48, 877434) ... })() # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE Transaction(_id=None, type_='BACKUP', uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), src=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), dst=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), ts=datetime.datetime(2012, 9, 26, 14, 29, 48, 877434), state=Backup...State_Node(tr_start_time=....datetime(2012, 9, 26, 14, 29, 48, 877434), tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), dataset_uuid=DatasetUUID('cf9a54b1-1239-...-d7fa927db125')), parent=UUID('a096cf37-dc4f-4d0e-9488-da50443c8c40'), wake_up_ts=datetime.datetime(2012, 10, 3, 12, 31, 8, 279807)) @rtype: Transaction """ assert cls.validate_schema(doc), repr(doc) state = cls.state_from_tr_bson(doc) return partial( super(Transaction, cls).from_bson(doc), type_=state.tr_type, uuid=TransactionUUID.safe_cast_uuid(state.tr_uuid), src=PeerUUID.safe_cast_uuid(state.tr_src_uuid), dst=PeerUUID.safe_cast_uuid(state.tr_dst_uuid), ts=state.tr_start_time, state=state, # Optional parent=doc.get('parent'), wake_up_ts=doc.get('wake_up_ts'))
def from_bson(cls, doc): r""" >>> from common.typed_uuids import DatasetUUID, MessageUUID, PeerUUID >>> # No optional arguments >>> Transaction.from_bson({ ... 'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), ... 'state': {'dataset_uuid': ... UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')}, ... 'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), ... 'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), ... 'type': 'BACKUP', ... 'ts': datetime(2012, 9, 26, 14, 29, 48, 877434) ... })() # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE Transaction(_id=None, type_='BACKUP', uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), src=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), dst=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), ts=datetime.datetime(2012, 9, 26, 14, 29, 48, 877434), state=BackupTransactionState_Node(tr_start_time=....datetime(2012, 9, 26, 14, 29, 48, 877434), tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), dataset_uuid=DatasetUUID('cf9a54b1-...-d7fa927db125'))) >>> # All optional arguments >>> Transaction.from_bson({ ... 'src': UUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), ... 'state': {'dataset_uuid': ... UUID('cf9a54b1-1239-48de-9b25-d7fa927db125')}, ... 'uuid': UUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), ... 'parent': UUID('a096cf37-dc4f-4d0e-9488-da50443c8c40'), ... 'dst': UUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), ... 'wake_up_ts': datetime(2012, 10, 3, 12, 31, 8, 279807), ... 'type': 'BACKUP', ... 'ts': datetime(2012, 9, 26, 14, 29, 48, 877434) ... })() # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE Transaction(_id=None, type_='BACKUP', uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), src=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), dst=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), ts=datetime.datetime(2012, 9, 26, 14, 29, 48, 877434), state=Backup...State_Node(tr_start_time=....datetime(2012, 9, 26, 14, 29, 48, 877434), tr_uuid=MessageUUID('1a82a181-741d-4a64-86e5-77a7dd000ba2'), tr_src_uuid=PeerUUID('fa87ebfd-d498-4ba6-9f04-a933e4512b24'), tr_dst_uuid=PeerUUID('e6aa4157-ee8a-449e-a2d5-3340a59e717d'), dataset_uuid=DatasetUUID('cf9a54b1-1239-...-d7fa927db125')), parent=UUID('a096cf37-dc4f-4d0e-9488-da50443c8c40'), wake_up_ts=datetime.datetime(2012, 10, 3, 12, 31, 8, 279807)) @rtype: Transaction """ assert cls.validate_schema(doc), repr(doc) state = cls.state_from_tr_bson(doc) return partial(super(Transaction, cls).from_bson(doc), type_=state.tr_type, uuid=TransactionUUID.safe_cast_uuid(state.tr_uuid), src=PeerUUID.safe_cast_uuid(state.tr_src_uuid), dst=PeerUUID.safe_cast_uuid(state.tr_dst_uuid), ts=state.tr_start_time, state=state, # Optional parent=doc.get('parent'), wake_up_ts=doc.get('wake_up_ts'))