-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add SHOW CONNECTORS functionality (#3210)
- Loading branch information
Showing
15 changed files
with
640 additions
and
0 deletions.
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
44 changes: 44 additions & 0 deletions
44
.../src/main/java/io/confluent/ksql/cli/console/table/builder/ConnectorListTableBuilder.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,44 @@ | ||
/* | ||
* 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 com.google.common.collect.ImmutableList; | ||
import io.confluent.ksql.cli.console.table.Table; | ||
import io.confluent.ksql.rest.entity.ConnectorList; | ||
import java.util.List; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.apache.kafka.connect.runtime.rest.entities.ConnectorType; | ||
|
||
public class ConnectorListTableBuilder implements TableBuilder<ConnectorList> { | ||
|
||
private static final List<String> HEADERS = ImmutableList.of( | ||
"Connector Name", "Type", "Class" | ||
); | ||
|
||
|
||
@Override | ||
public Table buildTable(final ConnectorList entity) { | ||
return new Table.Builder() | ||
.withColumnHeaders(HEADERS) | ||
.withRows(entity.getConnectors() | ||
.stream() | ||
.map(info -> ImmutableList.of( | ||
info.getName(), | ||
ObjectUtils.defaultIfNull(info.getType(), ConnectorType.UNKNOWN).name(), | ||
ObjectUtils.defaultIfNull(info.getClassName(), "")))) | ||
.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
66 changes: 66 additions & 0 deletions
66
ksql-parser/src/main/java/io/confluent/ksql/parser/tree/ListConnectors.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,66 @@ | ||
/* | ||
* 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 com.google.errorprone.annotations.Immutable; | ||
import io.confluent.ksql.parser.NodeLocation; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
@Immutable | ||
public class ListConnectors extends Statement { | ||
|
||
private final Scope scope; | ||
|
||
public enum Scope { | ||
ALL, | ||
SOURCE, | ||
SINK | ||
} | ||
|
||
public ListConnectors(final Optional<NodeLocation> location, final Scope scope) { | ||
super(location); | ||
this.scope = Objects.requireNonNull(scope, "scope"); | ||
} | ||
|
||
public Scope getScope() { | ||
return scope; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final ListConnectors that = (ListConnectors) o; | ||
return scope == that.scope; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(scope); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ListConnectors{" | ||
+ "scope=" + scope | ||
+ '}'; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
ksql-parser/src/test/java/io/confluent/ksql/parser/tree/ListConnectorsTest.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,42 @@ | ||
/* | ||
* 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 static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
|
||
import com.google.common.testing.EqualsTester; | ||
import io.confluent.ksql.parser.NodeLocation; | ||
import io.confluent.ksql.parser.tree.ListConnectors.Scope; | ||
import java.util.Optional; | ||
import org.junit.Test; | ||
|
||
public class ListConnectorsTest { | ||
|
||
@Test | ||
public void shouldImplementHashCodeAndEquals() { | ||
new EqualsTester() | ||
.addEqualityGroup( | ||
new ListConnectors(Optional.empty(), Scope.ALL), | ||
new ListConnectors(Optional.of(new NodeLocation(1, 1)), Scope.ALL) | ||
) | ||
.addEqualityGroup( | ||
new ListConnectors(Optional.empty(), Scope.SOURCE) | ||
) | ||
.testEquals(); | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
ksql-rest-app/src/main/java/io/confluent/ksql/rest/entity/ConnectorList.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,62 @@ | ||
/* | ||
* 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.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.errorprone.annotations.Immutable; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@Immutable | ||
public class ConnectorList extends KsqlEntity { | ||
|
||
private final ImmutableList<SimpleConnectorInfo> connectors; | ||
|
||
@JsonCreator | ||
public ConnectorList( | ||
@JsonProperty("statementText") final String statementText, | ||
@JsonProperty("warnings") final List<KsqlWarning> warnings, | ||
@JsonProperty("connectors") final List<SimpleConnectorInfo> connectors | ||
) { | ||
super(statementText, warnings); | ||
this.connectors = ImmutableList.copyOf(Objects.requireNonNull(connectors, "connectors")); | ||
} | ||
|
||
public ImmutableList<SimpleConnectorInfo> getConnectors() { | ||
return connectors; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final ConnectorList that = (ConnectorList) o; | ||
return Objects.equals(connectors, that.connectors); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(connectors); | ||
} | ||
} |
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
Oops, something went wrong.