-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-18026: KIP-1112, ProcessorWrapper API with PAPI and partial DSL…
… implementation (#17892) This PR includes the API for KIP-1112 and a partial implementation, which wraps any processors added through the PAPI and the DSL processors that are written to the topology through the ProcessorParameters#addProcessorTo method. Further PRs will complete the implementation by converting the remaining DSL operators to using the #addProcessorTo method, and future-proof the processor writing mechanism to prevent new DSL operators from being implemented incorrectly/without the wrapper Reviewers: Almog Gavra <[email protected]>, Guozhang Wang <[email protected]>
- Loading branch information
1 parent
8a90ca0
commit 87b902d
Showing
16 changed files
with
629 additions
and
18 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
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
85 changes: 85 additions & 0 deletions
85
streams/src/main/java/org/apache/kafka/streams/processor/api/ProcessorWrapper.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,85 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.kafka.streams.processor.api; | ||
|
||
import org.apache.kafka.common.Configurable; | ||
import org.apache.kafka.streams.StreamsBuilder; | ||
import org.apache.kafka.streams.StreamsConfig; | ||
import org.apache.kafka.streams.Topology; | ||
import org.apache.kafka.streams.TopologyConfig; | ||
import org.apache.kafka.streams.processor.internals.NoOpProcessorWrapper.WrappedFixedKeyProcessorSupplierImpl; | ||
import org.apache.kafka.streams.processor.internals.NoOpProcessorWrapper.WrappedProcessorSupplierImpl; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Wrapper class that can be used to inject custom wrappers around the processors of their application topology. | ||
* The returned instance should wrap the supplied {@code ProcessorSupplier} and the {@code Processor} it supplies | ||
* to avoid disrupting the regular processing of the application, although this is not required and any processor | ||
* implementation can be substituted in to replace the original processor entirely (which may be useful for example | ||
* while testing or debugging an application topology). | ||
* <p> | ||
* NOTE: in order to use this feature, you must set the {@link StreamsConfig#PROCESSOR_WRAPPER_CLASS_CONFIG} config and pass it | ||
* in as a {@link TopologyConfig} when creating the {@link StreamsBuilder} or {@link Topology} by using the | ||
* appropriate constructor (ie {@link StreamsBuilder#StreamsBuilder(TopologyConfig)} or {@link Topology#Topology(TopologyConfig)}) | ||
* <p> | ||
* Can be configured, if desired, by implementing the {@link #configure(Map)} method. This will be invoked when | ||
* the {@code ProcessorWrapper} is instantiated, and will provide it with the TopologyConfigs that were passed in | ||
* to the {@link StreamsBuilder} or {@link Topology} constructor. | ||
*/ | ||
public interface ProcessorWrapper extends Configurable { | ||
|
||
@Override | ||
default void configure(final Map<String, ?> configs) { | ||
// do nothing | ||
} | ||
|
||
/** | ||
* Wrap or replace the provided {@link ProcessorSupplier} and return a {@link WrappedProcessorSupplier} | ||
* To convert a {@link ProcessorSupplier} instance into a {@link WrappedProcessorSupplier}, | ||
* use the {@link ProcessorWrapper#asWrapped(ProcessorSupplier)} method | ||
*/ | ||
<KIn, VIn, KOut, VOut> WrappedProcessorSupplier<KIn, VIn, KOut, VOut> wrapProcessorSupplier(final String processorName, | ||
final ProcessorSupplier<KIn, VIn, KOut, VOut> processorSupplier); | ||
|
||
/** | ||
* Wrap or replace the provided {@link FixedKeyProcessorSupplier} and return a {@link WrappedFixedKeyProcessorSupplier} | ||
* To convert a {@link FixedKeyProcessorSupplier} instance into a {@link WrappedFixedKeyProcessorSupplier}, | ||
* use the {@link ProcessorWrapper#asWrappedFixedKey(FixedKeyProcessorSupplier)} method | ||
*/ | ||
<KIn, VIn, VOut> WrappedFixedKeyProcessorSupplier<KIn, VIn, VOut> wrapFixedKeyProcessorSupplier(final String processorName, | ||
final FixedKeyProcessorSupplier<KIn, VIn, VOut> processorSupplier); | ||
|
||
/** | ||
* Use to convert a {@link ProcessorSupplier} instance into a {@link WrappedProcessorSupplier} | ||
*/ | ||
static <KIn, VIn, KOut, VOut> WrappedProcessorSupplier<KIn, VIn, KOut, VOut> asWrapped( | ||
final ProcessorSupplier<KIn, VIn, KOut, VOut> processorSupplier | ||
) { | ||
return new WrappedProcessorSupplierImpl<>(processorSupplier); | ||
} | ||
|
||
/** | ||
* Use to convert a {@link FixedKeyProcessorSupplier} instance into a {@link WrappedFixedKeyProcessorSupplier} | ||
*/ | ||
static <KIn, VIn, VOut> WrappedFixedKeyProcessorSupplier<KIn, VIn, VOut> asWrappedFixedKey( | ||
final FixedKeyProcessorSupplier<KIn, VIn, VOut> processorSupplier | ||
) { | ||
return new WrappedFixedKeyProcessorSupplierImpl<>(processorSupplier); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...rc/main/java/org/apache/kafka/streams/processor/api/WrappedFixedKeyProcessorSupplier.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 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.kafka.streams.processor.api; | ||
|
||
/** | ||
* Marker interface for classes implementing {@link FixedKeyProcessorSupplier} | ||
* that have been wrapped via a {@link ProcessorWrapper}. | ||
* <p> | ||
* To convert a {@link FixedKeyProcessorSupplier} instance into a {@link WrappedFixedKeyProcessorSupplier}, | ||
* use the {@link ProcessorWrapper#asWrappedFixedKey(FixedKeyProcessorSupplier)} method | ||
*/ | ||
public interface WrappedFixedKeyProcessorSupplier<KIn, VIn, VOut> extends FixedKeyProcessorSupplier<KIn, VIn, VOut> { | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
streams/src/main/java/org/apache/kafka/streams/processor/api/WrappedProcessorSupplier.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 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.kafka.streams.processor.api; | ||
|
||
/** | ||
* Marker interface for classes implementing {@link ProcessorSupplier} | ||
* that have been wrapped via a {@link ProcessorWrapper}. | ||
* <p> | ||
* To convert a {@link ProcessorSupplier} instance into a {@link WrappedProcessorSupplier}, | ||
* use the {@link ProcessorWrapper#asWrapped(ProcessorSupplier)} method | ||
*/ | ||
public interface WrappedProcessorSupplier<KIn, VIn, KOut, VOut> extends ProcessorSupplier<KIn, VIn, KOut, VOut> { | ||
|
||
} |
Oops, something went wrong.