Search in sources :

Example 1 with LeaderAndIsrTopicError

use of org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError in project kafka by apache.

the class LeaderAndIsrRequestTest method testGetErrorResponse.

@Test
public void testGetErrorResponse() {
    Uuid topicId = Uuid.randomUuid();
    String topicName = "topic";
    int partition = 0;
    for (short version : LEADER_AND_ISR.allVersions()) {
        LeaderAndIsrRequest request = new LeaderAndIsrRequest.Builder(version, 0, 0, 0, Collections.singletonList(new LeaderAndIsrPartitionState().setTopicName(topicName).setPartitionIndex(partition)), Collections.singletonMap(topicName, topicId), Collections.emptySet()).build(version);
        LeaderAndIsrResponse response = request.getErrorResponse(0, new ClusterAuthorizationException("Not authorized"));
        assertEquals(Errors.CLUSTER_AUTHORIZATION_FAILED, response.error());
        if (version < 5) {
            assertEquals(Collections.singletonList(new LeaderAndIsrPartitionError().setTopicName(topicName).setPartitionIndex(partition).setErrorCode(Errors.CLUSTER_AUTHORIZATION_FAILED.code())), response.data().partitionErrors());
            assertEquals(0, response.data().topics().size());
        } else {
            LeaderAndIsrTopicError topicState = response.topics().find(topicId);
            assertEquals(topicId, topicState.topicId());
            assertEquals(Collections.singletonList(new LeaderAndIsrPartitionError().setPartitionIndex(partition).setErrorCode(Errors.CLUSTER_AUTHORIZATION_FAILED.code())), topicState.partitionErrors());
            assertEquals(0, response.data().partitionErrors().size());
        }
    }
}
Also used : LeaderAndIsrPartitionError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError) Uuid(org.apache.kafka.common.Uuid) LeaderAndIsrTopicError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError) ClusterAuthorizationException(org.apache.kafka.common.errors.ClusterAuthorizationException) LeaderAndIsrPartitionState(org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState) Test(org.junit.jupiter.api.Test)

Example 2 with LeaderAndIsrTopicError

use of org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError in project kafka by apache.

the class LeaderAndIsrResponseTest method createTopic.

private LeaderAndIsrTopicErrorCollection createTopic(Uuid id, List<Errors> errors) {
    LeaderAndIsrTopicErrorCollection topics = new LeaderAndIsrTopicErrorCollection();
    LeaderAndIsrTopicError topic = new LeaderAndIsrTopicError();
    topic.setTopicId(id);
    List<LeaderAndIsrPartitionError> partitions = new ArrayList<>();
    int partitionIndex = 0;
    for (Errors error : errors) {
        partitions.add(new LeaderAndIsrPartitionError().setPartitionIndex(partitionIndex++).setErrorCode(error.code()));
    }
    topic.setPartitionErrors(partitions);
    topics.add(topic);
    return topics;
}
Also used : LeaderAndIsrPartitionError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError) Errors(org.apache.kafka.common.protocol.Errors) LeaderAndIsrTopicErrorCollection(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicErrorCollection) ArrayList(java.util.ArrayList) LeaderAndIsrTopicError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError)

Example 3 with LeaderAndIsrTopicError

use of org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError in project kafka by apache.

the class LeaderAndIsrRequest method getErrorResponse.

@Override
public LeaderAndIsrResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    LeaderAndIsrResponseData responseData = new LeaderAndIsrResponseData();
    Errors error = Errors.forException(e);
    responseData.setErrorCode(error.code());
    if (version() < 5) {
        List<LeaderAndIsrPartitionError> partitions = new ArrayList<>();
        for (LeaderAndIsrPartitionState partition : partitionStates()) {
            partitions.add(new LeaderAndIsrPartitionError().setTopicName(partition.topicName()).setPartitionIndex(partition.partitionIndex()).setErrorCode(error.code()));
        }
        responseData.setPartitionErrors(partitions);
    } else {
        for (LeaderAndIsrTopicState topicState : data.topicStates()) {
            List<LeaderAndIsrPartitionError> partitions = new ArrayList<>(topicState.partitionStates().size());
            for (LeaderAndIsrPartitionState partition : topicState.partitionStates()) {
                partitions.add(new LeaderAndIsrPartitionError().setPartitionIndex(partition.partitionIndex()).setErrorCode(error.code()));
            }
            responseData.topics().add(new LeaderAndIsrTopicError().setTopicId(topicState.topicId()).setPartitionErrors(partitions));
        }
    }
    return new LeaderAndIsrResponse(responseData, version());
}
Also used : LeaderAndIsrPartitionError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError) Errors(org.apache.kafka.common.protocol.Errors) LeaderAndIsrResponseData(org.apache.kafka.common.message.LeaderAndIsrResponseData) ArrayList(java.util.ArrayList) LeaderAndIsrTopicState(org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrTopicState) LeaderAndIsrTopicError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError) LeaderAndIsrPartitionState(org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState)

Aggregations

LeaderAndIsrPartitionError (org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError)3 LeaderAndIsrTopicError (org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError)3 ArrayList (java.util.ArrayList)2 LeaderAndIsrPartitionState (org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState)2 Errors (org.apache.kafka.common.protocol.Errors)2 Uuid (org.apache.kafka.common.Uuid)1 ClusterAuthorizationException (org.apache.kafka.common.errors.ClusterAuthorizationException)1 LeaderAndIsrTopicState (org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrTopicState)1 LeaderAndIsrResponseData (org.apache.kafka.common.message.LeaderAndIsrResponseData)1 LeaderAndIsrTopicErrorCollection (org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicErrorCollection)1 Test (org.junit.jupiter.api.Test)1