You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@paimon.apache.org by ni...@apache.org on 2024/04/10 07:14:13 UTC

(paimon-webui) branch main updated: [Feature] Introduce executor factory provider (#188)

This is an automated email from the ASF dual-hosted git repository.

nicholasjiang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-webui.git


The following commit(s) were added to refs/heads/main by this push:
     new e36b442  [Feature] Introduce executor factory provider (#188)
e36b442 is described below

commit e36b442347576183b42a561cb6836c91c538ee16
Author: s7monk <34...@users.noreply.github.com>
AuthorDate: Wed Apr 10 15:14:09 2024 +0800

    [Feature] Introduce executor factory provider (#188)
---
 paimon-web-gateway/pom.xml                         | 17 +++++--
 .../paimon/web/gateway/config/ExecutionConfig.java | 38 +++++++++++++++
 .../paimon/web/gateway/enums/EngineType.java       | 34 +++++++++++++
 .../gateway/provider/ExecutorFactoryProvider.java  | 44 +++++++++++++++++
 .../provider/ExecutorFactoryProviderTest.java      | 55 ++++++++++++++++++++++
 5 files changed, 183 insertions(+), 5 deletions(-)

diff --git a/paimon-web-gateway/pom.xml b/paimon-web-gateway/pom.xml
index f7af161..3c19e94 100644
--- a/paimon-web-gateway/pom.xml
+++ b/paimon-web-gateway/pom.xml
@@ -31,10 +31,17 @@ under the License.
     <artifactId>paimon-web-gateway</artifactId>
     <name>Paimon : Web : Gateway</name>
 
-    <properties>
-        <maven.compiler.source>8</maven.compiler.source>
-        <maven.compiler.target>8</maven.compiler.target>
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.paimon</groupId>
+            <artifactId>paimon-web-engine-flink-sql-gateway</artifactId>
+            <version>${project.version}</version>
+        </dependency>
 
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
 </project>
\ No newline at end of file
diff --git a/paimon-web-gateway/src/main/java/org/apache/paimon/web/gateway/config/ExecutionConfig.java b/paimon-web-gateway/src/main/java/org/apache/paimon/web/gateway/config/ExecutionConfig.java
new file mode 100644
index 0000000..d926cf2
--- /dev/null
+++ b/paimon-web-gateway/src/main/java/org/apache/paimon/web/gateway/config/ExecutionConfig.java
@@ -0,0 +1,38 @@
+/*
+ * 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.paimon.web.gateway.config;
+
+import org.apache.paimon.web.engine.flink.sql.gateway.model.SessionEntity;
+
+import lombok.Builder;
+import lombok.Getter;
+
+import java.util.Map;
+
+/** Configuration for execution context. */
+@Builder
+@Getter
+public class ExecutionConfig {
+
+    private boolean isStreaming;
+
+    private SessionEntity sessionEntity;
+
+    private Map<String, String> configs;
+}
diff --git a/paimon-web-gateway/src/main/java/org/apache/paimon/web/gateway/enums/EngineType.java b/paimon-web-gateway/src/main/java/org/apache/paimon/web/gateway/enums/EngineType.java
new file mode 100644
index 0000000..1314a38
--- /dev/null
+++ b/paimon-web-gateway/src/main/java/org/apache/paimon/web/gateway/enums/EngineType.java
@@ -0,0 +1,34 @@
+/*
+ * 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.paimon.web.gateway.enums;
+
+/** The {@code EngineType} enum defines the types of engines that can be supported. */
+public enum EngineType {
+    SPARK,
+    FLINK;
+
+    public static EngineType fromName(String name) {
+        for (EngineType type : values()) {
+            if (type.name().equals(name)) {
+                return type;
+            }
+        }
+        throw new IllegalArgumentException("Unknown engine type value: " + name);
+    }
+}
diff --git a/paimon-web-gateway/src/main/java/org/apache/paimon/web/gateway/provider/ExecutorFactoryProvider.java b/paimon-web-gateway/src/main/java/org/apache/paimon/web/gateway/provider/ExecutorFactoryProvider.java
new file mode 100644
index 0000000..ad74633
--- /dev/null
+++ b/paimon-web-gateway/src/main/java/org/apache/paimon/web/gateway/provider/ExecutorFactoryProvider.java
@@ -0,0 +1,44 @@
+/*
+ * 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.paimon.web.gateway.provider;
+
+import org.apache.paimon.web.engine.flink.common.executor.ExecutorFactory;
+import org.apache.paimon.web.engine.flink.sql.gateway.executor.FlinkSqlGatewayExecutorFactory;
+import org.apache.paimon.web.gateway.config.ExecutionConfig;
+import org.apache.paimon.web.gateway.enums.EngineType;
+
+/** ExecutorFactoryProvider is responsible for providing the appropriate ExecutorFactory. */
+public class ExecutorFactoryProvider {
+
+    private final ExecutionConfig executionConfig;
+
+    public ExecutorFactoryProvider(ExecutionConfig executionConfig) {
+        this.executionConfig = executionConfig;
+    }
+
+    public ExecutorFactory getExecutorFactory(EngineType type) {
+        switch (type) {
+            case FLINK:
+                return new FlinkSqlGatewayExecutorFactory(executionConfig.getSessionEntity());
+            default:
+                throw new UnsupportedOperationException(
+                        type + " engine is not currently supported.");
+        }
+    }
+}
diff --git a/paimon-web-gateway/src/test/java/org/apache/paimon/web/gateway/provider/ExecutorFactoryProviderTest.java b/paimon-web-gateway/src/test/java/org/apache/paimon/web/gateway/provider/ExecutorFactoryProviderTest.java
new file mode 100644
index 0000000..89c19b5
--- /dev/null
+++ b/paimon-web-gateway/src/test/java/org/apache/paimon/web/gateway/provider/ExecutorFactoryProviderTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.paimon.web.gateway.provider;
+
+import org.apache.paimon.web.engine.flink.sql.gateway.executor.FlinkSqlGatewayExecutorFactory;
+import org.apache.paimon.web.engine.flink.sql.gateway.model.SessionEntity;
+import org.apache.paimon.web.gateway.config.ExecutionConfig;
+import org.apache.paimon.web.gateway.enums.EngineType;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/** Test for {@link ExecutorFactoryProvider}. */
+public class ExecutorFactoryProviderTest {
+
+    @Test
+    public void testGetExecutorFactoryWithFlink() {
+        ExecutionConfig config =
+                ExecutionConfig.builder().sessionEntity(SessionEntity.builder().build()).build();
+        EngineType engineType = EngineType.fromName("FLINK");
+        ExecutorFactoryProvider executorFactoryProvider = new ExecutorFactoryProvider(config);
+        assertSame(
+                FlinkSqlGatewayExecutorFactory.class,
+                executorFactoryProvider.getExecutorFactory(engineType).getClass());
+    }
+
+    @Test
+    public void testGetExecutorFactoryWithSpark() {
+        ExecutionConfig config =
+                ExecutionConfig.builder().sessionEntity(SessionEntity.builder().build()).build();
+        EngineType engineType = EngineType.fromName("SPARK");
+        ExecutorFactoryProvider executorFactoryProvider = new ExecutorFactoryProvider(config);
+        assertThrows(
+                UnsupportedOperationException.class,
+                () -> executorFactoryProvider.getExecutorFactory(engineType));
+    }
+}