From b40ad54daf70a133fb0631020ef34b771b231df7 Mon Sep 17 00:00:00 2001 From: Weimin Yu Date: Thu, 8 May 2025 13:29:30 -0400 Subject: [PATCH] Hardcode beam pipelines to use GKE for tasks (#2753) --- core/build.gradle | 1 + .../RegistryPipelineWorkerInitializer.java | 2 ++ ...RegistryPipelineWorkerInitializerTest.java | 36 +++++++++++++++++++ .../registry/util/RegistryEnvironment.java | 6 ++-- 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 core/src/test/java/google/registry/beam/common/RegistryPipelineWorkerInitializerTest.java diff --git a/core/build.gradle b/core/build.gradle index c715f748c..cdb1d3188 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -61,6 +61,7 @@ def fragileTestPatterns = [ // Currently changes a global configuration parameter that for some reason // results in timestamp inversions for other tests. TODO(mmuller): fix. "google/registry/flows/host/HostInfoFlowTest.*", + "google/registry/beam/common/RegistryPipelineWorkerInitializerTest.*", ] + dockerIncompatibleTestPatterns sourceSets { diff --git a/core/src/main/java/google/registry/beam/common/RegistryPipelineWorkerInitializer.java b/core/src/main/java/google/registry/beam/common/RegistryPipelineWorkerInitializer.java index 5dd54019b..7b98135f6 100644 --- a/core/src/main/java/google/registry/beam/common/RegistryPipelineWorkerInitializer.java +++ b/core/src/main/java/google/registry/beam/common/RegistryPipelineWorkerInitializer.java @@ -40,6 +40,8 @@ public class RegistryPipelineWorkerInitializer implements JvmInitializer { @Override public void beforeProcessing(PipelineOptions options) { + // TODO(b/416299900): remove next line after GAE is removed. + System.setProperty("google.registry.jetty", "true"); RegistryPipelineOptions registryOptions = options.as(RegistryPipelineOptions.class); RegistryEnvironment environment = registryOptions.getRegistryEnvironment(); if (environment == null || environment.equals(RegistryEnvironment.UNITTEST)) { diff --git a/core/src/test/java/google/registry/beam/common/RegistryPipelineWorkerInitializerTest.java b/core/src/test/java/google/registry/beam/common/RegistryPipelineWorkerInitializerTest.java new file mode 100644 index 000000000..16a084ece --- /dev/null +++ b/core/src/test/java/google/registry/beam/common/RegistryPipelineWorkerInitializerTest.java @@ -0,0 +1,36 @@ +// Copyright 2025 The Nomulus Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package google.registry.beam.common; + +import static com.google.common.truth.Truth.assertThat; + +import google.registry.util.RegistryEnvironment; +import org.apache.beam.sdk.options.PipelineOptionsFactory; +import org.junit.jupiter.api.Test; + +public class RegistryPipelineWorkerInitializerTest { + + @Test + void test() { + RegistryPipelineOptions options = + PipelineOptionsFactory.fromArgs( + "--registryEnvironment=ALPHA", "--isolationOverride=TRANSACTION_SERIALIZABLE") + .withValidation() + .as(RegistryPipelineOptions.class); + new RegistryPipelineWorkerInitializer().beforeProcessing(options); + assertThat(RegistryEnvironment.isOnJetty()).isTrue(); + System.clearProperty("google.registry.jetty"); + } +} diff --git a/util/src/main/java/google/registry/util/RegistryEnvironment.java b/util/src/main/java/google/registry/util/RegistryEnvironment.java index 2af902ad6..819efaa0b 100644 --- a/util/src/main/java/google/registry/util/RegistryEnvironment.java +++ b/util/src/main/java/google/registry/util/RegistryEnvironment.java @@ -61,9 +61,6 @@ public enum RegistryEnvironment { /** Name of the environmental variable of the container name. */ private static final String CONTAINER_ENV = "CONTAINER_NAME"; - private static final boolean ON_JETTY = - Boolean.parseBoolean(System.getProperty(JETTY_PROPERTY, "false")); - private static final boolean IS_CANARY = System.getenv().getOrDefault(CONTAINER_ENV, "").endsWith("-canary"); @@ -100,8 +97,9 @@ public enum RegistryEnvironment { return valueOf(Ascii.toUpperCase(System.getProperty(PROPERTY, UNITTEST.name()))); } + // TODO(b/416299900): remove method after GAE is removed. public static boolean isOnJetty() { - return ON_JETTY; + return Boolean.parseBoolean(System.getProperty(JETTY_PROPERTY, "false")); } public static boolean isCanary() {