-
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 connect templates and simplify JDBC source (MINOR) (#3231)
- Loading branch information
Showing
8 changed files
with
204 additions
and
54 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
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
77 changes: 77 additions & 0 deletions
77
ksql-engine/src/main/java/io/confluent/ksql/connect/supported/Connectors.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,77 @@ | ||
/* | ||
* 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.connect.supported; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.confluent.ksql.connect.Connector; | ||
import java.util.EnumSet; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo; | ||
|
||
public enum Connectors implements SupportedConnector { | ||
|
||
JDBC(JdbcSource.JDBC_SOURCE_CLASS, new JdbcSource()) | ||
; | ||
|
||
public static final String CONNECTOR_CLASS = "connector.class"; | ||
|
||
private static final Map<String, SupportedConnector> CONNECTORS = ImmutableMap.copyOf( | ||
EnumSet.allOf(Connectors.class) | ||
.stream() | ||
.collect(Collectors.toMap( | ||
Connectors::getConnectorClass, | ||
Function.identity())) | ||
); | ||
|
||
private final String connectorClass; | ||
private final SupportedConnector supportedConnector; | ||
|
||
Connectors(final String connectorClass, final SupportedConnector supportedConnector) { | ||
this.connectorClass = Objects.requireNonNull(connectorClass, "connectorClass"); | ||
this.supportedConnector = Objects.requireNonNull(supportedConnector, "supportedConnector"); | ||
} | ||
|
||
public static Optional<Connector> from(final ConnectorInfo info) { | ||
final SupportedConnector connector = | ||
CONNECTORS.get(info.config().get(CONNECTOR_CLASS)); | ||
return connector == null ? Optional.empty() : connector.fromConnectInfo(info); | ||
} | ||
|
||
public static Map<String, String> resolve(final Map<String, String> configs) { | ||
final SupportedConnector connector = | ||
CONNECTORS.get(configs.get(CONNECTOR_CLASS)); | ||
return connector == null ? configs : connector.resolveConfigs(configs); | ||
|
||
} | ||
|
||
@Override | ||
public Optional<Connector> fromConnectInfo(final ConnectorInfo info) { | ||
return supportedConnector.fromConnectInfo(info); | ||
} | ||
|
||
@Override | ||
public Map<String, String> resolveConfigs(final Map<String, String> configs) { | ||
return supportedConnector.resolveConfigs(configs); | ||
} | ||
|
||
public String getConnectorClass() { | ||
return connectorClass; | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
ksql-engine/src/main/java/io/confluent/ksql/connect/supported/SupportedConnector.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,40 @@ | ||
/* | ||
* 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.connect.supported; | ||
|
||
import io.confluent.ksql.connect.Connector; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo; | ||
|
||
/** | ||
* KSQL supports some "Blessed" connectors that we integrate well with. To be "blessed" | ||
* means that we can automatically import topics created by these connectors and that | ||
* we may provide templates that simplify configuration of these connectors. | ||
*/ | ||
public interface SupportedConnector { | ||
|
||
/** | ||
* Constructs a {@link Connector} from the configuration given to us by connect. | ||
*/ | ||
Optional<Connector> fromConnectInfo(ConnectorInfo info); | ||
|
||
/** | ||
* Resolves a template configuration into something that connect can understand. | ||
*/ | ||
Map<String, String> resolveConfigs(Map<String, String> configs); | ||
|
||
} |
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.