@@ -518,29 +518,16 @@ 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
522+ && workerOptions .getWorkerHarnessContainerImage () != null ) {
536523 LOG .warn (
537- "Prefer --sdkContainerImage over deprecated legacy option --workerHarnessContainerImage." );
538- containerImage = workerOptions .getWorkerHarnessContainerImage ();
524+ "Container specified for both --workerHarnessContainerImage and --sdkContainerImage. "
525+ + "If you are a Beam of Dataflow developer, this could make sense, "
526+ + "but otherwise may be a configuration error. "
527+ + "The value of --workerHarnessContainerImage will be used only if the pipeline runs on Dataflow V1 "
528+ + "and is *not* supported for end users. "
529+ + "The value of --sdkContainerImage will be used only if the pipeline runs on Dataflow V2" );
539530 }
540-
541- // Make sure both options have same value.
542- workerOptions .setSdkContainerImage (containerImage );
543- workerOptions .setWorkerHarnessContainerImage (containerImage );
544531 }
545532
546533 @ VisibleForTesting
@@ -1039,7 +1026,7 @@ protected RunnerApi.Pipeline applySdkEnvironmentOverrides(
10391026 if (containerImage .startsWith ("apache/beam" )
10401027 && !updated
10411028 // don't update if the container image is already configured by DataflowRunner
1042- && !containerImage .equals (getContainerImageForJob (options ))) {
1029+ && !containerImage .equals (getV2SdkHarnessContainerImageForJob (options ))) {
10431030 containerImage =
10441031 DataflowRunnerInfo .getDataflowRunnerInfo ().getContainerImageBaseRepository ()
10451032 + containerImage .substring (containerImage .lastIndexOf ("/" ));
@@ -1290,15 +1277,18 @@ public DataflowPipelineJob run(Pipeline pipeline) {
12901277 + "related to Google Compute Engine usage and other Google Cloud Services." );
12911278
12921279 DataflowPipelineOptions dataflowOptions = options .as (DataflowPipelineOptions .class );
1293- String workerHarnessContainerImageURL = DataflowRunner .getContainerImageForJob (dataflowOptions );
1280+ String v1WorkerContainerImageURL =
1281+ DataflowRunner .getV1WorkerContainerImageForJob (dataflowOptions );
1282+ String v2SdkHarnessContainerImageURL =
1283+ DataflowRunner .getV2SdkHarnessContainerImageForJob (dataflowOptions );
12941284
12951285 // This incorrectly puns the worker harness container image (which implements v1beta3 API)
12961286 // with the SDK harness image (which implements Fn API).
12971287 //
12981288 // The same Environment is used in different and contradictory ways, depending on whether
12991289 // it is a v1 or v2 job submission.
13001290 RunnerApi .Environment defaultEnvironmentForDataflow =
1301- Environments .createDockerEnvironment (workerHarnessContainerImageURL );
1291+ Environments .createDockerEnvironment (v2SdkHarnessContainerImageURL );
13021292
13031293 // The SdkComponents for portable an non-portable job submission must be kept distinct. Both
13041294 // need the default environment.
@@ -1469,7 +1459,7 @@ public DataflowPipelineJob run(Pipeline pipeline) {
14691459 // For runner_v1, only worker_harness_container is set.
14701460 // For runner_v2, both worker_harness_container and sdk_harness_container are set to the same
14711461 // value.
1472- String containerImage = getContainerImageForJob (options );
1462+ String containerImage = getV1WorkerContainerImageForJob (options );
14731463 for (WorkerPool workerPool : newJob .getEnvironment ().getWorkerPools ()) {
14741464 workerPool .setWorkerHarnessContainerImage (containerImage );
14751465 }
@@ -2634,59 +2624,101 @@ public Map<PCollection<?>, ReplacementOutput> mapOutputs(
26342624 }
26352625
26362626 @ VisibleForTesting
2637- static String getContainerImageForJob (DataflowPipelineOptions options ) {
2627+ static String getV1WorkerContainerImageForJob (DataflowPipelineOptions options ) {
2628+ String containerImage = options .getWorkerHarnessContainerImage ();
2629+
2630+ if (containerImage == null ) {
2631+ // If not set, construct and return default image URL.
2632+ return getDefaultV1WorkerContainerImageUrl (options );
2633+ } else if (containerImage .contains ("IMAGE" )) {
2634+ // Replace placeholder with default image name
2635+ return containerImage .replace ("IMAGE" , getDefaultV1WorkerContainerImageNameForJob (options ));
2636+ } else {
2637+ return containerImage ;
2638+ }
2639+ }
2640+
2641+ static String getV2SdkHarnessContainerImageForJob (DataflowPipelineOptions options ) {
26382642 String containerImage = options .getSdkContainerImage ();
26392643
26402644 if (containerImage == null ) {
26412645 // If not set, construct and return default image URL.
2642- return getDefaultContainerImageUrl (options );
2646+ return getDefaultV2SdkHarnessContainerImageUrl (options );
26432647 } else if (containerImage .contains ("IMAGE" )) {
26442648 // Replace placeholder with default image name
2645- return containerImage .replace ("IMAGE" , getDefaultContainerImageNameForJob ( options ));
2649+ return containerImage .replace ("IMAGE" , getDefaultV2SdkHarnessContainerImageNameForJob ( ));
26462650 } else {
26472651 return containerImage ;
26482652 }
26492653 }
26502654
2651- /** Construct the default Dataflow container full image URL. */
2652- static String getDefaultContainerImageUrl (DataflowPipelineOptions options ) {
2655+ /** Construct the default Dataflow worker container full image URL. */
2656+ static String getDefaultV1WorkerContainerImageUrl (DataflowPipelineOptions options ) {
26532657 DataflowRunnerInfo dataflowRunnerInfo = DataflowRunnerInfo .getDataflowRunnerInfo ();
26542658 return String .format (
26552659 "%s/%s:%s" ,
26562660 dataflowRunnerInfo .getContainerImageBaseRepository (),
2657- getDefaultContainerImageNameForJob (options ),
2658- getDefaultContainerVersion (options ));
2661+ getDefaultV1WorkerContainerImageNameForJob (options ),
2662+ getDefaultV1WorkerContainerVersion (options ));
2663+ }
2664+
2665+ /** Construct the default Java SDK container full image URL. */
2666+ static String getDefaultV2SdkHarnessContainerImageUrl (DataflowPipelineOptions options ) {
2667+ DataflowRunnerInfo dataflowRunnerInfo = DataflowRunnerInfo .getDataflowRunnerInfo ();
2668+ return String .format (
2669+ "%s/%s:%s" ,
2670+ dataflowRunnerInfo .getContainerImageBaseRepository (),
2671+ getDefaultV2SdkHarnessContainerImageNameForJob (),
2672+ getDefaultV2SdkHarnessContainerVersion (options ));
26592673 }
26602674
26612675 /**
2662- * Construct the default Dataflow container image name based on pipeline type and Java version.
2676+ * Construct the default Dataflow V1 worker container image name based on pipeline type and Java
2677+ * version.
26632678 */
2664- static String getDefaultContainerImageNameForJob (DataflowPipelineOptions options ) {
2679+ static String getDefaultV1WorkerContainerImageNameForJob (DataflowPipelineOptions options ) {
26652680 Environments .JavaVersion javaVersion = Environments .getJavaVersion ();
2666- if (useUnifiedWorker (options )) {
2667- return String .format ("beam_%s_sdk" , javaVersion .name ());
2668- } else if (options .isStreaming ()) {
2681+ if (options .isStreaming ()) {
26692682 return String .format ("beam-%s-streaming" , javaVersion .legacyName ());
26702683 } else {
26712684 return String .format ("beam-%s-batch" , javaVersion .legacyName ());
26722685 }
26732686 }
26742687
26752688 /**
2676- * Construct the default Dataflow container image name based on pipeline type and Java version.
2689+ * Construct the default Java SDK container image name based on pipeline type and Java version,
2690+ * for use by Dataflow V2.
2691+ */
2692+ static String getDefaultV2SdkHarnessContainerImageNameForJob () {
2693+ Environments .JavaVersion javaVersion = Environments .getJavaVersion ();
2694+ return String .format ("beam_%s_sdk" , javaVersion .name ());
2695+ }
2696+
2697+ /**
2698+ * Construct the default Dataflow V1 worker container image name based on pipeline type and Java
2699+ * version.
26772700 */
2678- static String getDefaultContainerVersion (DataflowPipelineOptions options ) {
2701+ static String getDefaultV1WorkerContainerVersion (DataflowPipelineOptions options ) {
26792702 DataflowRunnerInfo dataflowRunnerInfo = DataflowRunnerInfo .getDataflowRunnerInfo ();
26802703 ReleaseInfo releaseInfo = ReleaseInfo .getReleaseInfo ();
26812704 if (releaseInfo .isDevSdkVersion ()) {
2682- if (useUnifiedWorker (options )) {
2683- return dataflowRunnerInfo .getFnApiDevContainerVersion ();
2684- }
26852705 return dataflowRunnerInfo .getLegacyDevContainerVersion ();
26862706 }
26872707 return releaseInfo .getSdkVersion ();
26882708 }
26892709
2710+ /**
2711+ * Construct the default Dataflow container image name based on pipeline type and Java version.
2712+ */
2713+ static String getDefaultV2SdkHarnessContainerVersion (DataflowPipelineOptions options ) {
2714+ DataflowRunnerInfo dataflowRunnerInfo = DataflowRunnerInfo .getDataflowRunnerInfo ();
2715+ ReleaseInfo releaseInfo = ReleaseInfo .getReleaseInfo ();
2716+ if (releaseInfo .isDevSdkVersion ()) {
2717+ return dataflowRunnerInfo .getFnApiDevContainerVersion ();
2718+ }
2719+ return releaseInfo .getSdkVersion ();
2720+ }
2721+
26902722 static boolean useUnifiedWorker (DataflowPipelineOptions options ) {
26912723 return hasExperiment (options , "beam_fn_api" )
26922724 || hasExperiment (options , "use_runner_v2" )
0 commit comments