-
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(ksql-connect): wiring for creating connectors (#3149)
- Loading branch information
Showing
10 changed files
with
398 additions
and
3 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
30 changes: 30 additions & 0 deletions
30
.../src/main/java/io/confluent/ksql/cli/console/table/builder/ConnectorInfoTableBuilder.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.CreateConnectorEntity; | ||
|
||
public class ConnectorInfoTableBuilder implements TableBuilder<CreateConnectorEntity> { | ||
|
||
@Override | ||
public Table buildTable(final CreateConnectorEntity entity) { | ||
return new Table.Builder() | ||
.withColumnHeaders("Message") | ||
.withRow("Created connector " + entity.getInfo().name()) | ||
.build(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...li/src/main/java/io/confluent/ksql/cli/console/table/builder/ErrorEntityTableBuilder.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.ErrorEntity; | ||
|
||
public class ErrorEntityTableBuilder implements TableBuilder<ErrorEntity> { | ||
|
||
@Override | ||
public Table buildTable(final ErrorEntity entity) { | ||
return new Table.Builder() | ||
.withColumnHeaders("Error") | ||
.withRow(entity.getErrorMessage()) | ||
.build(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
ksql-rest-app/src/main/java/io/confluent/ksql/rest/entity/CreateConnectorEntity.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.rest.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.Objects; | ||
import org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class CreateConnectorEntity extends KsqlEntity { | ||
|
||
private final ConnectorInfo info; | ||
|
||
@JsonCreator | ||
public CreateConnectorEntity( | ||
@JsonProperty("statementText") final String statementText, | ||
@JsonProperty("info") final ConnectorInfo info | ||
) { | ||
super(statementText); | ||
this.info = Objects.requireNonNull(info, "info"); | ||
} | ||
|
||
public ConnectorInfo getInfo() { | ||
return info; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
final CreateConnectorEntity that = (CreateConnectorEntity) o; | ||
return Objects.equals(info, that.info); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(info); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CreateConnectorEntity{" | ||
+ "info=" + info | ||
+ '}'; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
ksql-rest-app/src/main/java/io/confluent/ksql/rest/entity/ErrorEntity.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,67 @@ | ||
/* | ||
* 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.errorprone.annotations.Immutable; | ||
import java.util.Objects; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@Immutable | ||
public class ErrorEntity extends KsqlEntity { | ||
|
||
private final String errorMessage; | ||
|
||
@JsonCreator | ||
public ErrorEntity( | ||
@JsonProperty("statementText") final String statementText, | ||
@JsonProperty("errorMessage") final String errorMessage | ||
) { | ||
super(statementText); | ||
this.errorMessage = Objects.requireNonNull(errorMessage, "errorMessage"); | ||
} | ||
|
||
public String getErrorMessage() { | ||
return errorMessage; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
final ErrorEntity that = (ErrorEntity) o; | ||
return Objects.equals(errorMessage, that.errorMessage); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(errorMessage); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ErrorEntity{" | ||
+ "errorMessage='" + errorMessage + '\'' | ||
+ '}'; | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
ksql-rest-app/src/main/java/io/confluent/ksql/rest/server/execution/ConnectExecutor.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,59 @@ | ||
/* | ||
* 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 com.google.common.collect.Maps; | ||
import io.confluent.ksql.KsqlExecutionContext; | ||
import io.confluent.ksql.parser.tree.CreateConnector; | ||
import io.confluent.ksql.rest.entity.CreateConnectorEntity; | ||
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 java.util.Optional; | ||
import org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo; | ||
|
||
public final class ConnectExecutor { | ||
|
||
private ConnectExecutor() { } | ||
|
||
public static Optional<KsqlEntity> execute( | ||
final ConfiguredStatement<CreateConnector> statement, | ||
final KsqlExecutionContext executionContext, | ||
final ServiceContext serviceContext | ||
) { | ||
final CreateConnector createConnector = statement.getStatement(); | ||
final ConnectClient client = serviceContext.getConnectClient(); | ||
|
||
final ConnectResponse<ConnectorInfo> response = client.create( | ||
createConnector.getName(), | ||
Maps.transformValues(createConnector.getConfig(), l -> l.getValue().toString())); | ||
|
||
if (response.datum().isPresent()) { | ||
return Optional.of( | ||
new CreateConnectorEntity( | ||
statement.getStatementText(), | ||
response.datum().get() | ||
) | ||
); | ||
} | ||
|
||
return response.error() | ||
.map(err -> new ErrorEntity(statement.getStatementText(), err)); | ||
} | ||
} |
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
Oops, something went wrong.