use of org.apache.kafka.common.protocol.Errors 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);
}
use of org.apache.kafka.common.protocol.Errors in project kafka by apache.
the class DescribeQuorumRequest method getPartitionLevelErrorResponse.
public static DescribeQuorumResponseData getPartitionLevelErrorResponse(DescribeQuorumRequestData data, Errors error) {
short errorCode = error.code();
List<DescribeQuorumResponseData.TopicData> topicResponses = new ArrayList<>();
for (DescribeQuorumRequestData.TopicData topic : data.topics()) {
topicResponses.add(new DescribeQuorumResponseData.TopicData().setTopicName(topic.topicName()).setPartitions(topic.partitions().stream().map(requestPartition -> new DescribeQuorumResponseData.PartitionData().setPartitionIndex(requestPartition.partitionIndex()).setErrorCode(errorCode)).collect(Collectors.toList())));
}
return new DescribeQuorumResponseData().setTopics(topicResponses);
}
use of org.apache.kafka.common.protocol.Errors in project kafka by apache.
the class AlterClientQuotasRequest method getErrorResponse.
@Override
public AlterClientQuotasResponse getErrorResponse(int throttleTimeMs, Throwable e) {
Errors error = Errors.forException(e);
List<AlterClientQuotasResponseData.EntryData> responseEntries = new ArrayList<>();
for (EntryData entryData : data.entries()) {
List<AlterClientQuotasResponseData.EntityData> responseEntities = new ArrayList<>();
for (EntityData entityData : entryData.entity()) {
responseEntities.add(new AlterClientQuotasResponseData.EntityData().setEntityType(entityData.entityType()).setEntityName(entityData.entityName()));
}
responseEntries.add(new AlterClientQuotasResponseData.EntryData().setEntity(responseEntities).setErrorCode(error.code()).setErrorMessage(error.message()));
}
AlterClientQuotasResponseData responseData = new AlterClientQuotasResponseData().setThrottleTimeMs(throttleTimeMs).setEntries(responseEntries);
return new AlterClientQuotasResponse(responseData);
}
use of org.apache.kafka.common.protocol.Errors in project kafka by apache.
the class KafkaAdminClientTest method testDescribeLogDirsOfflineDir.
@Test
public void testDescribeLogDirsOfflineDir() throws ExecutionException, InterruptedException {
Set<Integer> brokers = singleton(0);
String logDir = "/var/data/kafka";
Errors error = Errors.KAFKA_STORAGE_ERROR;
try (AdminClientUnitTestEnv env = mockClientEnv()) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
env.kafkaClient().prepareResponseFrom(prepareDescribeLogDirsResponse(error, logDir, emptyList()), env.cluster().nodeById(0));
DescribeLogDirsResult result = env.adminClient().describeLogDirs(brokers);
Map<Integer, KafkaFuture<Map<String, LogDirDescription>>> descriptions = result.descriptions();
assertEquals(brokers, descriptions.keySet());
assertNotNull(descriptions.get(0));
Map<String, LogDirDescription> descriptionsMap = descriptions.get(0).get();
assertEquals(singleton(logDir), descriptionsMap.keySet());
assertEquals(error.exception().getClass(), descriptionsMap.get(logDir).error().getClass());
assertEquals(emptySet(), descriptionsMap.get(logDir).replicaInfos().keySet());
Map<Integer, Map<String, LogDirDescription>> allDescriptions = result.allDescriptions().get();
assertEquals(brokers, allDescriptions.keySet());
Map<String, LogDirDescription> allMap = allDescriptions.get(0);
assertNotNull(allMap);
assertEquals(singleton(logDir), allMap.keySet());
assertEquals(error.exception().getClass(), allMap.get(logDir).error().getClass());
assertEquals(emptySet(), allMap.get(logDir).replicaInfos().keySet());
}
}
use of org.apache.kafka.common.protocol.Errors in project kafka by apache.
the class KafkaAdminClientTest method testAlterConsumerGroupOffsetsNonRetriableErrors.
@Test
public void testAlterConsumerGroupOffsetsNonRetriableErrors() throws Exception {
// Non-retriable errors throw an exception
final TopicPartition tp1 = new TopicPartition("foo", 0);
final List<Errors> nonRetriableErrors = Arrays.asList(Errors.GROUP_AUTHORIZATION_FAILED, Errors.INVALID_GROUP_ID, Errors.GROUP_ID_NOT_FOUND);
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(mockCluster(1, 0))) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
for (Errors error : nonRetriableErrors) {
env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
env.kafkaClient().prepareResponse(prepareOffsetCommitResponse(tp1, error));
Map<TopicPartition, OffsetAndMetadata> offsets = new HashMap<>();
offsets.put(tp1, new OffsetAndMetadata(123L));
AlterConsumerGroupOffsetsResult errorResult = env.adminClient().alterConsumerGroupOffsets(GROUP_ID, offsets);
TestUtils.assertFutureError(errorResult.all(), error.exception().getClass());
TestUtils.assertFutureError(errorResult.partitionResult(tp1), error.exception().getClass());
}
}
}
Aggregations