-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3bc83e1
commit 55ee98e
Showing
75 changed files
with
2,989 additions
and
89 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
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
61 changes: 61 additions & 0 deletions
61
...connect-common/src/main/java/io/lenses/streamreactor/common/config/base/KcqlSettings.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,61 @@ | ||
/* | ||
* Copyright 2017-2024 Lenses.io Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.lenses.streamreactor.common.config.base; | ||
|
||
import java.util.List; | ||
|
||
import lombok.Getter; | ||
import org.apache.kafka.common.config.ConfigDef; | ||
import org.apache.kafka.common.config.ConfigException; | ||
|
||
import io.lenses.kcql.Kcql; | ||
import io.lenses.streamreactor.common.config.base.model.ConnectorPrefix; | ||
import io.lenses.streamreactor.common.config.source.ConfigSource; | ||
import lombok.val; | ||
|
||
public class KcqlSettings implements ConfigSettings<List<Kcql>> { | ||
|
||
private final String KCQL_DOC = | ||
"Contains the Kafka Connect Query Language describing the flow from the source to the target system."; | ||
|
||
@Getter | ||
private final String kcqlSettingsKey; | ||
|
||
public KcqlSettings( | ||
ConnectorPrefix connectorPrefix) { | ||
kcqlSettingsKey = connectorPrefix.prefixKey("kcql"); | ||
} | ||
|
||
@Override | ||
public ConfigDef withSettings(ConfigDef configDef) { | ||
return configDef.define( | ||
kcqlSettingsKey, | ||
ConfigDef.Type.STRING, | ||
ConfigDef.Importance.HIGH, | ||
KCQL_DOC | ||
); | ||
} | ||
|
||
@Override | ||
public List<Kcql> parseFromConfig(ConfigSource configSource) { | ||
return Kcql.parseMultiple(getKCQLString(configSource)); | ||
} | ||
|
||
private String getKCQLString(ConfigSource configSource) { | ||
val raw = configSource.getString(kcqlSettingsKey); | ||
return raw.orElseThrow(() -> new ConfigException(String.format("Missing [%s]", kcqlSettingsKey))); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...nnect-common/src/main/java/io/lenses/streamreactor/common/config/base/intf/Converter.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,33 @@ | ||
/* | ||
* Copyright 2017-2024 Lenses.io Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.lenses.streamreactor.common.config.base.intf; | ||
|
||
import org.apache.kafka.common.config.ConfigException; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Picks out the settings required from KCQL | ||
*/ | ||
public abstract class Converter<S, T> { | ||
|
||
public List<T> convertAll(List<S> source) throws ConfigException { | ||
return source.stream().map(this::convert).collect(Collectors.toList()); | ||
} | ||
|
||
protected abstract T convert(S source) throws ConfigException; | ||
} |
29 changes: 29 additions & 0 deletions
29
...t-common/src/main/java/io/lenses/streamreactor/common/config/base/intf/KcqlConverter.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,29 @@ | ||
/* | ||
* Copyright 2017-2024 Lenses.io Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.lenses.streamreactor.common.config.base.intf; | ||
|
||
import io.lenses.kcql.Kcql; | ||
import org.apache.kafka.common.config.ConfigException; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Picks out the settings required from KCQL | ||
*/ | ||
public abstract class KcqlConverter<T> extends Converter<Kcql, T> { | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
.../kafka-connect-common/src/main/java/io/lenses/streamreactor/common/util/ListSplitter.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,56 @@ | ||
/* | ||
* Copyright 2017-2024 Lenses.io Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.lenses.streamreactor.common.util; | ||
|
||
import lombok.experimental.UtilityClass; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
@UtilityClass | ||
public class ListSplitter { | ||
|
||
/** | ||
* Splits the given list into {@code maxN} sublists of roughly equal size. | ||
* If the list cannot be divided evenly, the remaining elements are distributed | ||
* among the sublists so that the size difference between any two sublists is at most 1. | ||
* | ||
* @param list the list to be split | ||
* @param maxN the number of sublists to create | ||
* @param <T> the type of elements in the list | ||
* @return a list of sublists, where each sublist contains a portion of the original list | ||
* @throws IllegalArgumentException if {@code maxN} is less than or equal to 0 | ||
*/ | ||
public static <T> List<List<T>> splitList(List<T> list, int maxN) { | ||
if (maxN <= 0) { | ||
throw new IllegalArgumentException("Number of parts must be greater than zero."); | ||
} | ||
|
||
int totalSize = list.size(); | ||
int partSize = totalSize / maxN; | ||
int remainder = totalSize % maxN; | ||
|
||
return IntStream.range(0, maxN) | ||
.mapToObj(i -> { | ||
int start = i * partSize + Math.min(i, remainder); | ||
int end = start + partSize + (i < remainder ? 1 : 0); | ||
return list.subList(start, Math.min(end, totalSize)); | ||
}) | ||
.filter(sublist -> !sublist.isEmpty()) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...tors/kafka-connect-common/src/main/java/io/lenses/streamreactor/common/util/MapUtils.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,38 @@ | ||
/* | ||
* Copyright 2017-2024 Lenses.io Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.lenses.streamreactor.common.util; | ||
|
||
import lombok.experimental.UtilityClass; | ||
|
||
import java.util.Map; | ||
|
||
@UtilityClass | ||
public class MapUtils { | ||
|
||
@SuppressWarnings("unchecked") | ||
public static <K, V> Map<K, V> castMap(Map<?, ?> map, Class<K> targetKeyType, Class<V> targetValueType) { | ||
for (Map.Entry<?, ?> entry : map.entrySet()) { | ||
if (!(isInstance(entry.getKey(), targetKeyType)) || !(isInstance(entry.getValue(), targetValueType))) { | ||
throw new IllegalArgumentException("Map contains invalid key or value type"); | ||
} | ||
} | ||
return (Map<K, V>) map; | ||
} | ||
|
||
private static <T> boolean isInstance(Object obj, Class<T> type) { | ||
return obj == null || type.isInstance(obj); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...kafka-connect-common/src/main/java/io/lenses/streamreactor/common/util/TasksSplitter.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 2017-2024 Lenses.io Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.lenses.streamreactor.common.util; | ||
|
||
import static io.lenses.kcql.Kcql.KCQL_MULTI_STATEMENT_SEPARATOR; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import io.lenses.streamreactor.common.config.base.KcqlSettings; | ||
import lombok.val; | ||
import lombok.experimental.UtilityClass; | ||
|
||
/** | ||
* Utility class for splitting tasks based on KCQL statements. | ||
*/ | ||
@UtilityClass | ||
public class TasksSplitter { | ||
|
||
/** | ||
* Splits tasks based on the KCQL statements provided in the properties map. | ||
* Each resulting map will contain the original properties and a subset of the KCQL statements. | ||
* | ||
* @param maxTasks the maximum number of tasks to split into | ||
* @param props the original properties map containing KCQL settings | ||
* @param kcqlSettings the KCQL settings object that provides the key for KCQL settings in the properties map | ||
* @return a list of maps, each containing the original properties and a subset of the KCQL statements | ||
*/ | ||
public static List<Map<String, String>> splitByKcqlStatements(int maxTasks, Map<String, String> props, | ||
KcqlSettings kcqlSettings) { | ||
val kcqlSettingsKey = kcqlSettings.getKcqlSettingsKey(); | ||
val kcqls = | ||
Arrays | ||
.stream(props.get(kcqlSettingsKey).split(KCQL_MULTI_STATEMENT_SEPARATOR)) | ||
.collect(Collectors.toList()); | ||
|
||
return ListSplitter | ||
.splitList(kcqls, maxTasks) | ||
.stream() | ||
.map(kcqlsForTask -> Stream.concat( | ||
props.entrySet().stream(), | ||
Stream.of(Map.entry(kcqlSettingsKey, String.join(";", kcqlsForTask))) | ||
).collect(Collectors.toUnmodifiableMap( | ||
Map.Entry::getKey, | ||
Map.Entry::getValue, | ||
(existing, replacement) -> replacement | ||
))) | ||
.collect(Collectors.toUnmodifiableList()); | ||
} | ||
|
||
} |
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.