Search in sources :

Example 1 with PartitionResponse

use of org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse in project kafka by apache.

the class DescribeProducersRequest method getErrorResponse.

@Override
public DescribeProducersResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    Errors error = Errors.forException(e);
    DescribeProducersResponseData response = new DescribeProducersResponseData();
    for (TopicRequest topicRequest : data.topics()) {
        TopicResponse topicResponse = new TopicResponse().setName(topicRequest.name());
        for (int partitionId : topicRequest.partitionIndexes()) {
            topicResponse.partitions().add(new PartitionResponse().setPartitionIndex(partitionId).setErrorCode(error.code()));
        }
        response.topics().add(topicResponse);
    }
    return new DescribeProducersResponse(response);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) PartitionResponse(org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse) TopicRequest(org.apache.kafka.common.message.DescribeProducersRequestData.TopicRequest) TopicResponse(org.apache.kafka.common.message.DescribeProducersResponseData.TopicResponse) DescribeProducersResponseData(org.apache.kafka.common.message.DescribeProducersResponseData)

Example 2 with PartitionResponse

use of org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse in project kafka by apache.

the class DescribeProducersHandlerTest method testCompletedResult.

@Test
public void testCompletedResult() {
    TopicPartition topicPartition = new TopicPartition("foo", 5);
    DescribeProducersOptions options = new DescribeProducersOptions().brokerId(1);
    DescribeProducersHandler handler = newHandler(options);
    PartitionResponse partitionResponse = sampleProducerState(topicPartition);
    DescribeProducersResponse response = describeProducersResponse(singletonMap(topicPartition, partitionResponse));
    Node node = new Node(3, "host", 1);
    ApiResult<TopicPartition, PartitionProducerState> result = handler.handleResponse(node, mkSet(topicPartition), response);
    assertEquals(mkSet(topicPartition), result.completedKeys.keySet());
    assertEquals(emptyMap(), result.failedKeys);
    assertEquals(emptyList(), result.unmappedKeys);
    PartitionProducerState producerState = result.completedKeys.get(topicPartition);
    assertMatchingProducers(partitionResponse, producerState);
}
Also used : PartitionResponse(org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse) TopicPartition(org.apache.kafka.common.TopicPartition) Node(org.apache.kafka.common.Node) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState) DescribeProducersOptions(org.apache.kafka.clients.admin.DescribeProducersOptions) DescribeProducersResponse(org.apache.kafka.common.requests.DescribeProducersResponse) Test(org.junit.jupiter.api.Test)

Example 3 with PartitionResponse

use of org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse in project kafka by apache.

the class DescribeProducersHandlerTest method describeProducersResponse.

private DescribeProducersResponse describeProducersResponse(Map<TopicPartition, PartitionResponse> partitionResponses) {
    DescribeProducersResponseData response = new DescribeProducersResponseData();
    Map<String, Map<Integer, PartitionResponse>> partitionResponsesByTopic = CollectionUtils.groupPartitionDataByTopic(partitionResponses);
    for (Map.Entry<String, Map<Integer, PartitionResponse>> topicEntry : partitionResponsesByTopic.entrySet()) {
        String topic = topicEntry.getKey();
        Map<Integer, PartitionResponse> topicPartitionResponses = topicEntry.getValue();
        TopicResponse topicResponse = new TopicResponse().setName(topic);
        response.topics().add(topicResponse);
        for (Map.Entry<Integer, PartitionResponse> partitionEntry : topicPartitionResponses.entrySet()) {
            Integer partitionId = partitionEntry.getKey();
            PartitionResponse partitionResponse = partitionEntry.getValue();
            topicResponse.partitions().add(partitionResponse.setPartitionIndex(partitionId));
        }
    }
    return new DescribeProducersResponse(response);
}
Also used : PartitionResponse(org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse) TopicResponse(org.apache.kafka.common.message.DescribeProducersResponseData.TopicResponse) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) DescribeProducersResponseData(org.apache.kafka.common.message.DescribeProducersResponseData) DescribeProducersResponse(org.apache.kafka.common.requests.DescribeProducersResponse)

Example 4 with PartitionResponse

use of org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse in project kafka by apache.

the class DescribeProducersHandlerTest method sampleProducerState.

private PartitionResponse sampleProducerState(TopicPartition topicPartition) {
    PartitionResponse partitionResponse = new PartitionResponse().setPartitionIndex(topicPartition.partition()).setErrorCode(Errors.NONE.code());
    partitionResponse.setActiveProducers(asList(new ProducerState().setProducerId(12345L).setProducerEpoch(15).setLastSequence(75).setLastTimestamp(System.currentTimeMillis()).setCurrentTxnStartOffset(-1L), new ProducerState().setProducerId(98765L).setProducerEpoch(30).setLastSequence(150).setLastTimestamp(System.currentTimeMillis() - 5000).setCurrentTxnStartOffset(5000)));
    return partitionResponse;
}
Also used : PartitionResponse(org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse) ProducerState(org.apache.kafka.common.message.DescribeProducersResponseData.ProducerState) PartitionProducerState(org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState)

Aggregations

PartitionResponse (org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse)4 PartitionProducerState (org.apache.kafka.clients.admin.DescribeProducersResult.PartitionProducerState)2 DescribeProducersResponseData (org.apache.kafka.common.message.DescribeProducersResponseData)2 TopicResponse (org.apache.kafka.common.message.DescribeProducersResponseData.TopicResponse)2 DescribeProducersResponse (org.apache.kafka.common.requests.DescribeProducersResponse)2 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonMap (java.util.Collections.singletonMap)1 Map (java.util.Map)1 DescribeProducersOptions (org.apache.kafka.clients.admin.DescribeProducersOptions)1 Node (org.apache.kafka.common.Node)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 TopicRequest (org.apache.kafka.common.message.DescribeProducersRequestData.TopicRequest)1 ProducerState (org.apache.kafka.common.message.DescribeProducersResponseData.ProducerState)1 Errors (org.apache.kafka.common.protocol.Errors)1 Test (org.junit.jupiter.api.Test)1