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 handle(self, *args, **options): msg = ReplicationInitQuery() headers = { 'correlation_id': uuid(), 'sequence': 0, 'date': dpn_strftime(datetime.now()) } msg.set_headers(**headers) body = { 'message_name': 'replication-init-query', 'replication_size': 4502, 'protocol': ['https', 'rsync'], 'dpn_object_id': uuid() } msg.set_body(**body) msg.send(DPN_BROADCAST_KEY)