Skip to content
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
merged 11 commits into from
Jun 24, 2020

Conversation

vcrfxia
Copy link
Contributor

@vcrfxia vcrfxia commented Jun 23, 2020

Description

Fixes #4286

Adds support for listing streams, tables, and topics to the Java client.

Docs will come in a follow-up PR. Javadocs on the new methods and interfaces are included in this one.

Testing done

Added unit and integration tests.

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@vcrfxia vcrfxia requested a review from a team as a code owner June 23, 2020 22:49
@vcrfxia vcrfxia requested a review from purplefox June 23, 2020 22:50
Copy link
Contributor

@agavra agavra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment on lines +113 to +114
* <p>If a non-200 response is received from the server, the {@code CompletableFuture} will be
* failed.
Copy link
Contributor

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 and listTopic - maybe (if I'm understand what you're saying correctly):

Suggested change
* <p>If a non-200 response is received from the server, the {@code CompletableFuture} will be
* failed.
* <p>If the ksqlDb server receives a non-200 response is received from the kafka broker, the {@code CompletableFuture} will be
* failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually listStreams and listTables 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 as listTopics), 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.

Comment on lines 24 to 26
* Returns the name of this stream.
*
* @return stream name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, my personal preference is just to have @return the name of this stream as one line if it's a simple getter

final CompletableFuture<List<StreamInfo>> cf = new CompletableFuture<>();

makeRequest(
"/ksql",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might want to add some constants for the endpoints

import io.confluent.ksql.api.client.StreamInfo;
import java.util.Objects;

public class StreamInfoImpl implements StreamInfo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally worth having equals/hashcode/tostring on externally exposed classes so that people can leverage them if they want to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure I understand correctly: you're suggesting we add equals/hashcode/tostring methods to each of the implementation classes, not the interfaces, right? This makes sense to me, though I'm not sure whether it makes more sense for the toString method to say StreamInfoImpl{...} or StreamInfo{...} since the former is an implementation detail, but the latter is a bit misleading.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good point - I'm satisfied with StreamInfo because I dont' think we expect more than just this impl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'm going to merge this PR and then open a follow-up to add equals/hashcode/tostring to all the client interfaces, since none of the new interfaces have them (not just the ones in this PR).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the follow-up: #5681

) {
return new TypeSafeDiagnosingMatcher<StreamInfo>() {
@Override
protected boolean matchesSafely(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would we need this if we implemented .equals()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, for two reasons:

  • I think it's useful for the test to validate the StreamInfo methods (getName, getTopic, getFormat) explicitly, since they're external APIs, rather than simply perform a comparison.
  • StreamInfoImpl is package-private so the test can't even create StreamInfo instances for comparison, without exposing StreamInfoImpl which doesn't seem great.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I had missed the distinction between the impl and the interface

Copy link
Contributor Author

@vcrfxia vcrfxia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @agavra ! Responded to your questions inline.

Comment on lines +113 to +114
* <p>If a non-200 response is received from the server, the {@code CompletableFuture} will be
* failed.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually listStreams and listTables 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 as listTopics), 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.

import io.confluent.ksql.api.client.StreamInfo;
import java.util.Objects;

public class StreamInfoImpl implements StreamInfo {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure I understand correctly: you're suggesting we add equals/hashcode/tostring methods to each of the implementation classes, not the interfaces, right? This makes sense to me, though I'm not sure whether it makes more sense for the toString method to say StreamInfoImpl{...} or StreamInfo{...} since the former is an implementation detail, but the latter is a bit misleading.

) {
return new TypeSafeDiagnosingMatcher<StreamInfo>() {
@Override
protected boolean matchesSafely(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, for two reasons:

  • I think it's useful for the test to validate the StreamInfo methods (getName, getTopic, getFormat) explicitly, since they're external APIs, rather than simply perform a comparison.
  • StreamInfoImpl is package-private so the test can't even create StreamInfo instances for comparison, without exposing StreamInfoImpl which doesn't seem great.

@vcrfxia vcrfxia merged commit 7d0079a into confluentinc:master Jun 24, 2020
@vcrfxia vcrfxia deleted the java-client-admin-operations branch June 24, 2020 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add admin operations to Java client
2 participants