-
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: add DROP CONNECTOR functionality #3245
Merged
+421
−24
Merged
Changes from all commits
Commits
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
feat: add DROP CONNECTOR functionality
commit cd0da39aeda49e6d0d9efa51ee5c9262a44ddcd0
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
30 changes: 30 additions & 0 deletions
30
.../src/main/java/io/confluent/ksql/cli/console/table/builder/DropConnectorTableBuilder.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,30 @@ | ||
/* | ||
* Copyright 2019 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.cli.console.table.builder; | ||
|
||
import io.confluent.ksql.cli.console.table.Table; | ||
import io.confluent.ksql.rest.entity.DropConnectorEntity; | ||
|
||
public class DropConnectorTableBuilder implements TableBuilder<DropConnectorEntity> { | ||
|
||
@Override | ||
public Table buildTable(final DropConnectorEntity entity) { | ||
return new Table.Builder() | ||
.withColumnHeaders("Message") | ||
.withRow("Dropped connector \"" + entity.getConnectorName() + '"') | ||
.build(); | ||
} | ||
} |
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
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
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
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
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
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
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
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
58 changes: 58 additions & 0 deletions
58
ksql-parser/src/main/java/io/confluent/ksql/parser/tree/DropConnector.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,58 @@ | ||
/* | ||
* Copyright 2019 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.parser.tree; | ||
|
||
import io.confluent.ksql.parser.NodeLocation; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class DropConnector extends Statement { | ||
|
||
private final String connectorName; | ||
|
||
public DropConnector(final Optional<NodeLocation> location, final String connectorName) { | ||
super(location); | ||
this.connectorName = connectorName; | ||
} | ||
|
||
public String getConnectorName() { | ||
return connectorName; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final DropConnector that = (DropConnector) o; | ||
return Objects.equals(connectorName, that.connectorName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(connectorName); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DropConnector{" | ||
+ "connectorName='" + connectorName + '\'' | ||
+ '}'; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
ksql-rest-app/src/main/java/io/confluent/ksql/rest/entity/DropConnectorEntity.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,45 @@ | ||
/* | ||
* Copyright 2019 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.rest.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.Objects; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class DropConnectorEntity extends KsqlEntity { | ||
|
||
private final String connectorName; | ||
|
||
public DropConnectorEntity( | ||
@JsonProperty("statementText") final String statementText, | ||
@JsonProperty("connectorName") final String connectorName | ||
) { | ||
super(statementText); | ||
this.connectorName = Objects.requireNonNull(connectorName, "connectorName"); | ||
} | ||
|
||
public String getConnectorName() { | ||
return connectorName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DropConnectorEntity{" | ||
+ "connectorName='" + connectorName + '\'' | ||
+ '}'; | ||
} | ||
} |
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
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
47 changes: 47 additions & 0 deletions
47
...rest-app/src/main/java/io/confluent/ksql/rest/server/execution/DropConnectorExecutor.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,47 @@ | ||
/* | ||
* Copyright 2019 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.rest.server.execution; | ||
|
||
import io.confluent.ksql.KsqlExecutionContext; | ||
import io.confluent.ksql.parser.tree.DropConnector; | ||
import io.confluent.ksql.rest.entity.DropConnectorEntity; | ||
import io.confluent.ksql.rest.entity.ErrorEntity; | ||
import io.confluent.ksql.rest.entity.KsqlEntity; | ||
import io.confluent.ksql.services.ConnectClient.ConnectResponse; | ||
import io.confluent.ksql.services.ServiceContext; | ||
import io.confluent.ksql.statement.ConfiguredStatement; | ||
import java.util.Optional; | ||
|
||
public final class DropConnectorExecutor { | ||
|
||
private DropConnectorExecutor() { } | ||
|
||
public static Optional<KsqlEntity> execute( | ||
final ConfiguredStatement<DropConnector> statement, | ||
final KsqlExecutionContext executionContext, | ||
final ServiceContext serviceContext | ||
) { | ||
final String connectorName = statement.getStatement().getConnectorName(); | ||
final ConnectResponse<String> response = | ||
serviceContext.getConnectClient().delete(connectorName); | ||
|
||
if (response.error().isPresent()) { | ||
return Optional.of(new ErrorEntity(statement.getStatementText(), response.error().get())); | ||
} | ||
|
||
return Optional.of(new DropConnectorEntity(statement.getStatementText(), connectorName)); | ||
} | ||
} |
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
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
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
112 changes: 112 additions & 0 deletions
112
...-app/src/test/java/io/confluent/ksql/rest/server/execution/DropConnectorExecutorTest.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,112 @@ | ||
/* | ||
* Copyright 2019 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.rest.server.execution; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.confluent.ksql.parser.KsqlParser.PreparedStatement; | ||
import io.confluent.ksql.parser.tree.DropConnector; | ||
import io.confluent.ksql.rest.entity.DropConnectorEntity; | ||
import io.confluent.ksql.rest.entity.ErrorEntity; | ||
import io.confluent.ksql.rest.entity.KsqlEntity; | ||
import io.confluent.ksql.services.ConnectClient; | ||
import io.confluent.ksql.services.ConnectClient.ConnectResponse; | ||
import io.confluent.ksql.services.ServiceContext; | ||
import io.confluent.ksql.statement.ConfiguredStatement; | ||
import io.confluent.ksql.util.KsqlConfig; | ||
import java.util.Optional; | ||
import org.apache.http.HttpStatus; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class DropConnectorExecutorTest { | ||
|
||
private static final KsqlConfig CONFIG = new KsqlConfig(ImmutableMap.of()); | ||
|
||
private static final DropConnector CREATE_CONNECTOR = new DropConnector(Optional.empty(), "foo"); | ||
|
||
private static final ConfiguredStatement<DropConnector> DROP_CONNECTOR_CONFIGURED = | ||
ConfiguredStatement.of( | ||
PreparedStatement.of( | ||
"DROP CONNECTOR \"foo\"", | ||
CREATE_CONNECTOR), | ||
ImmutableMap.of(), | ||
CONFIG); | ||
|
||
@Mock | ||
private ServiceContext serviceContext; | ||
@Mock | ||
private ConnectClient connectClient; | ||
|
||
@Before | ||
public void setUp() { | ||
when(serviceContext.getConnectClient()).thenReturn(connectClient); | ||
} | ||
|
||
|
||
@Test | ||
public void shouldPassInCorrectArgsToConnectClient() { | ||
// Given: | ||
when(connectClient.delete(anyString())) | ||
.thenReturn(ConnectResponse.success("foo", HttpStatus.SC_OK)); | ||
|
||
// When: | ||
DropConnectorExecutor.execute(DROP_CONNECTOR_CONFIGURED, null, serviceContext); | ||
|
||
// Then: | ||
verify(connectClient).delete("foo"); | ||
} | ||
|
||
@Test | ||
public void shouldReturnOnSuccess() { | ||
// Given: | ||
when(connectClient.delete(anyString())) | ||
.thenReturn(ConnectResponse.success("foo", HttpStatus.SC_OK)); | ||
|
||
// When: | ||
final Optional<KsqlEntity> response = DropConnectorExecutor | ||
.execute(DROP_CONNECTOR_CONFIGURED, null, serviceContext); | ||
|
||
// Then: | ||
assertThat("expected response", response.isPresent()); | ||
assertThat(((DropConnectorEntity) response.get()).getConnectorName(), is("foo")); | ||
} | ||
|
||
@Test | ||
public void shouldReturnErrorEntityOnError() { | ||
// Given: | ||
when(connectClient.delete(anyString())) | ||
.thenReturn(ConnectResponse.failure("Danger Mouse!", HttpStatus.SC_INTERNAL_SERVER_ERROR)); | ||
|
||
// When: | ||
final Optional<KsqlEntity> entity = DropConnectorExecutor | ||
.execute(DROP_CONNECTOR_CONFIGURED, null, serviceContext); | ||
|
||
// Then: | ||
assertThat("Expected non-empty response", entity.isPresent()); | ||
assertThat(entity.get(), instanceOf(ErrorEntity.class)); | ||
} | ||
|
||
} |
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
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.
Should we also have
(IF EXISTS)
here?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.
I don't feel strongly about this, but using an
IF EXISTS
will require an extra call to connect. If it doesn't exist you just get a 404 in the response, which is probably okay.