Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LISAMZA-36419: support offspring #110

Merged
merged 12 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class BeamModulePlugin implements Plugin<Project> {

// Automatically use the official release version if we are performing a release
// otherwise append '-SNAPSHOT'
project.version = '2.45.16'
project.version = '2.45.17'
if (isLinkedin(project)) {
project.ext.mavenGroupId = 'com.linkedin.beam'
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ signing.gnupg.useLegacyGpg=true
# buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy.
# To build a custom Beam version make sure you change it in both places, see
# https://github.com/apache/beam/issues/21302.
version=2.45.16
sdk_version=2.45.16
version=2.45.17
sdk_version=2.45.17

javaVersion=1.8

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.apache.beam.sdk.options;

import java.util.Iterator;
import java.util.ServiceLoader;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Iterators;
import org.checkerframework.checker.initialization.qual.Initialized;
import org.checkerframework.checker.nullness.qual.Nullable;


/**
* Interface to support offspring wire-in for Li: if input class is a
* customized pipelineOptions created by an offspring factory,
* the pipelineOptions will be initialized.
*
*/
@SuppressWarnings("rawtypes")
public interface CustomPipelineOptionsInitializer<T> {
void init(T pipelineOptions, Class<T> clazz);

/**
* Inject the implementation for the interface
* <p>Usage:
*
* <pre>{@code
* @AutoService(CustomPipelineOptionsInitializer.Registrar.class)
* public static class Registrar implements CustomPipelineOptions.Registrar {
* @Override
* public CustomPipelineOptions create() {
* return new CustomPipelineOptions();
* }
* }</pre>
*/
interface Registrar {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how will the Registrar be used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the implementation, we will have a class annotated as AutoService(CustomePipelineOptionsInitializer.Registrar.class). It returns an instance of the implementation, so beam will know which implementation to use during runtime

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Can you add an example of usage in the javadoc?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

CustomPipelineOptionsInitializer create();
}


static @Initialized @Nullable CustomPipelineOptionsInitializer get() {
final Iterator<CustomPipelineOptionsInitializer.Registrar>
initializer = ServiceLoader.load(CustomPipelineOptionsInitializer.Registrar.class).iterator();
return initializer.hasNext() ? Iterators.getOnlyElement(initializer).create() : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public Object invoke(Object proxy, Method method, Object[] args) {
} else if (args != null && "as".equals(method.getName()) && args[0] instanceof Class) {
@SuppressWarnings("unchecked")
Class<? extends PipelineOptions> clazz = (Class<? extends PipelineOptions>) args[0];
return as(clazz);
return as(clazz, (PipelineOptions)proxy); // LI-specific change to wire in offspring
} else if (args != null
&& "populateDisplayData".equals(method.getName())
&& args[0] instanceof DisplayData.Builder) {
Expand Down Expand Up @@ -275,6 +275,10 @@ static BoundValue fromDefault(@Nullable Object value) {
* @return An object that implements the interface {@code <T>}.
*/
<T extends PipelineOptions> T as(Class<T> iface) {
return as(iface, null);
}

<T extends PipelineOptions> T as(Class<T> iface, PipelineOptions pipelineOptions) {
MabelYC marked this conversation as resolved.
Show resolved Hide resolved
checkNotNull(iface);
checkArgument(iface.isInterface(), "Not an interface: %s", iface);

Expand All @@ -300,6 +304,10 @@ <T extends PipelineOptions> T as(Class<T> iface) {

computedProperties =
computedProperties.updated(iface, existingOption, propertyDescriptors);
// Linkedin specific change: initialize the offspring generator
if (pipelineOptions != null && CustomPipelineOptionsInitializer.get() != null) {
CustomPipelineOptionsInitializer.get().init(existingOption, iface);
}
}
}
}
Expand Down
Loading