Ejemplo n.º 1
0
    def _find_conflicts(self, resources):
        """
        Find conflicting tasks, if any, and provide the following:
        * a task response, (accepted, postponed, rejected)
        * a (possibly empty) set of blocking call request ids
        * a list of blocking "reasons" in the form of TaskResource instances
        * a list of task resources corresponding to the given resources

        @param resources: dictionary of resources and their proposed operations
        @type  resources: dict
        @return: tuple of objects described above
        @rtype:  tuple
        """
        if not resources:
            return dispatch_constants.CALL_ACCEPTED_RESPONSE, set(), [], []

        postponing_call_requests = set()
        postponing_reasons = []
        rejecting_call_requests = set()
        rejecting_reasons = []

        call_resource_collection = CallResource.get_collection()
        call_resources = resource_dict_to_call_resources(resources)
        or_query = filter_dicts(call_resources, ('resource_type', 'resource_id'))
        cursor = call_resource_collection.find({'$or': or_query})

        for call_resource in cursor:
            proposed_operation = resources[call_resource['resource_type']][call_resource['resource_id']]
            queued_operation = call_resource['operation']

            postponing_operations = get_postponing_operations(proposed_operation)

            if queued_operation in postponing_operations:
                postponing_call_requests.add(call_resource['call_request_id'])
                reason = filter_dicts([call_resource], ('resource_type', 'resource_id'))[0]
                reason['operation'] = queued_operation

                if reason not in postponing_reasons:
                    postponing_reasons.append(reason)

            rejecting_operations = get_rejecting_operations(proposed_operation)

            if queued_operation in rejecting_operations:
                rejecting_call_requests.add(call_resource['call_request_id'])
                reason = filter_dicts([call_resource], ('resource_type', 'resource_id'))[0]
                reason['operation'] = queued_operation

                if reason not in rejecting_reasons:
                    rejecting_reasons.append(reason)

        if rejecting_call_requests:
            return dispatch_constants.CALL_REJECTED_RESPONSE, rejecting_call_requests, rejecting_reasons, call_resources

        if postponing_call_requests:
            return dispatch_constants.CALL_POSTPONED_RESPONSE, postponing_call_requests, postponing_reasons, call_resources

        return dispatch_constants.CALL_ACCEPTED_RESPONSE, set(), [], call_resources
Ejemplo n.º 2
0
def coordinator_dequeue_callback(call_request, call_report):
    """
    Callback to be executed upon call completion that will clean up the
    coordinator's accounting data pertaining to the call.
    @param call_request: call request for the call
    @type  call_request: L{call.CallRequest} instance
    @param call_report: call report for the call
    @type  call_report: L{call.CallReport} instance
    """
    collection = CallResource.get_collection()
    collection.remove({'call_request_id': call_request.id}, safe=True)
Ejemplo n.º 3
0
def coordinator_dequeue_callback(call_request, call_report):
    """
    Callback to be executed upon call completion that will clean up the
    coordinator's accounting data pertaining to the call.
    @param call_request: call request for the call
    @type  call_request: L{call.CallRequest} instance
    @param call_report: call report for the call
    @type  call_report: L{call.CallReport} instance
    """
    collection = CallResource.get_collection()
    collection.remove({'call_request_id': call_request.id}, safe=True)
Ejemplo n.º 4
0
 def setUp(self):
     super(CoordinatorTests, self).setUp()
     self.coordinator = coordinator.Coordinator()
     self._task_queue_factory = dispatch_factory._task_queue
     dispatch_factory._task_queue = mock.Mock() # replace the task queue
     self.collection = CallResource.get_collection()
Ejemplo n.º 5
0
 def setUp(self):
     super(CoordinatorTests, self).setUp()
     self.coordinator = coordinator.Coordinator()
     self._task_queue_factory = dispatch_factory._task_queue
     dispatch_factory._task_queue = mock.Mock()  # replace the task queue
     self.collection = CallResource.get_collection()
Ejemplo n.º 6
0
    def __init__(self, task_state_poll_interval=0.5):

        self.task_state_poll_interval = task_state_poll_interval
        self.call_resource_collection = CallResource.get_collection()
Ejemplo n.º 7
0
    def __init__(self, task_state_poll_interval=0.5):

        self.task_state_poll_interval = task_state_poll_interval
        self.call_resource_collection = CallResource.get_collection()
Ejemplo n.º 8
0
    def _find_conflicts(self, resources):
        """
        Find conflicting tasks, if any, and provide the following:
        * a task response, (accepted, postponed, rejected)
        * a (possibly empty) set of blocking call request ids
        * a list of blocking "reasons" in the form of TaskResource instances
        * a list of task resources corresponding to the given resources

        @param resources: dictionary of resources and their proposed operations
        @type  resources: dict
        @return: tuple of objects described above
        @rtype:  tuple
        """
        if not resources:
            return dispatch_constants.CALL_ACCEPTED_RESPONSE, set(), [], []

        postponing_call_requests = set()
        postponing_reasons = []
        rejecting_call_requests = set()
        rejecting_reasons = []

        call_resource_collection = CallResource.get_collection()
        call_resources = resource_dict_to_call_resources(resources)
        or_query = filter_dicts(call_resources,
                                ('resource_type', 'resource_id'))
        cursor = call_resource_collection.find({'$or': or_query})

        for call_resource in cursor:
            proposed_operation = resources[call_resource['resource_type']][
                call_resource['resource_id']]
            queued_operation = call_resource['operation']

            postponing_operations = get_postponing_operations(
                proposed_operation)

            if queued_operation in postponing_operations:
                postponing_call_requests.add(call_resource['call_request_id'])
                reason = filter_dicts([call_resource],
                                      ('resource_type', 'resource_id'))[0]
                reason['operation'] = queued_operation

                if reason not in postponing_reasons:
                    postponing_reasons.append(reason)

            rejecting_operations = get_rejecting_operations(proposed_operation)

            if queued_operation in rejecting_operations:
                rejecting_call_requests.add(call_resource['call_request_id'])
                reason = filter_dicts([call_resource],
                                      ('resource_type', 'resource_id'))[0]
                reason['operation'] = queued_operation

                if reason not in rejecting_reasons:
                    rejecting_reasons.append(reason)

        if rejecting_call_requests:
            return dispatch_constants.CALL_REJECTED_RESPONSE, rejecting_call_requests, rejecting_reasons, call_resources

        if postponing_call_requests:
            return dispatch_constants.CALL_POSTPONED_RESPONSE, postponing_call_requests, postponing_reasons, call_resources

        return dispatch_constants.CALL_ACCEPTED_RESPONSE, set(
        ), [], call_resources