You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/04/06 07:08:13 UTC

[GitHub] [flink-kubernetes-operator] wangyang0918 commented on a diff in pull request #141: [FLINK-26894] Support custom validator implementations

wangyang0918 commented on code in PR #141:
URL: https://github.com/apache/flink-kubernetes-operator/pull/141#discussion_r843537011


##########
flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/utils/ValidatorUtilsTest.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.kubernetes.operator.utils;
+
+import org.apache.flink.configuration.ConfigConstants;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.kubernetes.operator.TestUtils;
+import org.apache.flink.kubernetes.operator.validation.DefaultValidator;
+import org.apache.flink.kubernetes.operator.validation.FlinkResourceValidator;
+import org.apache.flink.kubernetes.operator.validation.TestValidator;
+import org.apache.flink.util.Preconditions;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/** Test class for {@link ValidatorUtils}. */
+public class ValidatorUtilsTest {
+
+    @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+    private static final String VALIDATOR_NAME = "test-validator";
+    private static final String VALIDATOR_JAR = VALIDATOR_NAME + "-test-jar.jar";
+
+    @Test
+    public void testDiscoverValidators() throws IOException {
+        File validatorRootFolder = temporaryFolder.newFolder();
+        File testValidatorFolder = new File(validatorRootFolder, VALIDATOR_NAME);
+        Preconditions.checkState(testValidatorFolder.mkdirs());

Review Comment:
   Use assert instead of `Preconditions` in the tests.



##########
flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/utils/ValidatorUtilsTest.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.kubernetes.operator.utils;
+
+import org.apache.flink.configuration.ConfigConstants;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.kubernetes.operator.TestUtils;
+import org.apache.flink.kubernetes.operator.validation.DefaultValidator;
+import org.apache.flink.kubernetes.operator.validation.FlinkResourceValidator;
+import org.apache.flink.kubernetes.operator.validation.TestValidator;
+import org.apache.flink.util.Preconditions;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/** Test class for {@link ValidatorUtils}. */
+public class ValidatorUtilsTest {
+
+    @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+    private static final String VALIDATOR_NAME = "test-validator";
+    private static final String VALIDATOR_JAR = VALIDATOR_NAME + "-test-jar.jar";
+
+    @Test
+    public void testDiscoverValidators() throws IOException {
+        File validatorRootFolder = temporaryFolder.newFolder();
+        File testValidatorFolder = new File(validatorRootFolder, VALIDATOR_NAME);
+        Preconditions.checkState(testValidatorFolder.mkdirs());
+        File testValidatorJar = new File("target", VALIDATOR_JAR);
+        Preconditions.checkState(
+                testValidatorJar.exists(),
+                "Unable to locate jar file for test: " + testValidatorJar);
+        Files.copy(
+                testValidatorJar.toPath(),
+                Paths.get(testValidatorFolder.toString(), VALIDATOR_JAR));
+        Map<String, String> systemEnv = new HashMap<>(System.getenv());
+        systemEnv.put(ConfigConstants.ENV_FLINK_PLUGINS_DIR, validatorRootFolder.getPath());
+        TestUtils.setEnv(systemEnv);

Review Comment:
   We need to restore the old env after this test. Otherwise, we will have some strange unstable tests in the future.



##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/FlinkOperator.java:
##########
@@ -75,10 +77,10 @@ public FlinkOperator(DefaultConfig defaultConfig) {
         this.configurationService = getConfigurationService(operatorConfiguration);
         this.operator = new Operator(client, configurationService);
         this.flinkService = new FlinkService(client, operatorConfiguration);
+        this.validators = ValidatorUtils.discoverValidators(defaultConfig.getFlinkConfig());

Review Comment:
   If will be great if we could log the discovered validator.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org