Search in sources :

Example 1 with ELECTION_NOT_NEEDED

use of org.apache.kafka.common.protocol.Errors.ELECTION_NOT_NEEDED in project kafka by apache.

the class ReplicationControlManagerTest method buildElectLeadersResponse.

private ElectLeadersResponseData buildElectLeadersResponse(Errors topLevelError, boolean electAllPartitions, Map<TopicPartition, ApiError> errors) {
    Map<String, List<Map.Entry<TopicPartition, ApiError>>> errorsByTopic = errors.entrySet().stream().collect(Collectors.groupingBy(entry -> entry.getKey().topic()));
    ElectLeadersResponseData response = new ElectLeadersResponseData().setErrorCode(topLevelError.code());
    errorsByTopic.forEach((topic, partitionErrors) -> {
        ReplicaElectionResult electionResult = new ReplicaElectionResult().setTopic(topic);
        electionResult.setPartitionResult(partitionErrors.stream().filter(entry -> !electAllPartitions || entry.getValue().error() != ELECTION_NOT_NEEDED).map(entry -> {
            TopicPartition topicPartition = entry.getKey();
            ApiError error = entry.getValue();
            return new PartitionResult().setPartitionId(topicPartition.partition()).setErrorCode(error.error().code()).setErrorMessage(error.message());
        }).collect(Collectors.toList()));
        response.replicaElectionResults().add(electionResult);
    });
    return response;
}
Also used : MockTime(org.apache.kafka.common.utils.MockTime) TopicPartitionsCollection(org.apache.kafka.common.message.ElectLeadersRequestData.TopicPartitionsCollection) ListPartitionReassignmentsTopics(org.apache.kafka.common.message.ListPartitionReassignmentsRequestData.ListPartitionReassignmentsTopics) ElectLeadersRequestData(org.apache.kafka.common.message.ElectLeadersRequestData) Collections.singletonList(java.util.Collections.singletonList) StaleBrokerEpochException(org.apache.kafka.common.errors.StaleBrokerEpochException) CreatePartitionsTopic(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopic) PartitionResult(org.apache.kafka.common.message.ElectLeadersResponseData.PartitionResult) Arrays.asList(java.util.Arrays.asList) LogContext(org.apache.kafka.common.utils.LogContext) Map(java.util.Map) TopicData(org.apache.kafka.common.message.AlterIsrRequestData.TopicData) AlterIsrResponseData(org.apache.kafka.common.message.AlterIsrResponseData) Set(java.util.Set) SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) NO_LEADER(org.apache.kafka.metadata.LeaderConstants.NO_LEADER) UNKNOWN_TOPIC_ID(org.apache.kafka.common.protocol.Errors.UNKNOWN_TOPIC_ID) PartitionChangeRecord(org.apache.kafka.common.metadata.PartitionChangeRecord) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Errors(org.apache.kafka.common.protocol.Errors) CreatableTopicResult(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) NO_REASSIGNMENT_IN_PROGRESS(org.apache.kafka.common.protocol.Errors.NO_REASSIGNMENT_IN_PROGRESS) BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration) ArrayList(java.util.ArrayList) FENCED_LEADER_EPOCH(org.apache.kafka.common.protocol.Errors.FENCED_LEADER_EPOCH) ElectionType(org.apache.kafka.common.ElectionType) NONE(org.apache.kafka.common.protocol.Errors.NONE) BrokerHeartbeatReply(org.apache.kafka.metadata.BrokerHeartbeatReply) ELECTION_NOT_NEEDED(org.apache.kafka.common.protocol.Errors.ELECTION_NOT_NEEDED) AlterPartitionReassignmentsRequestData(org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ValueSource(org.junit.jupiter.params.provider.ValueSource) CreatableReplicaAssignment(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableReplicaAssignment) ElectLeadersResponseData(org.apache.kafka.common.message.ElectLeadersResponseData) ReassignablePartition(org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData.ReassignablePartition) BrokerHeartbeatRequestData(org.apache.kafka.common.message.BrokerHeartbeatRequestData) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) AtomicLong(java.util.concurrent.atomic.AtomicLong) SEGMENT_BYTES_CONFIG(org.apache.kafka.common.config.TopicConfig.SEGMENT_BYTES_CONFIG) CreatableTopicCollection(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopicCollection) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) CreateTopicsRequestData(org.apache.kafka.common.message.CreateTopicsRequestData) RecordTestUtils(org.apache.kafka.metadata.RecordTestUtils) ReassignableTopic(org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData.ReassignableTopic) PartitionRecord(org.apache.kafka.common.metadata.PartitionRecord) PartitionData(org.apache.kafka.common.message.AlterIsrRequestData.PartitionData) CreatePartitionsAssignment(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsAssignment) POLICY_VIOLATION(org.apache.kafka.common.protocol.Errors.POLICY_VIOLATION) ConfigRecord(org.apache.kafka.common.metadata.ConfigRecord) LoggerFactory(org.slf4j.LoggerFactory) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) CreatePartitionsTopicResult(org.apache.kafka.common.message.CreatePartitionsResponseData.CreatePartitionsTopicResult) SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) ELIGIBLE_LEADERS_NOT_AVAILABLE(org.apache.kafka.common.protocol.Errors.ELIGIBLE_LEADERS_NOT_AVAILABLE) ReassignableTopicResponse(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignableTopicResponse) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ReplicaElectionResult(org.apache.kafka.common.message.ElectLeadersResponseData.ReplicaElectionResult) TopicRecord(org.apache.kafka.common.metadata.TopicRecord) TopicPartition(org.apache.kafka.common.TopicPartition) TopicPartitions(org.apache.kafka.common.message.ElectLeadersRequestData.TopicPartitions) INVALID_PARTITIONS(org.apache.kafka.common.protocol.Errors.INVALID_PARTITIONS) PartitionRegistration(org.apache.kafka.metadata.PartitionRegistration) Collectors(java.util.stream.Collectors) Replicas(org.apache.kafka.metadata.Replicas) Test(org.junit.jupiter.api.Test) List(java.util.List) TopicIdPartition(org.apache.kafka.controller.BrokersToIsrs.TopicIdPartition) Optional(java.util.Optional) CreateTopicsResponseData(org.apache.kafka.common.message.CreateTopicsResponseData) INVALID_TOPIC_EXCEPTION(org.apache.kafka.common.protocol.Errors.INVALID_TOPIC_EXCEPTION) Uuid(org.apache.kafka.common.Uuid) IntStream(java.util.stream.IntStream) ReassignablePartitionResponse(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData.ReassignablePartitionResponse) ListPartitionReassignmentsResponseData(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData) HashMap(java.util.HashMap) CreatableTopic(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic) OptionalInt(java.util.OptionalInt) ApiError(org.apache.kafka.common.requests.ApiError) HashSet(java.util.HashSet) ConfigResource(org.apache.kafka.common.config.ConfigResource) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) PolicyViolationException(org.apache.kafka.common.errors.PolicyViolationException) OngoingPartitionReassignment(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData.OngoingPartitionReassignment) OngoingTopicReassignment(org.apache.kafka.common.message.ListPartitionReassignmentsResponseData.OngoingTopicReassignment) Collections.singletonMap(java.util.Collections.singletonMap) UNKNOWN_TOPIC_OR_PARTITION(org.apache.kafka.common.protocol.Errors.UNKNOWN_TOPIC_OR_PARTITION) Utils(org.apache.kafka.common.utils.Utils) Logger(org.slf4j.Logger) InvalidReplicaAssignmentException(org.apache.kafka.common.errors.InvalidReplicaAssignmentException) PREFERRED_LEADER_NOT_AVAILABLE(org.apache.kafka.common.protocol.Errors.PREFERRED_LEADER_NOT_AVAILABLE) INVALID_REPLICA_ASSIGNMENT(org.apache.kafka.common.protocol.Errors.INVALID_REPLICA_ASSIGNMENT) TimeUnit(java.util.concurrent.TimeUnit) AlterPartitionReassignmentsResponseData(org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData) CreateTopicPolicy(org.apache.kafka.server.policy.CreateTopicPolicy) AlterIsrRequestData(org.apache.kafka.common.message.AlterIsrRequestData) RegisterBrokerRecord(org.apache.kafka.common.metadata.RegisterBrokerRecord) Timeout(org.junit.jupiter.api.Timeout) Collections(java.util.Collections) TopicPartition(org.apache.kafka.common.TopicPartition) ElectLeadersResponseData(org.apache.kafka.common.message.ElectLeadersResponseData) ReplicaElectionResult(org.apache.kafka.common.message.ElectLeadersResponseData.ReplicaElectionResult) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) List(java.util.List) ApiError(org.apache.kafka.common.requests.ApiError) PartitionResult(org.apache.kafka.common.message.ElectLeadersResponseData.PartitionResult) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap)

Aggregations

ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1 Set (java.util.Set)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 ElectionType (org.apache.kafka.common.ElectionType)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 Uuid (org.apache.kafka.common.Uuid)1 ConfigResource (org.apache.kafka.common.config.ConfigResource)1