def run(cls, args, cluster_config):
        # Setup the Kafka client
        client = KafkaToolClient(cluster_config.broker_list)
        client.load_metadata_for_topics()

        topics_dict = cls.preprocess_args(
            args.groupid,
            args.topic,
            args.partitions,
            cluster_config,
            client,
            force=args.force,
            use_admin_client=args.use_admin_client,
        )
        try:
            advance_consumer_offsets(
                client,
                args.groupid,
                topics_dict,
            )
        except TypeError:
            print("Error: Badly formatted input, please re-run command ",
                  "with --help option.",
                  file=sys.stderr)
            raise
        except UnknownMemberIdError:
            print(
                "Unable to advance offsets for group '{group_name}' from topic '{topic_name}'. \
                    You must ensure none of the consumers with this consumer group id are running before \
                    trying to advance the offsets stored in Kafka for this consumer group. Try stopping all \
                    of your consumers.".format(group_name=args.groupid,
                                               topic_name=args.topic), )
            raise

        client.close()
Beispiel #2
0
    def run(cls, args, cluster_config):
        # Setup the Kafka client
        client = KafkaToolClient(cluster_config.broker_list)
        client.load_metadata_for_topics()

        topics_dict = cls.preprocess_args(
            args.groupid,
            args.topic,
            args.partitions,
            cluster_config,
            client,
            force=args.force,
        )
        try:
            advance_consumer_offsets(
                client,
                args.groupid,
                topics_dict,
            )
        except TypeError:
            print(
                "Error: Badly formatted input, please re-run command ",
                "with --help option.", file=sys.stderr
            )
            raise

        client.close()
Beispiel #3
0
    def run(cls, args, cluster_config):
        # Setup the Kafka client
        client = KafkaToolClient(cluster_config.broker_list)
        client.load_metadata_for_topics()

        topics_dict = cls.preprocess_args(
            args.groupid,
            args.topic,
            args.partitions,
            cluster_config,
            client,
            force=args.force,
            use_admin_client=args.use_admin_client,
        )
        try:
            advance_consumer_offsets(
                client,
                args.groupid,
                topics_dict,
            )
        except TypeError:
            print(
                "Error: Badly formatted input, please re-run command ",
                "with --help option.", file=sys.stderr
            )
            raise

        client.close()
Beispiel #4
0
 def test_advance_consumer_offsets(self, kafka_client_mock):
     topics = {
         'topic1': [0, 1, 2],
         'topic2': [0, 1],
     }
     status = advance_consumer_offsets(kafka_client_mock, "group", topics)
     assert status == []
     assert kafka_client_mock.group_offsets == self.high_offsets
Beispiel #5
0
 def test_advance_consumer_offsets(self, kafka_client_mock):
     topics = {
         'topic1': [0, 1, 2],
         'topic2': [0, 1],
     }
     status = advance_consumer_offsets(
         kafka_client_mock,
         "group",
         topics
     )
     assert status == []
     assert kafka_client_mock.group_offsets == self.high_offsets
Beispiel #6
0
    def test_advance_consumer_offsets(self, kafka_client_mock):
        topics = {
            'topic1': [0, 1, 2],
            'topic2': [0, 1],
        }
        status = advance_consumer_offsets(kafka_client_mock, "group", topics)

        expected_status = [
            OffsetCommitResponsePayload("topic1", 0, 0),
            OffsetCommitResponsePayload("topic1", 1, 0),
            OffsetCommitResponsePayload("topic1", 2, 0),
            OffsetCommitResponsePayload("topic2", 0, 0),
            OffsetCommitResponsePayload("topic2", 1, 0),
        ]

        assert set(status) == set(expected_status)
        assert kafka_client_mock.group_offsets == self.high_offsets
Beispiel #7
0
    def test_advance_consumer_offsets_fail(self, kafka_client_mock):
        kafka_client_mock.set_commit_error()
        topics = {
            'topic1': [0, 1, 2],
            'topic2': [0, 1],
        }
        expected_status = [
            OffsetCommitError("topic1", 0, RequestTimedOutError.message),
            OffsetCommitError("topic1", 1, RequestTimedOutError.message),
            OffsetCommitError("topic1", 2, RequestTimedOutError.message),
            OffsetCommitError("topic2", 0, RequestTimedOutError.message),
            OffsetCommitError("topic2", 1, RequestTimedOutError.message),
        ]

        status = advance_consumer_offsets(kafka_client_mock, "group", topics)
        assert len(status) == len(expected_status)
        for expected in expected_status:
            assert any(actual == expected for actual in status)
        assert kafka_client_mock.group_offsets == self.group_offsets
Beispiel #8
0
    def test_advance_consumer_offsets(self, kafka_client_mock):
        topics = {
            'topic1': [0, 1, 2],
            'topic2': [0, 1],
        }
        status = advance_consumer_offsets(
            kafka_client_mock,
            "group",
            topics
        )

        expected_status = [
            OffsetCommitResponsePayload("topic1", 0, 0),
            OffsetCommitResponsePayload("topic1", 1, 0),
            OffsetCommitResponsePayload("topic1", 2, 0),
            OffsetCommitResponsePayload("topic2", 0, 0),
            OffsetCommitResponsePayload("topic2", 1, 0),
        ]

        assert set(status) == set(expected_status)
        assert kafka_client_mock.group_offsets == self.high_offsets
Beispiel #9
0
    def test_advance_consumer_offsets_fail(self, kafka_client_mock):
        kafka_client_mock.set_commit_error()
        topics = {
            'topic1': [0, 1, 2],
            'topic2': [0, 1],
        }
        expected_status = [
            OffsetCommitError("topic1", 0, RequestTimedOutError.message),
            OffsetCommitError("topic1", 1, RequestTimedOutError.message),
            OffsetCommitError("topic1", 2, RequestTimedOutError.message),
            OffsetCommitError("topic2", 0, RequestTimedOutError.message),
            OffsetCommitError("topic2", 1, RequestTimedOutError.message),
        ]

        status = advance_consumer_offsets(
            kafka_client_mock,
            "group",
            topics
        )
        assert len(status) == len(expected_status)
        for expected in expected_status:
            assert any(actual == expected for actual in status)
        assert kafka_client_mock.group_offsets == self.group_offsets