reghao 6 vuotta sitten
vanhempi
commit
d317d96475
100 muutettua tiedostoa jossa 1129 lisäystä ja 379 poistoa
  1. 6 0
      common/pom.xml
  2. 0 1
      common/src/main/java/cn/reghao/autodop/common/config/DeployConfig.java
  3. 1 1
      common/src/main/java/cn/reghao/autodop/common/dockerc/Container.java
  4. 1 1
      common/src/main/java/cn/reghao/autodop/common/dockerc/ContainerConfig.java
  5. 1 1
      common/src/main/java/cn/reghao/autodop/common/dockerc/ContainerInfo.java
  6. 1 1
      common/src/main/java/cn/reghao/autodop/common/dockerc/ContainerOps.java
  7. 1 1
      common/src/main/java/cn/reghao/autodop/common/dockerc/DockerApi.java
  8. 1 1
      common/src/main/java/cn/reghao/autodop/common/dockerc/DockerAuth.java
  9. 5 6
      common/src/main/java/cn/reghao/autodop/common/dockerc/DockerClient.java
  10. 1 1
      common/src/main/java/cn/reghao/autodop/common/dockerc/DockerException.java
  11. 1 1
      common/src/main/java/cn/reghao/autodop/common/dockerc/DockerHeader.java
  12. 1 1
      common/src/main/java/cn/reghao/autodop/common/dockerc/HostConfig.java
  13. 1 1
      common/src/main/java/cn/reghao/autodop/common/dockerc/ImageOps.java
  14. 4 4
      common/src/main/java/cn/reghao/autodop/common/dockerc/httpclient/HttpClient.java
  15. 1 1
      common/src/main/java/cn/reghao/autodop/common/dockerc/httpclient/HttpClientHandler.java
  16. 1 1
      common/src/main/java/cn/reghao/autodop/common/dockerc/httpclient/UnixSocketClient.java
  17. 1 1
      common/src/main/java/cn/reghao/autodop/common/grpc/facade/AppService.java
  18. 161 0
      common/src/main/java/cn/reghao/autodop/common/http/DefaultWebRequest.java
  19. 16 0
      common/src/main/java/cn/reghao/autodop/common/http/HttpApi.java
  20. 23 0
      common/src/main/java/cn/reghao/autodop/common/http/WebRequest.java
  21. 17 0
      common/src/main/java/cn/reghao/autodop/common/http/WebResponse.java
  22. 37 0
      common/src/main/java/cn/reghao/autodop/common/notification/DingNotify.java
  23. 9 0
      common/src/main/java/cn/reghao/autodop/common/notification/Notify.java
  24. 32 0
      common/src/main/java/cn/reghao/autodop/common/notification/ding/DingMsg.java
  25. 26 0
      common/src/main/java/cn/reghao/autodop/common/notification/ding/DingText.java
  26. 12 0
      common/src/main/java/cn/reghao/autodop/common/utils/security/Cryptor.java
  27. 21 0
      common/src/main/java/cn/reghao/autodop/common/utils/security/Salt.java
  28. 32 0
      common/src/main/java/cn/reghao/autodop/common/utils/security/Sha256Cryptor.java
  29. 42 0
      common/src/main/java/cn/reghao/autodop/common/webresult/WebResult.java
  30. 6 0
      dagent/pom.xml
  31. 1 1
      dagent/src/main/java/cn/reghao/autodop/dagent/DagentApplication.java
  32. 1 2
      dagent/src/main/java/cn/reghao/autodop/dagent/deploy/Deploy.java
  33. 4 6
      dagent/src/main/java/cn/reghao/autodop/dagent/deploy/DockerDeploy.java
  34. 6 7
      dagent/src/main/java/cn/reghao/autodop/dagent/deploy/ZipDeploy.java
  35. 5 7
      dagent/src/main/java/cn/reghao/autodop/dagent/deploy/ZipRemoteDeploy.java
  36. 15 0
      dagent/src/main/java/cn/reghao/autodop/dagent/kvm/Kvm.java
  37. 4 4
      dagent/src/main/java/cn/reghao/autodop/dagent/service/DeployServiceImpl.java
  38. 2 2
      dagent/src/main/java/cn/reghao/autodop/dagent/service/DockerAppServiceImpl.java
  39. 1 1
      dagent/src/main/resources/application-test.yml
  40. 26 15
      dmaster/pom.xml
  41. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/DmasterApplication.java
  42. 2 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppStatusController.java
  43. 11 22
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/BuildController.java
  44. 2 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/FileController.java
  45. 3 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/BuildLog.java
  46. 17 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/DeployLog.java
  47. 17 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/AppBuild.java
  48. 14 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/compile/AppCompile.java
  49. 14 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/pack/AppPack.java
  50. 14 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/update/AppRepo.java
  51. 13 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/update/AppUpdate.java
  52. 15 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/update/RepoAuth.java
  53. 11 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/constant/CompilerType.java
  54. 11 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/constant/NotifyType.java
  55. 11 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/constant/PackerType.java
  56. 11 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/constant/RepoType.java
  57. 18 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/deploy/AppDeploy.java
  58. 29 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/orchestration/AppOrchestration.java
  59. 14 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/orchestration/Notification.java
  60. 16 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/orchestration/ProjOrchestration.java
  61. 9 12
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppManager.java
  62. 2 5
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/OssService.java
  63. 3 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppBuildPipeline.java
  64. 3 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppIntegrate.java
  65. 13 15
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuildDispatcher.java
  66. 4 4
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuilderUtil.java
  67. 2 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/ProjectUpdateTask.java
  68. 6 7
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/deploy/AppDeploy.java
  69. 2 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/deploy/Deployer.java
  70. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/CodeCompiler.java
  71. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/DefaultCompiler.java
  72. 2 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/DnktMgrPreCompile.java
  73. 2 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/DotnetPreCompile.java
  74. 5 5
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/MavenCompiler.java
  75. 2 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/PreCompile.java
  76. 2 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/ShellCompiler.java
  77. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/CodePacker.java
  78. 7 9
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/DnktMgrZipPack.java
  79. 7 7
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/DockerPack.java
  80. 2 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/DotnetPack.java
  81. 2 3
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/ZipPack.java
  82. 2 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/ZipRemotePack.java
  83. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/CodeUpdater.java
  84. 20 22
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/GitImpl.java
  85. 2 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/SvnImpl.java
  86. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/config/AuthFailureHandlerImpl.java
  87. 1 11
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/config/AuthSuccessHandlerImpl.java
  88. 19 101
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/config/WebSecurityConfig.java
  89. 4 6
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/entity/UserAuth.java
  90. 66 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/impl/formlogin/UserDetailsServiceImpl.java
  91. 92 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/impl/formlogin/UsernamePasswordAuthFilter.java
  92. 51 0
      dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/impl/formlogin/UsernamePasswordAuthProvider.java
  93. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/common/config/CachingConfig.java
  94. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/common/config/OssProperties.java
  95. 5 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/common/config/SwaggerConfig.java
  96. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/common/config/SysConfigProperties.java
  97. 7 32
      dmaster/src/main/java/cn/reghao/autodop/dmaster/common/config/WebMvcConfig.java
  98. 4 4
      dmaster/src/main/java/cn/reghao/autodop/dmaster/common/exception/GlobalExceptionHandler.java
  99. 1 2
      dmaster/src/main/java/cn/reghao/autodop/dmaster/common/exception/WebErrorController.java
  100. 1 1
      dmaster/src/main/java/cn/reghao/autodop/dmaster/common/interceptor/MethodTimeInterceptor.java

+ 6 - 0
common/pom.xml

@@ -103,6 +103,12 @@
             <artifactId>httpmime</artifactId>
             <version>4.5.8</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.sun.mail</groupId>
+            <artifactId>javax.mail</artifactId>
+            <version>RELEASE</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 0 - 1
common/src/main/java/cn/reghao/autodop/common/config/DeployConfig.java

