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/10/10 08:00:58 UTC

[GitHub] [flink] martin-g commented on a diff in pull request #20636: [FLINK-28831][k8s]Support pluginable decorators mechanism - part 1st

martin-g commented on code in PR #20636:
URL: https://github.com/apache/flink/pull/20636#discussion_r991002281


##########
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/decorators/extended/ExtPluginDecorator.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * 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.kubeclient.decorators.extended;
+
+import org.apache.flink.kubernetes.kubeclient.decorators.KubernetesStepDecorator;
+import org.apache.flink.kubernetes.kubeclient.parameters.AbstractKubernetesParameters;
+
+/** The interface class which should be implemented by plugin decorators. */
+public interface ExtPluginDecorator extends KubernetesStepDecorator {

Review Comment:
   I found the meaning in the package name - `extended`



##########
flink-kubernetes/src/test/assembly/test-ext-decorator-assembly.xml:
##########
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<assembly>
+	<id>test-jar</id>
+	<formats>
+		<format>jar</format>
+	</formats>
+	<includeBaseDirectory>false</includeBaseDirectory>
+	<fileSets>
+		<fileSet>
+			<directory>${project.build.testOutputDirectory}</directory>
+			<outputDirectory>/</outputDirectory>
+			<!-- the service impl -->
+			<includes>
+				<include>org/apache/flink/kubernetes/kubeclient/decorators/extended/ExtTestDecorator.class</include>
+			</includes>
+		</fileSet>
+		<fileSet>
+			<!-- declaring the service impl -->
+			<directory>${project.basedir}/src/test/resources/META-INF/services/*ExtPluginDecorator*</directory>

Review Comment:
   Why not use the exact file name instead of the glob pattern ?
   Do you expect to have more than one `ExtPluginDecorator` in different packages ?



##########
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/decorators/extended/ExtPluginDecorator.java:
##########
@@ -0,0 +1,27 @@
+/*
+ * 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.kubeclient.decorators.extended;
+
+import org.apache.flink.kubernetes.kubeclient.decorators.KubernetesStepDecorator;
+import org.apache.flink.kubernetes.kubeclient.parameters.AbstractKubernetesParameters;
+
+/** The interface class which should be implemented by plugin decorators. */
+public interface ExtPluginDecorator extends KubernetesStepDecorator {

Review Comment:
   What is the meaning of `Ext` in the class name ?
   Either expand the class name or explain/mention the fullname in the javadoc.



##########
flink-kubernetes/src/test/java/org/apache/flink/kubernetes/kubeclient/decorators/ExtStepDecoratorUtilsTest.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.kubeclient.decorators;
+
+import org.apache.flink.client.deployment.ClusterSpecification;
+import org.apache.flink.configuration.ConfigConstants;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.core.testutils.CommonTestUtils;
+import org.apache.flink.kubernetes.kubeclient.decorators.extended.ExtTestDecorator;
+import org.apache.flink.kubernetes.kubeclient.parameters.KubernetesJobManagerParameters;
+
+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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/** The test class for {@link ExtStepDecoratorUtils}. */
+public class ExtStepDecoratorUtilsTest {
+    @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+    private static final String EXT_DECORATOR_NAME = "ext-decorator";
+    private static final String EXT_JAR = EXT_DECORATOR_NAME + "-test-jar.jar";
+
+    @Test
+    public void testLoadExtStepDecorators() throws IOException {
+        File testRootFolder = temporaryFolder.newFolder();
+        File testPluginFolder = new File(testRootFolder, EXT_DECORATOR_NAME);
+        assertTrue(testPluginFolder.mkdirs());
+        File testPluginJar = new File("target", EXT_JAR);
+        assertTrue(testPluginJar.exists());
+        Files.copy(testPluginJar.toPath(), Paths.get(testPluginFolder.toString(), EXT_JAR));
+        Map<String, String> oriEnv = System.getenv();

Review Comment:
   ```suggestion
           Map<String, String> origEnv = System.getenv();
   ```



##########
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/decorators/ExtStepDecoratorUtils.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.kubeclient.decorators;
+
+import org.apache.flink.core.plugin.PluginManager;
+import org.apache.flink.core.plugin.PluginUtils;
+import org.apache.flink.kubernetes.kubeclient.decorators.extended.ExtPluginDecorator;
+import org.apache.flink.kubernetes.kubeclient.parameters.AbstractKubernetesParameters;
+
+import org.apache.flink.shaded.guava30.com.google.common.collect.Iterators;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceLoader;
+
+/** The flink-kubernetes decorator plugins loading class. */
+public class ExtStepDecoratorUtils {
+    private static final Logger LOG = LoggerFactory.getLogger(ExtStepDecoratorUtils.class);
+
+    public static List<ExtPluginDecorator> loadExtStepDecorators(
+            AbstractKubernetesParameters kubernetesComponentConf) {
+        List<ExtPluginDecorator> extendedStepDecorators = new ArrayList<>();
+        Map<String, ExtPluginDecorator> decoratorFactories = new HashMap<>();
+        PluginManager pluginManager =
+                PluginUtils.createPluginManagerFromRootFolder(
+                        kubernetesComponentConf.getFlinkConfiguration());
+
+        // get all factories
+        Iterator<ExtPluginDecorator> factoryIteratorSPI =
+                ServiceLoader.load(ExtPluginDecorator.class).iterator();
+        Iterator<ExtPluginDecorator> factoryIteratorPlugins =
+                pluginManager != null
+                        ? pluginManager.load(ExtPluginDecorator.class)
+                        : Collections.emptyIterator();
+        Iterator<ExtPluginDecorator> factoryIterator =
+                Iterators.concat(factoryIteratorPlugins, factoryIteratorSPI);
+        while (factoryIterator.hasNext()) {
+            try {
+                ExtPluginDecorator factory = factoryIterator.next();
+                factory.configure(kubernetesComponentConf);
+                String factoryClassName = factory.getClass().getName();
+                ExtPluginDecorator existingFactory = decoratorFactories.get(factoryClassName);
+                if (existingFactory == null) {
+                    decoratorFactories.put(factoryClassName, factory);
+                    Collections.addAll(extendedStepDecorators, factory);
+                    LOG.info("Load ext plugin step decorator: {}.", factoryClassName);
+                }
+            } catch (Exception e) {
+                LOG.error("Loading ext plugin step decorator Failed: {}", e.getStackTrace());

Review Comment:
   ```suggestion
                   LOG.error("Loading ext plugin step decorator failed: {}", e.getMessage(), 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: issues-unsubscribe@flink.apache.org

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