zhuzhurk commented on code in PR #27324:
URL: https://github.com/apache/flink/pull/27324#discussion_r2647488085


##########
flink-clients/src/main/java/org/apache/flink/client/deployment/application/ApplicationJobUtils.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.flink.client.deployment.application;
+
+import org.apache.flink.api.common.ApplicationID;
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.configuration.ApplicationOptionsInternal;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.HighAvailabilityOptions;
+import org.apache.flink.configuration.PipelineOptionsInternal;
+import org.apache.flink.runtime.jobmanager.HighAvailabilityMode;
+import org.apache.flink.util.Preconditions;
+
+import java.util.Optional;
+
+/** Utility class to handle application/job related configuration options in 
application mode. */
+public class ApplicationJobUtils {
+
+    public static void maybeFixIds(Configuration configuration) {

Review Comment:
   Let's better to add some comments to explain the purpose and behavior of 
this method, because it is not straightforward.



##########
flink-clients/src/test/java/org/apache/flink/client/deployment/application/ApplicationJobUtilsTest.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.flink.client.deployment.application;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.configuration.ApplicationOptionsInternal;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.HighAvailabilityOptions;
+import org.apache.flink.configuration.PipelineOptionsInternal;
+import org.apache.flink.runtime.jobmanager.HighAvailabilityMode;
+import org.apache.flink.util.AbstractID;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import javax.annotation.Nullable;
+
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/** Tests for {@link ApplicationJobUtils}. */
+public class ApplicationJobUtilsTest {
+
+    private static final String TEST_HA_CLUSTER_ID = "cluster";
+    private static final String TEST_APPLICATION_ID = 
"ca0eb040022fbccd4cf05d1e274ae25e";
+    private static final String TEST_JOB_ID = 
"e79b6d171acd4baa6f421e3631168810";
+
+    private Configuration configuration;
+
+    @BeforeEach
+    void setUp() {
+        configuration = new Configuration();
+    }
+
+    @ParameterizedTest
+    @MethodSource("provideParametersForMaybeFixIds")
+    void testMaybeFixIds(
+            boolean isHAEnabled,
+            boolean isHaClusterIdSet,
+            boolean isApplicationIdSet,
+            boolean isJobIdSet,
+            @Nullable String expectedApplicationId,
+            @Nullable String expectedJobId) {
+        if (isHAEnabled) {
+            configuration.set(
+                    HighAvailabilityOptions.HA_MODE, 
HighAvailabilityMode.ZOOKEEPER.name());
+        }
+        if (isHaClusterIdSet) {
+            configuration.set(HighAvailabilityOptions.HA_CLUSTER_ID, 
TEST_HA_CLUSTER_ID);
+        }
+        if (isApplicationIdSet) {
+            configuration.set(ApplicationOptionsInternal.FIXED_APPLICATION_ID, 
TEST_APPLICATION_ID);
+        }
+        if (isJobIdSet) {
+            configuration.set(PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID, 
TEST_JOB_ID);
+        }
+
+        ApplicationJobUtils.maybeFixIds(configuration);
+
+        assertEquals(
+                expectedApplicationId,
+                
configuration.get(ApplicationOptionsInternal.FIXED_APPLICATION_ID));
+
+        assertEquals(
+                expectedJobId, 
configuration.get(PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID));
+    }
+
+    private static Stream<Arguments> provideParametersForMaybeFixIds() {
+        // all combinations for the five input: (isHAEnabled, 
isHaClusterIdSet, isApplicationIdSet,
+        // isJobIdSet)
+        return Stream.of(
+                Arguments.of(false, false, false, false, null, null),

Review Comment:
   Finally in the application execution what will the applicationId and JobId 
be like?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to