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 5cd7d51a [Feature] Support integrated frontend deployment (#307)
5cd7d51a is described below
commit 5cd7d51abe36dd7e18c3913fb3e4e96da2fe85e7
Author: yangyang zhong <[email protected]>
AuthorDate: Thu Jun 13 19:22:23 2024 +0800
[Feature] Support integrated frontend deployment (#307)
---
paimon-web-server/pom.xml | 15 +++++-
.../web/server/configrue/AppConfiguration.java | 43 ++++++++++++++++++
.../controller/PaimonWebErrorController.java | 49 ++++++++++++++++++++
.../controller/PaimonWebErrorControllerTest.java | 53 ++++++++++++++++++++++
4 files changed, 159 insertions(+), 1 deletion(-)
diff --git a/paimon-web-server/pom.xml b/paimon-web-server/pom.xml
index 3597573d..72c092dd 100644
--- a/paimon-web-server/pom.xml
+++ b/paimon-web-server/pom.xml
@@ -257,6 +257,13 @@ under the License.
<include>sql/**</include>
</includes>
</testResource>
+ <testResource>
+
<directory>${project.basedir}/../paimon-web-ui/dist/</directory>
+ <includes>
+ <include>**</include>
+ </includes>
+ <targetPath>ui</targetPath>
+ </testResource>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
@@ -270,7 +277,13 @@ under the License.
<exclude>static/**</exclude>
</excludes>
</resource>
-
+ <resource>
+
<directory>${project.basedir}/../paimon-web-ui/dist/</directory>
+ <includes>
+ <include>**</include>
+ </includes>
+ <targetPath>ui</targetPath>
+ </resource>
<resource>
<filtering>false</filtering>
<directory>src/main/resources</directory>
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/AppConfiguration.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/AppConfiguration.java
new file mode 100644
index 00000000..4334e357
--- /dev/null
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/AppConfiguration.java
@@ -0,0 +1,43 @@
+/*
+ * 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.server.configrue;
+
+import org.springframework.context.annotation.Configuration;
+import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import
org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+import java.util.Optional;
+
+/** AppConfiguration. */
+@Configuration
+public class AppConfiguration implements WebMvcConfigurer {
+
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ String uiPath =
Optional.ofNullable(System.getenv("UI_PATH")).orElse("file:ui/");
+ registry.addResourceHandler("/ui/**").addResourceLocations(uiPath);
+ }
+
+ @Override
+ public void addViewControllers(ViewControllerRegistry registry) {
+ registry.addViewController("/").setViewName("redirect:/ui/");
+
registry.addViewController("/ui/").setViewName("forward:/ui/index.html");
+ }
+}
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/PaimonWebErrorController.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/PaimonWebErrorController.java
new file mode 100644
index 00000000..690b340b
--- /dev/null
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/PaimonWebErrorController.java
@@ -0,0 +1,49 @@
+/*
+ * 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.server.controller;
+
+import org.springframework.boot.web.servlet.error.ErrorController;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.http.HttpServletRequest;
+
+/** PaimonWebErrorController. */
+@Controller
+public class PaimonWebErrorController implements ErrorController {
+
+ @RequestMapping("/error")
+ public ModelAndView handleError(HttpServletRequest request) {
+ Object status =
request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
+ ModelAndView modelAndView = new ModelAndView();
+ if (status != null) {
+ Integer statusCode = Integer.valueOf(status.toString());
+ if (statusCode == HttpStatus.NOT_FOUND.value()) {
+ modelAndView.setStatus(HttpStatus.OK);
+ modelAndView.setViewName("forward:/ui/index.html");
+ return modelAndView;
+ }
+ modelAndView.setStatus(HttpStatus.valueOf(statusCode));
+ }
+ return modelAndView;
+ }
+}
diff --git
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/PaimonWebErrorControllerTest.java
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/PaimonWebErrorControllerTest.java
new file mode 100644
index 00000000..7cfeb5c4
--- /dev/null
+++
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/PaimonWebErrorControllerTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.server.controller;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.HttpStatus;
+import org.springframework.test.web.servlet.MvcResult;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.http.HttpServletRequest;
+
+/** Test for {@link PaimonWebErrorController}. */
+@SpringBootTest
+@AutoConfigureMockMvc
+public class PaimonWebErrorControllerTest extends ControllerTestBase {
+
+ @MockBean private HttpServletRequest request;
+
+ @Test
+ public void testHandleErrorNotFoundRedirect() throws Exception {
+ MvcResult result =
+ mockMvc.perform(
+ MockMvcRequestBuilders.get("/error")
+ .requestAttr(
+
RequestDispatcher.ERROR_STATUS_CODE,
+ HttpStatus.NOT_FOUND.value()))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andReturn();
+ Assertions.assertEquals("forward:/ui/index.html",
result.getModelAndView().getViewName());
+ }
+}