def choose_and_send_location(correlation_id): """ Chooses the appropiates nodes to replicate with and sends the ContentLocationQuery to these nodes :param correlation_id: UUID of the IngestAction """ sequence = 2 # prepare headers for ReplicationLocationReply headers = _get_headers(correlation_id, sequence) file_actions = SendFileAction.objects.filter(ingest__pk=correlation_id, state=SUCCESS) if file_actions.count() >= settings.DPN_NUM_XFERS: selected_nodes = choose_nodes( list(file_actions.values_list('node', flat=True))) for action in file_actions: if action.node in selected_nodes: _validate_sequence(correlation_id, action.node, sequence) protocol = action.get_protocol_display() base_location = settings.DPN_BASE_LOCATION[protocol] bag_id = action.ingest.object_id body = { 'protocol': protocol, 'location': '{0}{1}.{2}'.format(base_location, bag_id, settings.DPN_BAGS_FILE_EXT) } rsp = ReplicationLocationReply(headers, body) rsp.send(action.reply_key) # mark action as chosen to transfer action.chosen_to_transfer = True action.location = body['location'] # mark file action as TRANSFER action.step = TRANSFER action.save()
def test_choose_node(self): node_list = [1, 2, 3, 4] for i in range(len(node_list)): with self.settings(DPN_NUM_XFERS=i): nodes_selected = choose_nodes(node_list) self.failUnlessEqual(i, len(nodes_selected))