@@ -518,29 +518,15 @@ static boolean isServiceEndpoint(String endpoint) {
518518 }
519519
520520 static void validateSdkContainerImageOptions (DataflowPipelineWorkerPoolOptions workerOptions ) {
521- // Check against null - empty string value for workerHarnessContainerImage
522- // must be preserved for legacy dataflowWorkerJar to work.
523- String sdkContainerOption = workerOptions .getSdkContainerImage ();
524- String workerHarnessOption = workerOptions .getWorkerHarnessContainerImage ();
525- Preconditions .checkArgument (
526- sdkContainerOption == null
527- || workerHarnessOption == null
528- || sdkContainerOption .equals (workerHarnessOption ),
529- "Cannot use legacy option workerHarnessContainerImage with sdkContainerImage. Prefer sdkContainerImage." );
530-
531- // Default to new option, which may be null.
532- String containerImage = workerOptions .getSdkContainerImage ();
533- if (workerOptions .getWorkerHarnessContainerImage () != null
534- && workerOptions .getSdkContainerImage () == null ) {
535- // Set image to old option if old option was set but new option is not set.
521+ if (workerOptions .getSdkContainerImage () != null && workerOptions .getWorkerHarnessContainerImage () != null ) {
536522 LOG .warn (
537- "Prefer --sdkContainerImage over deprecated legacy option --workerHarnessContainerImage." );
538- containerImage = workerOptions .getWorkerHarnessContainerImage ();
523+ "Container specified for both --workerHarnessContainerImage and --sdkContainerImage. "
524+ + "If you are a Beam of Dataflow developer, this could make sense, "
525+ + "but otherwise may be a configuration error. "
526+ + "The value of --workerHarnessContainerImage will be used only if the pipeline runs on Dataflow V1 "
527+ + "and is *not* supported for end users. "
528+ + "The value of --sdkContainerImage will be used only if the pipeline runs on Dataflow V2" );
539529 }
540-
541- // Make sure both options have same value.
542- workerOptions .setSdkContainerImage (containerImage );
543- workerOptions .setWorkerHarnessContainerImage (containerImage );
544530 }
545531
546532 @ VisibleForTesting
@@ -1039,7 +1025,7 @@ protected RunnerApi.Pipeline applySdkEnvironmentOverrides(
10391025 if (containerImage .startsWith ("apache/beam" )
10401026 && !updated
10411027 // don't update if the container image is already configured by DataflowRunner
1042- && !containerImage .equals (getContainerImageForJob (options ))) {
1028+ && !containerImage .equals (getV2SdkHarnessContainerImageForJob (options ))) {
10431029 containerImage =
10441030 DataflowRunnerInfo .getDataflowRunnerInfo ().getContainerImageBaseRepository ()
10451031 + containerImage .substring (containerImage .lastIndexOf ("/" ));
@@ -1290,15 +1276,18 @@ public DataflowPipelineJob run(Pipeline pipeline) {
12901276 + "related to Google Compute Engine usage and other Google Cloud Services." );
12911277
12921278 DataflowPipelineOptions dataflowOptions = options .as (DataflowPipelineOptions .class );
1293- String workerHarnessContainerImageURL = DataflowRunner .getContainerImageForJob (dataflowOptions );
1279+ String v1WorkerContainerImageURL =
1280+ DataflowRunner .getV1WorkerContainerImageForJob (dataflowOptions );
1281+ String v2SdkHarnessContainerImageURL =
1282+ DataflowRunner .getV2SdkHarnessContainerImageForJob (dataflowOptions );
12941283
12951284 // This incorrectly puns the worker harness container image (which implements v1beta3 API)
12961285 // with the SDK harness image (which implements Fn API).
12971286 //
12981287 // The same Environment is used in different and contradictory ways, depending on whether
12991288 // it is a v1 or v2 job submission.
13001289 RunnerApi .Environment defaultEnvironmentForDataflow =
1301- Environments .createDockerEnvironment (workerHarnessContainerImageURL );
1290+ Environments .createDockerEnvironment (v2SdkHarnessContainerImageURL );
13021291
13031292 // The SdkComponents for portable an non-portable job submission must be kept distinct. Both
13041293 // need the default environment.
@@ -1469,7 +1458,7 @@ public DataflowPipelineJob run(Pipeline pipeline) {
14691458 // For runner_v1, only worker_harness_container is set.
14701459 // For runner_v2, both worker_harness_container and sdk_harness_container are set to the same
14711460 // value.
1472- String containerImage = getContainerImageForJob (options );
1461+ String containerImage = getV1WorkerContainerImageForJob (options );
14731462 for (WorkerPool workerPool : newJob .getEnvironment ().getWorkerPools ()) {
14741463 workerPool .setWorkerHarnessContainerImage (containerImage );
14751464 }
@@ -2634,59 +2623,101 @@ public Map<PCollection<?>, ReplacementOutput> mapOutputs(
26342623 }
26352624
26362625 @ VisibleForTesting
2637- static String getContainerImageForJob (DataflowPipelineOptions options ) {
2626+ static String getV1WorkerContainerImageForJob (DataflowPipelineOptions options ) {
2627+ String containerImage = options .getWorkerHarnessContainerImage ();
2628+
2629+ if (containerImage == null ) {
2630+ // If not set, construct and return default image URL.
2631+ return getDefaultV1WorkerContainerImageUrl (options );
2632+ } else if (containerImage .contains ("IMAGE" )) {
2633+ // Replace placeholder with default image name
2634+ return containerImage .replace ("IMAGE" , getDefaultV1WorkerContainerImageNameForJob (options ));
2635+ } else {
2636+ return containerImage ;
2637+ }
2638+ }
2639+
2640+ static String getV2SdkHarnessContainerImageForJob (DataflowPipelineOptions options ) {
26382641 String containerImage = options .getSdkContainerImage ();
26392642
26402643 if (containerImage == null ) {
26412644 // If not set, construct and return default image URL.
2642- return getDefaultContainerImageUrl (options );
2645+ return getDefaultV2SdkHarnessContainerImageUrl (options );
26432646 } else if (containerImage .contains ("IMAGE" )) {
26442647 // Replace placeholder with default image name
2645- return containerImage .replace ("IMAGE" , getDefaultContainerImageNameForJob ( options ));
2648+ return containerImage .replace ("IMAGE" , getDefaultV2SdkHarnessContainerImageNameForJob ( ));
26462649 } else {
26472650 return containerImage ;
26482651 }
26492652 }
26502653
2651- /** Construct the default Dataflow container full image URL. */
2652- static String getDefaultContainerImageUrl (DataflowPipelineOptions options ) {
2654+ /** Construct the default Dataflow worker container full image URL. */
2655+ static String getDefaultV1WorkerContainerImageUrl (DataflowPipelineOptions options ) {
26532656 DataflowRunnerInfo dataflowRunnerInfo = DataflowRunnerInfo .getDataflowRunnerInfo ();
26542657 return String .format (
26552658 "%s/%s:%s" ,
26562659 dataflowRunnerInfo .getContainerImageBaseRepository (),
2657- getDefaultContainerImageNameForJob (options ),
2658- getDefaultContainerVersion (options ));
2660+ getDefaultV1WorkerContainerImageNameForJob (options ),
2661+ getDefaultV1WorkerContainerVersion (options ));
2662+ }
2663+
2664+ /** Construct the default Java SDK container full image URL. */
2665+ static String getDefaultV2SdkHarnessContainerImageUrl (DataflowPipelineOptions options ) {
2666+ DataflowRunnerInfo dataflowRunnerInfo = DataflowRunnerInfo .getDataflowRunnerInfo ();
2667+ return String .format (
2668+ "%s/%s:%s" ,
2669+ dataflowRunnerInfo .getContainerImageBaseRepository (),
2670+ getDefaultV2SdkHarnessContainerImageNameForJob (),
2671+ getDefaultV2SdkHarnessContainerVersion (options ));
26592672 }
26602673
26612674 /**
2662- * Construct the default Dataflow container image name based on pipeline type and Java version.
2675+ * Construct the default Dataflow V1 worker container image name based on pipeline type and Java
2676+ * version.
26632677 */
2664- static String getDefaultContainerImageNameForJob (DataflowPipelineOptions options ) {
2678+ static String getDefaultV1WorkerContainerImageNameForJob (DataflowPipelineOptions options ) {
26652679 Environments .JavaVersion javaVersion = Environments .getJavaVersion ();
2666- if (useUnifiedWorker (options )) {
2667- return String .format ("beam_%s_sdk" , javaVersion .name ());
2668- } else if (options .isStreaming ()) {
2680+ if (options .isStreaming ()) {
26692681 return String .format ("beam-%s-streaming" , javaVersion .legacyName ());
26702682 } else {
26712683 return String .format ("beam-%s-batch" , javaVersion .legacyName ());
26722684 }
26732685 }
26742686
26752687 /**
2676- * Construct the default Dataflow container image name based on pipeline type and Java version.
2688+ * Construct the default Java SDK container image name based on pipeline type and Java version,
2689+ * for use by Dataflow V2.
2690+ */
2691+ static String getDefaultV2SdkHarnessContainerImageNameForJob () {
2692+ Environments .JavaVersion javaVersion = Environments .getJavaVersion ();
2693+ return String .format ("beam_%s_sdk" , javaVersion .name ());
2694+ }
2695+
2696+ /**
2697+ * Construct the default Dataflow V1 worker container image name based on pipeline type and Java
2698+ * version.
26772699 */
2678- static String getDefaultContainerVersion (DataflowPipelineOptions options ) {
2700+ static String getDefaultV1WorkerContainerVersion (DataflowPipelineOptions options ) {
26792701 DataflowRunnerInfo dataflowRunnerInfo = DataflowRunnerInfo .getDataflowRunnerInfo ();
26802702 ReleaseInfo releaseInfo = ReleaseInfo .getReleaseInfo ();
26812703 if (releaseInfo .isDevSdkVersion ()) {
2682- if (useUnifiedWorker (options )) {
2683- return dataflowRunnerInfo .getFnApiDevContainerVersion ();
2684- }
26852704 return dataflowRunnerInfo .getLegacyDevContainerVersion ();
26862705 }
26872706 return releaseInfo .getSdkVersion ();
26882707 }
26892708
2709+ /**
2710+ * Construct the default Dataflow container image name based on pipeline type and Java version.
2711+ */
2712+ static String getDefaultV2SdkHarnessContainerVersion (DataflowPipelineOptions options ) {
2713+ DataflowRunnerInfo dataflowRunnerInfo = DataflowRunnerInfo .getDataflowRunnerInfo ();
2714+ ReleaseInfo releaseInfo = ReleaseInfo .getReleaseInfo ();
2715+ if (releaseInfo .isDevSdkVersion ()) {
2716+ return dataflowRunnerInfo .getFnApiDevContainerVersion ();
2717+ }
2718+ return releaseInfo .getSdkVersion ();
2719+ }
2720+
26902721 static boolean useUnifiedWorker (DataflowPipelineOptions options ) {
26912722 return hasExperiment (options , "beam_fn_api" )
26922723 || hasExperiment (options , "use_runner_v2" )
0 commit comments