-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add PIPELINE_OPTIONS_FILE environment variable to allow PIPELINE_OPTIONS to be read from a file #27841
Merged
Merged
Add PIPELINE_OPTIONS_FILE environment variable to allow PIPELINE_OPTIONS to be read from a file #27841
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,10 @@ | |
*/ | ||
package org.apache.beam.fn.harness; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Collections; | ||
import java.util.EnumMap; | ||
import java.util.Set; | ||
|
@@ -89,6 +93,8 @@ public class FnHarness { | |
private static final String CONTROL_API_SERVICE_DESCRIPTOR = "CONTROL_API_SERVICE_DESCRIPTOR"; | ||
private static final String LOGGING_API_SERVICE_DESCRIPTOR = "LOGGING_API_SERVICE_DESCRIPTOR"; | ||
private static final String STATUS_API_SERVICE_DESCRIPTOR = "STATUS_API_SERVICE_DESCRIPTOR"; | ||
|
||
private static final String PIPELINE_OPTIONS_FILE = "PIPELINE_OPTIONS_FILE"; | ||
private static final String PIPELINE_OPTIONS = "PIPELINE_OPTIONS"; | ||
private static final String RUNNER_CAPABILITIES = "RUNNER_CAPABILITIES"; | ||
private static final String ENABLE_DATA_SAMPLING_EXPERIMENT = "enable_data_sampling"; | ||
|
@@ -117,11 +123,29 @@ public static void main(Function<String, String> environmentVarGetter) throws Ex | |
"Control location %s%n", environmentVarGetter.apply(CONTROL_API_SERVICE_DESCRIPTOR)); | ||
System.out.format( | ||
"Status location %s%n", environmentVarGetter.apply(STATUS_API_SERVICE_DESCRIPTOR)); | ||
System.out.format("Pipeline options %s%n", environmentVarGetter.apply(PIPELINE_OPTIONS)); | ||
|
||
String id = environmentVarGetter.apply(HARNESS_ID); | ||
PipelineOptions options = | ||
PipelineOptionsTranslation.fromJson(environmentVarGetter.apply(PIPELINE_OPTIONS)); | ||
|
||
String pipelineOptionsJson = environmentVarGetter.apply(PIPELINE_OPTIONS); | ||
// Try looking for a file first. If that exists it should override PIPELINE_OPTIONS to avoid | ||
// maxing out the kernel's environment space | ||
try { | ||
String pipelineOptionsPath = environmentVarGetter.apply(PIPELINE_OPTIONS_FILE); | ||
System.out.format("Pipeline Options File %s%n", pipelineOptionsPath); | ||
if (pipelineOptionsPath != null) { | ||
Path filePath = Paths.get(pipelineOptionsPath); | ||
if (Files.exists(filePath)) { | ||
System.out.format( | ||
"Pipeline Options File %s exists. Overriding existing options.%n", | ||
pipelineOptionsPath); | ||
pipelineOptionsJson = new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8); | ||
} | ||
} | ||
} catch (Exception e) { | ||
System.out.format("Problem loading pipeline options from file: %s%n", e.getMessage()); | ||
} | ||
|
||
System.out.format("Pipeline options %s%n", pipelineOptionsJson); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intentionally not using logger? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind, I see it just continued the trend from before. |
||
PipelineOptions options = PipelineOptionsTranslation.fromJson(pipelineOptionsJson); | ||
|
||
Endpoints.ApiServiceDescriptor loggingApiServiceDescriptor = | ||
getApiServiceDescriptor(environmentVarGetter.apply(LOGGING_API_SERVICE_DESCRIPTOR)); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically we're not looking for the file first, so I say the comment needs adjusting. Otherwise LGTM.