Java Code Examples for org.apache.beam.sdk.extensions.gcp.options.GcpOptions#setWorkerZone()

The following examples show how to use org.apache.beam.sdk.extensions.gcp.options.GcpOptions#setWorkerZone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataflowRunner.java    From beam with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static void validateWorkerSettings(GcpOptions gcpOptions) {
  Preconditions.checkArgument(
      gcpOptions.getZone() == null || gcpOptions.getWorkerRegion() == null,
      "Cannot use option zone with workerRegion. Prefer either workerZone or workerRegion.");
  Preconditions.checkArgument(
      gcpOptions.getZone() == null || gcpOptions.getWorkerZone() == null,
      "Cannot use option zone with workerZone. Prefer workerZone.");
  Preconditions.checkArgument(
      gcpOptions.getWorkerRegion() == null || gcpOptions.getWorkerZone() == null,
      "workerRegion and workerZone options are mutually exclusive.");

  DataflowPipelineOptions dataflowOptions = gcpOptions.as(DataflowPipelineOptions.class);
  boolean hasExperimentWorkerRegion = false;
  if (dataflowOptions.getExperiments() != null) {
    for (String experiment : dataflowOptions.getExperiments()) {
      if (experiment.startsWith("worker_region")) {
        hasExperimentWorkerRegion = true;
        break;
      }
    }
  }
  Preconditions.checkArgument(
      !hasExperimentWorkerRegion || gcpOptions.getWorkerRegion() == null,
      "Experiment worker_region and option workerRegion are mutually exclusive.");
  Preconditions.checkArgument(
      !hasExperimentWorkerRegion || gcpOptions.getWorkerZone() == null,
      "Experiment worker_region and option workerZone are mutually exclusive.");

  if (gcpOptions.getZone() != null) {
    LOG.warn("Option --zone is deprecated. Please use --workerZone instead.");
    gcpOptions.setWorkerZone(gcpOptions.getZone());
    gcpOptions.setZone(null);
  }
}
 
Example 2
Source File: DataflowRunnerTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testZoneAndWorkerZoneMutuallyExclusive() {
  GcpOptions options = PipelineOptionsFactory.as(GcpOptions.class);
  options.setZone("us-east1-b");
  options.setWorkerZone("us-east1-c");
  assertThrows(
      IllegalArgumentException.class, () -> DataflowRunner.validateWorkerSettings(options));
}
 
Example 3
Source File: DataflowRunnerTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testExperimentRegionAndWorkerZoneMutuallyExclusive() {
  GcpOptions options = PipelineOptionsFactory.as(GcpOptions.class);
  DataflowPipelineOptions dataflowOptions = options.as(DataflowPipelineOptions.class);
  ExperimentalOptions.addExperiment(dataflowOptions, "worker_region=us-west1");
  options.setWorkerZone("us-east1-b");
  assertThrows(
      IllegalArgumentException.class, () -> DataflowRunner.validateWorkerSettings(options));
}
 
Example 4
Source File: DataflowRunnerTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testWorkerRegionAndWorkerZoneMutuallyExclusive() {
  GcpOptions options = PipelineOptionsFactory.as(GcpOptions.class);
  options.setWorkerRegion("us-east1");
  options.setWorkerZone("us-east1-b");
  assertThrows(
      IllegalArgumentException.class, () -> DataflowRunner.validateWorkerSettings(options));
}