def add_event(self, msg_id, msg, immediate=False):
        if self.client is None:
            logger.error(
                'Could not add event {0} because there are no attached clients',
                msg_id)
            return
        output("client_specific", "Trying to add an event to a client.")
        function_name = get_command_function_from_pb(msg_id)
        output("client_specific", "Function is {}".format(function_name))

        if function_name is not None:
            client_id = try_get_client_id_of_pending_command(function_name)
            output("client_specific", "Client is {}".format(client_id))

            if client_id is not None:
                remove_earliest_command_client(function_name)
                target_client = self.get_client(client_id)
                if target_client is not None:
                    target_client.add_event(msg_id, msg, immediate)
                    output("client_specific", "Adding event to client")

                    return
        output(
            "client_specific",
            "No suitable client found, so I'm just going to send it to everybody"
        )
        self.events.append((msg_id, msg))
        if immediate:
            self.process_events()
Example #2
0
    def send_op_with_no_owner_immediate(self, op):
        global _send_index

        journal_seed = self.journal._build_journal_seed(op, None, None)
        journal_entry = self.journal._build_journal_entry(journal_seed)
        (obj_id, operation, payload_type, manager_id, obj_name) = journal_entry

        view_update = Distributor_pb2.ViewUpdate()
        entry = view_update.entries.add()
        entry.primary_channel.id.manager_id = manager_id
        entry.primary_channel.id.object_id = obj_id
        entry.operation_list.operations.append(operation)

        if gsi_handlers.distributor_handlers.archiver.enabled or gsi_handlers.distributor_handlers.sim_archiver.enabled:
            _send_index += 1

            if _send_index >= 4294967295:
                _send_index = 0

            archive_operation(obj_id, obj_name, manager_id, operation,
                              payload_type, _send_index, self.client)

        for client_distributor in self.client_distributors:
            client_distributor.client.send_message(MSG_OBJECTS_VIEW_UPDATE,
                                                   view_update)

        if _distributor_log_enabled:
            logger.error('------- SENT IMMEDIATE --------')
 def _send_view_updates_for_client(self, client, all_ops):
     global _send_index
     view_update = None
     last_obj_id = None
     last_manager_id = None
     for (obj_id, operation, manager_id, obj_name) in all_ops:
         if view_update is None:
             view_update = protocols.ViewUpdate()
         if obj_id != last_obj_id or manager_id != last_manager_id:
             if _distributor_log_enabled:
                 logger.error('    Object: {}', obj_name or obj_id)
             entry = view_update.entries.add()
             entry.primary_channel.id.manager_id = manager_id
             entry.primary_channel.id.object_id = obj_id
             last_obj_id = obj_id
             last_manager_id = manager_id
         entry.operation_list.operations.append(operation)
         while gsi_handlers.distributor_handlers.archiver.enabled:
             _send_index += 1
             if _send_index >= 4294967295:
                 _send_index = 0
             archive_operation(obj_id, obj_name, manager_id, operation, _send_index, client)
     if view_update is not None:
         client.send_message(MSG_OBJECTS_VIEW_UPDATE, view_update)
         if _distributor_log_enabled:
             logger.error('------- SENT --------')
 def add_event(self, msg_id, msg, immediate=False):
     if self.client is None:
         logger.error('Could not add event {0} because there are no attached clients', msg_id)
         return
     self.events.append((msg_id, msg))
     if immediate:
         self.process_events()
Example #5
0
 def _build_journal_entry(self, journal_seed):
     op = journal_seed.op
     object_id = journal_seed.object_id
     manager_id = journal_seed.manager_id
     object_name = journal_seed.debug_object_name
     proto_buff = protocolbuffers.DistributorOps_pb2.Operation()
     mask_override = None
     if manager_id == MGR_UNMANAGED:
         mask_override = 0
     if op._force_execution_on_tag:
         mask_override = 0
     elif op._primary_channel_mask_override is not None:
         mask_override = op._primary_channel_mask_override
     if mask_override is not None:
         if mask_override != DEFAULT_MASK:
             proto_buff.primary_channel_mask_override = mask_override
     for channel in op._additional_channels:
         with ProtocolBufferRollback(
                 proto_buff.additional_channels) as additional_channel_msg:
             additional_channel_msg.id.manager_id = channel[0]
             additional_channel_msg.id.object_id = channel[1]
             if channel[1] == object_id and mask_override is not None:
                 additional_channel_msg.mask = mask_override
             else:
                 additional_channel_msg.mask = channel[2]
     op.write(proto_buff)
     if not proto_buff.IsInitialized():
         logger.error(
             'Message generated by {} is missing required fields: ' +
             str(proto_buff.FindInitializationErrors()), op)
     payload_type = op.payload_type
     entry = Journal.JournalEntry(object_id, proto_buff, payload_type,
                                  manager_id, object_name)
     return entry
 def _debug_validate_op(self, obj, op):
     objs = getattr(obj, 'client_objects_gen', None)
     if objs:
         for sub_obj in objs:
             self._debug_validate_op(sub_obj, op)
     else:
         if obj not in self.created_objects:
             logger.error('Target of Op ({}) is not on the client. Operation type: {}. This will result in errors in client state.', obj, op)
         if not (getattr(obj, 'valid_for_distribution', True) or getattr(op, 'is_create_op', False)):
             logger.error('Operation is being added for {}, but it is not valid_for_distribution. Operation type: {}. This will result in errors in client state.', obj, op)