kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewe...@apache.org
Subject kafka git commit: KAFKA-4372: Kafka Connect REST API does not handle DELETE of connector with slashes in their names
Date Fri, 04 Nov 2016 17:44:21 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 5e7190cf8 -> 0a659e50f


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

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.

Author: Olivier Girardot <o.girardot@lateral-thoughts.com>

Reviewers: Shikhar Bhushan <shikhar@confluent.io>, Ewen Cheslack-Postava <ewen@confluent.io>

Closes #2096 from ogirardot/fix/connectors-with-slashes-cannot-be-deleted


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/0a659e50
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/0a659e50
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/0a659e50

Branch: refs/heads/trunk
Commit: 0a659e50f7d98c0a195a7dca4ef9f117ab2aa257
Parents: 5e7190c
Author: Olivier Girardot <o.girardot@lateral-thoughts.com>
Authored: Fri Nov 4 10:44:05 2016 -0700
Committer: Ewen Cheslack-Postava <me@ewencp.org>
Committed: Fri Nov 4 10:44:05 2016 -0700

----------------------------------------------------------------------
 .../runtime/rest/resources/ConnectorsResource.java |  5 ++++-
 .../rest/resources/ConnectorsResourceTest.java     | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/0a659e50/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResource.java
----------------------------------------------------------------------
diff --git a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResource.java
b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResource.java
index 2ec35f4..0d856e3 100644
--- a/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResource.java
+++ b/connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResource.java
@@ -89,6 +89,9 @@ public class ConnectorsResource {
     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 '/'");
+        }
         Map<String, String> configs = createRequest.config();
         if (!configs.containsKey(ConnectorConfig.NAME_CONFIG))
             configs.put(ConnectorConfig.NAME_CONFIG, name);
@@ -211,7 +214,7 @@ public class ConnectorsResource {
     }
 
     @DELETE
-    @Path("/{connector}")
+    @Path("/{connector : .+}")
     public void destroyConnector(final @PathParam("connector") String connector,
                                  final @QueryParam("forward") Boolean forward) throws Throwable
{
         FutureCallback<Herder.Created<ConnectorInfo>> cb = new FutureCallback<>();

http://git-wip-us.apache.org/repos/asf/kafka/blob/0a659e50/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResourceTest.java
----------------------------------------------------------------------
diff --git a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResourceTest.java
b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResourceTest.java
index aa1b9a7..9e97087 100644
--- a/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResourceTest.java
+++ b/connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/resources/ConnectorsResourceTest.java
@@ -194,6 +194,23 @@ public class ConnectorsResourceTest {
         PowerMock.verifyAll();
     }
 
+    @Test(expected = BadRequestException.class)
+    public void testCreateConnectorWithASlashInItsName() throws Throwable {
+        String badConnectorName = CONNECTOR_NAME + "/" + "test";
+
+        CreateConnectorRequest body = new CreateConnectorRequest(badConnectorName, Collections.singletonMap(ConnectorConfig.NAME_CONFIG,
badConnectorName));
+
+        final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
+        herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()),
EasyMock.eq(false), EasyMock.capture(cb));
+        expectAndCallbackResult(cb, new Herder.Created<>(true, new ConnectorInfo(CONNECTOR_NAME,
CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES)));
+
+        PowerMock.replayAll();
+
+        connectorsResource.createConnector(FORWARD, body);
+
+        PowerMock.verifyAll();
+    }
+
     @Test
     public void testDeleteConnector() throws Throwable {
         final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();


Mime
View raw message