def _get_headers(correlation_id, sequence): return { 'correlation_id': correlation_id, 'date': dpn_strftime(datetime.now()), 'ttl': str_expire_on(datetime.now()), 'sequence': sequence }
def make_headers(): header = { 'from': 'testfrom', 'reply_key': 'testkey', 'correlation_id': 'testid', 'sequence': 10, 'date': dpn_strftime(datetime.now()), 'ttl': str_expire_on(datetime.now(), 566), } return header
def respond_to_replication_query(init_request): """ Verifies if current node is available and has enough storage to replicate bags and sends a ReplicationAvailableReply. :param init_request: ReplicationInitQuery already validated """ # Prep Reply headers = { 'correlation_id': init_request.headers['correlation_id'], 'date': dpn_strftime(datetime.now()), 'ttl': str_expire_on(datetime.now()), 'sequence': 1 } body = { 'message_att': 'nak' } sequence_info = store_sequence( headers['correlation_id'], init_request.headers['from'], headers['sequence'] ) validate_sequence(sequence_info) bag_size = init_request.body['replication_size'] avail_storage = available_storage(DPN_REPLICATION_ROOT) supported_protocols = [val for val in init_request.body['protocol'] if val in DPN_XFER_OPTIONS] if supported_protocols and \ bag_size < avail_storage and \ bag_size < DPN_MAX_SIZE: try: protocol = protocol_str2db(supported_protocols[0]) receive_available_workflow( node=init_request.headers["from"], protocol=protocol, id=init_request.headers["correlation_id"] ) body = { 'message_att': 'ack', 'protocol': DPN_DEFAULT_XFER_PROTOCOL } except ValidationError as err: logger.info('ValidationError: %s' % err) pass # Record not created nak sent except DPNWorkflowError as err: logger.info('DPN Workflow Error: %s' % err) pass # Record not created, nak sent rsp = ReplicationAvailableReply(headers, body) rsp.send(init_request.headers['reply_key'])
def initiate_ingest(dpn_object_id, size): """ Initiates an ingest operation by minting the correlation ID :param dpn_object_id: UUID of the DPN object to send to the federation (extracted from bag filename) :param size: Integer of the bag size :return: Correlation ID to be used by choose_and_send_location linked task. """ # NOTE: Before sending the request, when this is real, it should... # 1. Stage or confirm presence of bag in the staging area. # 2. Validate the bag before sending. action = IngestAction( correlation_id=str(uuid4()), object_id=dpn_object_id, state=STARTED ) headers = { "correlation_id": action.correlation_id, "date": dpn_strftime(datetime.now()), "ttl": str_expire_on(datetime.now()), "sequence": 0 } body = { "replication_size": size, "protocol": settings.DPN_XFER_OPTIONS, "dpn_object_id": dpn_object_id } sequence_info = store_sequence(headers['correlation_id'], settings.DPN_NODE_NAME, headers['sequence']) validate_sequence(sequence_info) try: msg = ReplicationInitQuery(headers, body) msg.send(settings.DPN_BROADCAST_KEY) action.state = SUCCESS except Exception as err: action.state = FAILED action.note = "%s" % err logger.error(err) action.save() return action.correlation_id
def test_str_expire_on(self): exp = "2014-01-01T01:00:10Z" self.failUnlessEqual(exp, str_expire_on(self.datetime, 10))