@@ -13,5 +13,4 @@ public class DeployConfig {
     private String packerType;
     private String runningDir;
     private String host;
-    private boolean isRun;
 }

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/dockerc/Container.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.common.docker;
+package cn.reghao.autodop.common.dockerc;
 
 import com.google.gson.annotations.SerializedName;
 import lombok.Data;

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/dockerc/ContainerConfig.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.common.docker;
+package cn.reghao.autodop.common.dockerc;
 
 /**
  * @author reghao

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/dockerc/ContainerInfo.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.common.docker;
+package cn.reghao.autodop.common.dockerc;
 
 import com.google.gson.annotations.SerializedName;
 import lombok.Data;

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/dockerc/ContainerOps.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.common.docker;
+package cn.reghao.autodop.common.dockerc;
 
 import java.io.IOException;
 import java.util.List;

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/dockerc/DockerApi.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.common.docker;
+package cn.reghao.autodop.common.dockerc;
 
 /**
  * Docker v1.40

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/dockerc/DockerAuth.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.common.docker;
+package cn.reghao.autodop.common.dockerc;
 
 import lombok.Data;
 

+ 5 - 6
common/src/main/java/cn/reghao/autodop/common/dockerc/DockerClient.java

@@ -1,7 +1,7 @@
-package cn.reghao.autodop.common.docker;
+package cn.reghao.autodop.common.dockerc;
 
-import cn.reghao.autodop.common.docker.httpclient.UnixSocketClient;
-import cn.reghao.autodop.common.docker.httpclient.WebClient;
+import cn.reghao.autodop.common.dockerc.httpclient.UnixSocketClient;
+import cn.reghao.autodop.common.dockerc.httpclient.HttpClient;
 import cn.reghao.autodop.common.utils.JsonUtil;
 import cn.reghao.autodop.common.utils.security.Base64Util;
 import cn.reghao.autodop.common.utils.compression.TarUtil;
@@ -9,7 +9,6 @@ import cn.reghao.autodop.common.utils.security.Md5Util;
 import cn.reghao.autodop.common.utils.text.TextFile;
 import com.google.gson.JsonObject;
 import io.netty.handler.codec.http.FullHttpResponse;
-import lombok.extern.slf4j.Slf4j;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -27,10 +26,10 @@ import java.util.*;
  */
 public class DockerClient implements ImageOps, ContainerOps, AutoCloseable {
     private static final Logger log = LoggerFactory.getLogger(DockerClient.class);
-    private WebClient client;
+    private HttpClient client;
 
     public DockerClient() {
-        client = new WebClient(new UnixSocketClient());
+        client = new HttpClient(new UnixSocketClient());
     }
 
     @Override

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/dockerc/DockerException.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.common.docker;
+package cn.reghao.autodop.common.dockerc;
 
 /**
  * @author reghao

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/dockerc/DockerHeader.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.common.docker;
+package cn.reghao.autodop.common.dockerc;
 
 import lombok.AllArgsConstructor;
 import lombok.Data;

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/dockerc/HostConfig.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.common.docker;
+package cn.reghao.autodop.common.dockerc;
 
 /**
  * @author reghao

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/dockerc/ImageOps.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.common.docker;
+package cn.reghao.autodop.common.dockerc;
 
 /**
  * @author reghao

+ 4 - 4
common/src/main/java/cn/reghao/autodop/common/dockerc/httpclient/HttpClient.java

@@ -1,6 +1,6 @@
-package cn.reghao.autodop.common.docker.httpclient;
+package cn.reghao.autodop.common.dockerc.httpclient;
 
-import cn.reghao.autodop.common.docker.DockerHeader;
+import cn.reghao.autodop.common.dockerc.DockerHeader;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.handler.codec.http.*;
@@ -13,10 +13,10 @@ import java.util.List;
  * @author reghao
  * @date 2020-01-15 10:13:21
  */
-public class WebClient {
+public class HttpClient {
     private UnixSocketClient client;
 
-    public WebClient(UnixSocketClient client) {
+    public HttpClient(UnixSocketClient client) {
         this.client = client;
     }
 

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/dockerc/httpclient/HttpClientHandler.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.common.docker.httpclient;
+package cn.reghao.autodop.common.dockerc.httpclient;
 
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInboundHandlerAdapter;

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/dockerc/httpclient/UnixSocketClient.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.common.docker.httpclient;
+package cn.reghao.autodop.common.dockerc.httpclient;
 
 import io.netty.bootstrap.Bootstrap;
 import io.netty.channel.*;

+ 1 - 1
common/src/main/java/cn/reghao/autodop/common/grpc/facade/AppService.java

@@ -1,6 +1,6 @@
 package cn.reghao.autodop.common.grpc.facade;
 
-import cn.reghao.autodop.common.docker.DockerException;
+import cn.reghao.autodop.common.dockerc.DockerException;
 import cn.reghao.autodop.common.grpc.common.annotation.GrpcService;
 import cn.reghao.autodop.common.grpc.common.serializer.SerializerType;
 

+ 161 - 0
common/src/main/java/cn/reghao/autodop/common/http/DefaultWebRequest.java

@@ -0,0 +1,161 @@
+package cn.reghao.autodop.common.http;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HeaderElement;
+import org.apache.http.HeaderElementIterator;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.CookieStore;
+import org.apache.http.client.config.CookieSpecs;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.conn.ConnectionKeepAliveStrategy;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.BasicCookieStore;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.message.BasicHeaderElementIterator;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.util.EntityUtils;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author reghao
+ * @date 2019-11-29 10:03:18
+ */
+@Slf4j
+public class DefaultWebRequest implements WebRequest {
+    private CloseableHttpClient client;
+    private String charset;
+
+    public DefaultWebRequest() {
+        init();
+    }
+
+    public DefaultWebRequest(String charset) {
+        this.charset = charset;
+        init();
+    }
+
+    ConnectionKeepAliveStrategy strategy = (response, context) -> {
+        HeaderElementIterator iterator =
+                new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
+        while (iterator.hasNext()) {
+            HeaderElement element = iterator.nextElement();
+            String name = element.getName();
+            String value = element.getValue();
+            if (value != null && "timeout".equalsIgnoreCase(name)) {
+                return Long.parseLong(value) * 1000;
+            }
+        }
+
+        return 60*1000;
+    };
+
+    private void init() {
+        PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
+        connectionManager.setMaxTotal(50);
+        connectionManager.setDefaultMaxPerRoute(20);
+
+        RequestConfig defaultRequestConfig = RequestConfig.custom()
+                .setConnectionRequestTimeout(10_000)
+                .setConnectTimeout(10_000)
+                .setSocketTimeout(10_000)
+                .setCookieSpec(CookieSpecs.STANDARD)
+                .build();
+
+        CookieStore cookieStore = new BasicCookieStore();
+        client = HttpClients.custom()
+                .setDefaultRequestConfig(defaultRequestConfig)
+                .setDefaultCookieStore(cookieStore)
+                .setConnectionManager(connectionManager)
+                .setKeepAliveStrategy(strategy)
+                .build();
+    }
+    
+    private void setDefaultHeaders(HttpRequestBase method) {
+        String desktop = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36";
+        method.setHeader("user-agent", desktop);
+        method.setHeader("connection", "keep-alive");
+    }
+
+    @Override
+    public WebResponse get(String url) {
+        HttpGet get = new HttpGet(url);
+        try {
+            return client.execute(get, response -> {
+                int statusCode = response.getStatusLine().getStatusCode();
+                // TODO 根据 content-type 中的编码获取字符串
+                String contentType = response.getFirstHeader("content-type").getValue();
+                String body;
+                if (charset != null) {
+                    body = EntityUtils.toString(response.getEntity(), charset);
+                } else {
+                    body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
+                }
+                return new WebResponse(statusCode, body);
+            });
+        } catch (Exception e) {
+            // TODO 是否应该放在 finally 块中?
+            return new WebResponse(600, e.getMessage());
+        }
+    }
+
+    @Override
+    public WebResponse postFormData(String url, Map<String, String> formData) {
+        List<NameValuePair> params = new ArrayList<>();
+        formData.forEach((k, v) -> {
+            params.add(new BasicNameValuePair(k, v));
+        });
+        UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(params, StandardCharsets.UTF_8);
+
+        HttpPost post = new HttpPost(url);
+        //post.addHeader("Content-Type", "application/json;charset=UTF-8");
+        post.setEntity(urlEncodedFormEntity);
+
+        try (CloseableHttpResponse response = client.execute(post)) {
+            int statusCode = response.getStatusLine().getStatusCode();
+            String body;
+            if (charset != null) {
+                body = EntityUtils.toString(response.getEntity(), charset);
+            } else {
+                body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
+            }
+            return new WebResponse(statusCode, body);
+        } catch (Exception e) {
+            return new WebResponse(600, e.getMessage());
+        }
+    }
+
+    @Override
+    public WebResponse postJson(String url, String json) {
+        StringEntity entity = new StringEntity(json, StandardCharsets.UTF_8);
+        entity.setContentEncoding("UTF-8");
+
+        HttpPost post = new HttpPost(url);
+        post.addHeader("Content-Type", "application/json;charset=UTF-8");
+        post.setEntity(entity);
+
+        try (CloseableHttpResponse response = client.execute(post)) {
+            int statusCode = response.getStatusLine().getStatusCode();
+            String body;
+            if (charset != null) {
+                body = EntityUtils.toString(response.getEntity(), charset);
+            } else {
+                body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
+            }
+            return new WebResponse(statusCode, body);
+        } catch (Exception e) {
+            return new WebResponse(600, e.getMessage());
+        }
+    }
+}

+ 16 - 0
common/src/main/java/cn/reghao/autodop/common/http/HttpApi.java

@@ -0,0 +1,16 @@
+package cn.reghao.autodop.common.http;
+
+/**
+ * @author reghao
+ * @date 2020-05-12 11:43:02
+ */
+public class HttpApi {
+    public static String url(String address, int port, String api) {
+        String prefix = "http://";
+        if (port != 80) {
+            return prefix + address + ":" + port + api;
+        } else {
+            return prefix + address + api;
+        }
+    }
+}

+ 23 - 0
common/src/main/java/cn/reghao/autodop/common/http/WebRequest.java

@@ -0,0 +1,23 @@
+package cn.reghao.autodop.common.http;
+
+import java.util.Map;
+
+/**
+ * HTTP 请求
+ *
+ * @author reghao
+ * @date 2019-08-01 16:27:55
+ */
+public interface WebRequest {
+    /**
+     * 使用代理的 GET 请求
+     *
+     * @return 成功返回响应 body,失败返回 null
+     * @date 2020-03-14 下午9:30
+     */
+    WebResponse get(String url);
+
+    WebResponse postFormData(String url, Map<String, String> formData);
+
+    WebResponse postJson(String url, String json);
+}

+ 17 - 0
common/src/main/java/cn/reghao/autodop/common/http/WebResponse.java

@@ -0,0 +1,17 @@
+package cn.reghao.autodop.common.http;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+/**
+ * HTTP 响应
+ *
+ * @author reghao
+ * @date 2019-08-01 16:27:55
+ */
+@Data
+@AllArgsConstructor
+public class WebResponse {
+    private int statusCode;
+    private String body;
+}

+ 37 - 0
common/src/main/java/cn/reghao/autodop/common/notification/DingNotify.java

@@ -0,0 +1,37 @@
+package cn.reghao.autodop.common.notification;
+
+import cn.reghao.autodop.common.http.DefaultWebRequest;
+import cn.reghao.autodop.common.http.WebRequest;
+import cn.reghao.autodop.common.http.WebResponse;
+import cn.reghao.autodop.common.notification.ding.DingText;
+import cn.reghao.autodop.common.utils.JsonUtil;
+
+/**
+ * @author reghao
+ * @date 2020-05-07 01:31:03
+ */
+public class DingNotify implements Notify {
+    private WebRequest webRequest = new DefaultWebRequest();
+
+    @Override
+    public boolean send(String destination, String content) {
+        try {
+            DingText dingText = new DingText(content);
+            WebResponse webResponse = webRequest.postJson(destination, JsonUtil.objectToJson(dingText));
+            if (webResponse.getStatusCode() == 200) {
+                return true;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    public static void main(String[] args) throws Exception {
+        String webhook = "https://oapi.dingtalk.com/robot/send?access_token=ba9cf0d846cff8c471168e0d2f91ec0c44645a086cf5e4e421697c9b0c606bd2";
+        DingNotify dingNotify = new DingNotify();
+
+        String content = "打发时间咯";
+        dingNotify.send(webhook, content);
+    }
+}

+ 9 - 0
common/src/main/java/cn/reghao/autodop/common/notification/Notify.java

@@ -0,0 +1,9 @@
+package cn.reghao.autodop.common.notification;
+
+/**
+ * @author reghao
+ * @date 2020-05-07 01:41:27
+ */
+public interface Notify {
+    boolean send(String dest, String content);
+}

+ 32 - 0
common/src/main/java/cn/reghao/autodop/common/notification/ding/DingMsg.java

@@ -0,0 +1,32 @@
+package cn.reghao.autodop.common.notification.ding;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 钉钉消息
+ *
+ * @author reghao
+ * @date 2019-10-24 15:00:28
+ */
+@Data
+public class DingMsg<T> {
+    private String msgtype;
+    private Map<String, String> at;
+
+    public DingMsg(String msgtype) {
+        this.msgtype = msgtype;
+
+        this.at = new HashMap<>();
+        at.put("atMobiles", null);
+        at.put("isAtAll", String.valueOf(true));
+    }
+
+    public void atMobiles(@NotNull String[] mobiles) {
+        at.put("atMobiles", Arrays.toString(mobiles));
+    }
+}

+ 26 - 0
common/src/main/java/cn/reghao/autodop/common/notification/ding/DingText.java

@@ -0,0 +1,26 @@
+package cn.reghao.autodop.common.notification.ding;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 钉钉文本消息
+ *
+ * @author reghao
+ * @date 2019-10-24 14:48:41
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class DingText extends DingMsg<String> {
+    private Map<String, String> text;
+
+    public DingText(String content) {
+        super("text");
+
+        text = new HashMap<>();
+        text.put("content", content);
+    }
+}

+ 12 - 0
common/src/main/java/cn/reghao/autodop/common/utils/security/Cryptor.java

@@ -0,0 +1,12 @@
+package cn.reghao.autodop.common.utils.security;
+
+/**
+ * 加密/解密
+ *
+ * @author reghao
+ * @date 2020-04-27 14:03:49
+ */
+public interface Cryptor {
+    String encrypt(String str);
+    String decrypt(String str);
+}

+ 21 - 0
common/src/main/java/cn/reghao/autodop/common/utils/security/Salt.java

@@ -0,0 +1,21 @@
+package cn.reghao.autodop.common.utils.security;
+
+import java.security.SecureRandom;
+import java.util.Base64;
+
+/**
+ * @author reghao
+ * @date 2019-04-05 12:23:47
+ */
+public class Salt {
+    private static SecureRandom random = new SecureRandom();
+
+    /**
+     * @return 盐值
+     * @date 2019-04-05 12:28:08
+     */
+    public static String get(int len) {
+        byte[] seed = random.generateSeed(len);
+        return Base64.getEncoder().encodeToString(seed);
+    }
+}

+ 32 - 0
common/src/main/java/cn/reghao/autodop/common/utils/security/Sha256Cryptor.java

@@ -0,0 +1,32 @@
+package cn.reghao.autodop.common.utils.security;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * @author reghao
+ * @date 2019-03-26 14:46:57
+ */
+public class Sha256Cryptor implements Cryptor {
+    private MessageDigest sha256;
+
+    public Sha256Cryptor() throws NoSuchAlgorithmException {
+        this.sha256 = MessageDigest.getInstance("SHA-256");
+    }
+
+    @Override
+    public String encrypt(String str) {
+        byte[] bytes = sha256.digest(str.getBytes());
+        StringBuilder sb = new StringBuilder();
+        for (byte aByte : bytes) {
+            sb.append(Integer.toString((aByte & 0xff) + 0x100, 16).substring(1));
+        }
+
+        return sb.toString();
+    }
+
+    @Override
+    public String decrypt(String str) {
+        return null;
+    }
+}

+ 42 - 0
common/src/main/java/cn/reghao/autodop/common/webresult/WebResult.java

@@ -0,0 +1,42 @@
+package cn.reghao.autodop.common.webresult;
+
+import com.google.gson.Gson;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Web 应用统一返回值
+ *
+ * @author reghao
+ * @date 2019-09-28 10:05:35
+ */
+@Data
+@NoArgsConstructor
+public class WebResult {
+    private Integer code;
+    private String message;
+    private String timestamp;
+    private Object data;
+
+    public WebResult(Integer code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    public static String success(Object data) {
+        WebResult webResult = new WebResult(200, "操作成功");
+        webResult.setTimestamp((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
+        webResult.setData(data);
+        return (new Gson()).toJson(webResult);
+    }
+
+    public static String fail(Object data) {
+        WebResult webResult = new WebResult(400, "操作失败");
+        webResult.setTimestamp((new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
+        webResult.setData(data);
+        return (new Gson()).toJson(webResult);
+    }
+}

+ 6 - 0
dagent/pom.xml

@@ -25,6 +25,12 @@
             <artifactId>common</artifactId>
             <version>1.0.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.libvirt</groupId>
+            <artifactId>libvirt</artifactId>
+            <version>0.5.1</version>
+        </dependency>
     </dependencies>
 
     <profiles>

+ 1 - 1
dagent/src/main/java/cn/reghao/autodop/dagent/DagentApplication.java

@@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
-@EnableScheduling
+//@EnableScheduling
 @ComponentScan({"cn.reghao.autodop.common.grpc", "cn.reghao.autodop.dagent"})
 @SpringBootApplication
 public class DagentApplication {

+ 1 - 2
dagent/src/main/java/cn/reghao/autodop/dagent/deploy/Deploy.java

@@ -15,10 +15,9 @@ public interface Deploy {
      * @param appId 应用标识
      * @param appPath 完成的应用路径(HTTP 地址或 docker 地址)
      * @param runningDir 应用运行根目录
-     * @param isRun 是否运行应用
      *
      * @return 0 - 部署成功,1 - 部署失败
      * @date 2019-10-15 下午4:57
      */
-    BuildDeployResult deploy(String appId, String appPath, String runningDir, boolean isRun);
+    BuildDeployResult deploy(String appId, String appPath, String runningDir);
 }

+ 4 - 6
dagent/src/main/java/cn/reghao/autodop/dagent/deploy/DockerDeploy.java

@@ -1,7 +1,7 @@
 package cn.reghao.autodop.dagent.deploy;
 
 import cn.reghao.autodop.common.config.BuildDeployResult;
-import cn.reghao.autodop.common.docker.DockerClient;
+import cn.reghao.autodop.common.dockerc.DockerClient;
 import lombok.extern.slf4j.Slf4j;
 
 /**
@@ -15,16 +15,14 @@ public class DockerDeploy implements Deploy {
     private DockerClient docker = new DockerClient();
 
     @Override
-    public BuildDeployResult deploy(String appId, String appPath, String runningDir, boolean isRun) {
+    public BuildDeployResult deploy(String appId, String appPath, String runningDir) {
         BuildDeployResult result = new BuildDeployResult();
         result.setAppId(appId);
         result.setStage("部署");
         try {
             docker.pull(appPath);
-            if (isRun) {
-                result.setStage("运行");
-                docker.run(appId, appPath);
-            }
+            result.setStage("运行");
+            docker.run(appId, appPath);
 
             result.setCode(0);
             result.setMsg("成功");

+ 6 - 7
dagent/src/main/java/cn/reghao/autodop/dagent/deploy/ZipDeploy.java

@@ -18,7 +18,7 @@ import java.io.File;
  */
 public class ZipDeploy implements Deploy {
     @Override
-    public BuildDeployResult deploy(String appId, String appPath, String runningDir, boolean isRun) {
+    public BuildDeployResult deploy(String appId, String appPath, String runningDir) {
         WebRequest request = new DefaultWebRequest();
 
         BuildDeployResult result = new BuildDeployResult();
@@ -31,15 +31,14 @@ public class ZipDeploy implements Deploy {
 
             String filepath = appDir + "/" + appPath.substring(appPath.lastIndexOf("/") + 1);
             if (!new File(filepath).exists()) {
-                request.download(appPath, filepath);
+                // TODO 下载静态文件包
+                //request.download(appPath, filepath);
             }
 
             // TODO 前端静态文件并不存在运行的概念,它与二进制运行文件和 Python 之类的应用不同
-            if (isRun) {
-                result.setStage("运行");
-                FileUtil.eraseDir(new File(appRunningDir));
-                ZipUtil.unzip(filepath, appRunningDir);
-            }
+            result.setStage("运行");
+            FileUtil.eraseDir(new File(appRunningDir));
+            ZipUtil.unzip(filepath, appRunningDir);
 
             result.setCode(0);
             result.setMsg("成功");

+ 5 - 7
dagent/src/main/java/cn/reghao/autodop/dagent/deploy/ZipRemoteDeploy.java

@@ -16,7 +16,7 @@ import java.io.File;
  */
 public class ZipRemoteDeploy implements Deploy {
     @Override
-    public BuildDeployResult deploy(String appId, String appPath, String runningDir, boolean isRun) {
+    public BuildDeployResult deploy(String appId, String appPath, String runningDir) {
         WebRequest request = new DefaultWebRequest();
 
         BuildDeployResult result = new BuildDeployResult();
@@ -29,13 +29,11 @@ public class ZipRemoteDeploy implements Deploy {
 
             String filepath = appDir + "/" + appPath;
             if (!new File(filepath).exists()) {
-                request.download(appPath, filepath);
-            }
-
-            if (isRun) {
-                FileUtil.eraseDir(new File(appRunningDir));
-                ZipUtil.unzip(filepath, appRunningDir);
+                // TODO 下载静态文件包
+                //request.download(appPath, filepath);
             }
+            FileUtil.eraseDir(new File(appRunningDir));
+            ZipUtil.unzip(filepath, appRunningDir);
 
             result.setMsg("成功");
         } catch (Exception e) {

+ 15 - 0
dagent/src/main/java/cn/reghao/autodop/dagent/kvm/Kvm.java

@@ -0,0 +1,15 @@
+package cn.reghao.autodop.dagent.kvm;
+
+import org.libvirt.Connect;
+import org.libvirt.Domain;
+
+/**
+ * @author reghao
+ * @date 2020-05-08 22:37:05
+ */
+public class Kvm {
+    public static void main(String[] args) throws Exception {
+        Connect conn = new Connect("test://default", true);
+        Domain domain = conn.domainLookupByName("test");
+    }
+}

+ 4 - 4
dagent/src/main/java/cn/reghao/autodop/dagent/service/DeployServiceImpl.java

@@ -31,19 +31,19 @@ public class DeployServiceImpl implements DeployService {
         String appPath = deployConfig.getAppPath();
         String runningDir = deployConfig.getRunningDir();
         String packerType = deployConfig.getPackerType();
-        boolean isRun = deployConfig.isRun();
+        //boolean isRun = deployConfig.isRun();
 
         // result 中只有 version 不需要设置
         BuildDeployResult result;
         if ("docker".equalsIgnoreCase(packerType)) {
             Deploy deployApp = new DockerDeploy();
-            result = deployApp.deploy(appId, appPath, null, isRun);
+            result = deployApp.deploy(appId, appPath, null);
         } else if ("zip".equalsIgnoreCase(packerType)) {
             Deploy deployApp = new ZipDeploy();
-            result = deployApp.deploy(appId, appPath, runningDir, isRun);
+            result = deployApp.deploy(appId, appPath, runningDir);
         } else if ("zip-remote".equalsIgnoreCase(packerType)) {
             Deploy deployApp = new ZipRemoteDeploy();
-            result = deployApp.deploy(appId, appPath, runningDir, isRun);
+            result = deployApp.deploy(appId, appPath, runningDir);
         } else {
             result = new BuildDeployResult(appId, "部署", 1, "打包类型不正确");
         }

+ 2 - 2
dagent/src/main/java/cn/reghao/autodop/dagent/service/DockerAppServiceImpl.java

@@ -1,7 +1,7 @@
 package cn.reghao.autodop.dagent.service;
 
-import cn.reghao.autodop.common.docker.DockerClient;
-import cn.reghao.autodop.common.docker.DockerException;
+import cn.reghao.autodop.common.dockerc.DockerClient;
+import cn.reghao.autodop.common.dockerc.DockerException;
 import cn.reghao.autodop.common.grpc.facade.AppService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;

+ 1 - 1
dagent/src/main/resources/application-test.yml

@@ -1,4 +1,4 @@
 dmaster:
-  address: 192.168.0.222
+  address: 192.168.0.50
   port: 4000
   api: /api/machine/status

+ 26 - 15
dmaster/pom.xml

@@ -28,6 +28,17 @@
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-devtools</artifactId>
@@ -84,21 +95,6 @@
             <artifactId>spring-boot-starter-security</artifactId>
         </dependency>
 
-        <!--<dependency>
-            <groupId>org.springframework.data</groupId>
-            <artifactId>spring-data-mongodb</artifactId>
-        </dependency>-->
-
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-thymeleaf</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.thymeleaf.extras</groupId>
-            <artifactId>thymeleaf-extras-springsecurity5</artifactId>
-            <version>RELEASE</version>
-        </dependency>
-
         <dependency>
             <groupId>cglib</groupId>
             <artifactId>cglib</artifactId>
@@ -128,6 +124,12 @@
             <artifactId>jsch</artifactId>
             <version>0.1.55</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.libvirt</groupId>
+            <artifactId>libvirt</artifactId>
+            <version>0.5.1</version>
+        </dependency>
     </dependencies>
 
     <profiles>
@@ -192,6 +194,15 @@
         </resources>
 
         <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/DmasterApplication.java

@@ -1,7 +1,7 @@
 package cn.reghao.autodop.dmaster;
 
 import cn.reghao.autodop.common.grpc.common.annotation.GrpcServiceScan;
-import cn.reghao.autodop.dmaster.utils.BeforeShutdown;
+import cn.reghao.autodop.dmaster.common.utils.BeforeShutdown;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.domain.EntityScan;

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/AppStatusController.java

@@ -14,10 +14,10 @@ import org.springframework.web.bind.annotation.RestController;
  * @date 2020-02-28 11:33:23
  */
 @Slf4j
-@Api(tags = "应用状态接口")
+@Api(tags = "应用状态管理接口")
 @RestController
 @RequestMapping("/api/app")
-public class StatusController {
+public class AppStatusController {
     @ApiOperation(value = "启动应用")
     @ApiImplicitParams(
             @ApiImplicitParam(name="appId", value="一个或多个应用(多个应用间使用 , 分隔)",

+ 11 - 22
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/BuildController.java

@@ -23,15 +23,15 @@ import java.util.Set;
  * @date 2019-08-30 18:49:15
  */
 @Slf4j
-@Api(tags = "后端应用构建部署接口")
+@Api(tags = "应用构建部署接口")
 @RestController
 @RequestMapping("/api/app")
-public class BackendController {
+public class BuildController {
     private BuildDispatcher buildDispatcher;
     private AppManager appManager;
     private OssService ossService;
 
-    public BackendController(BuildDispatcher buildDispatcher, AppManager appManager, OssService ossService) {
+    public BuildController(BuildDispatcher buildDispatcher, AppManager appManager, OssService ossService) {
         this.buildDispatcher = buildDispatcher;
         this.appManager = appManager;
         this.ossService = ossService;
@@ -43,47 +43,47 @@ public class BackendController {
                     paramType="path", dataType = "String")
     )
     @PostMapping("/build/{appId}")
-    public String buildApp(@PathVariable("appId") String appId) throws Exception {
+    public String build(@PathVariable("appId") String appId) throws Exception {
         Set<String> apps = checkArgs(appId);
         List<BuildDeployResult> results;
         if (apps.size() == 0) {
             return new WebResult<String>().jsonResult("ok");
         } else {
-            results = buildDispatcher.dispatch(apps, false, false);
+            results = buildDispatcher.dispatch(apps, false);
             return new WebResult<List>().jsonResult(results);
         }
     }
 
-    @ApiOperation(value = "构建部署应用")
+    @ApiOperation(value = "部署应用")
     @ApiImplicitParams(
             @ApiImplicitParam(name="appId", value="一个或多个应用(多个应用间使用 , 分隔)",
                     paramType="path", dataType = "String")
     )
     @PostMapping("/deploy/{appId}")
-    public String buildAndDeploy(@PathVariable("appId") String appId) throws Exception {
+    public String deploy(@PathVariable("appId") String appId) throws Exception {
         Set<String> apps = checkArgs(appId);
         List<BuildDeployResult> results;
         if (apps.size() == 0) {
             return new WebResult<String>().jsonResult("ok");
         } else {
-            results = buildDispatcher.dispatch(apps, true, false);
+            results = buildDispatcher.dispatch(apps, true);
             return new WebResult<List>().jsonResult(results);
         }
     }
 
-    @ApiOperation(value = "构建部署运行应用")
+    @ApiOperation(value = "构建部署应用")
     @ApiImplicitParams(
             @ApiImplicitParam(name="appId", value="一个或多个应用(多个应用间使用 , 分隔)",
                     paramType="path", dataType = "String")
     )
     @PostMapping("/pipeline/{appId}")
-    public String buildDeployAndRun(@PathVariable("appId") String appId) throws Exception {
+    public String buildAndDeploy(@PathVariable("appId") String appId) throws Exception {
         Set<String> apps = checkArgs(appId);
         List<BuildDeployResult> results;
         if (apps.size() == 0) {
             return new WebResult<String>().jsonResult("ok");
         } else {
-            results = buildDispatcher.dispatch(apps, true, true);
+            results = buildDispatcher.dispatch(apps, true);
             return new WebResult<List>().jsonResult(results);
         }
     }
@@ -99,17 +99,6 @@ public class BackendController {
         return null;
     }
 
-    @ApiOperation(value = "运行应用")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name="appId", value="应用标识", paramType="query", dataType = "String"),
-            @ApiImplicitParam(name="appPath", value="应用版本", paramType="query", dataType = "String")
-    })
-    @PostMapping("/run")
-    public String runApp(@RequestParam("appId") String appId, @RequestParam("appVersion") String appVersion)
-            throws Exception {
-        return null;
-    }
-
     @ApiOperation(value = "部署 OSS 资源")
     @ApiImplicitParams(
             @ApiImplicitParam(name="appId", value="一个或多个应用(多个应用间使用 , 分隔)",

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/FileController.java

@@ -1,7 +1,7 @@
 package cn.reghao.autodop.dmaster.app.controller;
 
-import cn.reghao.autodop.dmaster.result.WebResult;
-import cn.reghao.autodop.dmaster.utils.SpringBootUtil;
+import cn.reghao.autodop.dmaster.common.result.WebResult;
+import cn.reghao.autodop.dmaster.common.utils.SpringBootUtil;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.SysConfig;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;

+ 3 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/BuildLog.java

@@ -3,11 +3,13 @@ package cn.reghao.autodop.dmaster.app.pojo;
 import lombok.AllArgsConstructor;
 
 /**
+ * 构建日志
+ *
  * @author reghao
  * @date 2020-03-12 14:56:05
  */
 @AllArgsConstructor
-public class BuildMsg {
+public class BuildLog {
     private String appId;
     private String description;
     private String version;

+ 17 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/DeployLog.java

@@ -0,0 +1,17 @@
+package cn.reghao.autodop.dmaster.app.pojo;
+
+import lombok.AllArgsConstructor;
+
+/**
+ * 部署日志
+ *
+ * @author reghao
+ * @date 2020-03-12 14:56:05
+ */
+@AllArgsConstructor
+public class DeployLog {
+    private String appId;
+    private String description;
+    private String version;
+    private String env;
+}

+ 17 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/AppBuild.java

@@ -0,0 +1,17 @@
+package cn.reghao.autodop.dmaster.app.pojo.build;
+
+import cn.reghao.autodop.dmaster.app.pojo.build.compile.AppCompile;
+import cn.reghao.autodop.dmaster.app.pojo.build.pack.AppPack;
+import cn.reghao.autodop.dmaster.app.pojo.build.update.AppUpdate;
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2020-05-13 16:40:22
+ */
+@Data
+public class AppBuild {
+    private AppUpdate appUpdate;
+    private AppCompile appCompile;
+    private AppPack appPack;
+}

+ 14 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/compile/AppCompile.java

@@ -0,0 +1,14 @@
+package cn.reghao.autodop.dmaster.app.pojo.build.compile;
+
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2020-05-13 16:40:22
+ */
+@Data
+public class AppCompile {
+    private String compilerName;
+    private String compilerType;
+    private String script;
+}

+ 14 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/pack/AppPack.java

@@ -0,0 +1,14 @@
+package cn.reghao.autodop.dmaster.app.pojo.build.pack;
+
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2020-05-13 16:40:22
+ */
+@Data
+public class AppPack {
+    private String packerName;
+    private String packerType;
+    private String appRootPath;
+}

+ 14 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/update/AppRepo.java

@@ -0,0 +1,14 @@
+package cn.reghao.autodop.dmaster.app.pojo.build.update;
+
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2020-02-28 14:35:42
+ */
+@Data
+public class AppRepo {
+    private String repo;
+    // 多个仓库以 "," 分隔
+    private String dependencyRepos;
+}

+ 13 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/update/AppUpdate.java

@@ -0,0 +1,13 @@
+package cn.reghao.autodop.dmaster.app.pojo.build.update;
+
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2020-05-13 16:40:22
+ */
+@Data
+public class AppUpdate {
+    private RepoAuth repoAuth;
+    private AppRepo appRepo;
+}

+ 15 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/build/update/RepoAuth.java

@@ -0,0 +1,15 @@
+package cn.reghao.autodop.dmaster.app.pojo.build.update;
+
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2020-02-28 14:12:33
+ */
+@Data
+public class RepoAuth {
+    private String repoName;
+    private String repoType;
+    private String username;
+    private String password;
+}

+ 11 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/constant/CompilerType.java

@@ -0,0 +1,11 @@
+package cn.reghao.autodop.dmaster.app.pojo.constant;
+
+/**
+ * 编译工具
+ *
+ * @author reghao
+ * @date 2019-10-18 14:31:29
+ */
+public enum CompilerType {
+    none, dotnet, maven, npm, gobuild, gpp;
+}

+ 11 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/constant/NotifyType.java

@@ -0,0 +1,11 @@
+package cn.reghao.autodop.dmaster.app.pojo.constant;
+
+/**
+ * 通知工具
+ *
+ * @author reghao
+ * @date 2020-03-01 17:18:53
+ */
+public enum NotifyType {
+    ding, email, sms;
+}

+ 11 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/constant/PackerType.java

@@ -0,0 +1,11 @@
+package cn.reghao.autodop.dmaster.app.pojo.constant;
+
+/**
+ * 打包工具
+ *
+ * @author reghao
+ * @date 2019-11-15 21:59:35
+ */
+public enum PackerType {
+    docker, maven, jar, dotnetBinary, zip;
+}

+ 11 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/constant/RepoType.java

@@ -0,0 +1,11 @@
+package cn.reghao.autodop.dmaster.app.pojo.constant;
+
+/**
+ * 版本管理工具
+ *
+ * @author reghao
+ * @date 2019-11-15 22:41:04
+ */
+public enum RepoType {
+    svn, git;
+}

+ 18 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/deploy/AppDeploy.java

@@ -0,0 +1,18 @@
+package cn.reghao.autodop.dmaster.app.pojo.deploy;
+
+import cn.reghao.autodop.dmaster.orchestrate.pojo.build.AppLog;
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2020-05-13 16:59:20
+ */
+@Data
+public class AppDeploy {
+    // 多台主机以 “,” 分隔
+    private String hosts;
+    private int port;
+    private String healthCheck;
+    private String runningDir;
+    private AppLog log;
+}

+ 29 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/orchestration/AppOrchestration.java

@@ -0,0 +1,29 @@
+package cn.reghao.autodop.dmaster.app.pojo.orchestration;
+
+import cn.reghao.autodop.dmaster.app.pojo.build.AppBuild;
+import cn.reghao.autodop.dmaster.app.pojo.deploy.AppDeploy;
+import lombok.Data;
+import java.util.Map;
+
+/**
+ * @author reghao
+ * @date 2020-02-28 14:11:02
+ */
+@Data
+public class AppOrchestration {
+    private String appId;
+    // 应用代码所在目录的名字
+    private String dirname;
+    private String description;
+    private String env;
+    // 编译 app 时所处的目录,以仓库目录为起点
+    private String entryDir;
+    // 配置文件
+    private Map<String, String> configFiles;
+
+    // projId 和 appBuild 二者只能存在一个
+    private String projId;
+    private AppBuild appBuild;
+    private AppDeploy appDeploy;
+    private Notification notification;
+}

+ 14 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/orchestration/Notification.java

@@ -0,0 +1,14 @@
+package cn.reghao.autodop.dmaster.app.pojo.orchestration;
+
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2020-03-06 21:20:06
+ */
+@Data
+public class Notification {
+    private String notifyName;
+    private String notifyType;
+    private String destination;
+}

+ 16 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/pojo/orchestration/ProjOrchestration.java

@@ -0,0 +1,16 @@
+package cn.reghao.autodop.dmaster.app.pojo.orchestration;
+
+import cn.reghao.autodop.dmaster.app.pojo.build.AppBuild;
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2020-02-28 14:11:18
+ */
+@Data
+public class ProjOrchestration {
+    private String projId;
+    private String description;
+    // 同一个项目内所有应用的构建策略是相同的
+    private AppBuild build;
+}

+ 9 - 12
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppManager.java

@@ -1,10 +1,7 @@
 package cn.reghao.autodop.dmaster.app.service;
 
-import cn.reghao.autodop.common.docker.DockerException;
-import cn.reghao.autodop.common.grpc.client.GrpcClientProxy;
-import cn.reghao.autodop.common.grpc.facade.AppService;
+import cn.reghao.autodop.common.dockerc.DockerException;
 import cn.reghao.autodop.dmaster.orchestrate.caching.OrchestrationCaching;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
@@ -30,47 +27,47 @@ public class AppManager {
     }
 
     public void start(String appId) throws DockerException {
-        AppOrchestration app = caching.findAppByIdentifier(appId);
+        /*AppOrchestration app = caching.findAppByIdentifier(appId);
         String[] hosts = app.getDeploy().getHosts().split(",");
         for (String host : hosts) {
             AppService appService = (AppService) new GrpcClientProxy<AppService>()
                     .getProxy(host, GRPC_PORT, AppService.class);
 
             appService.start(appId);
-        }
+        }*/
     }
 
     public void stop(String appId) throws DockerException {
-        AppOrchestration app = caching.findAppByIdentifier(appId);
+        /*AppOrchestration app = caching.findAppByIdentifier(appId);
         String[] hosts = app.getDeploy().getHosts().split(",");
         for (String host : hosts) {
             AppService appService = (AppService) new GrpcClientProxy<AppService>()
                     .getProxy(host, GRPC_PORT, AppService.class);
 
             appService.stop(appId);
-        }
+        }*/
     }
 
     public void restart(String appId) throws DockerException {
-        AppOrchestration app = caching.findAppByIdentifier(appId);
+        /*AppOrchestration app = caching.findAppByIdentifier(appId);
         String[] hosts = app.getDeploy().getHosts().split(",");
         for (String host : hosts) {
             AppService appService = (AppService) new GrpcClientProxy<AppService>()
                     .getProxy(host, GRPC_PORT, AppService.class);
 
             appService.restart(appId);
-        }
+        }*/
     }
 
     public List<String> log(String appId) throws DockerException, IOException {
-        AppOrchestration app = caching.findAppByIdentifier(appId);
+        /*AppOrchestration app = caching.findAppByIdentifier(appId);
         String[] hosts = app.getDeploy().getHosts().split(",");
         for (String host : hosts) {
             AppService appService = (AppService) new GrpcClientProxy<AppService>()
                     .getProxy(host, GRPC_PORT, AppService.class);
 
             List<String> logs = appService.log(appId);
-        }
+        }*/
 
         return null;
     }

+ 2 - 5
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/OssService.java

@@ -1,15 +1,12 @@
 package cn.reghao.autodop.dmaster.app.service;
 
-import cn.reghao.autodop.common.utils.FileUtil;
-import cn.reghao.autodop.dmaster.app.service.build.tools.vc.SvnImpl;
+import cn.reghao.autodop.dmaster.app.service.tools.updater.SvnImpl;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.SysConfig;
-import cn.reghao.autodop.dmaster.utils.OssUtil;
+import cn.reghao.autodop.dmaster.common.utils.OssUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.tmatesoft.svn.core.SVNException;
 
-import java.io.File;
-
 /**
  * @author reghao
  * @date 2020-03-17 13:58:03

+ 3 - 3
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppBuildPipeline.java

@@ -19,7 +19,7 @@ import java.util.concurrent.Callable;
  * @date 2019-11-16 21:39:53
  */
 @Slf4j
-public class AppPipeline implements Callable<String> {
+public class AppBuildPipeline implements Callable<String> {
     private AppOrchestration app;
     private String version;
     private boolean isDeploy;
@@ -28,7 +28,7 @@ public class AppPipeline implements Callable<String> {
     private final String appLocalRepo;
     private final String appCompileDir;
 
-    public AppPipeline(AppOrchestration app, String version, boolean isDeploy) {
+    public AppBuildPipeline(AppOrchestration app, String version, boolean isDeploy) {
         this.app = app;
         this.version = version;
         this.isDeploy = isDeploy;
@@ -62,7 +62,7 @@ public class AppPipeline implements Callable<String> {
         if (isDeploy) {
             appIntegrate.deploy();
         }
-        
+
         /* 更新阶段 *//*
         if (version == null ) {
             try {

+ 3 - 3
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/AppIntegrate.java

@@ -20,7 +20,7 @@ import lombok.extern.slf4j.Slf4j;
  * @date 2019-10-09 10:54:43
  */
 @Slf4j
-public class AppBuildDeploy {
+public class AppIntegrate {
     private final String packDir = SysConfig.packDir;
     private AppOrchestration app;
     private CodeUpdater codeUpdater;
@@ -28,7 +28,7 @@ public class AppBuildDeploy {
     private CodeCompiler codeCompiler;
     private CodePacker codePacker;
 
-    public AppBuildDeploy() {
+    public AppIntegrate() {
     }
 
     public void setApp(AppOrchestration app) {
@@ -36,7 +36,7 @@ public class AppBuildDeploy {
         init();
     }
 
-    public AppBuildDeploy(AppOrchestration app) {
+    public AppIntegrate(AppOrchestration app) {
         this.app = app;
         init();
     }

+ 13 - 15
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuildDispatcher.java

@@ -2,13 +2,11 @@ package cn.reghao.autodop.dmaster.app.service.build;
 
 import cn.reghao.autodop.common.config.BuildDeployResult;
 import cn.reghao.autodop.common.utils.JsonUtil;
+import cn.reghao.autodop.dmaster.app.pojo.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.orchestrate.caching.OrchestrationCaching;
+import cn.reghao.autodop.dmaster.app.thread.ThreadPoolWrapper;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.build.AppBuild;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.build.CodeRepos;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.build.ProjBuild;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.ProjOrchestration;
-import cn.reghao.autodop.dmaster.app.thread.ThreadPoolWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
@@ -36,7 +34,7 @@ public class BuildDispatcher {
      * @return
      * @date 2019-11-12 上午9:48
      */
-    public List<BuildDeployResult> dispatch(Set<String> appIds, boolean isDeploy, boolean isRun) throws Exception {
+    public List<BuildDeployResult> dispatch(Set<String> appIds, boolean isDeploy) throws Exception {
         List<BuildDeployResult> results = new ArrayList<>();
         List<AppOrchestration> existApps = new ArrayList<>();
         // 分离出存在的应用和不存在的应用
@@ -65,11 +63,11 @@ public class BuildDispatcher {
             if (!STANDALONE_APP.equalsIgnoreCase(key)) {
                 // 首先更新整个项目,然后再分别更新,编译,打包应用
                 ProjOrchestration proj = caching.findProjByIdentifier(key);
-                projFutures.add(threadPool.submit(new ProjectUpdateTask(proj, apps)));
+                //projFutures.add(threadPool.submit(new ProjectUpdateTask(proj, apps)));
             } else {
                 // 更新,编译,打包独立的应用
                 apps.forEach(app -> {
-                    appFutures.add(threadPool.submit(new AppBuildPipeline(app, null, isDeploy, isRun)));
+                    appFutures.add(threadPool.submit(new AppBuildPipeline(app, null, isDeploy)));
                 });
             }
         }
@@ -88,8 +86,8 @@ public class BuildDispatcher {
                 List<ProjectUpdateTask.AppVersion> appVersions = future.get();
                 appVersions.forEach(appVersion -> {
                     if (appVersion.isUpdated()) {
-                        appFutures.add(threadPool.submit(
-                                new AppBuildPipeline(appVersion.getApp(), appVersion.getVersion(), isDeploy, isRun)));
+                        /*appFutures.add(threadPool.submit(
+                                new AppBuildPipeline(appVersion.getApp(), appVersion.getVersion(), isDeploy)));*/
                     } else {
                         BuildDeployResult buildDeployResult = new BuildDeployResult();
                         buildDeployResult.setAppId(appVersion.getApp().getIdentifier());
@@ -129,8 +127,8 @@ public class BuildDispatcher {
     private Map<String, List<AppOrchestration>> filterByProj(List<AppOrchestration> apps) {
         Map<String, List<AppOrchestration>> appMap = new HashMap<>();
         for (AppOrchestration app : apps) {
-            String mapkey;
-            if (app.getProjBuild() != null) {
+            String mapkey = null;
+            /*if (app.getProjBuild() != null) {
                 mapkey = app.getProjBuild().getProjId();
                 ProjOrchestration proj = caching.findProjByIdentifier(mapkey);
                 AppBuild projBuild = proj.getBuild();
@@ -138,7 +136,7 @@ public class BuildDispatcher {
             } else {
                 // 单独的应用,不隶属于任何项目
                 mapkey = STANDALONE_APP;
-            }
+            }*/
 
             if (appMap.containsKey(mapkey)) {
                 appMap.get(mapkey).add(app);
@@ -162,14 +160,14 @@ public class BuildDispatcher {
      * @date 2020-03-09 下午4:39
      */
     private void fillAppBuild(AppBuild build, AppOrchestration app) {
-        ProjBuild projBuild = app.getProjBuild();
+        //ProjBuild projBuild = app.getProjBuild();
 
         AppBuild appBuild = new AppBuild();
         appBuild.setNotifier(build.getNotifier());
         appBuild.setCodeCompiler(build.getCodeCompiler());
         appBuild.setAppPacker(build.getAppPacker());
 
-        String projReposUrl = build.getCodeRepos().getReposUrl();
+        /*String projReposUrl = build.getCodeRepos().getReposUrl();
         String appReposUrl = projReposUrl + projBuild.getAppReposUrl();
 
         CodeRepos codeRepos = new CodeRepos();
@@ -186,6 +184,6 @@ public class BuildDispatcher {
         }
 
         appBuild.setCodeRepos(codeRepos);
-        app.setBuild(appBuild);
+        app.setBuild(appBuild);*/
     }
 }

+ 4 - 4
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/BuilderUtil.java

@@ -6,9 +6,9 @@ import cn.reghao.autodop.dmaster.orchestrate.pojo.SysConfig;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.build.CodeRepos;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.ReposAuth;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
-import cn.reghao.autodop.dmaster.app.service.build.tools.vc.GitImpl;
-import cn.reghao.autodop.dmaster.app.service.build.tools.vc.SvnImpl;
-import cn.reghao.autodop.dmaster.app.service.build.tools.vc.VersionControl;
+import cn.reghao.autodop.dmaster.app.service.tools.updater.GitImpl;
+import cn.reghao.autodop.dmaster.app.service.tools.updater.SvnImpl;
+import cn.reghao.autodop.dmaster.app.service.tools.updater.CodeUpdater;
 import lombok.extern.slf4j.Slf4j;
 
 import java.io.File;
@@ -63,7 +63,7 @@ public class BuilderUtil {
         FileUtil.traversal(appCompileDir, new ReplaceCharacter());
     }
 
-    public static VersionControl versionControl(ReposAuth reposAuth) {
+    public static CodeUpdater versionControl(ReposAuth reposAuth) {
         if ("svn".equals(reposAuth.getReposType())) {
             return new SvnImpl(reposAuth.getUsername(), reposAuth.getPassword());
         } else if ("git".equals(reposAuth.getReposType())) {

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/build/ProjectUpdateTask.java

@@ -4,7 +4,7 @@ import cn.reghao.autodop.dmaster.orchestrate.pojo.SysConfig;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.build.CodeRepos;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.ProjOrchestration;
-import cn.reghao.autodop.dmaster.app.service.build.tools.vc.VersionControl;
+import cn.reghao.autodop.dmaster.app.service.tools.updater.CodeUpdater;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
@@ -27,7 +27,7 @@ public class ProjectUpdateTask implements Callable<List<ProjectUpdateTask.AppVer
     private ProjOrchestration proj;
     private List<AppOrchestration> apps;
     private final String localRepos;
-    private VersionControl vc;
+    private CodeUpdater vc;
 
     public ProjectUpdateTask(ProjOrchestration proj, List<AppOrchestration> apps) {
         this.proj = proj;

+ 6 - 7
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/deploy/AppDeploy.java

@@ -1,11 +1,10 @@
-package cn.reghao.autodop.dmaster.app.service.build;
+package cn.reghao.autodop.dmaster.app.service.deploy;
 
 import cn.reghao.autodop.common.config.BuildDeployResult;
 import cn.reghao.autodop.common.http.HttpApi;
 import cn.reghao.autodop.common.notification.DingNotify;
 import cn.reghao.autodop.common.notification.Notify;
-import cn.reghao.autodop.common.utils.JsonUtil;
-import cn.reghao.autodop.dmaster.app.pojo.BuildMsg;
+import cn.reghao.autodop.dmaster.app.pojo.BuildLog;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.AppPacker;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.Notifier;
@@ -26,7 +25,7 @@ public class AppDeploy {
      * @return
      * @date 2020-03-13 下午1:00
      */
-    public static List<BuildDeployResult> deploy(AppOrchestration app, String version, boolean isRun) throws Exception {
+    public static List<BuildDeployResult> deploy(AppOrchestration app, String version) throws Exception {
         Notifier notifier = app.getBuild().getNotifier();
 
         Notify notify = null;
@@ -58,14 +57,14 @@ public class AppDeploy {
             appPath = appPacker.getAppRootPath() + "/" + app.getIdentifier() + "_" + version;
         }
 
-        List<BuildDeployResult> results = Deployer.deploy(app, appPath, isRun);
+        List<BuildDeployResult> results = Deployer.deploy(app, appPath);
         for (BuildDeployResult result : results) {
             result.setVersion(version);
             result.setDescription(app.getDescription());
             if ("运行".equals(result.getStage()) && result.getCode() == 0) {
                 log.info("{} 已运行", app.getIdentifier());
-                BuildMsg buildMsg =
-                        new BuildMsg(app.getIdentifier(), app.getDescription(), version, app.getEnv());
+                BuildLog buildLog =
+                        new BuildLog(app.getIdentifier(), app.getDescription(), version, app.getEnv());
                 // TODO 异步通知
                 assert notify != null;
                 //notify.sendJson(JsonUtil.objectToJson(buildMsg));

+ 2 - 3
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/deploy/Deployer.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.service.build;
+package cn.reghao.autodop.dmaster.app.service.deploy;
 
 import cn.reghao.autodop.common.config.BuildDeployResult;
 import cn.reghao.autodop.common.grpc.client.GrpcClientProxy;
@@ -27,13 +27,12 @@ public class Deployer {
      * @return 返回 List 是因为可能是集群部署
      * @date 2020-03-12 下午3:18
      */
-    public static List<BuildDeployResult> deploy(AppOrchestration app, String appPath, boolean isRun) {
+    public static List<BuildDeployResult> deploy(AppOrchestration app, String appPath) {
         DeployConfig deployConfig = new DeployConfig();
         deployConfig.setAppId(app.getIdentifier());
         deployConfig.setAppPath(appPath);
         deployConfig.setPackerType(app.getBuild().getAppPacker().getPackerType());
         deployConfig.setRunningDir(app.getRunning().getRunningDir());
-        deployConfig.setRun(isRun);
 
         List<BuildDeployResult> results = new ArrayList<>();
         String[] hosts = app.getDeploy().getHosts().split(",");

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/CodeCompiler.java

@@ -6,7 +6,7 @@ package cn.reghao.autodop.dmaster.app.service.tools.compiler;
  * @author reghao
  * @date 2020-01-21 16:17:22
  */
-public interface CompileCode {
+public interface CodeCompiler {
     /**
      * @param appName 应用名字
      * @param appDir 应用目录

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/DefaultCompiler.java

@@ -6,7 +6,7 @@ package cn.reghao.autodop.dmaster.app.service.tools.compiler;
  * @author reghao
  * @date 2019-10-12 23:55:01
  */
-public class DefaultCompile implements CompileCode {
+public class DefaultCompiler implements CodeCompiler {
     @Override
     public void compile(String appName, String appDir) throws Exception {
     }

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/DnktMgrPreCompile.java

@@ -1,7 +1,7 @@
-package cn.reghao.autodop.dmaster.app.service.build.tools.compiler;
+package cn.reghao.autodop.dmaster.app.service.tools.compiler;
 
 import cn.reghao.autodop.common.utils.FileUtil;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.pojo.orchestration.AppOrchestration;
 import lombok.extern.slf4j.Slf4j;
 
 import java.io.IOException;

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/DotnetPreCompile.java

@@ -1,7 +1,7 @@
-package cn.reghao.autodop.dmaster.app.service.build.tools.compiler;
+package cn.reghao.autodop.dmaster.app.service.tools.compiler;
 
 import cn.reghao.autodop.common.utils.FileUtil;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.pojo.orchestration.AppOrchestration;
 import lombok.extern.slf4j.Slf4j;
 
 import java.io.IOException;

+ 5 - 5
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/MavenCompiler.java

@@ -1,6 +1,6 @@
 package cn.reghao.autodop.dmaster.app.service.tools.compiler;
 
-import cn.reghao.autodop.dmaster.app.service.tools.packer.PackApp;
+import cn.reghao.autodop.dmaster.app.service.tools.packer.CodePacker;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.maven.shared.invoker.*;
 
@@ -17,12 +17,12 @@ import java.util.List;
  * @date 2019-10-12 23:55:01
  */
 @Slf4j
-public class MavenCompile implements CompileCode, PackApp {
+public class MavenCompiler implements CodeCompiler, CodePacker {
     private InvocationRequest request;
     private Invoker invoker;
     private List<String> compileLog;
 
-    public MavenCompile(String mvnHome) {
+    public MavenCompiler(String mvnHome) {
         System.setProperty("maven.home", mvnHome);
         this.request = new DefaultInvocationRequest();
         this.invoker = new DefaultInvoker();
@@ -72,7 +72,7 @@ public class MavenCompile implements CompileCode, PackApp {
         String mvnHome = "/home/reghao/opt/tools/maven-3.6.0";
         String projPath = "/home/reghao/code/aha/emall";
 
-        CompileCode compileCode = new MavenCompile(mvnHome);
-        compileCode.compile("file", projPath);
+        CodeCompiler codeCompiler = new MavenCompiler(mvnHome);
+        codeCompiler.compile("file", projPath);
     }
 }

+ 2 - 3
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/PreCompile.java

@@ -1,9 +1,8 @@
-package cn.reghao.autodop.dmaster.app.service.build.tools.compiler;
+package cn.reghao.autodop.dmaster.app.service.tools.compiler;
 
-import cn.reghao.autodop.dmaster.orchestrate.pojo.orchestration.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.pojo.orchestration.AppOrchestration;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * @author reghao

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/compiler/ShellCompiler.java

@@ -13,11 +13,11 @@ import java.util.Map;
  * @author reghao
  * @date 2019-10-12 23:55:01
  */
-public class ShellCompile implements CompileCode {
+public class ShellCompiler implements CodeCompiler {
     private String script;
     private ShellExecutor shell;
 
-    public ShellCompile(String script) {
+    public ShellCompiler(String script) {
         this.script = script;
         this.shell = new ShellExecutor();
     }

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/CodePacker.java

@@ -7,7 +7,7 @@ package cn.reghao.autodop.dmaster.app.service.tools.packer;
  * @author reghao
  * @date 2020-01-21 16:18:37
  */
-public interface PackApp {
+public interface CodePacker {
     /**
      * 打包方式确定运行方式
      *

+ 7 - 9
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/DnktMgrZipPack.java

@@ -1,8 +1,7 @@
-package cn.reghao.autodop.dmaster.app.service.build.tools.packer;
+package cn.reghao.autodop.dmaster.app.service.tools.packer;
 
 import cn.reghao.autodop.common.utils.FileUtil;
 import cn.reghao.autodop.common.utils.compression.ZipUtil;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.AppPacker;
 import lombok.extern.slf4j.Slf4j;
 
 import java.io.File;
@@ -14,18 +13,17 @@ import java.io.File;
  * @date 2020-03-11 13:37:36
  */
 @Slf4j
-public class DnktMgrZipPack implements PackApp {
-    private final String SUFFIX = ".zip";
-    private AppPacker appPacker;
+public class DnktMgrZipPack implements CodePacker {
+    private String appRootPath;
 
-    public DnktMgrZipPack(AppPacker appPacker) {
-        this.appPacker = appPacker;
+    public DnktMgrZipPack(String appRootPath) {
+        this.appRootPath = appRootPath;
     }
 
     @Override
     public void pack(String appId, String version, String appEntryDir) throws Exception {
-        String tag = appId + "_" + version + SUFFIX;
-        String dst = appPacker.getAppRootPath() + "/" + tag;
+        String tag = appId + "_" + version + ".zip";
+        String dst = appRootPath + "/" + tag;
         if (new File(dst).exists()) {
             return;
         }

+ 7 - 7
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/DockerPack.java

@@ -1,6 +1,6 @@
-package cn.reghao.autodop.dmaster.app.service.build.tools.packer;
+package cn.reghao.autodop.dmaster.app.service.tools.packer;
 
-import cn.reghao.autodop.common.docker.DockerClient;
+import cn.reghao.autodop.common.dockerc.DockerClient;
 import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.AppPacker;
 
 /**
@@ -9,17 +9,17 @@ import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.AppPacker;
  * @author reghao
  * @date 2019-10-14 22:02:04
  */
-public class DockerPack implements PackApp {
-    private AppPacker appPacker;
+public class DockerPack implements CodePacker {
+    private String appRootPath;
 
-    public DockerPack(AppPacker appPacker) {
-        this.appPacker = appPacker;
+    public DockerPack(String appRootPath) {
+        this.appRootPath = appRootPath;
     }
 
     @Override
     public void pack(String appId, String version, String appEntryDir) throws Exception {
         DockerClient docker = new DockerClient();
-        String repo = appPacker.getAppRootPath() + "/" + appId;
+        String repo = appRootPath + "/" + appId;
         String image = repo + ":" + version;
 
         docker.build(image, appEntryDir);

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/DotnetPack.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.service.build.tools.packer;
+package cn.reghao.autodop.dmaster.app.service.tools.packer;
 
 /**
  * TODO dotnet 应用(二进制版)
@@ -6,7 +6,7 @@ package cn.reghao.autodop.dmaster.app.service.build.tools.packer;
  * @author reghao
  * @date 2019-11-09 15:03:27
  */
-public class DotnetPack implements PackApp {
+public class DotnetPack implements CodePacker {
     @Override
     public void pack(String appId, String version, String appEntryDir) throws Exception {
     }

+ 2 - 3
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/ZipPack.java

@@ -1,7 +1,6 @@
-package cn.reghao.autodop.dmaster.app.service.build.tools.packer;
+package cn.reghao.autodop.dmaster.app.service.tools.packer;
 
 import cn.reghao.autodop.common.utils.compression.ZipUtil;
-import cn.reghao.autodop.dmaster.orchestrate.pojo.tools.AppPacker;
 import lombok.extern.slf4j.Slf4j;
 
 import java.io.File;
@@ -11,7 +10,7 @@ import java.io.File;
  * @date 2020-03-11 13:37:36
  */
 @Slf4j
-public class ZipPack implements PackApp {
+public class ZipPack implements CodePacker {
     private final String SUFFIX = ".zip";
     private String packDir;
 

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/packer/ZipRemotePack.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.service.build.tools.packer;
+package cn.reghao.autodop.dmaster.app.service.tools.packer;
 
 import cn.reghao.autodop.common.utils.compression.ZipUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -10,7 +10,7 @@ import java.io.File;
  * @date 2020-03-11 13:37:36
  */
 @Slf4j
-public class ZipRemotePack implements PackApp {
+public class ZipRemotePack implements CodePacker {
     private final String SUFFIX = ".zip";
     private String packDir;
 

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/CodeUpdater.java

@@ -6,7 +6,7 @@ package cn.reghao.autodop.dmaster.app.service.tools.updater;
  * @author reghao
  * @date 2019-10-12 22:24:28
  */
-public interface UpdateCode {
+public interface CodeUpdater {
     /**
      * 更新代码
      *

+ 20 - 22
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/GitImpl.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.service.tools.vc;
+package cn.reghao.autodop.dmaster.app.service.tools.updater;
 
 import org.eclipse.jgit.api.CloneCommand;
 import org.eclipse.jgit.api.Git;
@@ -11,13 +11,14 @@ import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
 import java.io.File;
 
 /**
- * TODO git 实现
+ * git 实现
  *
  * @author reghao
  * @date 2019-10-12 22:22:00
  */
-public class GitImpl implements VersionControl {
-    private final String GIT = "/.git";
+public class GitImpl implements CodeUpdater {
+    private String GIT = "/.git";
+    private String branch = "master";
 
     private final UsernamePasswordCredentialsProvider credentials;
 
@@ -27,26 +28,22 @@ public class GitImpl implements VersionControl {
 
     @Override
     public String update(String remote, String local) throws Exception {
-        File localRepos = new File(local + GIT);
-        if (!localRepos.exists()) {
-            return null;
-        }
-
-        Repository repos = null;
-        try {
-            repos = new FileRepository(localRepos.getAbsolutePath());
-            Git git = new Git(repos);
-            PullCommand pull = git.pull();
-            pull.call();
-        } catch (Exception e) {
+        File localRepo = new File(local + GIT);
+        if (!localRepo.exists()) {
+            clone(remote, local);
+        } else {
+            Repository repo = new FileRepository(localRepo.getAbsolutePath());
+            PullCommand gitPull = new Git(repo).pull();
+            gitPull.call();
         }
 
         return null;
     }
 
     private void clone(String remote, String local) throws GitAPIException {
-        CloneCommand clone = Git.cloneRepository().setURI(remote);
-        clone.setDirectory(new File(local)).call();
+        CloneCommand gitClone = Git.cloneRepository().setURI(remote).setBranch(branch);
+        Git git = gitClone.setDirectory(new File(local)).call();
+        System.out.println();
     }
 
     @Override
@@ -56,10 +53,11 @@ public class GitImpl implements VersionControl {
 
     public static void main(String[] args) throws Exception {
         GitImpl git = new GitImpl("reghao", "gjs");
-        String remote = "http://git.reghao.cn/reghao/autodop.git";
-        String local = "/home/reghao/tmp/autodop/opt/data/git";
+        String remote = "http://git.reghao.cn/reghao/spiderlab.git";
+        String local = "/home/reghao/tmp/autodop/opt/data/git/spiderlab";
 
-        CloneCommand clone = Git.cloneRepository().setURI(remote);
-        clone.setDirectory(new File(local)).call();
+        /*CloneCommand clone = Git.cloneRepository().setURI(remote);
+        clone.setDirectory(new File(local)).call();*/
+        git.update(remote, local);
     }
 }

+ 2 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/tools/updater/SvnImpl.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.app.service.tools.vc;
+package cn.reghao.autodop.dmaster.app.service.tools.updater;
 
 import org.tmatesoft.svn.core.SVNDepth;
 import org.tmatesoft.svn.core.SVNException;
@@ -18,7 +18,7 @@ import java.io.File;
  * @author reghao
  * @date 2019-09-07 16:18:46
  */
-public class SvnImpl implements VersionControl {
+public class SvnImpl implements CodeUpdater {
     private SVNUpdateClient updateClient;
 
     public SvnImpl(String username, String password) {

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/config/AuthFailureHandlerImpl.java

@@ -15,7 +15,7 @@ import java.io.IOException;
  * @author reghao
  * @date 2019-04-09 00:02:34
  */
-public class AuthSuccessHandlerImpl implements AuthenticationFailureHandler {
+public class AuthFailureHandlerImpl implements AuthenticationFailureHandler {
     @Override
     public void onAuthenticationFailure(HttpServletRequest request,
                                         HttpServletResponse response,

+ 1 - 11
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/config/AuthSuccessHandlerImpl.java

@@ -15,22 +15,12 @@ import java.io.IOException;
  * @author reghao
  * @date 2019-04-08 23:50:51
  */
-public class AuthSuccessHandlerImpl1 implements AuthenticationSuccessHandler {
+public class AuthSuccessHandlerImpl implements AuthenticationSuccessHandler {
     @Override
     public void onAuthenticationSuccess(HttpServletRequest request,
                                         HttpServletResponse response,
                                         Authentication authentication)
             throws IOException, ServletException {
-
-        /*SavedRequest savedRequest = (SavedRequest) request.getSession().getAttribute("SPRING_SECURITY_SAVED_REQUEST");
-        if (savedRequest != null) {
-            String redirectUrl = savedRequest.getRedirectUrl();
-            // 跳转到登录前的 URL
-            response.sendRedirect(redirectUrl);
-        } else {
-            response.sendRedirect("/");
-        }*/
-
         String body = "";
         response.getOutputStream().print(body);
     }

+ 19 - 101
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/config/WebSecurityConfig.java

@@ -1,8 +1,7 @@
 package cn.reghao.autodop.dmaster.auth.config;
 
-import cn.reghao.autodop.dmaster.utils.Md5Encrypt;
-import cn.reghao.autodop.dmaster.auth.filter.LoginRedirectFilter;
-import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import cn.reghao.autodop.dmaster.auth.impl.formlogin.UserDetailsServiceImpl;
+import cn.reghao.autodop.dmaster.auth.impl.formlogin.UsernamePasswordAuthFilter;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.security.access.expression.SecurityExpressionHandler;
@@ -11,16 +10,12 @@ import org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl;
 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
 import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.builders.WebSecurity;
 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.security.web.FilterInvocation;
 import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler;
 import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
 
-import javax.servlet.Filter;
-
 /**
  * Web 应用安全配置
  *
@@ -29,11 +24,11 @@ import javax.servlet.Filter;
  */
 @Configuration
 @EnableWebSecurity
-@EnableGlobalMethodSecurity(prePostEnabled = true)
+//@EnableGlobalMethodSecurity(prePostEnabled = true)
 public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
-    private WebUserDetailsServiceImpl userDetailsService;
+    private UserDetailsServiceImpl userDetailsService;
 
-    public WebSecurityConfig(WebUserDetailsServiceImpl userDetailsService) {
+    public WebSecurityConfig(UserDetailsServiceImpl userDetailsService) {
         this.userDetailsService = userDetailsService;
     }
 
@@ -41,15 +36,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
     protected void configure(HttpSecurity http) throws Exception {
         http.authorizeRequests()
                 .expressionHandler(webExpressionHandler())
-                // 认证接口
-                .antMatchers("/signin").permitAll()
-                .antMatchers("/auth").permitAll()
-                // 注册接口
-                .antMatchers("/register").permitAll()
-                // 不需要认证的接口
-                //.antMatchers("/api/**").permitAll()
+                .antMatchers("/api/**").permitAll()
                 .antMatchers("/**").permitAll()
-                .antMatchers("/favicon.ico").permitAll()
+                .antMatchers("/actuator/health").permitAll()
                 .anyRequest().authenticated();
 
         http.exceptionHandling().accessDeniedPage("/deny");
@@ -58,26 +47,19 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
         //http.csrf().requireCsrfProtectionMatcher(new AntPathRequestMatcher("/oauth/authorize")).disable();
         http.csrf().disable();
 
-        // 在 UsernamePasswordAuthenticationFilter 后添加 filter
-        http.addFilterAfter(new LoginRedirectFilter(), UsernamePasswordAuthenticationFilter.class)
-                .headers().frameOptions().disable();
-
         // 基于表单的认证
         http.formLogin()
                 // 登录接口
-                .loginProcessingUrl("/signin")
-                .successHandler(new WebAuthenticationSuccessHandlerImpl())
-                .failureHandler(new WebAuthenticationFailureHandlerImpl())
-                // 登录页面
-                .loginPage("/signin")
+                .loginProcessingUrl("/login")
+                .successHandler(new AuthSuccessHandlerImpl())
+                .failureHandler(new AuthFailureHandlerImpl())
                 .and()
                 .logout()
-                .logoutSuccessUrl("/login")
+                //.logoutSuccessUrl("/login")
                 .and()
                 .httpBasic().disable();
 
-        // HTTP Basic 认证
-        http.httpBasic();
+        http.addFilterBefore(usernamePasswordAuthFilter(), UsernamePasswordAuthenticationFilter.class);
     }
 
     /**
@@ -87,60 +69,18 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
      * @return
      * @date 2019-07-05 上午11:25
      */
-    /*@Override
-    public void configure(AuthenticationManagerBuilder auth) throws Exception {
-        auth.userDetailsService(userDetailsService);
-    }*/
-
-    /**
-     * 使用内存存储
-     *
-     * @param
-     * @return
-     * @date 2019-07-05 上午11:25
-     */
     @Override
     public void configure(AuthenticationManagerBuilder auth) throws Exception {
-        auth.inMemoryAuthentication()
-                .withUser("admin")
-                // 12345678 的 MD5
-                .password("ca29f850198e55ba496476d9de227648")
-                .authorities("ROLE_ADMIN");
-
-        auth.inMemoryAuthentication()
-                .withUser("reghao")
-                .password("ca29f850198e55ba496476d9de227648")
-                .authorities("ROLE_USER");
+        auth.userDetailsService(userDetailsService);
     }
 
-    /**
-     * 静态资源不做认证
-     *
-     * @param
-     * @return
-     * @date 2019-06-04 下午10:48
-     */
-    @Override
-    public void configure(WebSecurity web) throws Exception {
-        web.ignoring()
-                //.antMatchers("/")
-                .antMatchers("/assets/**")
-                .antMatchers("/js/**")
-                .antMatchers("/imgs/**")
-                .antMatchers("/css/**")
-                .antMatchers("/html/**");
-    }
+    private UsernamePasswordAuthFilter usernamePasswordAuthFilter() throws Exception {
+        UsernamePasswordAuthFilter filter = new UsernamePasswordAuthFilter("/login", "POST");
+        filter.setAuthenticationManager(super.authenticationManager());
+        filter.setAuthenticationSuccessHandler(new AuthSuccessHandlerImpl());
+        filter.setAuthenticationFailureHandler(new AuthFailureHandlerImpl());
 
-    /**
-     * password 编码器
-     *
-     * @param
-     * @return
-     * @date 2019-06-04 下午10:53
-     */
-    @Bean
-    public PasswordEncoder passwordEncoder() {
-        return Md5Encrypt.getInstance();
+        return filter;
     }
 
     /**
@@ -155,7 +95,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
     public RoleHierarchy roleHierarchy() {
         RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
         roleHierarchy.setHierarchy("ROLE_ADMIN > ROLE_USER");
-
         return roleHierarchy;
     }
 
@@ -166,25 +105,4 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
 
         return defaultWebSecurityExpressionHandler;
     }
-
-    /**
-     * 注册一个过滤器
-     * TODO: 添加多个过滤器时,指定其顺序
-     *
-     * @param
-     * @return
-     * @date 2019-07-05 下午2:11
-     */
-    @Bean
-    public FilterRegistrationBean filterRegistrationBean() {
-        FilterRegistrationBean registration = new FilterRegistrationBean();
-        registration.setFilter(loginRedirectFilter());
-
-        return registration;
-    }
-
-    @Bean
-    public Filter loginRedirectFilter() {
-        return new LoginRedirectFilter();
-    }
 }

+ 4 - 6
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/entity/UserAuth.java

@@ -31,6 +31,7 @@ public class UserAuth implements Serializable, UserDetails {
     // 用户名和密码
     private String username;
     private String password;
+    private String salt;
 
     // 数据库表中默认为 ROLE_USER
     private int roleId;
@@ -39,15 +40,12 @@ public class UserAuth implements Serializable, UserDetails {
     // 数据库表中默认为 0
     private int locked;
     @ElementCollection(fetch = FetchType.LAZY)
-    private Set<SimpleGrantedAuthority> authorities = new HashSet<>();
+    private Set<GrantedAuthority> authorities;
 
-    public UserAuth(String username, String password, List<GrantedAuthority> grantedAuthorities) {
+    public UserAuth(String username, String password, Set<GrantedAuthority> grantedAuthorities) {
         this.username = username;
         this.password = password;
-
-        grantedAuthorities.forEach(grantedAuthority -> {
-            this.authorities.add((SimpleGrantedAuthority)grantedAuthority);
-        });
+        this.authorities = grantedAuthorities;
     }
 
     public UserAuth(String username, String password) {

+ 66 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/impl/formlogin/UserDetailsServiceImpl.java

@@ -0,0 +1,66 @@
+package cn.reghao.autodop.dmaster.auth.impl.formlogin;
+
+import cn.reghao.autodop.dmaster.auth.entity.UserAuth;
+import cn.reghao.autodop.dmaster.auth.repository.RoleRepository;
+import cn.reghao.autodop.dmaster.auth.repository.UserAuthRepository;
+import org.springframework.security.authentication.DisabledException;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.stereotype.Service;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * 用户名密码认证
+ *
+ * @author reghao
+ * @date 2019-05-20 11:03:56
+ */
+@Service
+public class UserDetailsServiceImpl implements UserDetailsService {
+    private UserAuthRepository authRepository;
+    private RoleRepository roleRepository;
+
+    public UserDetailsServiceImpl(UserAuthRepository authRepository, RoleRepository roleRepository) {
+        this.authRepository = authRepository;
+        this.roleRepository = roleRepository;
+    }
+
+    @Override
+    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
+        if ("admin".equals(username)) {
+            UserAuth userAuth = new UserAuth();
+            userAuth.setId(1);
+            userAuth.setUsername(username);
+            userAuth.setPassword("12345678");
+            userAuth.setRoleId(1);
+            userAuth.setStatus(0);
+
+            Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
+            GrantedAuthority grantedAuthority = new SimpleGrantedAuthority("ADMIN");
+            grantedAuthorities.add(grantedAuthority);
+            // 用户的权限
+            userAuth.setAuthorities(grantedAuthorities);
+            return userAuth;
+        }
+
+        /*UserAuth userAuth = authRepository.findUserAuthByUsername(username);
+        if (userAuth != null) {
+            String role = roleRepository.findRoleById(userAuth.getRoleId());
+            Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
+            GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(role);
+            grantedAuthorities.add(grantedAuthority);
+            // 用户的权限
+            userAuth.setAuthorities(grantedAuthorities);
+            return userAuth;
+        }*/ else {
+            // Spring Security 会将 UsernameNotFoundException 捕获并替换,使得前端无法看到信息
+            //throw new UsernameNotFoundException(email + " 未注册");
+            throw new DisabledException(username + " 未注册");
+        }
+    }
+}

+ 92 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/impl/formlogin/UsernamePasswordAuthFilter.java

@@ -0,0 +1,92 @@
+package cn.reghao.autodop.dmaster.auth.impl.formlogin;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
+import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedReader;
+import java.io.IOException;
+
+/**
+ * 替换 UsernamePasswordAuthenticationFilter
+ *
+ * @author reghao
+ * @date 2019-11-18 08:55:59
+ */
+public class UsernamePasswordAuthFilter extends AbstractAuthenticationProcessingFilter {
+    private String httpMethod;
+
+    public UsernamePasswordAuthFilter(String authUrl, String httpMethod) {
+        super(new AntPathRequestMatcher(authUrl, httpMethod));
+        this.httpMethod = httpMethod;
+    }
+
+    @Override
+    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
+            throws AuthenticationException, IOException, ServletException {
+
+        // form-data 中的 username 和 password 参数
+        String username = request.getParameter("user");
+        String password = request.getParameter("password");
+        if (username == null && password == null) {
+            // 请求数据放在 request 的 body 中
+            JsonObject jsonObject = getBody(request);
+            username = jsonObject.get("user").getAsString();
+            password = jsonObject.get("password").getAsString();
+        }
+
+        UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(username, password);
+        return this.getAuthenticationManager().authenticate(authToken);
+    }
+
+    /**
+     * 用户认证通过后颁发 JWT 令牌
+     *
+     * @param
+     * @return
+     * @date 2019-11-18 上午11:15
+     */
+    /*@Override
+    protected void successfulAuthentication(HttpServletRequest request,
+                                            HttpServletResponse response,
+                                            FilterChain chain,
+                                            Authentication auth) throws IOException, ServletException {
+
+        SavedRequest savedRequest = (SavedRequest) request.getSession().getAttribute("SPRING_SECURITY_SAVED_REQUEST");
+        if (savedRequest != null) {
+            String redirectUrl = savedRequest.getRedirectUrl();
+            // 跳转到登录前
+            response.sendRedirect(redirectUrl);
+        } else {
+            JwtTokenProvider.setAuthentication(response, auth.getName());
+        }
+    }*/
+
+    /*@Override
+    protected void unsuccessfulAuthentication(HttpServletRequest request,
+                                              HttpServletResponse response,
+                                              AuthenticationException failed) throws IOException, ServletException {
+
+        response.setContentType("application/json");
+        response.setStatus(HttpServletResponse.SC_OK);
+        response.getOutputStream().println("Internal Server Error");
+    }*/
+
+    private JsonObject getBody(HttpServletRequest request) throws IOException {
+        BufferedReader br = request.getReader();
+        StringBuilder sb = new StringBuilder();
+        String line;
+        while((line = br.readLine()) != null) {
+            sb.append(line);
+        }
+
+        return new JsonParser().parse(sb.toString()).getAsJsonObject();
+    }
+}

+ 51 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/auth/impl/formlogin/UsernamePasswordAuthProvider.java

@@ -0,0 +1,51 @@
+package cn.reghao.autodop.dmaster.auth.impl.formlogin;
+
+import cn.reghao.autodop.common.utils.security.Cryptor;
+import cn.reghao.autodop.common.utils.security.Sha256Cryptor;
+import cn.reghao.autodop.dmaster.auth.entity.UserAuth;
+import org.springframework.security.authentication.AuthenticationProvider;
+import org.springframework.security.authentication.DisabledException;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.stereotype.Component;
+
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * 认证用户名/密码登录的 provider
+ *
+ * @author reghao
+ * @date 2019-04-09 09:07:40
+ */
+@Component
+public class UsernamePasswordAuthProvider implements AuthenticationProvider {
+    private UserDetailsServiceImpl userDetailsService;
+    private Cryptor cryptor;
+
+    public UsernamePasswordAuthProvider(UserDetailsServiceImpl userDetailsService)
+            throws NoSuchAlgorithmException {
+        this.userDetailsService = userDetailsService;
+        this.cryptor = new Sha256Cryptor();
+    }
+
+    @Override
+    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
+        String username = authentication.getName();
+        String password = (String) authentication.getCredentials();
+
+        // 从数据库中获取用户认证信息
+        UserAuth userAuth = (UserAuth) userDetailsService.loadUserByUsername(username);
+        String encodedPassword = cryptor.encrypt(password + userAuth.getSalt());
+        if (!userAuth.getPassword().equals(encodedPassword)) {
+            throw new DisabledException("用户名/密码错误");
+        }
+
+        return new UsernamePasswordAuthenticationToken(userAuth, password, userAuth.getAuthorities());
+    }
+
+    @Override
+    public boolean supports(Class<?> authentication) {
+        return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
+    }
+}

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/common/config/CachingConfig.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.config;
+package cn.reghao.autodop.dmaster.common.config;
 
 import com.github.benmanes.caffeine.cache.*;
 import org.springframework.cache.CacheManager;

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/common/config/OssProperties.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.config;
+package cn.reghao.autodop.dmaster.common.config;
 
 import lombok.Data;
 import org.springframework.beans.factory.annotation.Value;

+ 5 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/common/config/SwaggerConfig.java

@@ -1,7 +1,8 @@
-package cn.reghao.autodop.dmaster.config;
+package cn.reghao.autodop.dmaster.common.config;
 
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
 import springfox.documentation.builders.ApiInfoBuilder;
 import springfox.documentation.builders.PathSelectors;
 import springfox.documentation.builders.RequestHandlerSelectors;
@@ -16,6 +17,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
  * @author reghao
  * @date 2019-05-14 17:01:07
  */
+@Profile({"dev1", "test"})
 @Configuration
 @EnableSwagger2
 public class SwaggerConfig {
@@ -25,6 +27,7 @@ public class SwaggerConfig {
                 .apiInfo(apiInfo())
                 .select()
                 .apis(RequestHandlerSelectors.basePackage("cn.reghao.autodop.dmaster"))
+                //.apis(RequestHandlerSelectors.any())
                 .paths(PathSelectors.any())
                 .build();
     }
@@ -34,7 +37,7 @@ public class SwaggerConfig {
                 .title("Dmaster APIs")
                 .description("")
                 .termsOfServiceUrl("")
-                .version("1.0")
+                .version("1.0.0")
                 .build();
     }
 }

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/common/config/SysConfigProperties.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.config;
+package cn.reghao.autodop.dmaster.common.config;
 
 import lombok.Data;
 import org.springframework.beans.factory.annotation.Value;

+ 7 - 32
dmaster/src/main/java/cn/reghao/autodop/dmaster/common/config/WebMvcConfig.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.config;
+package cn.reghao.autodop.dmaster.common.config;
 
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -19,44 +19,19 @@ import java.util.List;
 @EnableWebMvc
 public class WebMvcConfig implements WebMvcConfigurer {
     /**
-     * 增加 controller 到 html 的映射
+     * swagger-ui 接口页面
      *
      * @param
      * @return
-     * @date 2019-06-04 下午10:52
-     */
-    @Override
-    public void addViewControllers(ViewControllerRegistry registry) {
-        /*registry.addViewController("/").setViewName("index");
-        registry.addViewController("/login").setViewName("views/login");*/
-    }
-
-    /**
-     * 映射 url 中的静态资源到 classpath 下的 static 目录
-     *
-     * @param
-     * @return
-     * @date 2019-05-20 上午11:09
+     * @date 2020-05-12 下午4:59
      */
     @Override
     public void addResourceHandlers(ResourceHandlerRegistry registry) {
-        registry.addResourceHandler("/layui/**").addResourceLocations("classpath:/static/layui/");
-        registry.addResourceHandler("/layuix/**").addResourceLocations("classpath:/static/layuix/");
+        registry.addResourceHandler("swagger-ui.html")
+                .addResourceLocations("classpath:/META-INF/resources/");
 
-        /*registry.addResourceHandler("/imgs/**").addResourceLocations("classpath:/static/imgs/");
-        registry.addResourceHandler("/layuix/**").addResourceLocations("classpath:/static/layuix/");*/
-    }
-
-    /**
-     * 开启默认 servlet 处理 web 项目的静态文件
-     *
-     * @param
-     * @return
-     * @date 2019-05-20 上午11:09
-     */
-    @Override
-    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
-        configurer.enable();
+        registry.addResourceHandler("/webjars/**")
+                .addResourceLocations("classpath:/META-INF/resources/webjars/");
     }
 
     /**

+ 4 - 4
dmaster/src/main/java/cn/reghao/autodop/dmaster/common/exception/GlobalExceptionHandler.java

@@ -1,8 +1,8 @@
-package cn.reghao.autodop.dmaster.exception;
+package cn.reghao.autodop.dmaster.common.exception;
 
-import cn.reghao.autodop.dmaster.result.ErrorResult;
-import cn.reghao.autodop.dmaster.result.ResultCode;
-import cn.reghao.autodop.dmaster.result.WebResult;
+import cn.reghao.autodop.dmaster.common.result.ErrorResult;
+import cn.reghao.autodop.dmaster.common.result.ResultCode;
+import cn.reghao.autodop.dmaster.common.result.WebResult;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.bind.annotation.ExceptionHandler;

+ 1 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/common/exception/WebErrorController.java

@@ -1,9 +1,8 @@
-package cn.reghao.autodop.dmaster.exception;
+package cn.reghao.autodop.dmaster.common.exception;
 
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.web.servlet.error.ErrorController;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
 

+ 1 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/common/interceptor/MethodTimeInterceptor.java

@@ -1,4 +1,4 @@
-package cn.reghao.autodop.dmaster.interceptor;
+package cn.reghao.autodop.dmaster.common.interceptor;
 
 import lombok.extern.slf4j.Slf4j;
 import org.aspectj.lang.ProceedingJoinPoint;

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä