Compare commits
5 Commits
master_suz
...
master
Author | SHA1 | Date |
---|---|---|
|
682dd2f6e0 | |
|
a3059cbbf7 | |
|
3857e3a875 | |
|
4d1cb943ac | |
|
e6100a1318 |
103
pom.xml
103
pom.xml
|
@ -38,6 +38,7 @@
|
||||||
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
||||||
<mqttv3.version>1.2.5</mqttv3.version>
|
<mqttv3.version>1.2.5</mqttv3.version>
|
||||||
<spring-kafka.version>2.8.0</spring-kafka.version>
|
<spring-kafka.version>2.8.0</spring-kafka.version>
|
||||||
|
<aliyun.ecs.version>3.1.12</aliyun.ecs.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<!-- 依赖声明 -->
|
<!-- 依赖声明 -->
|
||||||
|
@ -263,7 +264,17 @@
|
||||||
<artifactId>zhilian-common-business</artifactId>
|
<artifactId>zhilian-common-business</artifactId>
|
||||||
<version>${zhilian.version}</version>
|
<version>${zhilian.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 阿里云ESC服务版本控制-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun</groupId>
|
||||||
|
<artifactId>ecs20140526</artifactId>
|
||||||
|
<version>${aliyun.ecs.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
@ -317,57 +328,57 @@
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- 要将源码放上去,需要加入这个插件 -->
|
<!-- 要将源码放上去,需要加入这个插件 -->
|
||||||
<plugin>
|
<!-- <plugin>-->
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<!-- <artifactId>maven-source-plugin</artifactId>-->
|
||||||
<version>3.0.1</version>
|
<!-- <version>3.0.1</version>-->
|
||||||
<configuration>
|
<!-- <configuration>-->
|
||||||
<attach>true</attach>
|
<!-- <attach>true</attach>-->
|
||||||
</configuration>
|
<!-- </configuration>-->
|
||||||
<executions>
|
<!-- <executions>-->
|
||||||
<execution>
|
<!-- <execution>-->
|
||||||
<phase>compile</phase>
|
<!-- <phase>compile</phase>-->
|
||||||
<goals>
|
<!-- <goals>-->
|
||||||
<goal>jar</goal>
|
<!-- <goal>jar</goal>-->
|
||||||
</goals>
|
<!-- </goals>-->
|
||||||
</execution>
|
<!-- </execution>-->
|
||||||
</executions>
|
<!-- </executions>-->
|
||||||
</plugin>
|
<!-- </plugin>-->
|
||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<distributionManagement>
|
<!-- <distributionManagement>-->
|
||||||
<repository>
|
<!-- <repository>-->
|
||||||
<id>releases</id>
|
<!-- <id>releases</id>-->
|
||||||
<name>releases</name>
|
<!-- <name>releases</name>-->
|
||||||
<url>http://nexus.zhilian.com:8081/repository/maven-releases/</url>
|
<!-- <url>http://nexus.zhilian.com:8081/repository/maven-releases/</url>-->
|
||||||
</repository>
|
<!-- </repository>-->
|
||||||
</distributionManagement>
|
<!-- </distributionManagement>-->
|
||||||
|
|
||||||
<repositories>
|
<!-- <repositories>-->
|
||||||
<repository>
|
<!-- <repository>-->
|
||||||
<id>public</id>
|
<!-- <id>public</id>-->
|
||||||
<name>aliyun nexus</name>
|
<!-- <name>aliyun nexus</name>-->
|
||||||
<url>http://nexus.zhilian.com:8081/repository/maven-public/</url>
|
<!-- <url>http://nexus.zhilian.com:8081/repository/maven-public/</url>-->
|
||||||
<releases>
|
<!-- <releases>-->
|
||||||
<enabled>true</enabled>
|
<!-- <enabled>true</enabled>-->
|
||||||
</releases>
|
<!-- </releases>-->
|
||||||
</repository>
|
<!-- </repository>-->
|
||||||
</repositories>
|
<!-- </repositories>-->
|
||||||
|
|
||||||
<pluginRepositories>
|
<!-- <pluginRepositories>-->
|
||||||
<pluginRepository>
|
<!-- <pluginRepository>-->
|
||||||
<id>public</id>
|
<!-- <id>public</id>-->
|
||||||
<name>aliyun nexus</name>
|
<!-- <name>aliyun nexus</name>-->
|
||||||
<url>http://nexus.zhilian.com:8081/repository/maven-public/</url>
|
<!-- <url>http://nexus.zhilian.com:8081/repository/maven-public/</url>-->
|
||||||
<releases>
|
<!-- <releases>-->
|
||||||
<enabled>true</enabled>
|
<!-- <enabled>true</enabled>-->
|
||||||
</releases>
|
<!-- </releases>-->
|
||||||
<snapshots>
|
<!-- <snapshots>-->
|
||||||
<enabled>false</enabled>
|
<!-- <enabled>false</enabled>-->
|
||||||
</snapshots>
|
<!-- </snapshots>-->
|
||||||
</pluginRepository>
|
<!-- </pluginRepository>-->
|
||||||
</pluginRepositories>
|
<!-- </pluginRepositories>-->
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -156,13 +156,13 @@ public class RedisService {
|
||||||
/**
|
/**
|
||||||
* 缓存Set
|
* 缓存Set
|
||||||
*
|
*
|
||||||
* @param key 缓存键值
|
* @param key 缓存键值
|
||||||
* @param setValue 缓存的数据
|
* @param setValue 缓存的数据
|
||||||
* @return 缓存数据的对象
|
* @return 缓存数据的对象
|
||||||
*/
|
*/
|
||||||
public <T> BoundSetOperations<String, T> setCacheSet(final String key, final T setValue) {
|
public <T> BoundSetOperations<String, T> setCacheSet(final String key, final T setValue) {
|
||||||
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
|
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
|
||||||
setOperation.add(setValue);
|
setOperation.add(setValue);
|
||||||
return setOperation;
|
return setOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,8 +272,6 @@ public class RedisService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取Zset集合大小
|
* 获取Zset集合大小
|
||||||
*
|
*
|
||||||
|
@ -310,6 +308,7 @@ public class RedisService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 范围查询集合携带分数
|
* 范围查询集合携带分数
|
||||||
|
*
|
||||||
* @param zkey
|
* @param zkey
|
||||||
* @param start
|
* @param start
|
||||||
* @param end
|
* @param end
|
||||||
|
@ -329,46 +328,50 @@ public class RedisService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改对应键值分数,delta为正数则增加,为负数则减少
|
* 修改对应键值分数,delta为正数则增加,为负数则减少
|
||||||
|
*
|
||||||
* @param zkey
|
* @param zkey
|
||||||
* @param value
|
* @param value
|
||||||
* @param delta
|
* @param delta
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public <T> Double incrementScore(final String zkey, final T value, final Double delta){
|
public <T> Double incrementScore(final String zkey, final T value, final Double delta) {
|
||||||
return redisTemplate.opsForZSet().incrementScore(zkey,value,delta);
|
return redisTemplate.opsForZSet().incrementScore(zkey, value, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除元素
|
* 删除元素
|
||||||
|
*
|
||||||
* @param zkey
|
* @param zkey
|
||||||
* @param values
|
* @param values
|
||||||
* @return
|
|
||||||
* @param <T>
|
* @param <T>
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public <T> Long removeCacheZsetBatch(final String zkey,final T... values){
|
public <T> Long removeCacheZsetBatch(final String zkey, final T... values) {
|
||||||
return redisTemplate.opsForZSet().remove(zkey,values);
|
return redisTemplate.opsForZSet().remove(zkey, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 排序并限制结果集大小,按降序返回有序集合的部分元素,支持指定索引范围。
|
* 排序并限制结果集大小,按降序返回有序集合的部分元素,支持指定索引范围。
|
||||||
|
*
|
||||||
* @param zkey
|
* @param zkey
|
||||||
* @param start
|
* @param start
|
||||||
* @param end
|
* @param end
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Double> reverseRange(final String zkey,final Long start,final Long end){
|
public Set<Double> reverseRange(final String zkey, final Long start, final Long end) {
|
||||||
return redisTemplate.opsForZSet().reverseRange(zkey,start,end);
|
return redisTemplate.opsForZSet().reverseRange(zkey, start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按分数范围查询
|
* 按分数范围查询
|
||||||
|
*
|
||||||
* @param zkey
|
* @param zkey
|
||||||
* @param min
|
* @param min
|
||||||
* @param max
|
* @param max
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Double> rangeByScore(final String zkey,final Double min,final Double max){
|
public Set<Double> rangeByScore(final String zkey, final Double min, final Double max) {
|
||||||
return redisTemplate.opsForZSet().rangeByScore(zkey,min,max);
|
return redisTemplate.opsForZSet().rangeByScore(zkey, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -377,7 +380,7 @@ public class RedisService {
|
||||||
* @param zkey
|
* @param zkey
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ZSetOperations.TypedTuple getCacheZsetMin(final String zkey){
|
public ZSetOperations.TypedTuple getCacheZsetMin(final String zkey) {
|
||||||
ZSetOperations.TypedTuple typedTuple = redisTemplate.opsForZSet().popMin(zkey);
|
ZSetOperations.TypedTuple typedTuple = redisTemplate.opsForZSet().popMin(zkey);
|
||||||
return typedTuple;
|
return typedTuple;
|
||||||
}
|
}
|
||||||
|
@ -393,13 +396,43 @@ public class RedisService {
|
||||||
return redisTemplate.keys(pattern);
|
return redisTemplate.keys(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteCacheSet(String key) {
|
public void deleteCacheSet(final String key) {
|
||||||
SetOperations setOperations = redisTemplate.opsForSet();
|
SetOperations setOperations = redisTemplate.opsForSet();
|
||||||
setOperations.remove(key);
|
setOperations.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void deleteCacheSetValue(String key, T value) {
|
public <T> void deleteCacheSetValue(final String key, final T value) {
|
||||||
SetOperations setOperations = redisTemplate.opsForSet();
|
SetOperations setOperations = redisTemplate.opsForSet();
|
||||||
setOperations.remove(key,value);
|
setOperations.remove(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public <T> void deleteCacheZsetValue(final String key, final T value) {
|
||||||
|
ZSetOperations zSetOperations = redisTemplate.opsForZSet();
|
||||||
|
zSetOperations.remove(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 根据下标获取List中value
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: key ,index 下标
|
||||||
|
* @return: value
|
||||||
|
**/
|
||||||
|
public <T> T getcacheListValue(final String key, final Long index) {
|
||||||
|
ListOperations listOperations = redisTemplate.opsForList();
|
||||||
|
|
||||||
|
return (T) listOperations.index(key, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 增加String类型中缓存值
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: key,number
|
||||||
|
* @return: Long 增加后的值
|
||||||
|
**/
|
||||||
|
public Long increment(final String key,final Long number) {
|
||||||
|
ValueOperations valueOperations = redisTemplate.opsForValue();
|
||||||
|
return valueOperations.increment(key,number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,12 +98,18 @@
|
||||||
<artifactId>spring-kafka</artifactId>
|
<artifactId>spring-kafka</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 业务系统远程调用-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.zhilian</groupId>
|
<groupId>com.zhilian</groupId>
|
||||||
<artifactId>zhilian-common-business</artifactId>
|
<artifactId>zhilian-common-business</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 阿里云Ecs服务依赖(openAPI)-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun</groupId>
|
||||||
|
<artifactId>ecs20140526</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.zhilian.online.Timer;
|
||||||
|
|
||||||
|
import com.zhilian.online.uitls.AliyunOpenAPIUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.Timer
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-17 21:53
|
||||||
|
* @Description: 收集节点监视者
|
||||||
|
* @Option: 监视节点负载量来决定是否需要扩容
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class LoadObserver {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阿里云api接口类
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private AliyunOpenAPIUtils aliyunOpenAPIUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监视负载量是否需要扩容
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0/10 * * * * ?")
|
||||||
|
public void addInstance(){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监视负载量是否需要缩容
|
||||||
|
*/
|
||||||
|
@Scheduled(cron = "0/10 * * * * ?")
|
||||||
|
public void ReduceInstance(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,11 +4,18 @@ import com.zhilian.common.security.annotation.EnableCustomConfig;
|
||||||
import com.zhilian.common.security.annotation.EnableMyFeignClients;
|
import com.zhilian.common.security.annotation.EnableMyFeignClients;
|
||||||
import com.zhilian.common.swagger.annotation.EnableCustomSwagger2;
|
import com.zhilian.common.swagger.annotation.EnableCustomSwagger2;
|
||||||
import com.zhilian.online.controller.OnlineLoadCenterController;
|
import com.zhilian.online.controller.OnlineLoadCenterController;
|
||||||
|
import com.zhilian.online.domain.EcsInstance;
|
||||||
|
import com.zhilian.online.domain.req.EcsCreateReq;
|
||||||
|
import com.zhilian.online.uitls.AliyunOpenAPIUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import com.aliyun.ecs20140526.models.RunInstancesRequest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @version:
|
* @version:
|
||||||
|
@ -20,9 +27,45 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
@EnableCustomSwagger2
|
@EnableCustomSwagger2
|
||||||
@EnableMyFeignClients
|
@EnableMyFeignClients
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class ZhiLianOnlineApplication{
|
@Slf4j
|
||||||
|
public class ZhiLianOnlineApplication implements ApplicationRunner {
|
||||||
|
@Autowired
|
||||||
|
private AliyunOpenAPIUtils aliyunOpenAPIUtils;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ZhiLianOnlineApplication.class,args);
|
SpringApplication.run(ZhiLianOnlineApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
|
log.info("项目启动,调用创建实例方法");
|
||||||
|
RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new RunInstancesRequest.RunInstancesRequestSystemDisk();
|
||||||
|
systemDisk = systemDisk.setSize("20").setCategory("cloud_efficiency");
|
||||||
|
EcsCreateReq ecs = EcsCreateReq.builder()
|
||||||
|
.regionId("cn-zhangjiakou")
|
||||||
|
.imageId("m-8vbfx0e48cekro0f13bx")
|
||||||
|
.instanceType("ecs.t6-c1m1.large")
|
||||||
|
.securityGroupId("sg-8vb49jd1c1lsa3akwo02")
|
||||||
|
.vSwitchId("vsw-8vb0krtyfdmb27nhcmzc2")
|
||||||
|
.instanceName("gather-node")
|
||||||
|
.internetMaxBandwidthIn(80)
|
||||||
|
.internetMaxBandwidthOut(10)
|
||||||
|
.uniqueSuffix(true)
|
||||||
|
.password("142730.Ly")
|
||||||
|
.zoneId("cn-zhangjiakou-c")
|
||||||
|
.internetChargeType("PayByTraffic")
|
||||||
|
.systemDiskSize("20")
|
||||||
|
.systemDickCategory("cloud_efficiency")
|
||||||
|
.amount(1)
|
||||||
|
.minAmount(1)
|
||||||
|
.periodUnit("Week")
|
||||||
|
.period(1)
|
||||||
|
.instanceChargeType("PostPaid")
|
||||||
|
// .privateIpAddress("10.10.27.1")
|
||||||
|
.build();
|
||||||
|
List<String> instance = aliyunOpenAPIUtils.createInstance(ecs);
|
||||||
|
|
||||||
|
List<EcsInstance> ecsInstances = aliyunOpenAPIUtils.queryEcsInstances(instance);
|
||||||
|
log.info("创建的实例信息为{}" , ecsInstances);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.zhilian.online.config;
|
||||||
|
|
||||||
|
import com.aliyun.ecs20140526.Client;
|
||||||
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import com.aliyun.ecs20140526.Client;
|
||||||
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.config
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-12 14:43
|
||||||
|
* @Description: 阿里云Ecs服务账号配置
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties("aliyun.ecs")
|
||||||
|
@Data
|
||||||
|
@Slf4j
|
||||||
|
public class AliyunEcsConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 令牌账号
|
||||||
|
*/
|
||||||
|
private String accessKeyId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 令牌密码
|
||||||
|
*/
|
||||||
|
private String accessKeySecret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阿里云端点地址
|
||||||
|
*/
|
||||||
|
private String endpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地域
|
||||||
|
*/
|
||||||
|
private String regionId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用AK&SK初始化账号Client
|
||||||
|
* @return Client
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Bean()
|
||||||
|
public Client createClient() throws Exception {
|
||||||
|
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||||
|
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
|
||||||
|
Config config = new Config()
|
||||||
|
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||||
|
.setAccessKeyId(accessKeyId)
|
||||||
|
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||||
|
.setAccessKeySecret(accessKeySecret)
|
||||||
|
.setRegionId(regionId);
|
||||||
|
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||||
|
config.endpoint = endpoint;
|
||||||
|
Client aliyunClient = new Client(config);
|
||||||
|
return aliyunClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -100,7 +100,7 @@ public class MqttxConfig {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@PostConstruct
|
// @PostConstruct
|
||||||
public void initMqtt() {
|
public void initMqtt() {
|
||||||
log.info("mqttx连接中......");
|
log.info("mqttx连接中......");
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class OnlineConstants {
|
||||||
/**
|
/**
|
||||||
* 申请注册令牌缓存前缀
|
* 申请注册令牌缓存前缀
|
||||||
*/
|
*/
|
||||||
public static final String ONLINE_TOKEN_PREFIX = "online_token:";
|
public static final String NODE_TOKEN_PREFIX = "node_token:";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 申请令牌过期时间
|
* 申请令牌过期时间
|
||||||
|
@ -26,11 +26,26 @@ public class OnlineConstants {
|
||||||
/**
|
/**
|
||||||
* 节点负载前缀
|
* 节点负载前缀
|
||||||
*/
|
*/
|
||||||
public static final String GATHER_LOAD_CONTROL = "gather_info_control";
|
public static final String GATHER_LOAD_PREFIX = "gather:load:";
|
||||||
/**
|
/**
|
||||||
* 节点负载信息
|
* 在线节点前缀
|
||||||
*/
|
*/
|
||||||
public static final String ONLINE_VEHICLE = "online_vehicle:";
|
public static final String ONLINE_GATHER_PREFIX = "online_vehicle:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http请求前缀
|
||||||
|
*/
|
||||||
|
public static final String HTTP_PREFIX = "http://";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https请求前缀
|
||||||
|
*/
|
||||||
|
public static final String HTTPS_PREFIX = "https://";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fluxMQ请求地址
|
||||||
|
*/
|
||||||
|
public static final String FLUXMQ_INFO_URL = ":8080/public/cluster";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,19 @@
|
||||||
package com.zhilian.online.consumer;
|
package com.zhilian.online.consumer;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import com.zhilian.common.core.constant.Constants;
|
import com.zhilian.common.core.constant.Constants;
|
||||||
import com.zhilian.common.core.domain.Result;
|
|
||||||
import com.zhilian.common.redis.service.RedisService;
|
import com.zhilian.common.redis.service.RedisService;
|
||||||
import com.zhilian.online.config.RabbitConfig;
|
|
||||||
import com.zhilian.online.constans.OnlineConstants;
|
import com.zhilian.online.constans.OnlineConstants;
|
||||||
import com.zhilian.online.domain.Gather;
|
import com.zhilian.online.domain.model.GatewayNodeInfo;
|
||||||
import com.zhilian.online.domain.req.GatherRegReq;
|
import com.zhilian.online.load.cache.GatewayNodeInfoCache;
|
||||||
|
import com.zhilian.online.load.cache.GatewayNodeWeightCache;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @BelongsProject: smart-cloud-server
|
* @BelongsProject: smart-cloud-server
|
||||||
|
@ -39,19 +33,26 @@ public class DeadQueueConsumer {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GatewayNodeInfoCache gatewayNodeInfoCache;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GatewayNodeWeightCache gatewayNodeWeightCache;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消费死信队列中的消息,确保车辆上线成功
|
* 消费死信队列中的消息,确保车辆上线成功
|
||||||
* 向节点地址的fluxMQ发送http请求,通过响应码来确定节点是否成功上线
|
* 向节点地址的fluxMQ发送http请求,通过响应码来确定节点是否成功上线
|
||||||
*/
|
*/
|
||||||
@RabbitListener(queues = RabbitConfig.DEAD_QUEUE_NAME)
|
// @RabbitListener(queues = RabbitConfig.DEAD_QUEUE_NAME)
|
||||||
public void SecureOnline(String gatherMsg) {
|
public void SecureOnline(String gatherMsg) {
|
||||||
Gather gather = JSON.parseObject(gatherMsg, Gather.class);
|
|
||||||
log.info("开始检查节点{}的上线状态......", gatherMsg);
|
log.info("开始检查节点{}的上线状态......", gatherMsg);
|
||||||
String ipAddress = gather.getIpAddress();
|
GatewayNodeInfo gatewayNodeInfo = JSONObject.parseObject(gatherMsg, GatewayNodeInfo.class);
|
||||||
|
|
||||||
|
String ipAddress = "";
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
try {
|
try {
|
||||||
ipAddress = "http://" + ipAddress;
|
ipAddress = OnlineConstants.HTTP_PREFIX + ipAddress + OnlineConstants.FLUXMQ_INFO_URL;
|
||||||
URL url = new URL(ipAddress);
|
URL url = new URL(ipAddress);
|
||||||
connection = (HttpURLConnection)url.openConnection();
|
connection = (HttpURLConnection)url.openConnection();
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod("GET");
|
||||||
|
@ -62,10 +63,10 @@ public class DeadQueueConsumer {
|
||||||
}
|
}
|
||||||
if (Constants.FAIL == responseCode){
|
if (Constants.FAIL == responseCode){
|
||||||
log.error("节点{}上线失败",gatherMsg);
|
log.error("节点{}上线失败",gatherMsg);
|
||||||
|
//删除节点数据
|
||||||
|
gatewayNodeInfoCache.remove(gatewayNodeInfo.getNodeId());
|
||||||
//上线失败需要将该节点的负载均衡缓存删除
|
//上线失败需要将该节点的负载均衡缓存删除
|
||||||
if (redisService.hasKey(OnlineConstants.ONLINE_TOKEN_PREFIX + gather.getClientId())){
|
gatewayNodeWeightCache.remove(gatewayNodeInfo);
|
||||||
redisService.removeCacheZsetBatch(OnlineConstants.ONLINE_TOKEN_PREFIX + gather.getClientId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("节点上线失败{}",e.getMessage());
|
log.error("节点上线失败{}",e.getMessage());
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
package com.zhilian.online.controller;
|
|
||||||
|
|
||||||
import com.zhilian.common.core.domain.Result;
|
|
||||||
|
|
||||||
import com.zhilian.online.service.OnlineGatherService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @version:
|
|
||||||
* @Author: LiYuan
|
|
||||||
* @description: 车辆收集节点控制层
|
|
||||||
* @date: 2024/3/29 20:46
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/gather")
|
|
||||||
public class OnlineGatherController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 车辆收集节点
|
|
||||||
*/
|
|
||||||
@Autowired
|
|
||||||
private OnlineGatherService onlineGatherService;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -5,7 +5,7 @@ import com.zhilian.common.core.domain.Result;
|
||||||
import com.zhilian.common.core.utils.ip.IpUtils;
|
import com.zhilian.common.core.utils.ip.IpUtils;
|
||||||
import com.zhilian.common.core.web.controller.BaseController;
|
import com.zhilian.common.core.web.controller.BaseController;
|
||||||
|
|
||||||
import com.zhilian.online.domain.Gather;
|
import com.zhilian.online.domain.ApifoxModel;
|
||||||
import com.zhilian.online.service.OnlineLoadCenterService;
|
import com.zhilian.online.service.OnlineLoadCenterService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -45,9 +45,9 @@ public class OnlineLoadCenterController extends BaseController {
|
||||||
* @return: Result<OnlineAccount>
|
* @return: Result<OnlineAccount>
|
||||||
**/
|
**/
|
||||||
@GetMapping("/applyForReg")
|
@GetMapping("/applyForReg")
|
||||||
public Result<String> applyForReg(Gather gather) {
|
public Result<String> applyForReg(String clusterId) {
|
||||||
log.info("申请注册令牌{}", JSON.toJSONString(gather));
|
log.info("节点{}申请注册令牌",clusterId);
|
||||||
return onlineLoadCenterService.applyForReg(gather);
|
return onlineLoadCenterService.applyForReg(clusterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,11 +58,9 @@ public class OnlineLoadCenterController extends BaseController {
|
||||||
* @return: Result
|
* @return: Result
|
||||||
**/
|
**/
|
||||||
@PostMapping("/regGather")
|
@PostMapping("/regGather")
|
||||||
public Result regGather(@Validated @RequestBody Gather gather) {
|
public Result regGather(@Validated @RequestBody ApifoxModel apifoxModel) {
|
||||||
String ipAddr = IpUtils.getIpAddr(request);
|
log.info("节点{}正在上线", JSON.toJSONString(apifoxModel));
|
||||||
gather.setIpAddress(ipAddr);
|
return onlineLoadCenterService.regGather(apifoxModel);
|
||||||
log.info("节点{}正在上线", JSON.toJSONString(gather));
|
|
||||||
return onlineLoadCenterService.regGather(gather);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,7 +74,8 @@ public class OnlineLoadCenterController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@GetMapping("/applyForConnectToGather")
|
@GetMapping("/applyForConnectToGather")
|
||||||
public Result applyForConnectToGather(@RequestParam("vin") String vin) {
|
public Result applyForConnectToGather(@RequestParam("vin") String vin) {
|
||||||
return Result.success(onlineLoadCenterService.applyForConnectToGather(vin));
|
onlineLoadCenterService.applyForConnectToGather(vin);
|
||||||
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
package com.zhilian.online.controller;/**
|
|
||||||
* @version:
|
|
||||||
* @Author: LiYuan
|
|
||||||
* @description:
|
|
||||||
* @date: 2024/3/30 11:18
|
|
||||||
*/
|
|
||||||
|
|
||||||
import com.zhilian.common.core.domain.Result;
|
|
||||||
import com.zhilian.online.domain.model.MqttServerModel;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: smart-cloud-server
|
|
||||||
* @BelongsPackage: com.zhilian.online.controller
|
|
||||||
* @Author: LiYuan
|
|
||||||
* @CreateTime: 2024-03-30 11:18
|
|
||||||
* @Description: 新增车辆上线验证控制器
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/verify")
|
|
||||||
public class OnlineVerifyController {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 读取配置文件中的mqtt服务地址
|
|
||||||
*/
|
|
||||||
@Value("${mqtt.server.broker}")
|
|
||||||
private String broker;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 读取配置文件中的订阅主题
|
|
||||||
*/
|
|
||||||
@Value("${mqtt.server.topic}")
|
|
||||||
private String topic;
|
|
||||||
|
|
||||||
@PostMapping("/vehicleConnection")
|
|
||||||
public Result<MqttServerModel> vehicleConnection() {
|
|
||||||
return Result.success(
|
|
||||||
MqttServerModel.builder()
|
|
||||||
.broker(broker)
|
|
||||||
.topic(topic)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.zhilian.online.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ApifoxModel {
|
||||||
|
/**
|
||||||
|
* 节点ID
|
||||||
|
*/
|
||||||
|
private String clusterId;
|
||||||
|
/**
|
||||||
|
* CPU使用信息
|
||||||
|
*/
|
||||||
|
private CPUInfo cpuInfo;
|
||||||
|
/**
|
||||||
|
* 节点状态
|
||||||
|
*/
|
||||||
|
private FlowInfo flowInfo;
|
||||||
|
/**
|
||||||
|
* HTTP请求地址
|
||||||
|
*/
|
||||||
|
private String httpUrl;
|
||||||
|
/**
|
||||||
|
* JVM使用信息
|
||||||
|
*/
|
||||||
|
private JVMInfo jvmInfo;
|
||||||
|
/**
|
||||||
|
* MQTT事件信息
|
||||||
|
*/
|
||||||
|
private MqttInfo mqttInfo;
|
||||||
|
/**
|
||||||
|
* MQTTS请求地址
|
||||||
|
*/
|
||||||
|
private String mqttsUrl;
|
||||||
|
/**
|
||||||
|
* MQTT请求地址
|
||||||
|
*/
|
||||||
|
private String mqttUrl;
|
||||||
|
/**
|
||||||
|
* 节点名称
|
||||||
|
*/
|
||||||
|
private String nodeName;
|
||||||
|
/**
|
||||||
|
* 启动时间
|
||||||
|
*/
|
||||||
|
private String startJvmTime;
|
||||||
|
/**
|
||||||
|
* 节点版本
|
||||||
|
*/
|
||||||
|
private String version;
|
||||||
|
/**
|
||||||
|
* websocket请求地址
|
||||||
|
*/
|
||||||
|
private String websocketUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公网地址
|
||||||
|
*/
|
||||||
|
private String publicIpAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内网地址
|
||||||
|
*/
|
||||||
|
private String privateIpAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请令牌
|
||||||
|
*/
|
||||||
|
private String token;
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.zhilian.online.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CPU使用信息
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CPUInfo {
|
||||||
|
/**
|
||||||
|
* CPU核数
|
||||||
|
*/
|
||||||
|
private long cpuNum;
|
||||||
|
/**
|
||||||
|
* 内核态使用率
|
||||||
|
*/
|
||||||
|
private String cSys;
|
||||||
|
/**
|
||||||
|
* 空闲率
|
||||||
|
*/
|
||||||
|
private String idle;
|
||||||
|
/**
|
||||||
|
* I/O等待
|
||||||
|
*/
|
||||||
|
private String iowait;
|
||||||
|
/**
|
||||||
|
* 用户态使用率
|
||||||
|
*/
|
||||||
|
private String user;
|
||||||
|
}
|
|
@ -0,0 +1,261 @@
|
||||||
|
package com.zhilian.online.domain;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.domain
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-12 15:01
|
||||||
|
* @Description: 阿里云ECS服务器实体类
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@ToString
|
||||||
|
public class EcsInstance {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例创建时间。以 ISO 8601 为标准,并使用 UTC+0 时间,格式为 yyyy-MM-ddTHH:mmZ
|
||||||
|
*/
|
||||||
|
private String creationTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例序列号
|
||||||
|
*/
|
||||||
|
private String serialNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部署集ID
|
||||||
|
*/
|
||||||
|
private String deploymentSetId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密钥对名称。
|
||||||
|
*/
|
||||||
|
private String keyPairName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按量实例的竞价策略。可能值:
|
||||||
|
* NoSpot:正常按量付费实例。
|
||||||
|
* SpotWithPriceLimit:设置上限价格的抢占式实例。
|
||||||
|
* SpotAsPriceGo:系统自动出价
|
||||||
|
*/
|
||||||
|
private String spotStrategy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例是否支持挂载磁盘。
|
||||||
|
*/
|
||||||
|
private Boolean deviceAvailable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例挂载的本地存储容量。单位:GiB
|
||||||
|
*/
|
||||||
|
private Long localStorageCapacity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抢占式实例的保留时长,单位为小时。可能值:
|
||||||
|
* 1:创建后阿里云会保证实例运行 1 小时不会被自动释放;超过 1 小时后,系统会自动比较出价与市场价格、检查资源库存,来决定实例的持有和回收。
|
||||||
|
* 0:创建后,阿里云不保证实例运行 1 小时,系统会自动比较出价与市场价格、检查资源库存,来决定实例的持有和回收。
|
||||||
|
*/
|
||||||
|
private Integer spotDuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例网络类型。可能值:
|
||||||
|
* classic:经典网络。
|
||||||
|
* vpc:专有网络 VPC。
|
||||||
|
*/
|
||||||
|
private String instanceNetworkType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例名称
|
||||||
|
*/
|
||||||
|
private String instanceName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例ID
|
||||||
|
*/
|
||||||
|
private String instanceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例操作系统的英文名称
|
||||||
|
*/
|
||||||
|
private String osNameEn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*实例所属的 HPC 集群 ID。
|
||||||
|
*/
|
||||||
|
private String hpcClusterId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例的每小时最高价格。支持最大 3 位小数,参数 SpotStrategy=SpotWithPriceLimit 时,该参数生效。
|
||||||
|
*/
|
||||||
|
private Number spotPriceLimit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内存大小,单位为 MiB。
|
||||||
|
*/
|
||||||
|
private Integer memory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例的操作系统名称
|
||||||
|
*/
|
||||||
|
private String osName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ECS 实例绑定部署集分散部署时,实例在部署集中的分组位置。
|
||||||
|
*/
|
||||||
|
private String deploymentSetGroupNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例运行的镜像 ID。
|
||||||
|
*/
|
||||||
|
private String imageId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例的 GPU 类型。
|
||||||
|
*/
|
||||||
|
private String gpuSpec;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例释放保护属性,指定是否支持通过控制台或 API(DeleteInstance)释放实例。
|
||||||
|
* true:已开启实例释放保护。
|
||||||
|
* false:未开启实例释放保护。
|
||||||
|
*/
|
||||||
|
private Boolean deletionProtection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例停机后是否继续收费。可能值:
|
||||||
|
* KeepCharging:停机后继续收费,为您继续保留库存资源。
|
||||||
|
* StopCharging:停机后不收费。停机后,我们释放实例对应的资源,例如 vCPU、内存和公网 IP 等资源。重启是否成功依赖于当前地域中是否仍有资源库存。
|
||||||
|
* Not-applicable:本实例不支持停机不收费功能。
|
||||||
|
*/
|
||||||
|
private String stoppedMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例规格附带的 GPU 数量。
|
||||||
|
*/
|
||||||
|
private Integer gpuAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例主机名
|
||||||
|
*/
|
||||||
|
private String hostName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公网出带宽最大值,单位:Mbit/s
|
||||||
|
*/
|
||||||
|
private Integer internetMaxBandwidthOut;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公网入带宽最大值,单位:Mbit/s
|
||||||
|
*/
|
||||||
|
private Integer internetMaxBandwidthIn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例规格
|
||||||
|
*/
|
||||||
|
private String instanceType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例的计费方式。可能值:
|
||||||
|
* PrePaid:包年包月。
|
||||||
|
* PostPaid:按量付费。
|
||||||
|
*/
|
||||||
|
private String instanceChargeType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例所属地域 ID。
|
||||||
|
*/
|
||||||
|
private String regionId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为 I/O 优化型实例。
|
||||||
|
*/
|
||||||
|
private Boolean ioOptimized;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例最近一次的启动时间。以 ISO 8601 为标准,并使用 UTC+0 时间,格式为 yyyy-MM-ddTHH:mmZ
|
||||||
|
*/
|
||||||
|
private String startTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vCPU 数
|
||||||
|
*/
|
||||||
|
private Integer cpu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例挂载的本地存储数量。
|
||||||
|
*/
|
||||||
|
private Integer localStorageAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过期时间。以 ISO 8601 为标准,并使用 UTC+0 时间,格式为 yyyy-MM-ddTHH:mmZ
|
||||||
|
*/
|
||||||
|
private String expiredTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例所属可用区。
|
||||||
|
*/
|
||||||
|
private String zoneId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例是否可以回收。
|
||||||
|
*/
|
||||||
|
private Boolean recyclable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 突发性能实例的运行模式。可能值:
|
||||||
|
* Standard:标准模式。有关实例性能的更多信息,请参见什么是突发性能实例中的性能约束模式章节。
|
||||||
|
* Unlimited:无性能约束模式,有关实例性能的更多信息,请参见什么是突发性能实例中的无性能约束模式章节。
|
||||||
|
*/
|
||||||
|
private String creditSpecification;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例规格族。
|
||||||
|
*/
|
||||||
|
private String instanceTypeFamily;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例的操作系统类型,分为 Windows Server 和 Linux 两种。可能值:
|
||||||
|
* windows。
|
||||||
|
* linux。
|
||||||
|
*/
|
||||||
|
private String osType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公网IP地址
|
||||||
|
*/
|
||||||
|
private String publicIpAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内网IP地址
|
||||||
|
*/
|
||||||
|
private String privateIpAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 专有网络ID
|
||||||
|
*/
|
||||||
|
private String vpcId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全组ID
|
||||||
|
*/
|
||||||
|
private List<String> securityGroupIds;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.zhilian.online.domain;
|
||||||
|
|
||||||
|
import lombok.Data; /**
|
||||||
|
* 节点状态
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class FlowInfo {
|
||||||
|
/**
|
||||||
|
* 上次读取吞吐量
|
||||||
|
*/
|
||||||
|
private String lastReadThroughput;
|
||||||
|
/**
|
||||||
|
* 上次写入吞吐量
|
||||||
|
*/
|
||||||
|
private String lastWriteThroughput;
|
||||||
|
/**
|
||||||
|
* 读取总吞吐量
|
||||||
|
*/
|
||||||
|
private String readBytesHistory;
|
||||||
|
/**
|
||||||
|
* 实写字节
|
||||||
|
*/
|
||||||
|
private String realWriteBytes;
|
||||||
|
/**
|
||||||
|
* 写入总吞吐量
|
||||||
|
*/
|
||||||
|
private String writeBytesHistory;
|
||||||
|
}
|
|
@ -1,70 +0,0 @@
|
||||||
package com.zhilian.online.domain;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.zhilian.common.core.web.domain.BaseEntity;
|
|
||||||
import lombok.*;
|
|
||||||
import org.bouncycastle.util.IPAddress;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: smart-cloud-server
|
|
||||||
* @BelongsPackage: com.zhilian.online.domain
|
|
||||||
* @Author: LiYuan
|
|
||||||
* @CreateTime: 2024-03-31 08:58
|
|
||||||
* @Description: 收集节点实体类
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@ToString
|
|
||||||
public class Gather extends BaseEntity {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 收集节点ID
|
|
||||||
*/
|
|
||||||
private String clientId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 收集节点登录令牌
|
|
||||||
*/
|
|
||||||
private String token;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* broker
|
|
||||||
*/
|
|
||||||
@NotBlank
|
|
||||||
private String broker;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* username
|
|
||||||
*/
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* password
|
|
||||||
*/
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* qos
|
|
||||||
*/
|
|
||||||
private Integer qos;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* topic
|
|
||||||
*/
|
|
||||||
@NotBlank
|
|
||||||
private String topic;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ip地址
|
|
||||||
*/
|
|
||||||
private String ipAddress;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.zhilian.online.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JVM使用信息
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class JVMInfo {
|
||||||
|
/**
|
||||||
|
* 文件描述(句柄)
|
||||||
|
*/
|
||||||
|
private String fileDescriptors;
|
||||||
|
/**
|
||||||
|
* 堆内存
|
||||||
|
*/
|
||||||
|
private String heapCommit;
|
||||||
|
/**
|
||||||
|
* 堆初始化空间
|
||||||
|
*/
|
||||||
|
private String heapInit;
|
||||||
|
/**
|
||||||
|
* 堆最大内存
|
||||||
|
*/
|
||||||
|
private String heapMax;
|
||||||
|
/**
|
||||||
|
* 堆使用空间
|
||||||
|
*/
|
||||||
|
private String heapUsed;
|
||||||
|
/**
|
||||||
|
* JAVA目录
|
||||||
|
*/
|
||||||
|
private String jdkHome;
|
||||||
|
/**
|
||||||
|
* JDK版本
|
||||||
|
*/
|
||||||
|
private String jdkVersion;
|
||||||
|
/**
|
||||||
|
* 非堆空间
|
||||||
|
*/
|
||||||
|
private String noHeapCommit;
|
||||||
|
/**
|
||||||
|
* 非堆初始化空间
|
||||||
|
*/
|
||||||
|
private String noHeapInit;
|
||||||
|
/**
|
||||||
|
* 非堆最大空间
|
||||||
|
*/
|
||||||
|
private String noHeapMax;
|
||||||
|
/**
|
||||||
|
* 非堆使用空间
|
||||||
|
*/
|
||||||
|
private String noHeapUsed;
|
||||||
|
/**
|
||||||
|
* 线程数量
|
||||||
|
*/
|
||||||
|
private long threadCount;
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.zhilian.online.domain;// ApifoxModel.java
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
|
||||||
|
// JVMInfo.java
|
||||||
|
|
||||||
|
|
||||||
|
// MqttInfo.java
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MQTT事件信息
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MqttInfo {
|
||||||
|
/**
|
||||||
|
* 关闭事件数量
|
||||||
|
*/
|
||||||
|
private long closeEventSize;
|
||||||
|
/**
|
||||||
|
* 连接事件数量
|
||||||
|
*/
|
||||||
|
private long connectEventSize;
|
||||||
|
/**
|
||||||
|
* 链接总数
|
||||||
|
*/
|
||||||
|
private long connectSize;
|
||||||
|
/**
|
||||||
|
* 断开链接数量
|
||||||
|
*/
|
||||||
|
private long disconnectEventSize;
|
||||||
|
/**
|
||||||
|
* 推送数量
|
||||||
|
*/
|
||||||
|
private long publishEventSize;
|
||||||
|
/**
|
||||||
|
* 发布重试事件数量
|
||||||
|
*/
|
||||||
|
private long publishRetryEventSize;
|
||||||
|
/**
|
||||||
|
* 保留消息数量
|
||||||
|
*/
|
||||||
|
private long retainSize;
|
||||||
|
/**
|
||||||
|
* 订阅事件数量
|
||||||
|
*/
|
||||||
|
private long subscribeEventSize;
|
||||||
|
/**
|
||||||
|
* 订阅数量
|
||||||
|
*/
|
||||||
|
private long subscribeSize;
|
||||||
|
/**
|
||||||
|
* 主题数量
|
||||||
|
*/
|
||||||
|
private long topicSize;
|
||||||
|
/**
|
||||||
|
* 取消订阅数量
|
||||||
|
*/
|
||||||
|
private long unSubscribeEventSize;
|
||||||
|
}
|
|
@ -1,37 +0,0 @@
|
||||||
//package com.zhilian.online.domain;/**
|
|
||||||
// * @version:
|
|
||||||
// * @Author: LiYuan
|
|
||||||
// * @description:
|
|
||||||
// * @date: 2024/3/29 21:44
|
|
||||||
// */
|
|
||||||
//
|
|
||||||
//import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
//import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
//import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
//import com.zhilian.common.core.web.domain.BaseEntity;
|
|
||||||
//import lombok.*;
|
|
||||||
//
|
|
||||||
//import javax.validation.constraints.NotBlank;
|
|
||||||
//import javax.validation.constraints.NotNull;
|
|
||||||
//import java.util.Date;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// *@BelongsProject: smart-cloud-server
|
|
||||||
// *@BelongsPackage: com.zhilian.online.domain
|
|
||||||
// *@Author: LiYuan
|
|
||||||
// *@CreateTime: 2024-03-29 21:44
|
|
||||||
// *@Description: 汽车类,测试使用
|
|
||||||
// *@Version: 1.0
|
|
||||||
// */
|
|
||||||
//@Data
|
|
||||||
////@AllArgsConstructor
|
|
||||||
////@NoArgsConstructor
|
|
||||||
//@Builder
|
|
||||||
//@ToString
|
|
||||||
//@EqualsAndHashCode(callSuper = true)
|
|
||||||
//@TableName("vehicle")
|
|
||||||
//public class Vehicle extends BaseEntity {
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//}
|
|
|
@ -1,70 +0,0 @@
|
||||||
package com.zhilian.online.domain;/**
|
|
||||||
* @version:
|
|
||||||
* @Author: LiYuan
|
|
||||||
* @description:
|
|
||||||
* @date: 2024/3/29 21:49
|
|
||||||
*/
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.zhilian.common.core.web.domain.BaseEntity;
|
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*@BelongsProject: smart-cloud-server
|
|
||||||
*@BelongsPackage: com.zhilian.online.domain
|
|
||||||
*@Author: LiYuan
|
|
||||||
*@CreateTime: 2024-03-29 21:49
|
|
||||||
*@Description: 车辆申请注册成功后返回的一次性账户数据
|
|
||||||
*@Version: 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NotBlank
|
|
||||||
@ToString
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@TableName("vehicle_account")
|
|
||||||
public class VehicleAccount extends BaseEntity{
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 车辆VIN
|
|
||||||
*/
|
|
||||||
@TableId(type = IdType.INPUT)
|
|
||||||
private String vin;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 申请时间
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
private Date applyTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 申请唯一标识
|
|
||||||
*/
|
|
||||||
@NotBlank
|
|
||||||
private String applyCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 一次性用户名
|
|
||||||
*/
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 一次性密码
|
|
||||||
*/
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 可以进行连接的收集节点id
|
|
||||||
*/
|
|
||||||
private String clientId;
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.zhilian.online.domain.model;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.domain.model
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-18 19:47
|
||||||
|
* @Description: 收集节点信息
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@ToString
|
||||||
|
@Builder
|
||||||
|
public class GatewayNodeInfo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点id
|
||||||
|
*/
|
||||||
|
private String nodeId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公网IP
|
||||||
|
*/
|
||||||
|
private String publicIpAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内网IP
|
||||||
|
*/
|
||||||
|
private String privateIpAddress;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,123 @@
|
||||||
|
package com.zhilian.online.domain.req;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.domain.req
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-16 20:23
|
||||||
|
* @Description: 阿里openAPI创建实例请求
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@ToString
|
||||||
|
@Builder
|
||||||
|
public class EcsCreateReq {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 磁盘大小
|
||||||
|
*/
|
||||||
|
private String systemDiskSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 磁盘类型
|
||||||
|
*/
|
||||||
|
private String systemDickCategory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地域ID
|
||||||
|
*/
|
||||||
|
private String regionId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 镜像ID
|
||||||
|
*/
|
||||||
|
private String imageId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例规格
|
||||||
|
*/
|
||||||
|
private String instanceType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全组ID
|
||||||
|
*/
|
||||||
|
private String securityGroupId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 专有网络ID
|
||||||
|
*/
|
||||||
|
private String vSwitchId;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例名称
|
||||||
|
*/
|
||||||
|
private String instanceName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公网入网流量大小
|
||||||
|
*/
|
||||||
|
private Integer internetMaxBandwidthIn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公网出网流量大小
|
||||||
|
*/
|
||||||
|
private Integer internetMaxBandwidthOut;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 唯一后缀
|
||||||
|
*/
|
||||||
|
private Boolean uniqueSuffix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 专有网络ID
|
||||||
|
*/
|
||||||
|
private String zoneId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网络计费类型
|
||||||
|
*/
|
||||||
|
private String internetChargeType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 购买数量
|
||||||
|
*/
|
||||||
|
private Integer amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最小购买数量
|
||||||
|
*/
|
||||||
|
private Integer minAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 购买时长单位
|
||||||
|
*/
|
||||||
|
private String periodUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 购买时长
|
||||||
|
*/
|
||||||
|
private Integer period;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例付费类型
|
||||||
|
*/
|
||||||
|
private String instanceChargeType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 私网IP
|
||||||
|
*/
|
||||||
|
private String privateIpAddress;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
package com.zhilian.online.domain.req;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.domain.req
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-12 15:37
|
||||||
|
* @Description: 阿里云openAPI查询实例请求
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@ToString
|
||||||
|
@Builder
|
||||||
|
public class EcsQueryReq {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例所属地域 ID。
|
||||||
|
*/
|
||||||
|
@NotBlank
|
||||||
|
private String regionId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 专有网络ID
|
||||||
|
*/
|
||||||
|
private String vpcId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 交换机ID
|
||||||
|
*/
|
||||||
|
private String vSwitchId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 可用区ID。
|
||||||
|
*/
|
||||||
|
private String zoneId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例网络类型。可能值:
|
||||||
|
* classic:经典网络。
|
||||||
|
* vpc:专有网络 VPC。
|
||||||
|
*/
|
||||||
|
private String instanceNetworkType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全组ID
|
||||||
|
*/
|
||||||
|
private String securityGroupId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例ID ["i-bp67acfmxazb4p****", "i-bp67acfmxazb4p****", … "i-bp67acfmxazb4p****"]
|
||||||
|
*/
|
||||||
|
private List<String> instanceIds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页码
|
||||||
|
*/
|
||||||
|
private Integer pageNumber = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每页条数
|
||||||
|
*/
|
||||||
|
private Integer pageSize = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内网IP地址集 ["172.16.1.1", "172.16.2.1", … "172.16.10.1"]
|
||||||
|
*/
|
||||||
|
private String privateIpAddresses;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内网IP地址集 ["172.16.1.1", "172.16.2.1", … "172.16.10.1"]
|
||||||
|
*/
|
||||||
|
private String publicIpAddresses;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例名称,支持使用通配符*进行模糊搜索。
|
||||||
|
*/
|
||||||
|
private String instanceName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 镜像ID
|
||||||
|
*/
|
||||||
|
private String imageId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例规格
|
||||||
|
*/
|
||||||
|
private String instanceType;
|
||||||
|
|
||||||
|
}
|
|
@ -1,34 +0,0 @@
|
||||||
package com.zhilian.online.domain.req;
|
|
||||||
|
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: smart-cloud-server
|
|
||||||
* @BelongsPackage: com.zhilian.online.domain.req
|
|
||||||
* @Author: LiYuan
|
|
||||||
* @CreateTime: 2024-03-31 09:03
|
|
||||||
* @Description: 节点申请注册请求体
|
|
||||||
* @Version: 1.0
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@ToString
|
|
||||||
@Builder
|
|
||||||
public class GatherRegReq {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端ID
|
|
||||||
*/
|
|
||||||
@NotBlank
|
|
||||||
private String clientId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 令牌
|
|
||||||
*/
|
|
||||||
private String token;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.zhilian.online.load.abs;
|
||||||
|
|
||||||
|
import com.zhilian.common.redis.service.RedisService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.load.abs
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-18 19:09
|
||||||
|
* @Description: 网关负载均衡缓存抽象类
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public abstract class GatewayCacheAbs<K> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public RedisService redisService;
|
||||||
|
|
||||||
|
public abstract String getPre();
|
||||||
|
|
||||||
|
public String encode(K key) {
|
||||||
|
return getPre() + key;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package com.zhilian.online.load.cache;
|
||||||
|
|
||||||
|
import com.zhilian.common.redis.service.RedisService;
|
||||||
|
import com.zhilian.online.load.abs.GatewayCacheAbs;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.load.cache
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-18 19:11
|
||||||
|
* @Description: 加权轮询的100个节点IP 为之后车辆上线取用
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class GatewayLoadNodeCache extends GatewayCacheAbs<String> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private final static String gatewayLoadNodeKey = "node";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPre() {
|
||||||
|
return "gateway:load:";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 存放
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: nodeList
|
||||||
|
* @return: void
|
||||||
|
**/
|
||||||
|
public void put(List<String> nodeList) {
|
||||||
|
redisService.deleteObject(encode(gatewayLoadNodeKey));
|
||||||
|
redisService.setCacheList(encode(gatewayLoadNodeKey), nodeList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取所有负载节点
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: null
|
||||||
|
* @return: List<String>
|
||||||
|
**/
|
||||||
|
public List<String> get() {
|
||||||
|
return redisService.getCacheList(encode(gatewayLoadNodeKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 通过下标获取节点
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: index 下标
|
||||||
|
* @return: String node 节点
|
||||||
|
**/
|
||||||
|
public String getByIndex(Long index){
|
||||||
|
if (null == index || index > 100){
|
||||||
|
throw new RuntimeException("下标违法,不在[0-100]内");
|
||||||
|
}
|
||||||
|
return redisService.getcacheListValue(encode(gatewayLoadNodeKey),index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.zhilian.online.load.cache;
|
||||||
|
|
||||||
|
import com.zhilian.online.load.abs.GatewayCacheAbs;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.load.cache
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-18 19:34
|
||||||
|
* @Description: 网关负载自增序列
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class GatewayLoadSeriesCache extends GatewayCacheAbs<String> {
|
||||||
|
|
||||||
|
private final static String gatewayLoadSeriesKey = "series";
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPre() {
|
||||||
|
return "gateway:load:";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 创建Bean后初始化自增序列
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
**/
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
redisService.setCacheObject(encode(gatewayLoadSeriesKey), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取自增序列的值
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param:
|
||||||
|
* @return: Long
|
||||||
|
**/
|
||||||
|
public Long incrementAndGet() {
|
||||||
|
return redisService.increment(encode(gatewayLoadSeriesKey), 1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取当前序列的值
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
**/
|
||||||
|
public Long get() {
|
||||||
|
return redisService.getCacheObject(encode(gatewayLoadSeriesKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 重置序列中的值
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
**/
|
||||||
|
public void reset() {
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.zhilian.online.load.cache;
|
||||||
|
|
||||||
|
import com.zhilian.online.load.abs.GatewayCacheAbs;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.load.cache
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-19 19:42
|
||||||
|
* @Description: 节点负载的车辆数据操作
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public class GatewayNodeCarsCache extends GatewayCacheAbs<String> {
|
||||||
|
@Override
|
||||||
|
public String getPre() {
|
||||||
|
return "gateway:node:cars";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 车辆上线添加数据
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: String nodeId, String vin
|
||||||
|
* @return: void
|
||||||
|
**/
|
||||||
|
public void put(String nodeId, String vin) {
|
||||||
|
redisService.setCacheSet(encode(nodeId), vin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 根据节点获取其负载车辆vin列表
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: String nodeId
|
||||||
|
* @return: void
|
||||||
|
**/
|
||||||
|
public List<String> get(String nodeId) {
|
||||||
|
Set<String> res = redisService.getCacheSet(encode(nodeId));
|
||||||
|
return res.stream().map(String::valueOf).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 删除下线车辆
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: String nodeId, String vin
|
||||||
|
* @return: void
|
||||||
|
**/
|
||||||
|
public void remove(String nodeId, String vin) {
|
||||||
|
redisService.deleteCacheSetValue(encode(nodeId), vin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package com.zhilian.online.load.cache;
|
||||||
|
|
||||||
|
import com.zhilian.online.domain.model.GatewayNodeInfo;
|
||||||
|
import com.zhilian.online.load.abs.GatewayCacheAbs;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.load.cache
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-18 19:44
|
||||||
|
* @Description: 网关负载中心节点数据缓存 String key(节点ID) + 节点 对象
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class GatewayNodeInfoCache extends GatewayCacheAbs<String > {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPre() {
|
||||||
|
return "gateway:node:info:";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 增加节点数据
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: GatewayNodeInfo 节点数据
|
||||||
|
* @return:
|
||||||
|
**/
|
||||||
|
public void put(GatewayNodeInfo gatewayNodeInfo){
|
||||||
|
redisService.setCacheObject(encode(gatewayNodeInfo.getNodeId()),gatewayNodeInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取节点缓存数据
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: nodeId 节点Id
|
||||||
|
* @return:
|
||||||
|
**/
|
||||||
|
public GatewayNodeInfo get(String nodeId){
|
||||||
|
return redisService.getCacheObject(encode(nodeId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取所有节点数据
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
**/
|
||||||
|
public List<GatewayNodeInfo> get(){
|
||||||
|
return redisService.getCacheObject(encode(getPre()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 删除网关节点
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
**/
|
||||||
|
public void remove(String nodeId){
|
||||||
|
redisService.deleteObject(encode(nodeId));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
package com.zhilian.online.load.cache;
|
||||||
|
|
||||||
|
import com.zhilian.online.domain.model.GatewayNodeInfo;
|
||||||
|
import com.zhilian.online.load.abs.GatewayCacheAbs;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.load.cache
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-18 20:03
|
||||||
|
* @Description: 节点权重数据
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class GatewayNodeWeightCache extends GatewayCacheAbs<String > {
|
||||||
|
|
||||||
|
private final static String gatewayNodeLoadKey = "weight";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPre() {
|
||||||
|
return "gateway:node:";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取所有Zset集合
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: void
|
||||||
|
* @return: Map<Object,Double>
|
||||||
|
**/
|
||||||
|
public Map<Object,Double> get(){
|
||||||
|
return redisService.getCacheObject(encode(gatewayNodeLoadKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取指定节点分数
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: gatewayNodeInfo
|
||||||
|
* @return: score
|
||||||
|
**/
|
||||||
|
public Double get(GatewayNodeInfo gatewayNodeInfo){
|
||||||
|
return redisService.getCacheZsetScore(encode(gatewayNodeLoadKey),gatewayNodeInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
**/
|
||||||
|
public void put(GatewayNodeInfo gatewayNodeInfo){
|
||||||
|
redisService.setCacheZsetValue(encode(gatewayNodeLoadKey),gatewayNodeInfo,0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
**/
|
||||||
|
public void increment(GatewayNodeInfo gatewayNodeInfo,Double score){
|
||||||
|
redisService.incrementScore(encode(gatewayNodeLoadKey),gatewayNodeInfo,score);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param:
|
||||||
|
* @return:
|
||||||
|
**/
|
||||||
|
public void remove(GatewayNodeInfo gatewayNodeInfo) {
|
||||||
|
redisService.deleteCacheZsetValue(encode(gatewayNodeLoadKey),gatewayNodeInfo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.zhilian.online.load.cache;
|
||||||
|
|
||||||
|
import com.zhilian.online.load.abs.GatewayCacheAbs;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.load.cache
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-18 19:58
|
||||||
|
* @Description: 车辆连接数据
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class GatewayVehicleNodeCaChe extends GatewayCacheAbs<String> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPre() {
|
||||||
|
return "gateway:car:";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 存放车辆数据
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: String vin, String nodeId
|
||||||
|
* @return:
|
||||||
|
**/
|
||||||
|
public void put(String vin, String nodeId) {
|
||||||
|
redisService.setCacheObject(encode(vin),nodeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description:删除车辆数据
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: String vin
|
||||||
|
* @return:
|
||||||
|
**/
|
||||||
|
public void remove(String vin){
|
||||||
|
redisService.deleteObject(encode(vin));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 获取车辆连接数据
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: String vin
|
||||||
|
* @return:
|
||||||
|
**/
|
||||||
|
public String get(String vin){
|
||||||
|
return redisService.getCacheObject(encode(vin));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,17 +0,0 @@
|
||||||
package com.zhilian.online.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @version:
|
|
||||||
* @Author: LiYuan
|
|
||||||
* @description: 车辆收集节点数据层
|
|
||||||
* @date: 2024/3/29 20:48
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface OnlineGatherMapper{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.zhilian.online.mapper;
|
package com.zhilian.online.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.zhilian.online.domain.VehicleAccount;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||||
* @date: 2024/3/29 20:45
|
* @date: 2024/3/29 20:45
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface OnlineLoadCenterMapper extends BaseMapper<VehicleAccount> {
|
public interface OnlineLoadCenterMapper{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package com.zhilian.online.service;
|
package com.zhilian.online.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.zhilian.common.core.domain.Result;
|
import com.zhilian.common.core.domain.Result;
|
||||||
import com.zhilian.online.domain.Gather;
|
import com.zhilian.online.domain.ApifoxModel;
|
||||||
import com.zhilian.online.domain.VehicleAccount;
|
|
||||||
import com.zhilian.online.domain.req.GatherRegReq;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @version:
|
* @version:
|
||||||
|
@ -12,7 +9,7 @@ import com.zhilian.online.domain.req.GatherRegReq;
|
||||||
* @description: 车辆负载中心服务接口
|
* @description: 车辆负载中心服务接口
|
||||||
* @date: 2024/3/29 20:42
|
* @date: 2024/3/29 20:42
|
||||||
*/
|
*/
|
||||||
public interface OnlineLoadCenterService extends IService<VehicleAccount> {
|
public interface OnlineLoadCenterService{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 车辆申请注解令牌接口,仅限内网访问
|
* @description: 车辆申请注解令牌接口,仅限内网访问
|
||||||
|
@ -20,7 +17,7 @@ public interface OnlineLoadCenterService extends IService<VehicleAccount> {
|
||||||
* @param: vehicle
|
* @param: vehicle
|
||||||
* @return: Result<OnlineAccount>
|
* @return: Result<OnlineAccount>
|
||||||
**/
|
**/
|
||||||
Result<String> applyForReg(Gather gather);
|
Result<String> applyForReg(String clusterId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 车辆使用申请的一次性账户连接收集节点
|
* @description: 车辆使用申请的一次性账户连接收集节点
|
||||||
|
@ -28,7 +25,7 @@ public interface OnlineLoadCenterService extends IService<VehicleAccount> {
|
||||||
* @param:
|
* @param:
|
||||||
* @return: Result
|
* @return: Result
|
||||||
**/
|
**/
|
||||||
Result regGather(Gather gather);
|
Result regGather(ApifoxModel apifoxModel);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +34,7 @@ public interface OnlineLoadCenterService extends IService<VehicleAccount> {
|
||||||
* @param: vin
|
* @param: vin
|
||||||
* @return gather
|
* @return gather
|
||||||
*/
|
*/
|
||||||
Gather applyForConnectToGather(String vin);
|
void applyForConnectToGather(String vin);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
package com.zhilian.online.service.impl;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.zhilian.common.core.domain.Result;
|
|
||||||
import com.zhilian.online.mapper.OnlineGatherMapper;
|
|
||||||
import com.zhilian.online.service.OnlineGatherService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @version:
|
|
||||||
* @Author: LiYuan
|
|
||||||
* @description: 车辆收集节点服务层
|
|
||||||
* @date: 2024/3/29 20:48
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class OnlineGatherServiceImpl implements OnlineGatherService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private OnlineGatherMapper onlineGatherMapper;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,23 +1,27 @@
|
||||||
package com.zhilian.online.service.impl;
|
package com.zhilian.online.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.zhilian.common.core.domain.Result;
|
import com.zhilian.common.core.domain.Result;
|
||||||
import com.zhilian.common.core.utils.uuid.IdUtils;
|
import com.zhilian.common.core.utils.uuid.IdUtils;
|
||||||
import com.zhilian.common.redis.service.RedisService;
|
import com.zhilian.common.redis.service.RedisService;
|
||||||
import com.zhilian.online.config.RabbitConfig;
|
import com.zhilian.online.config.RabbitConfig;
|
||||||
import com.zhilian.online.constans.OnlineConstants;
|
import com.zhilian.online.constans.OnlineConstants;
|
||||||
import com.zhilian.online.domain.Gather;
|
import com.zhilian.online.domain.ApifoxModel;
|
||||||
import com.zhilian.online.domain.VehicleAccount;
|
import com.zhilian.online.domain.EcsInstance;
|
||||||
|
import com.zhilian.online.domain.model.GatewayNodeInfo;
|
||||||
|
import com.zhilian.online.load.cache.GatewayNodeInfoCache;
|
||||||
|
import com.zhilian.online.load.cache.GatewayNodeWeightCache;
|
||||||
import com.zhilian.online.mapper.OnlineLoadCenterMapper;
|
import com.zhilian.online.mapper.OnlineLoadCenterMapper;
|
||||||
import com.zhilian.online.service.OnlineLoadCenterService;
|
import com.zhilian.online.service.OnlineLoadCenterService;
|
||||||
|
import com.zhilian.online.uitls.AliyunOpenAPIUtils;
|
||||||
|
import com.zhilian.online.uitls.MqttUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.ZSetOperations;
|
import org.springframework.data.redis.core.ZSetOperations;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -30,7 +34,7 @@ import java.util.stream.Collectors;
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class OnlineLoadCenterServiceImpl extends ServiceImpl<OnlineLoadCenterMapper, VehicleAccount> implements OnlineLoadCenterService {
|
public class OnlineLoadCenterServiceImpl implements OnlineLoadCenterService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆负载中心数据层
|
* 车辆负载中心数据层
|
||||||
|
@ -50,20 +54,36 @@ public class OnlineLoadCenterServiceImpl extends ServiceImpl<OnlineLoadCenterMap
|
||||||
@Autowired
|
@Autowired
|
||||||
private RabbitTemplate rabbitTemplate;
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AliyunOpenAPIUtils aliyunOpenAPIUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 车辆申请注解令牌接口, 仅限内网访问
|
* MQTT服务
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private MqttUtil mqttUtil;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GatewayNodeInfoCache gatewayNodeInfoCache;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GatewayNodeWeightCache gatewayNodeWeightCache;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 申请注解令牌接口, 仅限内网访问
|
||||||
* @author: LiYuan
|
* @author: LiYuan
|
||||||
* @param: vehicle
|
* @param: vehicle
|
||||||
* @return: Result<OnlineAccount>
|
* @return: Result<OnlineAccount>
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public Result<String> applyForReg(Gather gather) {
|
public Result<String> applyForReg(String clusterId) {
|
||||||
|
|
||||||
//生成一次性令牌
|
//生成一次性令牌
|
||||||
String token = IdUtils.fastSimpleUUID();
|
String token = IdUtils.fastSimpleUUID();
|
||||||
|
|
||||||
//将令牌信息缓存到Redis中
|
//将令牌信息缓存到Redis中
|
||||||
redisService.setCacheObject(OnlineConstants.ONLINE_TOKEN_PREFIX+gather.getClientId(),token, OnlineConstants.ONLINE_TOKEN_EXPIRE, TimeUnit.SECONDS);
|
redisService.setCacheObject(OnlineConstants.NODE_TOKEN_PREFIX + clusterId, token, OnlineConstants.ONLINE_TOKEN_EXPIRE, TimeUnit.SECONDS);
|
||||||
|
|
||||||
//将令牌信息返回客户端
|
//将令牌信息返回客户端
|
||||||
return Result.success(token);
|
return Result.success(token);
|
||||||
|
@ -77,52 +97,59 @@ public class OnlineLoadCenterServiceImpl extends ServiceImpl<OnlineLoadCenterMap
|
||||||
* @return: Result
|
* @return: Result
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public Result regGather(Gather gather) {
|
public Result regGather(ApifoxModel apifoxModel) {
|
||||||
//判断登录令牌是否过期,一致
|
//判断登录令牌是否过期,一致
|
||||||
if (!redisService.hasKey(OnlineConstants.ONLINE_TOKEN_PREFIX + gather.getClientId())) {
|
if (!redisService.hasKey(OnlineConstants.NODE_TOKEN_PREFIX + apifoxModel.getClusterId())) {
|
||||||
return Result.error("令牌已过期");
|
return Result.error("令牌已过期");
|
||||||
}
|
}
|
||||||
String token = redisService.getCacheObject(OnlineConstants.ONLINE_TOKEN_PREFIX + gather.getClientId());
|
String token = redisService.getCacheObject(OnlineConstants.NODE_TOKEN_PREFIX + apifoxModel.getClusterId());
|
||||||
if (!token.equals(gather.getToken())){
|
if (!token.equals(apifoxModel.getToken())) {
|
||||||
return Result.error("令牌错误");
|
return Result.error("令牌错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
//为该节点创建负载均衡缓存
|
GatewayNodeInfo gatewayNodeInfo = generateGatewayNodeInfo(apifoxModel);
|
||||||
redisService.setCacheZsetValue(OnlineConstants.GATHER_LOAD_CONTROL + gather.getClientId(), JSON.toJSONString(gather), 0.0);
|
|
||||||
|
//添加节点数据缓存
|
||||||
|
gatewayNodeInfoCache.put(gatewayNodeInfo);
|
||||||
|
|
||||||
|
//为该节点创建Zset负载均衡缓存,将该节点加入List在线节点缓存
|
||||||
|
gatewayNodeWeightCache.put(gatewayNodeInfo);
|
||||||
|
|
||||||
//向RabbitMQ||RocketMQ发送30s延迟消息,确保后续节点上线
|
//向RabbitMQ||RocketMQ发送30s延迟消息,确保后续节点上线
|
||||||
rabbitTemplate.convertAndSend(RabbitConfig.DELAY_EXCHANGE_NAME, RabbitConfig.DELAY_ROUTING_KEY, JSON.toJSONString(gather));
|
rabbitTemplate.convertAndSend(RabbitConfig.DELAY_EXCHANGE_NAME, RabbitConfig.DELAY_ROUTING_KEY, JSON.toJSONString(apifoxModel));
|
||||||
|
|
||||||
return Result.success("节点上线");
|
return Result.success(gatewayNodeInfo,"节点上线");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆申请上线收集节点
|
* 车辆申请上线收集节点
|
||||||
|
*
|
||||||
|
* @return gather
|
||||||
* @author: LiYuan
|
* @author: LiYuan
|
||||||
* @param: vin
|
* @param: vin
|
||||||
* @return gather
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Gather applyForConnectToGather(String vin) {
|
public void applyForConnectToGather(String vin) {
|
||||||
//判断车辆是否是我们的车
|
//判断车辆是否是我们的车
|
||||||
List<Object> cacheList = redisService.getCacheList("our_car");
|
List<Object> cacheList = redisService.getCacheList("our_car");
|
||||||
List<String> list = cacheList.stream().map(item -> {
|
List<String> list = cacheList.stream().map(item -> {
|
||||||
return String.valueOf(item);
|
return String.valueOf(item);
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
if (!list.contains(vin)){
|
if (!list.contains(vin)) {
|
||||||
throw new RuntimeException("车辆未登记");
|
throw new RuntimeException("车辆未登记");
|
||||||
}
|
}
|
||||||
//获取负载最少的车辆进行链接
|
//获取负载最少的车辆进行链接
|
||||||
ZSetOperations.TypedTuple cacheZsetMin = redisService.getCacheZsetMin(OnlineConstants.GATHER_LOAD_CONTROL);
|
ZSetOperations.TypedTuple cacheZsetMin = redisService.getCacheZsetMin(OnlineConstants.GATHER_LOAD_PREFIX);
|
||||||
Gather gather = JSON.parseObject((String) cacheZsetMin.getValue(), Gather.class);
|
|
||||||
//存放节点车辆信息
|
|
||||||
redisService.setCacheObject(OnlineConstants.ONLINE_VEHICLE+vin,gather.getClientId());
|
|
||||||
//发送延迟队列确定车辆上线
|
|
||||||
rabbitTemplate.convertAndSend(RabbitConfig.DELAY_EXCHANGE_FOR_CAR, RabbitConfig.DELAY_ROUTING_FOR_CAR,vin);
|
|
||||||
|
|
||||||
return gather;
|
//存放节点车辆信息
|
||||||
|
redisService.setCacheObject(OnlineConstants.GATHER_LOAD_PREFIX + vin, 1);
|
||||||
|
//发送延迟队列确定车辆上线
|
||||||
|
rabbitTemplate.convertAndSend(RabbitConfig.DELAY_EXCHANGE_FOR_CAR, RabbitConfig.DELAY_ROUTING_FOR_CAR, vin);
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description:车辆下线接口
|
* @description:车辆下线接口
|
||||||
* @author: LiYuan
|
* @author: LiYuan
|
||||||
|
@ -135,4 +162,19 @@ public class OnlineLoadCenterServiceImpl extends ServiceImpl<OnlineLoadCenterMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public GatewayNodeInfo generateGatewayNodeInfo(ApifoxModel apifoxModel) {
|
||||||
|
|
||||||
|
EcsInstance ecsInstance = aliyunOpenAPIUtils.queryEcsInstances(new ArrayList<String>() {{
|
||||||
|
add(apifoxModel.getPrivateIpAddress());
|
||||||
|
}}).get(0);
|
||||||
|
|
||||||
|
|
||||||
|
return GatewayNodeInfo.builder()
|
||||||
|
.nodeId(apifoxModel.getClusterId())
|
||||||
|
.privateIpAddress(ecsInstance.getPrivateIpAddress())
|
||||||
|
.publicIpAddress(ecsInstance.getPublicIpAddress())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,386 @@
|
||||||
|
package com.zhilian.online.uitls;
|
||||||
|
|
||||||
|
import com.aliyun.ecs20140526.models.*;
|
||||||
|
import com.aliyun.tea.TeaException;
|
||||||
|
import com.aliyun.teautil.models.RuntimeOptions;
|
||||||
|
import com.zhilian.common.core.domain.Result;
|
||||||
|
import com.zhilian.online.config.AliyunEcsConfig;
|
||||||
|
import com.zhilian.online.domain.EcsInstance;
|
||||||
|
import com.zhilian.online.domain.req.EcsCreateReq;
|
||||||
|
import com.zhilian.online.domain.req.EcsQueryReq;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import com.aliyun.ecs20140526.Client;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.uitls
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-12 14:57
|
||||||
|
* @Description: 阿里云OpenApi调用工具类
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class AliyunOpenAPIUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阿里云ECS客户端
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private Client aliyunClient;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AliyunEcsConfig aliyunEcsConfig;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询实例方法
|
||||||
|
*
|
||||||
|
* @param: ecsQueryReq
|
||||||
|
* @return: List<EcsInstance>
|
||||||
|
*/
|
||||||
|
public List<EcsInstance> queryEcsInstances(EcsQueryReq ecsQueryReq) {
|
||||||
|
log.info("开始查询实例{}",ecsQueryReq.getInstanceIds());
|
||||||
|
List<EcsInstance> ecsInstances = new ArrayList<>();
|
||||||
|
DescribeInstancesResponse describeInstancesResponse = null;
|
||||||
|
|
||||||
|
//将请求参数写入查询请求中
|
||||||
|
DescribeInstancesRequest describeInstancesRequest = setQueryReq(ecsQueryReq);
|
||||||
|
|
||||||
|
RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||||
|
try {
|
||||||
|
// 复制代码运行请自行打印 API 的返回值
|
||||||
|
describeInstancesResponse = aliyunClient.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||||
|
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||||
|
DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances = body.getInstances();
|
||||||
|
|
||||||
|
ecsInstances = takeQueryInstances(instances);
|
||||||
|
|
||||||
|
} catch (TeaException error) {
|
||||||
|
log.error("code:[{}],message:[{}],data:[{}]", error.getCode(), error.getMessage(), error.getData());
|
||||||
|
} catch (Exception aError) {
|
||||||
|
TeaException error = new TeaException(aError.getMessage(), aError);
|
||||||
|
log.error("code:[{}],message:[{}],data:[{}]", error.getCode(), error.getMessage(), error.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
return ecsInstances;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询实例方法
|
||||||
|
*
|
||||||
|
* @param: ecsQueryReq
|
||||||
|
* @return: List<EcsInstance>
|
||||||
|
*/
|
||||||
|
public List<EcsInstance> queryEcsInstancesByPrivateIp(List<String> privateIpAddress) {
|
||||||
|
log.info("开始查询实例{}",privateIpAddress);
|
||||||
|
List<EcsInstance> ecsInstances = new ArrayList<>();
|
||||||
|
DescribeInstancesResponse describeInstancesResponse = null;
|
||||||
|
|
||||||
|
//将请求参数写入查询请求中
|
||||||
|
String ipaddress = parseIpListToString(privateIpAddress);
|
||||||
|
DescribeInstancesRequest describeInstancesRequest = setQueryReq(ipaddress);
|
||||||
|
|
||||||
|
RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||||
|
try {
|
||||||
|
// 复制代码运行请自行打印 API 的返回值
|
||||||
|
describeInstancesResponse = aliyunClient.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||||
|
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||||
|
DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances = body.getInstances();
|
||||||
|
|
||||||
|
ecsInstances = takeQueryInstances(instances);
|
||||||
|
|
||||||
|
} catch (TeaException error) {
|
||||||
|
log.error("code:[{}],message:[{}],data:[{}]", error.getCode(), error.getMessage(), error.getData());
|
||||||
|
} catch (Exception aError) {
|
||||||
|
TeaException error = new TeaException(aError.getMessage(), aError);
|
||||||
|
log.error("code:[{}],message:[{}],data:[{}]", error.getCode(), error.getMessage(), error.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
return ecsInstances;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询实例方法
|
||||||
|
*
|
||||||
|
* @param: instanceIds
|
||||||
|
* @return: List<EcsInstance>
|
||||||
|
*/
|
||||||
|
public List<EcsInstance> queryEcsInstances(List<String> instanceIds) {
|
||||||
|
log.info("开始查询实例{}",instanceIds);
|
||||||
|
List<EcsInstance> ecsInstances = new ArrayList<>();
|
||||||
|
DescribeInstancesResponse describeInstancesResponse = null;
|
||||||
|
|
||||||
|
//将请求参数写入查询请求中
|
||||||
|
DescribeInstancesRequest describeInstancesRequest = setQueryReq(instanceIds);
|
||||||
|
|
||||||
|
RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||||
|
try {
|
||||||
|
// 复制代码运行请自行打印 API 的返回值
|
||||||
|
describeInstancesResponse = aliyunClient.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||||
|
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||||
|
DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances = body.getInstances();
|
||||||
|
|
||||||
|
ecsInstances = takeQueryInstances(instances);
|
||||||
|
|
||||||
|
} catch (TeaException error) {
|
||||||
|
log.error("code:[{}],message:[{}],data:[{}]", error.getCode(), error.getMessage(), error.getData());
|
||||||
|
} catch (Exception aError) {
|
||||||
|
TeaException error = new TeaException(aError.getMessage(), aError);
|
||||||
|
log.error("code:[{}],message:[{}],data:[{}]", error.getCode(), error.getMessage(), error.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
return ecsInstances;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 创建阿里云实例
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param:
|
||||||
|
* @return: void
|
||||||
|
**/
|
||||||
|
public List<String> createInstance(EcsCreateReq ecsCreateReq) {
|
||||||
|
//创建实例请求
|
||||||
|
RunInstancesRequest runInstancesRequest = makeRunInstancesRequest(ecsCreateReq);
|
||||||
|
|
||||||
|
RuntimeOptions runtime = new RuntimeOptions();
|
||||||
|
|
||||||
|
List<String> instanceIds = new ArrayList<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 复制代码运行请自行打印 API 的返回值
|
||||||
|
RunInstancesResponse res = aliyunClient.runInstancesWithOptions(runInstancesRequest, runtime);
|
||||||
|
|
||||||
|
//打印执行结果
|
||||||
|
RunInstancesResponseBody body = res.getBody();
|
||||||
|
instanceIds = body.getInstanceIdSets().getInstanceIdSet();
|
||||||
|
log.info("执行结果:[{}],请求ID:[{}],创建实例ID:[{}]",
|
||||||
|
200 == res.getStatusCode() ? "创建成功" : "创建失败",
|
||||||
|
body.getRequestId(), instanceIds);
|
||||||
|
|
||||||
|
} catch (TeaException error) {
|
||||||
|
log.error("code:[{}],message:[{}],data:[{}]",
|
||||||
|
error.getCode(), error.getMessage(), error.getData());
|
||||||
|
} catch (Exception aError) {
|
||||||
|
TeaException error = new TeaException(aError.getMessage(), aError);
|
||||||
|
log.error("code:[{}],message:[{}],data:[{}]",
|
||||||
|
error.getCode(), error.getMessage(), error.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// List<EcsInstance> ecsInstances = queryEcsInstances(instanceIds);
|
||||||
|
// putNodeOfCreatedCache(ecsInstances);
|
||||||
|
|
||||||
|
return instanceIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result deleteInstance(String instanceId) {
|
||||||
|
Result result = new Result<>();
|
||||||
|
DeleteInstancesRequest deleteInstancesRequest = new DeleteInstancesRequest()
|
||||||
|
.setRegionId(aliyunEcsConfig.getRegionId())
|
||||||
|
.setDryRun(false)
|
||||||
|
.setForce(true)
|
||||||
|
.setTerminateSubscription(false)
|
||||||
|
.setInstanceId(Arrays.asList(instanceId));
|
||||||
|
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||||
|
try {
|
||||||
|
// 复制代码运行请自行打印 API 的返回值
|
||||||
|
DeleteInstancesResponse deleteInstancesResponse = aliyunClient.deleteInstancesWithOptions(deleteInstancesRequest, runtime);
|
||||||
|
Integer statusCode = deleteInstancesResponse.getStatusCode();
|
||||||
|
DeleteInstancesResponseBody body = deleteInstancesResponse.getBody();
|
||||||
|
log.info(200 == statusCode ? "删除成功" : "删除失败");
|
||||||
|
result.setCode(statusCode);
|
||||||
|
result.setData(body);
|
||||||
|
result.setMsg(200 == statusCode ? "删除成功" : "删除失败");
|
||||||
|
} catch (TeaException error) {
|
||||||
|
log.error("code:[{}],message:[{}],data:[{}]", error.getCode(), error.getMessage(), error.getData());
|
||||||
|
} catch (Exception _error) {
|
||||||
|
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||||
|
log.error("code:[{}],message:[{}],data:[{}]", error.getCode(), error.getMessage(), error.getData());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 将请求参数写入查询请求中
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: EcsQueryReq
|
||||||
|
* @return: DescribeInstancesRequest
|
||||||
|
**/
|
||||||
|
public DescribeInstancesRequest setQueryReq(EcsQueryReq ecsQueryReq) {
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
stringBuffer.append("[");
|
||||||
|
ecsQueryReq.getInstanceIds().forEach(item ->{
|
||||||
|
stringBuffer.append("\"" + item + "\",");
|
||||||
|
});
|
||||||
|
stringBuffer.deleteCharAt(stringBuffer.length()-1);
|
||||||
|
stringBuffer.append("]");
|
||||||
|
return new DescribeInstancesRequest()
|
||||||
|
.setRegionId(aliyunEcsConfig.getRegionId())
|
||||||
|
.setInstanceIds(stringBuffer.toString());
|
||||||
|
// .setInstanceName(ecsQueryReq.getInstanceName())
|
||||||
|
// .setPageNumber(ecsQueryReq.getPageNumber())
|
||||||
|
// .setPageSize(ecsQueryReq.getPageSize())
|
||||||
|
// .setVpcId(ecsQueryReq.getVpcId())
|
||||||
|
// .setVSwitchId(ecsQueryReq.getVSwitchId())
|
||||||
|
// .setZoneId(ecsQueryReq.getZoneId())
|
||||||
|
// .setInstanceNetworkType(ecsQueryReq.getInstanceNetworkType())
|
||||||
|
// .setSecurityGroupId(ecsQueryReq.getSecurityGroupId())
|
||||||
|
// .setPrivateIpAddresses(ecsQueryReq.getPrivateIpAddresses())
|
||||||
|
// .setPublicIpAddresses(ecsQueryReq.getPublicIpAddresses())
|
||||||
|
// .setInstanceName(ecsQueryReq.getInstanceName())
|
||||||
|
// .setImageId(ecsQueryReq.getImageId())
|
||||||
|
// .setInstanceType(ecsQueryReq.getInstanceType())
|
||||||
|
// .setStatus(ecsQueryReq.getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 将请求参数写入查询请求中
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: EcsQueryReq
|
||||||
|
* @return: DescribeInstancesRequest
|
||||||
|
**/
|
||||||
|
public DescribeInstancesRequest setQueryReq(String ipAddresses) {
|
||||||
|
return new DescribeInstancesRequest()
|
||||||
|
.setRegionId(aliyunEcsConfig.getRegionId())
|
||||||
|
.setPrivateIpAddresses(ipAddresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String parseIpListToString(List<String> ipAddress){
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
stringBuffer.append("[");
|
||||||
|
ipAddress.forEach(item ->{
|
||||||
|
stringBuffer.append("\"" + item + "\",");
|
||||||
|
});
|
||||||
|
stringBuffer.deleteCharAt(stringBuffer.length()-1);
|
||||||
|
stringBuffer.append("]");
|
||||||
|
return stringBuffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 将请求参数写入查询请求中
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: EcsQueryReq
|
||||||
|
* @return: DescribeInstancesRequest
|
||||||
|
**/
|
||||||
|
public DescribeInstancesRequest setQueryReq(List<String> instances) {
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
stringBuffer.append("[");
|
||||||
|
instances.forEach(item ->{
|
||||||
|
stringBuffer.append("\"" + item + "\",");
|
||||||
|
});
|
||||||
|
stringBuffer.deleteCharAt(stringBuffer.length()-1);
|
||||||
|
stringBuffer.append("]");
|
||||||
|
return new DescribeInstancesRequest()
|
||||||
|
.setRegionId(aliyunEcsConfig.getRegionId())
|
||||||
|
.setInstanceIds(stringBuffer.toString());
|
||||||
|
// .setInstanceName(ecsQueryReq.getInstanceName())
|
||||||
|
// .setPageNumber(ecsQueryReq.getPageNumber())
|
||||||
|
// .setPageSize(ecsQueryReq.getPageSize())
|
||||||
|
// .setVpcId(ecsQueryReq.getVpcId())
|
||||||
|
// .setVSwitchId(ecsQueryReq.getVSwitchId())
|
||||||
|
// .setZoneId(ecsQueryReq.getZoneId())
|
||||||
|
// .setInstanceNetworkType(ecsQueryReq.getInstanceNetworkType())
|
||||||
|
// .setSecurityGroupId(ecsQueryReq.getSecurityGroupId())
|
||||||
|
// .setPrivateIpAddresses(ecsQueryReq.getPrivateIpAddresses())
|
||||||
|
// .setPublicIpAddresses(ecsQueryReq.getPublicIpAddresses())
|
||||||
|
// .setInstanceName(ecsQueryReq.getInstanceName())
|
||||||
|
// .setImageId(ecsQueryReq.getImageId())
|
||||||
|
// .setInstanceType(ecsQueryReq.getInstanceType())
|
||||||
|
// .setStatus(ecsQueryReq.getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 取出查询结果
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances
|
||||||
|
* @return: List<EcsInstance>
|
||||||
|
**/
|
||||||
|
public List<EcsInstance> takeQueryInstances(DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances) {
|
||||||
|
ArrayList<EcsInstance> ecsInstances = new ArrayList<>();
|
||||||
|
//遍历请求结果,取出查询到的Ecs实例
|
||||||
|
instances.getInstance().stream().forEach(item -> {
|
||||||
|
EcsInstance ecsInstance = EcsInstance.builder()
|
||||||
|
.instanceId(item.getInstanceId())
|
||||||
|
.instanceName(item.getInstanceName())
|
||||||
|
.regionId(aliyunEcsConfig.getRegionId())
|
||||||
|
.status(item.getStatus())
|
||||||
|
.instanceType(item.getInstanceType())
|
||||||
|
.cpu(item.getCpu())
|
||||||
|
.memory(item.getMemory())
|
||||||
|
.localStorageCapacity(item.getLocalStorageCapacity())
|
||||||
|
.osName(item.getOSName())
|
||||||
|
.instanceNetworkType(item.getInstanceNetworkType())
|
||||||
|
.internetMaxBandwidthOut(item.getInternetMaxBandwidthOut())
|
||||||
|
.internetMaxBandwidthIn(item.getInternetMaxBandwidthIn())
|
||||||
|
.publicIpAddress(item.getPublicIpAddress().getIpAddress())
|
||||||
|
.privateIpAddress(item.getVpcAttributes().getPrivateIpAddress().getIpAddress())
|
||||||
|
.vpcId(item.getVpcAttributes().getVpcId())
|
||||||
|
.securityGroupIds(item.getSecurityGroupIds().getSecurityGroupId())
|
||||||
|
.creationTime(item.getCreationTime())
|
||||||
|
.expiredTime(item.getExpiredTime())
|
||||||
|
.recyclable(item.getRecyclable())
|
||||||
|
.build();
|
||||||
|
ecsInstances.add(ecsInstance);
|
||||||
|
});
|
||||||
|
|
||||||
|
return ecsInstances;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建阿里云创建实例请求
|
||||||
|
*
|
||||||
|
* @param: ecsCreateReq
|
||||||
|
* @return: RunInstancesRequest
|
||||||
|
*/
|
||||||
|
public RunInstancesRequest makeRunInstancesRequest(EcsCreateReq ecsCreateReq) {
|
||||||
|
|
||||||
|
//构建磁盘配置
|
||||||
|
RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||||
|
.setSize(ecsCreateReq.getSystemDiskSize())
|
||||||
|
.setCategory(ecsCreateReq.getSystemDickCategory());
|
||||||
|
//构建创建实例请求
|
||||||
|
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
|
||||||
|
.setRegionId(aliyunEcsConfig.getRegionId())
|
||||||
|
.setImageId(ecsCreateReq.getImageId())
|
||||||
|
.setInstanceType(ecsCreateReq.getInstanceType())
|
||||||
|
.setSecurityGroupId(ecsCreateReq.getSecurityGroupId())
|
||||||
|
.setVSwitchId(ecsCreateReq.getVSwitchId())
|
||||||
|
.setInstanceName(ecsCreateReq.getInstanceName())
|
||||||
|
.setInternetMaxBandwidthIn(ecsCreateReq.getInternetMaxBandwidthIn())
|
||||||
|
.setInternetMaxBandwidthOut(ecsCreateReq.getInternetMaxBandwidthOut())
|
||||||
|
.setUniqueSuffix(ecsCreateReq.getUniqueSuffix())
|
||||||
|
.setPassword(ecsCreateReq.getPassword())
|
||||||
|
.setZoneId(ecsCreateReq.getZoneId())
|
||||||
|
.setInternetChargeType(ecsCreateReq.getInternetChargeType())
|
||||||
|
.setSystemDisk(systemDisk)
|
||||||
|
.setAmount(ecsCreateReq.getAmount())
|
||||||
|
.setMinAmount(ecsCreateReq.getMinAmount())
|
||||||
|
.setPeriodUnit(ecsCreateReq.getPeriodUnit())
|
||||||
|
.setPeriod(ecsCreateReq.getPeriod())
|
||||||
|
.setInstanceChargeType(ecsCreateReq.getInstanceChargeType())
|
||||||
|
.setPrivateIpAddress(ecsCreateReq.getPrivateIpAddress());
|
||||||
|
return runInstancesRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package com.zhilian.online.uitls;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.zhilian.online.constans.OnlineConstants;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.test.web.servlet.RequestBuilder;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: smart-cloud-server
|
||||||
|
* @BelongsPackage: com.zhilian.online.uitls
|
||||||
|
* @Author: LiYuan
|
||||||
|
* @CreateTime: 2024-04-17 21:41
|
||||||
|
* @Description: mqtt工具类
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class MqttUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 通过ip地址调用mqtt服务获取fluxmq的负载量
|
||||||
|
* @author: LiYuan
|
||||||
|
* @param: ipAddress
|
||||||
|
* @return: Integer
|
||||||
|
**/
|
||||||
|
public Integer getLoadInfoByIp(String ipAddress) {
|
||||||
|
|
||||||
|
int num = 0;
|
||||||
|
|
||||||
|
String URL = OnlineConstants.HTTP_PREFIX + ipAddress + OnlineConstants.FLUXMQ_INFO_URL;
|
||||||
|
|
||||||
|
OkHttpClient client = new OkHttpClient();
|
||||||
|
Request build = new Request.Builder()
|
||||||
|
.url(URL)
|
||||||
|
.get()
|
||||||
|
.addHeader("User-Agent","Apifox/1.0.0(https://apifox.com)")
|
||||||
|
.addHeader("AccessToken","")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Response response = client.newCall(build).execute();
|
||||||
|
JSONArray jsonArray = JSONArray.parseArray(response.body().string());
|
||||||
|
JSONObject jsonObject = jsonArray.getJSONObject(0);
|
||||||
|
|
||||||
|
//获取mqttInfo对象的值
|
||||||
|
JSONObject mqttInfo = jsonObject.getJSONObject("mqttInfo");
|
||||||
|
|
||||||
|
//获取fluxmq链接数
|
||||||
|
num = mqttInfo.getIntValue("connectSize");
|
||||||
|
|
||||||
|
log.info("{}的fluxMq链接数为:{}",ipAddress,num);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return num;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,7 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper
|
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
<mapper namespace="com.zhilian.online.mapper.OnlineGatherMapper">
|
|
||||||
|
|
||||||
</mapper>
|
|
Loading…
Reference in New Issue