修改为打包的同时将适配器也进行打包并且加入到core项目中。

This commit is contained in:
dengqichen 2024-08-13 15:41:33 +08:00
parent 22016b35d3
commit b7be97f7ae
24 changed files with 283 additions and 204 deletions

1
.mvn/maven.config Normal file
View File

@ -0,0 +1 @@
-Dadapter-revision=1.0.0

View File

@ -1,6 +1,6 @@
# 启动参数
````
-DNACOS_CONFIG_SERVER=192.168.105.1:8848
-DNACOS_CONFIG_SERVER=192.168.0.166:8848
-DTENANT_CODE=longi
-DDEPLOY_ENV=deploy-ease-dev
-DNACOS_USER=nacos

View File

@ -0,0 +1,15 @@
package com.qc.soft.deploy.ease.api.base;
import java.io.Serializable;
import java.time.LocalDateTime;
public abstract class BaseResponse implements Serializable {
private LocalDateTime createTime;
private LocalDateTime updateTime;
private Boolean isDeleted;
}

View File

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

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;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class TenantResponse extends BaseResponse {
private String tenantCode;
private String tenantName;
private boolean enabled;
}

View File

@ -128,6 +128,11 @@
<artifactId>deploy-ease-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.qc.soft</groupId>
<artifactId>deploy-ease-tenant-adapter</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
@ -142,11 +147,119 @@
</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>
<version>3.0.0</version>
<executions>
<execution>
<id>build-tenant-adapter</id>
<phase>initialize</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>mvn</executable>
<workingDirectory>${project.basedir}/../deploy-ease-tenant-adapter</workingDirectory>
<arguments>
<argument>clean</argument>
<argument>install</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${maven-antrun-plugin.version}</version>
<executions>
<execution>
<id>copy-tenant-adapter</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<mkdir dir="${project.build.directory}/BOOT-INF/lib"/>
<copy file="${basedir}/../deploy-ease-tenant-adapter/target/deploy-ease-tenant-adapter-${deploy-ease-tenant-adapter.version}.jar"
todir="${project.build.directory}/BOOT-INF/lib"/>
<move file="${project.build.directory}/BOOT-INF/lib/deploy-ease-tenant-adapter-${deploy-ease-tenant-adapter.version}.jar"
tofile="${project.build.directory}/BOOT-INF/lib/tenant-adapter.jar"/>
/>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludeDevtools>false</excludeDevtools>
<includeSystemScope>false</includeSystemScope>
<excludes>
<exclude>
<groupId>com.qc.soft</groupId>
<artifactId>deploy-ease-tenant-adapter</artifactId>
</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>${project.build.directory}/BOOT-INF/lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</build>
<parent>
<groupId>com.qc.soft</groupId>
<artifactId>deploy-ease</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
</project>

View File

@ -6,6 +6,9 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import java.net.URL;
import java.net.URLClassLoader;
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan("com.qc.soft.deploy.ease.*")
@ -15,6 +18,13 @@ import org.springframework.scheduling.annotation.EnableAsync;
public class DeployEaseApplication {
public static void main(String[] args) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader instanceof URLClassLoader) {
URL[] urls = ((URLClassLoader) classLoader).getURLs();
for (URL url : urls) {
System.out.println(url.getFile());
}
}
SpringApplication.run(DeployEaseApplication.class, args);
}
}

View File

@ -0,0 +1,6 @@
package com.qc.soft.deploy.ease.consts;
public class Consts {
public static final String TENANT_ADAPTER_SERVICE_NAME = "deploy-ease-adapter-%s";
}

View File

@ -2,15 +2,11 @@ package com.qc.soft.deploy.ease.controller;
import com.qc.soft.deploy.ease.api.controller.INacosController;
import com.qc.soft.deploy.ease.service.INacosService;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
@RequestMapping("/deploy-ease/nacos")
public class NacosController implements INacosController {
@ -19,7 +15,6 @@ public class NacosController implements INacosController {
@Override
@GetMapping("/instances")
public void instances() {
nacosService.instances();
}

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.convert.api.response;
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;
@ -8,9 +8,9 @@ import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface DictionaryApiResponseConvert {
public interface DictionaryConvert {
DictionaryApiResponseConvert INSTANCE = Mappers.getMapper(DictionaryApiResponseConvert.class);
DictionaryConvert INSTANCE = Mappers.getMapper(DictionaryConvert.class);
List<DictionaryResponse> entityToResponse(List<Dictionary> dictionaries);

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.convert.api.response;
package com.qc.soft.deploy.ease.convert.response;
import com.qc.soft.deploy.ease.api.response.ProjectResponse;
import com.qc.soft.deploy.ease.entity.Project;
@ -8,9 +8,9 @@ import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface ProjectApiResponseConvert {
public interface ProjectConvert {
ProjectApiResponseConvert INSTANCE = Mappers.getMapper(ProjectApiResponseConvert.class);
ProjectConvert INSTANCE = Mappers.getMapper(ProjectConvert.class);
List<ProjectResponse> entityToResponse(List<Project> projects);

View File

@ -0,0 +1,20 @@
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;
import java.util.List;
@Mapper
public interface TenantConvert {
TenantConvert INSTANCE = Mappers.getMapper(TenantConvert.class);
List<TenantResponse> listToResponse(List<Tenant> tenants);
}

View File

@ -1,4 +1,4 @@
package com.qc.soft.deploy.ease.convert.api.response;
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;
@ -8,9 +8,9 @@ import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface TenantDictionaryApiResponseConvert {
public interface TenantDictionaryConvert {
TenantDictionaryApiResponseConvert INSTANCE = Mappers.getMapper(TenantDictionaryApiResponseConvert.class);
TenantDictionaryConvert INSTANCE = Mappers.getMapper(TenantDictionaryConvert.class);
List<TenantDictionaryResponse> entityToResponse(List<TenantDictionary> dictionaries);

View File

@ -0,0 +1,11 @@
package com.qc.soft.deploy.ease.service;
import com.qc.soft.deploy.ease.api.response.ProjectResponse;
import com.qc.soft.deploy.ease.api.response.TenantResponse;
import java.util.List;
public interface ITenantService {
List<TenantResponse> tenants();
}

View File

@ -3,9 +3,8 @@ package com.qc.soft.deploy.ease.service.impl;
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.TenantContext;
import com.qc.soft.deploy.ease.convert.api.response.DictionaryApiResponseConvert;
import com.qc.soft.deploy.ease.convert.api.response.TenantDictionaryApiResponseConvert;
import com.qc.soft.deploy.ease.convert.dto.DictionaryConvert;
import com.qc.soft.deploy.ease.convert.response.DictionaryConvert;
import com.qc.soft.deploy.ease.convert.response.TenantDictionaryConvert;
import com.qc.soft.deploy.ease.entity.Dictionary;
import com.qc.soft.deploy.ease.entity.TenantDictionary;
import com.qc.soft.deploy.ease.repository.IDictionaryRepository;
@ -32,7 +31,7 @@ public class DictionaryServiceImpl implements IDictionaryService {
@Override
public List<DictionaryResponse> findSystemDicts() {
return DictionaryApiResponseConvert.INSTANCE.entityToResponse(dictionaryRepository.findAll());
return DictionaryConvert.INSTANCE.entityToResponse(dictionaryRepository.findAll());
}
@Override
@ -46,10 +45,10 @@ public class DictionaryServiceImpl implements IDictionaryService {
Map<String, TenantDictionary> tenantDictMap = tenantDict.stream().collect(Collectors.toMap(TenantDictionary::getCode, tenantDictionary -> tenantDictionary));
TenantDictionary tenantDictionary = tenantDictMap.get(systemDictCode);
if (tenantDictionary == null) {
tenantDictMap.put(systemDictCode, DictionaryConvert.INSTANCE.systemDictionaryToTenantDictionary(v));
tenantDictMap.put(systemDictCode, com.qc.soft.deploy.ease.convert.dto.DictionaryConvert.INSTANCE.systemDictionaryToTenantDictionary(v));
}
mergeTenantDict.addAll(tenantDictMap.values());
});
return TenantDictionaryApiResponseConvert.INSTANCE.entityToResponse(mergeTenantDict);
return TenantDictionaryConvert.INSTANCE.entityToResponse(mergeTenantDict);
}
}

View File

@ -5,7 +5,10 @@ import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.qc.soft.deploy.ease.api.response.TenantResponse;
import com.qc.soft.deploy.ease.consts.Consts;
import com.qc.soft.deploy.ease.service.INacosService;
import com.qc.soft.deploy.ease.service.ITenantService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -17,14 +20,19 @@ public class NacosServiceImpl implements INacosService {
@Resource
private NacosDiscoveryProperties nacosDiscoveryProperties;
private final static String SYNCHRONIZER_SERVICE_NAME = "deploy-ease-synchronizer-longi-%s";
@Resource
private ITenantService tenantService;
@Override
public void instances() {
try {
NamingService namingService = NamingFactory.createNamingService(nacosDiscoveryProperties.getNacosProperties());
List<Instance> allInstances = namingService.getAllInstances(SYNCHRONIZER_SERVICE_NAME, nacosDiscoveryProperties.getGroup());
System.out.println(allInstances);
List<TenantResponse> tenants = tenantService.tenants();
for (TenantResponse tenantResponse : tenants) {
List<Instance> instances = namingService.getAllInstances(String.format(Consts.TENANT_ADAPTER_SERVICE_NAME, tenantResponse.getTenantCode()), nacosDiscoveryProperties.getGroup());
System.out.println(instances);
}
} catch (NacosException e) {
throw new RuntimeException(e);
}

View File

@ -2,7 +2,7 @@ package com.qc.soft.deploy.ease.service.impl;
import com.qc.soft.deploy.ease.api.response.ProjectResponse;
import com.qc.soft.deploy.ease.context.TenantContext;
import com.qc.soft.deploy.ease.convert.api.response.ProjectApiResponseConvert;
import com.qc.soft.deploy.ease.convert.response.ProjectConvert;
import com.qc.soft.deploy.ease.repository.IProjectRepository;
import com.qc.soft.deploy.ease.service.IProjectService;
import org.springframework.stereotype.Service;
@ -20,6 +20,6 @@ public class ProjectServiceImpl implements IProjectService {
@Override
public List<ProjectResponse> list() {
String tenantCode = TenantContext.getCurrentTenant();
return ProjectApiResponseConvert.INSTANCE.entityToResponse(projectRepository.findByTenantCode(tenantCode));
return ProjectConvert.INSTANCE.entityToResponse(projectRepository.findByTenantCode(tenantCode));
}
}

View File

@ -0,0 +1,32 @@
package com.qc.soft.deploy.ease.service.impl;
import com.qc.soft.deploy.ease.api.response.TenantResponse;
import com.qc.soft.deploy.ease.convert.response.TenantConvert;
import com.qc.soft.deploy.ease.holder.K8sApiHolder;
import com.qc.soft.deploy.ease.k8s.K8sDeploymentResponse;
import com.qc.soft.deploy.ease.k8s.K8sNamespaceResponse;
import com.qc.soft.deploy.ease.k8s.K8sPodResponse;
import com.qc.soft.deploy.ease.repository.ITenantRepository;
import com.qc.soft.deploy.ease.service.IK8sService;
import com.qc.soft.deploy.ease.service.ITenantService;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class TenantServiceImpl implements ITenantService {
@Resource
private ITenantRepository tenantRepository;
@Override
public List<TenantResponse> tenants() {
return TenantConvert.INSTANCE.listToResponse(tenantRepository.findAll());
}
}

View File

@ -1,18 +1,16 @@
spring:
cloud:
nacos:
server-addr: ${NACOS_CONFIG_SERVER:192.168.105.1:8848}
server-addr: ${NACOS_CONFIG_SERVER:192.168.0.166:8848}
username: ${NACOS_USER}
password: ${NACOS_PWD}
discovery:
group: ${DEPLOY_ENV}
namespace: ${DEPLOY_ENV}
username: ${NACOS_USER}
password: ${NACOS_PWD}
enabled: true
config:
group: ${DEPLOY_ENV}
namespace: ${DEPLOY_ENV}
username: ${NACOS_USER}
password: ${NACOS_PWD}
extension-configs[0]:
data-id: common.yml
group: common

View File

@ -1,113 +0,0 @@
<?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-synchronizer</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version> <!-- 检查最新版本 -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>transmittable-thread-local</artifactId>
<version>${transmittable-thread-local.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<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>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>${kubernetes.version}</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>${freemarker.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>${fastjson-version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp3.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${mapstruct.version}</version>
</dependency>
<dependency>
<groupId>com.qc.soft</groupId>
<artifactId>deploy-ease-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</dependency>
</dependencies>
<parent>
<groupId>com.qc.soft</groupId>
<artifactId>deploy-ease</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
</project>

View File

@ -1,18 +0,0 @@
package com.qc.soft.deploy.ease.synchronizer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootConfiguration
@EnableAutoConfiguration
@EnableScheduling
@EnableAsync
public class DeployEaseSynchronizerApplication {
public static void main(String[] args) {
SpringApplication.run(DeployEaseSynchronizerApplication.class, args);
}
}

View File

@ -1,27 +0,0 @@
spring:
cloud:
nacos:
server-addr: ${NACOS_CONFIG_SERVER}
username: ${NACOS_USER}
password: ${NACOS_PWD}
discovery:
group: ${DEPLOY_ENV}
namespace: ${DEPLOY_ENV}
enabled: true
config:
group: ${DEPLOY_ENV}
namespace: ${DEPLOY_ENV}
extension-configs[0]:
data-id: common.yml
group: common
refresh: false
extension-configs[1]:
data-id: deploy-ease-synchronizer.yml
group: business
refresh: false
config:
override-none: false
allow-override: true
override-system-properties: false
main:
allow-bean-definition-overriding: true

22
pom.xml
View File

@ -9,6 +9,7 @@
<packaging>pom</packaging>
<properties>
<deploy-ease-tenant-adapter.version>${adapter-revision}</deploy-ease-tenant-adapter.version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -29,6 +30,8 @@
<okhttp3.version>4.9.1</okhttp3.version>
<nacos-client.version>2.3.0</nacos-client.version>
<nacos-cloud.version>2.2.9.RELEASE</nacos-cloud.version>
<flatten-maven-plugin.version>1.6.0</flatten-maven-plugin.version>
<maven-antrun-plugin.version>3.1.0</maven-antrun-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
@ -60,29 +63,32 @@
<artifactId>nacos-client</artifactId>
<version>${nacos-client.version}</version>
</dependency>
<dependency>
<groupId>com.qc.soft</groupId>
<artifactId>deploy-ease-tenant-adapter</artifactId>
<version>${deploy-ease-tenant-adapter.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>deploy-ease-core</module>
<module>deploy-ease-api</module>
<module>deploy-ease-synchronizer</module>
<module>deploy-ease-tenant-adapter</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.6.0</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
</plugins>
</build>
</project>