1996fanrui commented on code in PR #26713:
URL: https://github.com/apache/flink/pull/26713#discussion_r2187625192


##########
flink-architecture-tests/flink-architecture-tests-production/src/main/java/org/apache/flink/architecture/rules/CheckpointingConfigurationAccessRules.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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.architecture.rules;
+
+import com.tngtech.archunit.base.DescribedPredicate;
+import com.tngtech.archunit.core.domain.JavaFieldAccess;
+import com.tngtech.archunit.core.domain.JavaMethodCall;
+import com.tngtech.archunit.junit.ArchTest;
+import com.tngtech.archunit.lang.ArchRule;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
+
+/**
+ * Architecture rules to prevent direct access to certain checkpointing 
configuration options. These
+ * rules help ensure that helper methods with proper validation logic are used 
instead of direct
+ * Configuration.get() or getOptional() calls.
+ */
+public class CheckpointingConfigurationAccessRules {
+
+    private static final String CHECKPOINTING_OPTIONS_CLASS =
+            "org.apache.flink.configuration.CheckpointingOptions";
+
+    // Prohibited configuration fields that should not be used with 
Configuration.get() or
+    // Configuration.getOptional()
+    private static final Set<String> PROHIBITED_CONFIG_FIELDS =
+            new HashSet<>(
+                    Arrays.asList(
+                            "ENABLE_UNALIGNED",
+                            "CHECKPOINTING_CONSISTENCY_MODE",
+                            "ENABLE_UNALIGNED_INTERRUPTIBLE_TIMERS"));

Review Comment:
   Good suggestion!
   
   Class can be easily converted into a String name, for example: 
`CheckpointingOptions.class.getName();`. But Java variable and method names are 
difficult to convert directly into String names. I used reflection to load 
variables and methods, and an exception will be thrown if the loading fails. 
(This arch test will be failed if these variables or methods are removed in the 
future.)
   
   Following is a demo:
   
   ```
       private static Set<String> getProhibitedFieldNames() {
           try {
               return new HashSet<>(
                       Arrays.asList(
                               
CheckpointingOptions.class.getField("ENABLE_UNALIGNED").getName(),
                               CheckpointingOptions.class
                                       
.getField("CHECKPOINTING_CONSISTENCY_MODE")
                                       .getName(),
                               CheckpointingOptions.class
                                       
.getField("ENABLE_UNALIGNED_INTERRUPTIBLE_TIMERS")
                                       .getName()));
           } catch (NoSuchFieldException e) {
               // This makes the test class fail to load if a field is ever 
renamed.
               throw new ExceptionInInitializerError(e);
           }
       }
   ```



-- 
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