-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(client): support admin operations in Java client #5671
Merged
vcrfxia
merged 11 commits into
confluentinc:master
from
vcrfxia:java-client-admin-operations
Jun 24, 2020
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
37af3d4
feat: support listing streams/table from Java client (wip)
vcrfxia b67a6f0
chore: finish implementing list streams
vcrfxia 5a8e501
refactor: prep for other methods
vcrfxia e541855
test: add tests for list streams
vcrfxia bf8e886
feat: support list tables
vcrfxia d6ee218
feat: support list topics
vcrfxia 7466c72
test: add error response test for list topics
vcrfxia 33e2c67
chore: checkstyle
vcrfxia d5dbc34
docs: javadocs
vcrfxia 2456569
Merge branch 'master' into java-client-admin-operations
vcrfxia 97e17f6
chore: feedback
vcrfxia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
ksqldb-api-client/src/main/java/io/confluent/ksql/api/client/StreamInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2020 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.api.client; | ||
|
||
/** | ||
* Metadata for a ksqlDB stream. | ||
*/ | ||
public interface StreamInfo { | ||
|
||
/** | ||
* @return the name of this stream | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* @return the name of the Kafka topic underlying this ksqlDB stream | ||
*/ | ||
String getTopic(); | ||
|
||
/** | ||
* @return the format of the data in this stream | ||
*/ | ||
String getFormat(); | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
ksqldb-api-client/src/main/java/io/confluent/ksql/api/client/TableInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2020 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.api.client; | ||
|
||
/** | ||
* Metadata for a ksqlDB table. | ||
*/ | ||
public interface TableInfo { | ||
|
||
/** | ||
* @return the name of this table | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* @return the name of the Kafka topic underlying this ksqlDB table | ||
*/ | ||
String getTopic(); | ||
|
||
/** | ||
* @return the format of the data in this table | ||
*/ | ||
String getFormat(); | ||
|
||
/** | ||
* @return whether this ksqlDB table is windowed | ||
*/ | ||
boolean isWindowed(); | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
ksqldb-api-client/src/main/java/io/confluent/ksql/api/client/TopicInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2020 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.api.client; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Metadata for a Kafka topic available for use with ksqlDB. | ||
*/ | ||
public interface TopicInfo { | ||
|
||
/** | ||
* @return the name of this topic | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* @return the number of partitions for this topic | ||
*/ | ||
int getPartitions(); | ||
|
||
/** | ||
* Returns the number of replicas for each topic partition. | ||
* | ||
* @return a list with size equal to the number of partitions. Each element is the number of | ||
* replicas for the partition corresponding to the list index. | ||
*/ | ||
List<Integer> getReplicasPerPartition(); | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
ksqldb-api-client/src/main/java/io/confluent/ksql/api/client/impl/AdminResponseHandlers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright 2020 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.api.client.impl; | ||
|
||
import io.confluent.ksql.api.client.StreamInfo; | ||
import io.confluent.ksql.api.client.TableInfo; | ||
import io.confluent.ksql.api.client.TopicInfo; | ||
import io.vertx.core.json.JsonArray; | ||
import io.vertx.core.json.JsonObject; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
|
||
final class AdminResponseHandlers { | ||
|
||
private AdminResponseHandlers() { | ||
} | ||
|
||
static void handleListStreamsResponse( | ||
final JsonObject streamsListEntity, | ||
final CompletableFuture<List<StreamInfo>> cf | ||
) { | ||
try { | ||
final JsonArray streams = streamsListEntity.getJsonArray("streams"); | ||
cf.complete(streams.stream() | ||
.map(o -> (JsonObject) o) | ||
.map(o -> new StreamInfoImpl( | ||
o.getString("name"), | ||
o.getString("topic"), | ||
o.getString("format"))) | ||
.collect(Collectors.toList()) | ||
); | ||
} catch (Exception e) { | ||
cf.completeExceptionally(new IllegalStateException( | ||
"Unexpected server response format. Response: " + streamsListEntity)); | ||
} | ||
} | ||
|
||
static void handleListTablesResponse( | ||
final JsonObject tablesListEntity, | ||
final CompletableFuture<List<TableInfo>> cf | ||
) { | ||
try { | ||
final JsonArray tables = tablesListEntity.getJsonArray("tables"); | ||
cf.complete(tables.stream() | ||
.map(o -> (JsonObject) o) | ||
.map(o -> new TableInfoImpl( | ||
o.getString("name"), | ||
o.getString("topic"), | ||
o.getString("format"), | ||
o.getBoolean("isWindowed"))) | ||
.collect(Collectors.toList()) | ||
); | ||
} catch (Exception e) { | ||
cf.completeExceptionally(new IllegalStateException( | ||
"Unexpected server response format. Response: " + tablesListEntity)); | ||
} | ||
} | ||
|
||
static void handleListTopicsResponse( | ||
final JsonObject kafkaTopicsListEntity, | ||
final CompletableFuture<List<TopicInfo>> cf | ||
) { | ||
try { | ||
final JsonArray topics = kafkaTopicsListEntity.getJsonArray("topics"); | ||
cf.complete(topics.stream() | ||
.map(o -> (JsonObject) o) | ||
.map(o -> { | ||
final List<Integer> replicaInfo = o.getJsonArray("replicaInfo").stream() | ||
.map(v -> (Integer)v) | ||
.collect(Collectors.toList()); | ||
return new TopicInfoImpl( | ||
o.getString("name"), | ||
replicaInfo.size(), | ||
replicaInfo); | ||
}) | ||
.collect(Collectors.toList()) | ||
); | ||
} catch (Exception e) { | ||
cf.completeExceptionally(new IllegalStateException( | ||
"Unexpected server response format. Response: " + kafkaTopicsListEntity)); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be worth adding some documentation as to why this is different than
listStreams
andlistTopic
- maybe (if I'm understand what you're saying correctly):There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually
listStreams
andlistTables
that were different from all the rest of the methods (if you look at the other Client methods, you'll see they all have the same note aslistTopics
), since if ksqlDB is operating correctly, those shouldn't ever fail. However, it occurs to me that those requests can still fail if, e.g., ksqlDB is unavailable, or because of misconfigurations in the client, so I've added the note to those methods as well.