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

KAFKA-4372: Kafka Connect REST API does not handle DELETE of connector with slashes in their names #2096

Conversation

ogirardot
Copy link
Contributor

Kafka Connect REST API does not handle in many places connectors with slashes in their names because it expects PathParams, this PR intends to :

  • Reject as bad requests API calls trying to create connectors with slashes in their names
  • Add support for connector with slashes in their names in the DELETE part of the API to allow users to cleanup their connectors without dropping everything.

This PR adds as well the Unit Test needed for the creation part and was tested manually for the DELETE part.

Olivier Girardot added 2 commits November 3, 2016 14:24
Even though the rest of the API points accept connector names containing slashes
Added a BadRequestException if someone tries to create one like that
and added unit test to check that
@ogirardot
Copy link
Contributor Author

The test failures do not seem to be related to the PR

@@ -89,6 +89,9 @@ public ConnectorsResource(Herder herder) {
public Response createConnector(final @QueryParam("forward") Boolean forward,
final CreateConnectorRequest createRequest) throws Throwable {
String name = createRequest.name();
if (name.contains("/")){
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: missing whitespace between (}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -89,6 +89,9 @@ public ConnectorsResource(Herder herder) {
public Response createConnector(final @QueryParam("forward") Boolean forward,
final CreateConnectorRequest createRequest) throws Throwable {
String name = createRequest.name();
if (name.contains("/")) {
throw new BadRequestException("connector name should not contain '/'");
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe connectors can also be created via putConnectorConfig() below, PUT additionally allows for 'replace' while that is not allowed for this endpoint. So for consistency I think we should either disallow it in both places or neither.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well the PUT API takes a PathParam so it won't allow for a slash in the connector name. I agree it is not explicit but no connector with a slash in its name can be PUT

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, make sense.

@shikhar
Copy link
Contributor

shikhar commented Nov 3, 2016

LGTM

cc @ewencp or @hachikuji for review

Copy link
Contributor

@ewencp ewencp left a comment

Choose a reason for hiding this comment

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

One minor style issue, but LGTM. We might want to eventually refactor so this is reusable (and since we may find other constraints we want to enforce, but given current usage I think its fine to leave inline like this for now.

@@ -194,6 +194,23 @@ public void testCreateConnectorExists() throws Throwable {
PowerMock.verifyAll();
}

@Test(expected = BadRequestException.class)
public void testCreateConnectorWithASlashInItsName() throws Throwable {
String badConnectorName = CONNECTOR_NAME+"/"+"test";
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't pass checkstyle -- you need spaces before and after the +.

@ogirardot
Copy link
Contributor Author

Fixed code styling in tests too

@ewencp
Copy link
Contributor

ewencp commented Nov 4, 2016

LGTM, thanks!

@asfgit asfgit closed this in 0a659e5 Nov 4, 2016
@ogirardot ogirardot deleted the fix/connectors-with-slashes-cannot-be-deleted branch November 4, 2016 17:46
@ogirardot
Copy link
Contributor Author

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants