nacos加入到项目当中

This commit is contained in:
dengqichen 2024-08-16 13:30:58 +08:00
parent c362baa0c6
commit b12f37331d
166 changed files with 2031 additions and 915 deletions

2
.gitignore vendored
View File

@ -25,3 +25,5 @@ hs_err_pid*
.flattened-pom.xml
/bin/nacos-server-2.3.0/logs/
/bin/nacos-server-2.3.0/data/protocol/raft/*/log/
/bin/nacos/nacos-server-2.3.0/logs/
/bin/nacos/nacos-server-2.3.0/data/protocol/raft/*/log/

View File

@ -1 +1,2 @@
-Dversion=1.0-SNAPSHOT
-Dadapter-revision=1.0.0

98
bin/maven/settings.xml Normal file
View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<localRepository>D:\work\maven-space\</localRepository>
<pluginGroups>
<pluginGroup>org.eclipse.jkube</pluginGroup>
<pluginGroup>org.springframework.boot</pluginGroup>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>snapshots</id>
<username>devops</username>
<password>LianYu_123#</password>
</server>
<server>
<id>public</id>
<username>devops</username>
<password>LianYu_123#</password>
</server>
<server>
<id>releases</id>
<username>devops</username>
<password>LianYu_123#</password>
</server>
</servers>
<mirrors>
<mirror>
<id>snapshots</id>
<name>snapshots</name>
<url>http://119.3.241.212:8088/repository/maven-snapshots/</url>
<mirrorOf>com.lianyu:*-SNAPSHOT</mirrorOf>
</mirror>
<mirror>
<id>releases</id>
<name>releases</name>
<url>http://119.3.241.212:8088/repository/maven-releases/</url>
<mirrorOf>com.lianyu:*-RELEASE</mirrorOf>
</mirror>
<mirror>
<id>public</id>
<name>public</name>
<url>http://119.3.241.212:8088/repository/maven-public/</url>
<mirrorOf>*,!com.qc.soft.*:*,!com.lianyu:*-SNAPSHOT,!com.lianyu:*-RELEASE</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus-env-profile</id>
<repositories>
<repository>
<id>public</id>
<url>http://119.3.241.212:8088/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>http://119.3.241.212:8088/repository/maven-snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>releases</id>
<url>http://119.3.241.212:8088/repository/maven-releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>
<pluginRepositories>
</pluginRepositories>
<properties>
<snapshot.repository.id>snapshots</snapshot.repository.id>
<snapshot.repository.name>snapshots</snapshot.repository.name>
<snapshot.repository.url>http://119.3.241.212:8088/repository/maven-snapshots/</snapshot.repository.url>
<release.repository.id>snapshots</release.repository.id>
<release.repository.name>snapshots</release.repository.name>
<release.repository.url>http://119.3.241.212:8088/repository/maven-releases/</release.repository.url>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus-env-profile</activeProfile>
</activeProfiles>
</settings>

View File

@ -1,5 +0,0 @@
server:
port: 9090
spring:
application:
name: deploy-ease-core

View File

@ -1,5 +0,0 @@
server:
port: 0
spring:
application:
name: deploy-ease-synchronizer-${TENANT_CODE}

View File

@ -1 +0,0 @@
D:\work\github-workspace\deploy-ease-backend\bin\nacos-server-2.3.0\bin\startup.cmd -m standalone

View File

Before

Width:  |  Height:  |  Size: 894 B

After

Width:  |  Height:  |  Size: 894 B

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,8 @@
server:
port: 9090
spring:
application:
name: deploy-ease-core
deploy-ease:
adapter:
path: D:\work\github-workspace\deploy-ease-backend\deploy-ease-tenant-adapter\target\deploy-ease-tenant-adapter-1.0.0.jar

View File

@ -0,0 +1,5 @@
server:
port: 0
spring:
application:
name: deploy-ease-tenant-adapter-${TENANT_CODE}

View File

@ -1,4 +1,9 @@
spring:
http:
encoding:
charset: UTF-8
enabled: true
force: true
jpa:
show-sql: true
properties:

View File

@ -0,0 +1 @@
D:\work\github-workspace\deploy-ease-backend\bin\nacos\nacos-server-2.3.0\bin\startup.cmd -m standalone

View File

@ -4,6 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>deploy-ease-api</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
@ -20,8 +21,8 @@
<parent>
<groupId>com.qc.soft</groupId>
<artifactId>deploy-ease</artifactId>
<version>1.0-SNAPSHOT</version>
<artifactId>deploy-ease-parent</artifactId>
<version>${version}</version>
</parent>
</project>

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.api.controller;
package com.qc.soft.deploy.ease.api;
import com.qc.soft.deploy.ease.api.response.DictionaryResponse;
import com.qc.soft.deploy.ease.api.response.TenantDictionaryResponse;
@ -9,13 +9,13 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/deploy-ease/dict")
public interface IDictionaryController {
@RequestMapping("/api/v1")
public interface IDictionaryApi {
@GetMapping("/system")
@GetMapping("/dict/system")
List<DictionaryResponse> systemDicts();
@GetMapping("/tenant")
@GetMapping("/dict/tenant")
List<TenantDictionaryResponse> tenantDicts();
}

View File

@ -1,11 +1,11 @@
package com.qc.soft.deploy.ease.api.controller;
package com.qc.soft.deploy.ease.api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/deploy-ease/jenkins")
public interface IJenkinsController {
@RequestMapping("/api/v1")
public interface IJenkinsApi {
}

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.api.controller;
package com.qc.soft.deploy.ease.api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/deploy-ease/k8s")
public interface IK8sController {
public interface IK8sApi {
// @GetMapping("namespaces")

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.api.controller;
package com.qc.soft.deploy.ease.api;
import org.springframework.web.bind.annotation.GetMapping;
@ -6,8 +6,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/deploy-ease/nacos")
public interface INacosController {
@RequestMapping("/api/nacos")
public interface INacosApi {
@GetMapping("/instances")
void instances();

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.api.controller;
package com.qc.soft.deploy.ease.api;
import com.qc.soft.deploy.ease.api.response.ProjectResponse;
import org.springframework.web.bind.annotation.GetMapping;
@ -9,7 +9,7 @@ import java.util.List;
@RestController
@RequestMapping("/deploy-ease/project")
public interface IProjectController {
public interface IProjectApi {
@GetMapping("/list")

View File

@ -0,0 +1,16 @@
package com.qc.soft.deploy.ease.api;
import com.qc.soft.deploy.ease.api.response.TenantAdapterContextResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/v1")
public interface ITenantApi {
@GetMapping("/tenant/getAdapterContext")
TenantAdapterContextResponse tenantAdapterContext();
}

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.api.controller;
package com.qc.soft.deploy.ease.api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/deploy-ease/test")
public interface ITestController {
public interface ITestApi {
@GetMapping("test")
void test();

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.api.controller;
package com.qc.soft.deploy.ease.api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/deploy-ease/user")
public interface IUserController {
public interface IUserApi {
@GetMapping("/login")

View File

@ -1,11 +1,16 @@
package com.qc.soft.deploy.ease.api.base;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
public abstract class BaseResponse implements Serializable {
private Long id;
private LocalDateTime createTime;
private LocalDateTime updateTime;

View File

@ -0,0 +1,23 @@
package com.qc.soft.deploy.ease.api.response;
import com.qc.soft.deploy.ease.api.base.BaseResponse;
import lombok.Data;
@Data
public class JenkinsResponse extends BaseResponse {
private String code;
private String name;
private String username;
private String password;
private String url;
private String envCode;
private String tenantCode;
}

View File

@ -0,0 +1,15 @@
package com.qc.soft.deploy.ease.api.response;
import com.qc.soft.deploy.ease.api.base.BaseResponse;
import lombok.Data;
import java.util.List;
@Data
public class TenantAdapterContextResponse extends BaseResponse {
private TenantResponse tenant;
private List<TenantEnvResponse> envList;
}

View File

@ -0,0 +1,17 @@
package com.qc.soft.deploy.ease.api.response;
import com.qc.soft.deploy.ease.api.base.BaseResponse;
import lombok.Data;
@Data
public class TenantEnvJenkinsResponse extends BaseResponse {
private String viewName;
private String username;
private String password;
private String url;
}

View File

@ -0,0 +1,20 @@
package com.qc.soft.deploy.ease.api.response;
import com.qc.soft.deploy.ease.api.base.BaseResponse;
import lombok.Data;
@Data
public class TenantEnvResponse extends BaseResponse {
private String code;
private String name;
private int type;
private boolean isVpn;
private TenantEnvJenkinsResponse jenkins;
}

51
deploy-ease-basic/pom.xml Normal file
View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>deploy-ease-basic</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>transmittable-thread-local</artifactId>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
<parent>
<groupId>com.qc.soft</groupId>
<artifactId>deploy-ease-parent</artifactId>
<version>${version}</version>
</parent>
</project>

View File

@ -0,0 +1,37 @@
package com.qc.soft.framework.basic.config;
import com.qc.soft.framework.basic.entity.BasicResponseState;
import com.qc.soft.framework.basic.exception.BasicException;
import com.qc.soft.framework.basic.web.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
public GlobalExceptionHandler() {
log.info("Framework global exception handler registered successfully!!!");
}
@Resource
private HttpServletRequest httpServletRequest;
@ExceptionHandler(BasicException.class)
public Object parameterBodyMissingExceptionHandler(BasicException exception) {
log.error("An exception occurred while requesting an interface{}", httpServletRequest.getRequestURI(), exception);
if (!httpServletRequest.getRequestURI().startsWith("/api/v1")) {
return exception;
}
if (StringUtils.isNotEmpty(exception.getMessage())) {
BasicResponseState error = exception.getError();
error.setMessage(exception.getMessage());
}
return ApiResult.builder().code(exception.getError().getCode()).message(exception.getError().getMessage()).build();
}
}

View File

@ -1,6 +1,8 @@
package com.qc.soft.deploy.ease.config;
package com.qc.soft.framework.basic.config;
import com.qc.soft.deploy.ease.enums.ResponseCode;
import com.qc.soft.framework.basic.enums.IBasicState;
import com.qc.soft.framework.basic.web.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@ -9,8 +11,13 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
@ControllerAdvice
@Slf4j
public class GlobalResponseHandler implements ResponseBodyAdvice<Object> {
public GlobalResponseHandler() {
log.info("Framework global response handler registered successfully!!!");
}
@Override
public boolean supports(MethodParameter returnType, Class converterType) {
return true;
@ -18,18 +25,15 @@ public class GlobalResponseHandler implements ResponseBodyAdvice<Object> {
@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, org.springframework.http.server.ServerHttpRequest request, ServerHttpResponse response) {
if (body instanceof ResponseEntity) {
if (!request.getURI().getPath().startsWith("/api/v1")) {
return body;
}
if (body instanceof String) {
if (body instanceof ResponseEntity || body instanceof ApiResult) {
return body;
}
if (body == null) {
return ApiResponse.builder().code(ResponseCode.SUCCESS.getCode()).message(ResponseCode.SUCCESS.getMessage()).build();
return ApiResult.builder().code(IBasicState.SUCCESS.getCode()).message(IBasicState.SUCCESS.getMessage()).build();
}
if (body instanceof ApiResponse) {
return body;
}
return ApiResponse.builder().data(body).code(ResponseCode.SUCCESS.getCode()).message(ResponseCode.SUCCESS.getMessage()).build();
return ApiResult.builder().data(body).code(IBasicState.SUCCESS.getCode()).message(IBasicState.SUCCESS.getMessage()).build();
}
}

View File

@ -0,0 +1,42 @@
package com.qc.soft.framework.basic.config;
import com.qc.soft.framework.basic.context.TenantContext;
import com.qc.soft.framework.basic.enums.IBasicState;
import com.qc.soft.framework.basic.exception.BasicException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Slf4j
@Component
@Import({GlobalResponseHandler.class, GlobalExceptionHandler.class})
public class GlobalTenantInterceptor implements HandlerInterceptor {
public GlobalTenantInterceptor() {
log.info("Framework global tenant interceptor registered successfully!!!");
}
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
String tenantCode = request.getHeader("x-tenant-code");
if (null == tenantCode || StringUtils.isEmpty(tenantCode)) {
throw new BasicException(IBasicState.TENANT_DOES_NOT_EXIST, "请求头未携带x-tenant-code");
}
TenantContext.setCurrentTenant(tenantCode);
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
TenantContext.clear();
}
}

View File

@ -1,15 +1,18 @@
package com.qc.soft.deploy.ease.config;
package com.qc.soft.framework.basic.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.qc.soft.deploy.ease.interceptor.TenantInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
@ -17,14 +20,16 @@ import java.text.SimpleDateFormat;
import java.util.List;
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Slf4j
@Import(GlobalTenantInterceptor.class)
public class GlobalWebConfigurer implements WebMvcConfigurer {
@Resource
private TenantInterceptor tenantInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(tenantInterceptor).addPathPatterns("/**");
private GlobalTenantInterceptor globalTenantInterceptor;
public GlobalWebConfigurer() {
log.info("Framework global web configurer registered successfully!!!");
}
@Override
@ -35,6 +40,20 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
mapper.registerModule(new JavaTimeModule());
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
converters.add(new MappingJackson2HttpMessageConverter(mapper));
super.configureMessageConverters(converters);
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
//TODO 搜索引用的项目继承这个拦截器没有如果继承了就自动加载比如 自己写一个注解将拦截的路径都自动加载
registry.addInterceptor(globalTenantInterceptor).addPathPatterns("/**").order(-9999);
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") // 允许跨域的路径
.allowedOrigins("*") // 允许跨域请求的域名
.allowedHeaders("*") // 允许的请求头
.allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的请求方法
.allowCredentials(true); // 是否允许证书cookies
}
}

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.context;
package com.qc.soft.framework.basic.context;
import com.alibaba.ttl.TransmittableThreadLocal;

View File

@ -0,0 +1,28 @@
package com.qc.soft.framework.basic.entity;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.time.LocalDateTime;
@MappedSuperclass
public abstract class BaseEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, updatable = false)
private LocalDateTime createTime;
@Column(nullable = false)
private LocalDateTime updateTime;
private Boolean isDeleted;
}

View File

@ -0,0 +1,16 @@
package com.qc.soft.framework.basic.entity;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;
@Data
@Builder
@ToString
public class BasicResponseState {
private String code;
private String message;
}

View File

@ -0,0 +1,16 @@
package com.qc.soft.framework.basic.enums;
import com.qc.soft.framework.basic.entity.BasicResponseState;
public interface IBasicState {
BasicResponseState SUCCESS = BasicResponseState.builder().code("SUCCESS").message("操作成功").build();
BasicResponseState FAILURE = BasicResponseState.builder().code("FAILURE").message("操作失败").build();
BasicResponseState TENANT_DOES_NOT_EXIST = BasicResponseState.builder().code("TENANT_DOES_NOT_EXIST").message("租户不存在").build();
BasicResponseState TENANT_NOT_ENABLED = BasicResponseState.builder().code("TENANT_NOT_ENABLED").message("%s租户未启用").build();
}

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.enums;
package com.qc.soft.framework.basic.enums;
import lombok.Getter;

View File

@ -0,0 +1,32 @@
package com.qc.soft.framework.basic.exception;
import com.qc.soft.framework.basic.entity.BasicResponseState;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class BasicException extends RuntimeException {
private BasicResponseState error;
public BasicException(String message) {
super(message, null);
}
public BasicException(BasicResponseState error) {
super(error.getMessage(), null);
this.error = error;
}
public BasicException(BasicResponseState error, String message) {
super(message, null);
this.error = error;
}
public BasicException(BasicResponseState error, Throwable e) {
super(error.getMessage(), e);
this.error = error;
}
}

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.utils;
package com.qc.soft.framework.basic.utils;
import java.util.Base64;

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.utils;
package com.qc.soft.framework.basic.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.utils;
package com.qc.soft.framework.basic.utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.Resource;

View File

@ -1,10 +1,9 @@
package com.qc.soft.deploy.ease.utils;
package com.qc.soft.framework.basic.utils;
import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.hc.client5.http.classic.methods.HttpDelete;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPost;
@ -15,7 +14,6 @@ import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.logging.log4j.util.Strings;
import java.io.File;
import java.io.FileOutputStream;

View File

@ -1,8 +1,8 @@
package com.qc.soft.deploy.ease.utils;
package com.qc.soft.framework.basic.utils;
import java.util.Map;
import java.util.HashMap;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
public class MapUtils {
public static Map<String, Object> toMap(Object object) {

View File

@ -0,0 +1,36 @@
package com.qc.soft.framework.basic.utils;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@Slf4j
public class ProcessUtils {
public static String execPowershellCommand(String command) {
String[] execCommand = {
"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"-Command",
command
};
try {
val processBuilder = new ProcessBuilder(execCommand);
val process = processBuilder.start();
val reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
StringBuilder output = new StringBuilder();
while ((line = reader.readLine()) != null) {
output.append(line).append("\n");
}
int exitCode = process.waitFor();
log.info("Exec powershell done, exitCode:{}", exitCode);
return output.toString();
} catch (IOException | InterruptedException e) {
log.error("Exec powershell command failed, command:{}", execCommand, e);
}
return null;
}
}

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.utils;
package com.qc.soft.framework.basic.utils;
public class StrUtils {

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.utils;
package com.qc.soft.framework.basic.utils;
import java.util.HashMap;
import java.util.Map;

View File

@ -0,0 +1,40 @@
package com.qc.soft.framework.basic.web;
import com.qc.soft.framework.basic.entity.BasicResponseState;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.io.Serializable;
@Setter
@Getter
@Builder
@ToString
public class ApiResult<T> implements Serializable {
private String code;
private String message;
private T data;
public ApiResult(String code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
}
public ApiResult(BasicResponseState state) {
this.code = state.getCode();
this.message = state.getMessage();
}
public ApiResult(BasicResponseState state, T data) {
this.code = state.getCode();
this.message = state.getMessage();
this.data = data;
}
}

View File

@ -0,0 +1,3 @@
artifactId=deploy-ease-basic
groupId=com.qc.soft
version=1.0-SNAPSHOT

View File

@ -0,0 +1,21 @@
com\qc\soft\framework\basic\config\GlobalTenantInterceptor.class
com\qc\soft\framework\basic\web\ApiResult.class
com\qc\soft\framework\basic\entity\BasicResponseState$BasicResponseStateBuilder.class
com\qc\soft\framework\basic\utils\DateUtils.class
com\qc\soft\framework\basic\entity\BasicResponseState.class
com\qc\soft\framework\basic\utils\StrUtils.class
com\qc\soft\framework\basic\enums\JenkinsJobStatus.class
com\qc\soft\framework\basic\utils\TemplateParamsBuildUtils.class
com\qc\soft\framework\basic\utils\MapUtils.class
com\qc\soft\framework\basic\context\TenantContext.class
com\qc\soft\framework\basic\config\GlobalWebConfigurer.class
com\qc\soft\framework\basic\utils\HttpUtils.class
com\qc\soft\framework\basic\config\GlobalResponseHandler.class
com\qc\soft\framework\basic\exception\BasicException.class
com\qc\soft\framework\basic\utils\FileUtils.class
com\qc\soft\framework\basic\utils\ProcessUtils.class
com\qc\soft\framework\basic\config\GlobalExceptionHandler.class
com\qc\soft\framework\basic\enums\IBasicState.class
com\qc\soft\framework\basic\entity\BaseEntity.class
com\qc\soft\framework\basic\utils\BasicAuthUtils.class
com\qc\soft\framework\basic\web\ApiResult$ApiResultBuilder.class

View File

@ -0,0 +1,19 @@
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\context\TenantContext.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\config\GlobalTenantInterceptor.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\config\GlobalWebConfigurer.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\config\GlobalExceptionHandler.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\utils\HttpUtils.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\web\ApiResult.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\utils\DateUtils.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\utils\BasicAuthUtils.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\enums\IBasicState.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\entity\BasicResponseState.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\utils\FileUtils.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\utils\TemplateParamsBuildUtils.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\config\GlobalResponseHandler.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\enums\JenkinsJobStatus.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\utils\ProcessUtils.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\entity\BaseEntity.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\utils\StrUtils.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\exception\BasicException.java
D:\work\github-workspace\deploy-ease-backend\deploy-ease-basic\src\main\java\com\qc\soft\framework\basic\utils\MapUtils.java

View File

@ -78,11 +78,6 @@
<artifactId>httpclient5</artifactId>
<version>${http5.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
@ -123,10 +118,15 @@
<artifactId>mapstruct-jdk8</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>com.qc.soft</groupId>
<artifactId>deploy-ease-basic</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.qc.soft</groupId>
<artifactId>deploy-ease-api</artifactId>
<version>1.0-SNAPSHOT</version>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
@ -140,36 +140,16 @@
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>${flatten-maven-plugin.version}</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
@ -255,7 +235,7 @@
<parent>
<groupId>com.qc.soft</groupId>
<artifactId>deploy-ease-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<version>${version}</version>
</parent>
</project>

View File

@ -11,7 +11,7 @@ import java.net.URLClassLoader;
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan("com.qc.soft.deploy.ease.*")
@ComponentScan("com.qc.soft.deploy.ease")
@EnableAsync
public class DeployEaseApplication {

View File

@ -1,54 +0,0 @@
package com.qc.soft.deploy.ease.config;
import com.qc.soft.deploy.ease.enums.BusinessErrorCode;
import lombok.Builder;
import lombok.ToString;
import java.io.Serializable;
import java.util.StringJoiner;
@Builder
@ToString
public class ApiResponse<T> implements Serializable {
private BusinessErrorCode code;
private String message;
private T data;
public ApiResponse(BusinessErrorCode code, String message) {
this.code = code;
this.message = message;
}
public ApiResponse(BusinessErrorCode code, String message, T data) {
this(code, message);
this.data = data;
}
public BusinessErrorCode getCode() {
return code;
}
public void setCode(BusinessErrorCode code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}

View File

@ -0,0 +1,24 @@
package com.qc.soft.deploy.ease.config;
import com.qc.soft.deploy.ease.interceptor.BusinessTenantInterceptor;
import com.qc.soft.framework.basic.config.GlobalWebConfigurer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
@Configuration
@Slf4j
@AutoConfigureAfter(GlobalWebConfigurer.class)
public class BusinessWebConfigurer implements WebMvcConfigurer {
@Resource
private BusinessTenantInterceptor businessTenantInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(businessTenantInterceptor).addPathPatterns("/**");
}
}

View File

@ -1,23 +0,0 @@
package com.qc.soft.deploy.ease.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class GlobalCorsConfig {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") // 允许跨域的路径
.allowedOrigins("*") // 允许跨域请求的域名
.allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的请求方法
.allowedHeaders("*") // 允许的请求头
.allowCredentials(true); // 是否允许证书cookies
}
};
}
}

View File

@ -1,25 +0,0 @@
package com.qc.soft.deploy.ease.config;
import com.qc.soft.deploy.ease.enums.ResponseCode;
import com.qc.soft.deploy.ease.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
@Autowired
private HttpServletRequest httpServletRequest;
@ExceptionHandler(BusinessException.class)
public ApiResponse parameterBodyMissingExceptionHandler(BusinessException exception) {
String requestURI = httpServletRequest.getRequestURI();
log.error("An exception occurred while requesting an interface{}", requestURI, exception);
return ApiResponse.builder().code(exception.getCode()).message(exception.getMessage()).build();
}
}

View File

@ -0,0 +1,22 @@
package com.qc.soft.deploy.ease.config;
import com.qc.soft.deploy.ease.context.TenantAdapterProcessContext;
import com.qc.soft.deploy.ease.dto.TenantAdapterJarDTO;
import com.qc.soft.framework.basic.utils.ProcessUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class ShutdownContextClosedEventListener implements ApplicationListener<ContextClosedEvent> {
@Override
public void onApplicationEvent(ContextClosedEvent event) {
System.out.println("The service is terminating and starts destroying the adapter project!!!");
for (TenantAdapterJarDTO tenantAdapterJar : TenantAdapterProcessContext.getTenantJarProcess()) {
String output = ProcessUtils.execPowershellCommand(String.format("Stop-Process -Id %s", tenantAdapterJar.getPid()));
log.info("Tenant {} adapter project it has been destroyed,output:{}", tenantAdapterJar.getTenantCode(), output);
}
}
}

View File

@ -1,77 +1,170 @@
package com.qc.soft.deploy.ease.config;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.qc.soft.deploy.ease.consts.Consts;
import com.qc.soft.deploy.ease.api.response.TenantResponse;
import com.qc.soft.deploy.ease.context.TenantAdapterProcessContext;
import com.qc.soft.deploy.ease.dto.TenantAdapterJarDTO;
import com.qc.soft.deploy.ease.enums.BusinessState;
import com.qc.soft.deploy.ease.exception.BusinessException;
import com.qc.soft.deploy.ease.service.INacosService;
import com.qc.soft.deploy.ease.service.ITenantService;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static com.qc.soft.framework.basic.utils.ProcessUtils.execPowershellCommand;
@Component
@Slf4j
public class TenantAdapterRunner implements CommandLineRunner {
private static final int QUERY_INTERVAL_MS = 10000;
private static final int MAX_ATTEMPTS = 10;
@Resource
private ITenantService tenantService;
@Resource
private INacosService nacosService;
@Resource
private NacosDiscoveryProperties nacosDiscoveryProperties;
@Value("${deploy-ease.adapter.path}")
private String adapterJarFile;
@Override
public void run(String... args) {
String env;
String classLoaderName = getClass().getClassLoader().getClass().getName();
if (classLoaderName.contains("LaunchedURLClassLoader")) {
System.out.println("Application started via java -jar or from a fat JAR.");
env = "prod";
} else {
env = "dev";
}
// -DNACOS_CONFIG_SERVER=192.168.0.166:8848
// -DTENANT_CODE=longi
// -DDEPLOY_ENV=deploy-ease-dev
// -DNACOS_USER=nacos
// -DNACOS_PWD=qichen5210523
List<TenantResponse> tenants = tenantService.tenants();
log.info("Start the tenant adapter project!!!");
ExecutorService pool = Executors.newFixedThreadPool(tenants.size());
ExecutorService checkRegistered = Executors.newSingleThreadExecutor();
// for (TenantResponse tenant : tenants) {
// runTenantAdapterJar(tenant.getTenantCode());
// }
CompletableFuture.allOf(tenants.stream().map(tenant -> CompletableFuture.runAsync(() -> execStartTenantAdapterJar(tenant.getTenantCode()), pool)).toArray(CompletableFuture[]::new));
pool.shutdown();
checkRegistered.submit(() -> {
boolean nacosResult = false;
int attempts = 0;
while (!nacosResult && attempts < MAX_ATTEMPTS) {
List<Pair<String, Boolean>> registered = nacosService.instances(tenants.stream().map(TenantResponse::getTenantCode).collect(Collectors.toList()));
nacosResult = registered.stream().allMatch(Pair::getRight);
if (!nacosResult) {
attempts++;
log.error("Check tenant adapter registered nacos not complete successfully {} attempts", attempts);
try {
Thread.sleep(QUERY_INTERVAL_MS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.error("Check registered task thread was interrupted: ", e);
break;
}
}
}
if (nacosResult) {
TenantAdapterProcessContext.setTenantJarProcess(getWindowTenantAdapterProcess());
log.info("All tenant adapter registered nacos registration complete!!!");
} else {
log.error("Check tenant adapter registered nacos did not complete successfully within the maximum attempts!!!");
}
checkRegistered.shutdown();
try {
if (!checkRegistered.awaitTermination(60, TimeUnit.SECONDS)) {
checkRegistered.shutdownNow();
}
} catch (InterruptedException e) {
checkRegistered.shutdownNow();
Thread.currentThread().interrupt();
}
});
}
@NotNull
private String[] buildTenantAdapterNacosArgs(String tenantCode) {
Properties nacosProperties = nacosDiscoveryProperties.getNacosProperties();
System.out.println(nacosProperties);
String tenantAdapterJarPath = Consts.TENANT_ADAPTER_SERVICE_JAR_PATH.get(env);
return new String[] {String.format("--NACOS_CONFIG_SERVER=%s", nacosProperties.get("serverAddr")), String.format("--TENANT_CODE=%s", tenantCode), String.format("--DEPLOY_ENV=%s", nacosProperties.get("namespace")), String.format("--NACOS_USER=%s", nacosProperties.get("username")), String.format("--NACOS_PWD=%s", nacosProperties.get("password"))};
}
String nacosOptions = String.format("-DNACOS_CONFIG_SERVER=%s -DDEPLOY_ENV=%s -DTENANT_CODE=longi -DNACOS_USER=%s -DNACOS_PWD=%s",
nacosProperties.get("serverAddr"),
nacosProperties.get("namespace"),
nacosProperties.get("username"),
nacosProperties.get("password")
);
String[] command = {"java", "-jar", nacosOptions, tenantAdapterJarPath};
private void execStartTenantAdapterJar(String tenantCode) {
String[] runArgs = buildTenantAdapterNacosArgs(tenantCode);
try {
log.info("Start the {} adapter project", tenantCode);
String[] command = {"java", "-jar", adapterJarFile};
ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.inheritIO();
processBuilder.redirectErrorStream(true);
processBuilder.command().addAll(java.util.Arrays.asList(runArgs));
Process process = processBuilder.start();
Executors.newSingleThreadExecutor().submit(() -> {
new Thread(() -> {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
log.warn(line);
}
} catch (Exception e) {
e.printStackTrace();
log.error("Read boot jar log error", e);
}
});
// 等待进程结束
int exitCode = process.waitFor();
System.out.println("Process exited with code: " + exitCode);
}).start();
log.info("Startup {} adapter project complete!!!", tenantCode);
} catch (Exception e) {
log.error("Failed to start the adapter jar", e);
log.error("Failed to start the adapter project jar, args:{}", runArgs, e);
}
}
public List<TenantAdapterJarDTO> getWindowTenantAdapterProcess() {
String command = "Get-WmiObject Win32_Process | Where-Object { $_.Name -like 'java.exe' -and $_.CommandLine -like '*deploy-ease-tenant-adapter-1.0.0.jar*' } | Select-Object ProcessId, CommandLine | Format-List -Property ProcessId, CommandLine";
String output = execPowershellCommand(command);
if (StringUtils.isEmpty(output)) {
return new ArrayList<>();
}
List<TenantAdapterJarDTO> result = new ArrayList<>();
List<String> processIds = new ArrayList<>();
List<String> tenantCodes = new ArrayList<>();
Pattern processIdPattern = Pattern.compile("ProcessId\\s+:\\s+(\\d+)");
Matcher processIdMatcher = processIdPattern.matcher(output);
while (processIdMatcher.find()) {
String processId = processIdMatcher.group(1);
processIds.add(processId);
}
Pattern tenantCodePattern = Pattern.compile("--TENANT_CODE=([^\\s]+)");
Matcher tenantCodeMatcher = tenantCodePattern.matcher(output);
while (tenantCodeMatcher.find()) {
String tenantCode = tenantCodeMatcher.group(1);
tenantCodes.add(tenantCode);
}
int size = Math.min(processIds.size(), tenantCodes.size());
if (processIds.size() != tenantCodes.size()) {
throw new BusinessException(BusinessState.TENANT_CODE_AND_NUMBER_PROCESSES_INCONSISTENT);
}
for (int i = 0; i < size; i++) {
result.add(TenantAdapterJarDTO.builder().pid(processIds.get(i)).tenantCode(tenantCodes.get(i)).build());
}
log.info("Query window tenant start process is finished!!!");
return result;
}
}

View File

@ -4,11 +4,11 @@ import java.util.HashMap;
import java.util.Map;
public class Consts {
public static final String TENANT_ADAPTER_SERVICE_NAME = "deploy-ease-adapter-%s";
public static final String TENANT_ADAPTER_SERVICE_NAME = "deploy-ease-tenant-adapter-%s";
public static final Map<String, String> TENANT_ADAPTER_SERVICE_JAR_PATH = new HashMap<>();
static {
TENANT_ADAPTER_SERVICE_JAR_PATH.put("dev", "D://workgithub-workspace//deploy-ease-backend//deploy-ease-tenant-adapter//target//deploy-ease-tenant-adapter-1.0.0.jar");
TENANT_ADAPTER_SERVICE_JAR_PATH.put("dev", "D:\\work\\github-workspace\\deploy-ease-backend\\deploy-ease-tenant-adapter\\target\\deploy-ease-tenant-adapter-1.0.0.jar");
}
}

View File

@ -0,0 +1,17 @@
package com.qc.soft.deploy.ease.context;
import com.qc.soft.deploy.ease.dto.TenantAdapterJarDTO;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
public class TenantAdapterProcessContext {
@Getter
private static final List<TenantAdapterJarDTO> tenantJarProcess = new ArrayList<>();
public static void setTenantJarProcess(List<TenantAdapterJarDTO> tenantsProcess) {
tenantJarProcess.addAll(tenantsProcess);
}
}

View File

@ -0,0 +1,27 @@
package com.qc.soft.deploy.ease.controller.api;
import com.qc.soft.deploy.ease.api.IDictionaryApi;
import com.qc.soft.deploy.ease.api.response.DictionaryResponse;
import com.qc.soft.deploy.ease.api.response.TenantDictionaryResponse;
import com.qc.soft.deploy.ease.service.IDictionaryService;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
public class DictionaryApiApiController implements IDictionaryApi {
@Resource
private IDictionaryService dictionaryService;
@Override
public List<DictionaryResponse> systemDicts() {
return dictionaryService.findSystemDicts();
}
@Override
public List<TenantDictionaryResponse> tenantDicts() {
return dictionaryService.findDictsByTenantCode();
}
}

View File

@ -1,13 +1,13 @@
package com.qc.soft.deploy.ease.controller;
package com.qc.soft.deploy.ease.controller.api;
import com.qc.soft.deploy.ease.api.controller.INacosController;
import com.qc.soft.deploy.ease.api.INacosApi;
import com.qc.soft.deploy.ease.service.INacosService;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
public class NacosController implements INacosController {
public class NacosApiApiController implements INacosApi {
@Resource

View File

@ -0,0 +1,32 @@
package com.qc.soft.deploy.ease.controller.mgmt;
import com.qc.soft.deploy.ease.api.IDictionaryApi;
import com.qc.soft.deploy.ease.api.response.DictionaryResponse;
import com.qc.soft.deploy.ease.api.response.TenantDictionaryResponse;
import com.qc.soft.deploy.ease.context.TenantAdapterProcessContext;
import com.qc.soft.deploy.ease.dto.TenantAdapterJarDTO;
import com.qc.soft.deploy.ease.service.IDictionaryService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/mgmt")
public class DictionaryController implements IDictionaryApi {
@Resource
private IDictionaryService dictionaryService;
@Override
public List<DictionaryResponse> systemDicts() {
List<TenantAdapterJarDTO> tenantJarProcess = TenantAdapterProcessContext.getTenantJarProcess();
return dictionaryService.findSystemDicts();
}
@Override
public List<TenantDictionaryResponse> tenantDicts() {
return dictionaryService.findDictsByTenantCode();
}
}

View File

@ -0,0 +1,22 @@
package com.qc.soft.deploy.ease.controller.mgmt;
import com.qc.soft.deploy.ease.api.ITenantApi;
import com.qc.soft.deploy.ease.api.response.TenantAdapterContextResponse;
import com.qc.soft.deploy.ease.service.ITenantService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
@RequestMapping("/mgmt")
public class TenantController implements ITenantApi {
@Resource
private ITenantService tenantService;
@Override
public TenantAdapterContextResponse tenantAdapterContext() {
return tenantService.getTenantAdapterContext();
}
}

View File

@ -1,8 +1,7 @@
package com.qc.soft.deploy.ease.convert.dto;
import com.qc.soft.deploy.ease.convert.K8sNamespaceConvert;
import com.qc.soft.deploy.ease.entity.Dictionary;
import com.qc.soft.deploy.ease.entity.TenantDictionary;
import com.qc.soft.deploy.ease.entity.SysDict;
import com.qc.soft.deploy.ease.entity.TenantDict;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
@ -15,9 +14,9 @@ public interface DictionaryConvert {
@Mappings(
@Mapping(target = "tenantCode", expression = "java(com.qc.soft.deploy.ease.context.TenantContext.getCurrentTenant())")
@Mapping(target = "tenantCode", expression = "java(com.qc.soft.framework.basic.context.TenantContext.getCurrentTenant())")
)
TenantDictionary systemDictionaryToTenantDictionary(Dictionary dictionary);
TenantDict systemDictionaryToTenantDictionary(SysDict sysDict);
}

View File

@ -1,7 +1,7 @@
package com.qc.soft.deploy.ease.convert.response;
import com.qc.soft.deploy.ease.api.response.DictionaryResponse;
import com.qc.soft.deploy.ease.entity.Dictionary;
import com.qc.soft.deploy.ease.entity.SysDict;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -13,6 +13,6 @@ public interface DictionaryConvert {
DictionaryConvert INSTANCE = Mappers.getMapper(DictionaryConvert.class);
List<DictionaryResponse> entityToResponse(List<Dictionary> dictionaries);
List<DictionaryResponse> entityToResponse(List<SysDict> dictionaries);
}

View File

@ -1,9 +1,7 @@
package com.qc.soft.deploy.ease.convert.response;
import com.qc.soft.deploy.ease.api.response.TenantDictionaryResponse;
import com.qc.soft.deploy.ease.api.response.TenantResponse;
import com.qc.soft.deploy.ease.entity.Tenant;
import com.qc.soft.deploy.ease.entity.TenantDictionary;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

View File

@ -1,7 +1,7 @@
package com.qc.soft.deploy.ease.convert.response;
import com.qc.soft.deploy.ease.api.response.TenantDictionaryResponse;
import com.qc.soft.deploy.ease.entity.TenantDictionary;
import com.qc.soft.deploy.ease.entity.TenantDict;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@ -13,6 +13,6 @@ public interface TenantDictionaryConvert {
TenantDictionaryConvert INSTANCE = Mappers.getMapper(TenantDictionaryConvert.class);
List<TenantDictionaryResponse> entityToResponse(List<TenantDictionary> dictionaries);
List<TenantDictionaryResponse> entityToResponse(List<TenantDict> dictionaries);
}

View File

@ -0,0 +1,14 @@
package com.qc.soft.deploy.ease.dto;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class TenantAdapterJarDTO {
private String pid;
private String tenantCode;
}

View File

@ -6,17 +6,13 @@ import lombok.EqualsAndHashCode;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@EqualsAndHashCode(callSuper = true)
@Table(name = "dictionary")
@Table(name = "sys_dict")
@Entity
@Data
public class Dictionary extends BaseEntity {
public class SysDict extends BaseEntity {
@Column(name = "dictionary_code")
private String code;

View File

@ -0,0 +1,29 @@
package com.qc.soft.deploy.ease.entity;
import com.qc.soft.framework.basic.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@EqualsAndHashCode(callSuper = true)
@Table(name = "sys_jenkins_config")
@Entity
@Data
public class SysJenkinsConfig extends BaseEntity {
@Column(name = "jenkins_code")
private String jenkinsCode;
@Column(name = "jenkins_name")
private String jenkinsName;
private String username;
private String password;
private String url;
}

View File

@ -6,18 +6,13 @@ import lombok.EqualsAndHashCode;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@EqualsAndHashCode(callSuper = true)
@Table(name = "user")
@Table(name = "sys_user")
@Entity
@Data
public class User extends BaseEntity {
public class SysUser extends BaseEntity {
@Column(name = "user_name")
private String username;

View File

@ -12,7 +12,7 @@ import javax.persistence.Table;
@Table(name = "tenant_dictionary")
@Entity
@Data
public class TenantDictionary extends BaseEntity {
public class TenantDict extends BaseEntity {
@Column(name = "dictionary_code")
private String code;

View File

@ -0,0 +1,32 @@
package com.qc.soft.deploy.ease.entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@EqualsAndHashCode(callSuper = true)
@Table(name = "tenant_env")
@Entity
@Data
public class TenantEnv extends BaseEntity {
@Column(name = "code")
private String envCode;
@Column(name = "name")
private String envName;
@Column(name = "type")
private int evnType;
@Column(name = "tenant_code")
private String tenantCode;
@Column(name = "is_vpn")
private boolean isVpn;
}

View File

@ -0,0 +1,29 @@
package com.qc.soft.deploy.ease.entity;
import com.qc.soft.framework.basic.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@EqualsAndHashCode(callSuper = true)
@Table(name = "tenant_env_jenkins")
@Entity
@Data
public class TenantEnvJenkins extends BaseEntity {
@Column(name = "view_name")
private String viewName;
@Column(name = "jenkins_code")
private String jenkinsCode;
@Column(name = "env_code")
private String envCode;
@Column(name = "tenant_code")
private String tenantCode;
}

Some files were not shown because too many files have changed in this diff Show More