wanghongkai 5 years ago
parent
commit
0b8a2173f3

+ 16 - 0
pom.xml

@@ -114,6 +114,22 @@
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
             </plugin>
+            <plugin>
+                <groupId>org.hibernate.orm.tooling</groupId>
+                <artifactId>hibernate-enhance-maven-plugin</artifactId>
+                <version>${hibernate.version}</version>
+                <executions>
+                    <execution>
+                        <configuration>
+                            <failOnError>true</failOnError>
+                            <enableLazyInitialization>true</enableLazyInitialization>
+                        </configuration>
+                        <goals>
+                            <goal>enhance</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
 

+ 4 - 2
src/main/java/cn/seecoder/paas/data/entity/Environment.java

@@ -43,7 +43,8 @@ public class Environment {
     @Column(name = "build_type_value")
     private String buildTypeValue;
 
-    @Basic
+    @Basic(fetch = FetchType.LAZY)
+    @Lob
     @Column(name = "build_output", columnDefinition = "MEDIUMTEXT")
     private String buildOutput;
 
@@ -63,7 +64,8 @@ public class Environment {
     @Column(name = "deploy_start_time")
     private LocalDateTime deployStartTime;
 
-    @Basic
+    @Basic(fetch = FetchType.LAZY)
+    @Lob
     @Column(name = "deploy_output", columnDefinition = "TEXT")
     private String deployOutput;
 

+ 1 - 1
src/main/java/cn/seecoder/paas/service/EnvironmentService.java

@@ -12,7 +12,7 @@ public interface EnvironmentService {
 
     void delete(Integer id);
 
-    EnvironmentVO get(Integer id) throws ServiceException;
+    EnvironmentVO get(Integer id, boolean fetchAll) throws ServiceException;
 
     List<EnvironmentVO> getListByAppId(Integer appId);
 

+ 10 - 2
src/main/java/cn/seecoder/paas/service/impl/EnvironmentServiceImpl.java

@@ -119,7 +119,7 @@ public class EnvironmentServiceImpl implements EnvironmentService {
             if (environment == null) {
                 throw ServiceException.BAD_REQUEST;
             }
-            BeanUtils.copyProperties(environmentVO, environment, "id", "appId", "buildStatus", "buildOutput", "deployStatus", "image", "buildStartTime", "deployStartTime");
+            BeanUtils.copyProperties(environmentVO, environment, "id", "appId", "buildStatus", "buildOutput", "deployStatus", "image", "buildStartTime", "deployStartTime", "deployOutput");
         }
         EnvironmentVO result = EnvironmentConverter.convertToVO(environmentDAO.save(environment));
         ConfigVO resultConfigVO;
@@ -156,13 +156,17 @@ public class EnvironmentServiceImpl implements EnvironmentService {
     }
 
     @Override
-    public EnvironmentVO get(Integer id) throws ServiceException {
+    public EnvironmentVO get(Integer id, boolean fetchAll) throws ServiceException {
         Environment result = environmentDAO.findById(id).orElse(null);
         if (result == null) {
             throw ServiceException.BAD_REQUEST;
         }
         ConfigVO resultConfigVO = ConfigConverter.convertToVO(configDAO.findByConfigBelongsAndAndEntityId(ConfigBelongsToType.ENVIRONMENT, result.getId()));
         EnvironmentVO vo = EnvironmentConverter.convertToVO(result);
+        if (fetchAll) {
+            vo.setBuildOutput(result.getBuildOutput());
+            vo.setDeployOutput(result.getDeployOutput());
+        }
         vo.setConfig(resultConfigVO);
         String labelKey = ResourceLabel.RESOURCE.getCode();
         String labelValue = ResourceLabel.RESOURCE.getGenerator().gen("environment", String.valueOf(result.getAppId()), String.valueOf(result.getId()));
@@ -296,6 +300,10 @@ public class EnvironmentServiceImpl implements EnvironmentService {
                     LoggerUtil.error(logger, e, "构建失败!gitUrl={}, branchOrCommit={}", application.getGitUrl(), result.getBuildTypeValue());
                     return;
                 }
+            } else if (result.getBuildType() == BuildType.FROM_IMAGE) {
+                result.setBuildStatus(BuildStatus.SUCCESS);
+                result.setBuildOutput("镜像构建无需部署");
+                environmentDAO.save(result);
             }
 
             String[] ports = configContent.getServicePort().split(",");

+ 2 - 2
src/main/java/cn/seecoder/paas/service/model/converter/EnvironmentConverter.java

@@ -9,13 +9,13 @@ public class EnvironmentConverter {
 
     public static EnvironmentVO convertToVO(Environment environment) {
         EnvironmentVO environmentVO = new EnvironmentVO();
-        BeanUtils.copyProperties(environment, environmentVO);
+        BeanUtils.copyProperties(environment, environmentVO, "deployOutput", "buildOutput");
         return environmentVO;
     }
 
     public static Environment convertToEntity(EnvironmentVO environmentVO) {
         Environment environment = new Environment();
-        BeanUtils.copyProperties(environmentVO, environment);
+        BeanUtils.copyProperties(environmentVO, environment, "buildStatus", "buildOutput", "deployStatus", "image", "buildStartTime", "deployStartTime", "deployOutput");
         return environment;
     }
 }

+ 4 - 2
src/main/java/cn/seecoder/paas/web/controller/api/EnvironmentController.java

@@ -7,6 +7,7 @@ import cn.seecoder.paas.web.model.Response;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
 
 @RestController
@@ -36,8 +37,9 @@ public class EnvironmentController {
     }
 
     @GetMapping("/{id}")
-    public Response get(@PathVariable("id") Integer id) throws ServiceException {
-        return Response.buildSuccess(environmentService.get(id));
+    public Response get(@PathVariable("id") Integer id, HttpServletRequest request) throws ServiceException {
+        Boolean fetchAll = Boolean.valueOf(request.getParameter("fetchAll"));
+        return Response.buildSuccess(environmentService.get(id, fetchAll == null ? false : fetchAll));
     }
 
     @DeleteMapping("/{id}")

+ 3 - 0
src/main/resources/application.yml

@@ -12,6 +12,9 @@ spring:
         implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
         physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
     database-platform: org.hibernate.dialect.MySQL57InnoDBDialect
+#    show-sql: true
+#    properties:
+#      hibernate.format_sql: true
   security:
     user:
       name: root