@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { Map<String, ApiError> topicErrors = new HashMap<>(); for (String topic : newPartitions.keySet()) { topicErrors.put(topic, ApiError.fromThrowable(e)); } short versionId = version(); switch (versionId) { case 0: case 1: return new CreatePartitionsResponse(throttleTimeMs, topicErrors); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.CREATE_PARTITIONS.latestVersion())); } }
@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { short version = version(); switch (version) { case 0: case 1: ApiError error = ApiError.fromThrowable(e); Map<ConfigResource, ApiError> errors = new HashMap<>(configs.size()); for (ConfigResource resource : configs.keySet()) errors.put(resource, error); return new AlterConfigsResponse(throttleTimeMs, errors); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", version, this.getClass().getSimpleName(), ApiKeys.ALTER_CONFIGS.latestVersion())); } }
@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable throwable) { short versionId = version(); switch (versionId) { case 0: case 1: return new DescribeAclsResponse(throttleTimeMs, ApiError.fromThrowable(throwable), Collections.emptySet()); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.DESCRIBE_ACLS.latestVersion())); } }
@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable throwable) { short versionId = version(); switch (versionId) { case 0: case 1: List<CreateAclsResponse.AclCreationResponse> responses = new ArrayList<>(); for (int i = 0; i < aclCreations.size(); i++) responses.add(new CreateAclsResponse.AclCreationResponse(ApiError.fromThrowable(throwable))); return new CreateAclsResponse(throttleTimeMs, responses); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.CREATE_ACLS.latestVersion())); } }
@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable throwable) { short versionId = version(); switch (versionId) { case 0: case 1: List<DeleteAclsResponse.AclFilterResponse> responses = new ArrayList<>(); for (int i = 0; i < filters.size(); i++) { responses.add(new DeleteAclsResponse.AclFilterResponse( ApiError.fromThrowable(throwable), Collections.emptySet())); } return new DeleteAclsResponse(throttleTimeMs, responses); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.DELETE_ACLS.latestVersion())); } }
@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { Map<String, ApiError> topicErrors = new HashMap<>(); for (String topic : topics.keySet()) { topicErrors.put(topic, ApiError.fromThrowable(e)); } short versionId = version(); switch (versionId) { case 0: case 1: return new CreateTopicsResponse(topicErrors); case 2: case 3: return new CreateTopicsResponse(throttleTimeMs, topicErrors); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.CREATE_TOPICS.latestVersion())); } }
@Override public DescribeConfigsResponse getErrorResponse(int throttleTimeMs, Throwable e) { short version = version(); switch (version) { case 0: case 1: case 2: ApiError error = ApiError.fromThrowable(e); Map<ConfigResource, DescribeConfigsResponse.Config> errors = new HashMap<>(resources().size()); DescribeConfigsResponse.Config config = new DescribeConfigsResponse.Config(error, Collections.emptyList()); for (ConfigResource resource : resources()) errors.put(resource, config); return new DescribeConfigsResponse(throttleTimeMs, errors); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", version, this.getClass().getSimpleName(), ApiKeys.DESCRIBE_CONFIGS.latestVersion())); } }
synchronized void addError(Throwable throwable, Node node) { ApiError error = ApiError.fromThrowable(throwable); if (error.message() == null || error.message().isEmpty()) { errors.add(error.error().exception("Error listing groups on " + node)); } else { errors.add(error.error().exception("Error listing groups on " + node + ": " + error.message())); } }
private CreatePartitionsResponse createCreatePartitionsResponse() { Map<String, ApiError> results = new HashMap<>(); results.put("my_topic", ApiError.fromThrowable( new InvalidReplicaAssignmentException("The assigned brokers included an unknown broker"))); results.put("my_topic", ApiError.NONE); return new CreatePartitionsResponse(42, results); }
@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { ElectPreferredLeadersResponseData response = new ElectPreferredLeadersResponseData(); response.setThrottleTimeMs(throttleTimeMs); ApiError apiError = ApiError.fromThrowable(e); for (TopicPartitions topic : data.topicPartitions()) { ReplicaElectionResult electionResult = new ReplicaElectionResult().setTopic(topic.topic()); for (Integer partitionId : topic.partitionId()) { electionResult.partitionResult().add(new ElectPreferredLeadersResponseData.PartitionResult() .setPartitionId(partitionId) .setErrorCode(apiError.error().code()) .setErrorMessage(apiError.message())); } response.replicaElectionResults().add(electionResult); } return new ElectPreferredLeadersResponse(response); }
@Test public void testCreatePartitions() throws Exception { try (AdminClientUnitTestEnv env = mockClientEnv()) { env.kafkaClient().setNodeApiVersions(NodeApiVersions.create()); Map<String, ApiError> m = new HashMap<>(); m.put("my_topic", ApiError.NONE); m.put("other_topic", ApiError.fromThrowable(new InvalidTopicException("some detailed reason"))); // Test a call where one filter has an error. env.kafkaClient().prepareResponse(new CreatePartitionsResponse(0, m)); Map<String, NewPartitions> counts = new HashMap<>(); counts.put("my_topic", NewPartitions.increaseTo(3)); counts.put("other_topic", NewPartitions.increaseTo(3, asList(asList(2), asList(3)))); CreatePartitionsResult results = env.adminClient().createPartitions(counts); Map<String, KafkaFuture<Void>> values = results.values(); KafkaFuture<Void> myTopicResult = values.get("my_topic"); myTopicResult.get(); KafkaFuture<Void> otherTopicResult = values.get("other_topic"); try { otherTopicResult.get(); fail("get() should throw ExecutionException"); } catch (ExecutionException e0) { assertTrue(e0.getCause() instanceof InvalidTopicException); InvalidTopicException e = (InvalidTopicException) e0.getCause(); assertEquals("some detailed reason", e.getMessage()); } } }
ApiError value = ApiError.fromThrowable(new ClusterAuthorizationException(null)); ElectPreferredLeadersResponseData responseData = new ElectPreferredLeadersResponseData(); ReplicaElectionResult r = new ReplicaElectionResult().setTopic(topic1.topic());