Пример #1
0
    def create_consumer_group(self,
                              group_id,
                              display_name=None,
                              description=None,
                              consumer_ids=None,
                              notes=None):
        """
        Create a new consumer group.
        @param group_id: unique id of the consumer group
        @param display_name: display name of the consumer group
        @type  display_name: str or None
        @param description: description of the consumer group
        @type  description: str or None
        @param consumer_ids: list of ids for consumers initially belonging to the consumer group
        @type  consumer_ids: list or None
        @param notes: notes for the consumer group
        @type  notes: dict or None
        @return: SON representation of the consumer group
        @rtype:  L{bson.SON}
        """
        if group_id is None or _CONSUMER_GROUP_ID_REGEX.match(
                group_id) is None:
            raise InvalidValue(['group_id'])

        collection = ConsumerGroup.get_collection()
        consumer_group = ConsumerGroup(group_id, display_name, description,
                                       consumer_ids, notes)
        try:
            collection.insert(consumer_group, safe=True)
        except DuplicateKeyError:
            raise pulp_exceptions.DuplicateResource(
                group_id), None, sys.exc_info()[2]
        group = collection.find_one({'id': group_id})
        return group
Пример #2
0
    def create_consumer_group(group_id, display_name=None, description=None, consumer_ids=None,
                              notes=None):
        """
        Create a new consumer group.

        :param group_id:     unique id of the consumer group
        :type  group_id:     str
        :param display_name: display name of the consumer group
        :type  display_name: str or None
        :param description:  description of the consumer group
        :type  description:  str or None
        :param consumer_ids: list of ids for consumers initially belonging to the consumer group
        :type  consumer_ids: list or None
        :param notes:        notes for the consumer group
        :type  notes:        dict or None
        :return:             SON representation of the consumer group
        :rtype:              bson.SON
        """
        validation_errors = []
        if group_id is None:
            validation_errors.append(PulpCodedException(error_codes.PLP1002, field='group_id'))
        elif _CONSUMER_GROUP_ID_REGEX.match(group_id) is None:
            validation_errors.append(PulpCodedException(error_codes.PLP1003, field='group_id'))

        if consumer_ids:
            # Validate that all the consumer_ids exist and raise an exception if they don't
            consumer_collection = Consumer.get_collection()
            matched_consumers = consumer_collection.find({'id': {'$in': consumer_ids}})
            if matched_consumers.count() is not len(consumer_ids):
                # Create a set of all the matched consumer_ids
                matched_consumers_set = set()
                for consumer in matched_consumers:
                    matched_consumers_set.add(consumer.get('id'))
                # find the missing items
                for consumer_id in (set(consumer_ids)).difference(matched_consumers_set):
                    validation_errors.append(PulpCodedException(error_codes.PLP1001,
                                                                consumer_id=consumer_id))

        if validation_errors:
            raise pulp_exceptions.PulpCodedValidationException(validation_errors)

        collection = ConsumerGroup.get_collection()
        consumer_group = ConsumerGroup(group_id, display_name, description, consumer_ids, notes)
        try:
            collection.insert(consumer_group)
        except DuplicateKeyError:
            raise pulp_exceptions.DuplicateResource(group_id), None, sys.exc_info()[2]

        group = collection.find_one({'id': group_id})
        return group
Пример #3
0
 def test_constructor(self):
     try:
         ConsumerGroup('contructor_group')
     except:
         self.fail(traceback.format_exc())