Beispiel #1
0
 def test_store_sequence(self):
     id = "some uuid correlation id"
     node = "test node"
     sequence_num = 1
     
     # We test when tere is no sequence in the database
     sequence = store_sequence(self.id, self.node, sequence_num)
     self._test_sequence(str(sequence_num), sequence)
     
     # We test when there is a sequence in the database
     sequence_num = 2
     sequence = store_sequence(self.id, self.node, sequence_num)
     sequence_num = "1,2"
     self._test_sequence(sequence_num, sequence)
Beispiel #2
0
def _validate_sequence(correlation_id, node_from, sequence):
    sequence_info = store_sequence(
        correlation_id,
        node_from,
        sequence
    )
    validate_sequence(sequence_info)
Beispiel #3
0
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