14优化注释
parent
f70594f630
commit
09ff525c26
|
@ -5,15 +5,23 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* 负载中心模块启动类
|
||||
*
|
||||
* @ProjectName: Default (Template) Project
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/1
|
||||
* @Description: 负载中心模块启动类
|
||||
*/
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class LoadCenterApplication {
|
||||
/**
|
||||
* 启动类main方法
|
||||
*
|
||||
* @Date: 2024/4/19 20:23
|
||||
* @Param: [args]
|
||||
* @Return: void
|
||||
**/
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(LoadCenterApplication.class, args);
|
||||
System.out.println("负载中心模块启动成功");
|
||||
|
|
|
@ -10,10 +10,11 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 阿里云客户端配置类
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/16
|
||||
* @Description: 阿里云配置
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "config.aliyun")
|
||||
|
@ -21,27 +22,26 @@ import org.springframework.context.annotation.Configuration;
|
|||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AliConfig {
|
||||
/*
|
||||
/**
|
||||
* access-key-id
|
||||
* */
|
||||
*/
|
||||
private String accessKeyId;
|
||||
|
||||
/*
|
||||
/**
|
||||
* access-key-secret
|
||||
* */
|
||||
*/
|
||||
private String accessKeySecret;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 地域id
|
||||
* */
|
||||
*/
|
||||
private String regionId;
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/16 21:29
|
||||
* @Description: 初始化客户端实例
|
||||
* @Param: [aliConfig]
|
||||
* @Return: com.aliyun.ecs20140526.Client
|
||||
/**
|
||||
* 初始化客户端实例
|
||||
* Date: 2024/4/19 20:17
|
||||
* Param: [aliConfig]
|
||||
* Return: com.aliyun.ecs20140526.Client
|
||||
**/
|
||||
@Bean
|
||||
public Client createEcsClient(AliConfig aliConfig) throws Exception {
|
||||
|
|
|
@ -8,10 +8,11 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 实例规格
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/16
|
||||
* @Description: 实例规格
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "config.instance")
|
||||
|
@ -21,54 +22,54 @@ import org.springframework.stereotype.Component;
|
|||
@Component
|
||||
public class InstanceSpecification {
|
||||
|
||||
/*
|
||||
/**
|
||||
* 镜像 ID,启动实例时选择的镜像资源。
|
||||
* */
|
||||
*/
|
||||
private String imageId;
|
||||
|
||||
/*
|
||||
*实例规格
|
||||
* */
|
||||
/**
|
||||
* 实例规格
|
||||
*/
|
||||
private String instanceType;
|
||||
|
||||
/*
|
||||
*新创建实例所属于的安全组 ID。
|
||||
* */
|
||||
/**
|
||||
* 新创建实例所属于的安全组 ID。
|
||||
*/
|
||||
private String securityGroupId;
|
||||
|
||||
/*
|
||||
*虚拟交换机 ID。
|
||||
* */
|
||||
/**
|
||||
* 虚拟交换机 ID。
|
||||
*/
|
||||
private String vSwitchId;
|
||||
|
||||
/*
|
||||
*公网出带宽最大值,单位为 Mbit/s。取值范围:0~100。 默认值:0。
|
||||
* */
|
||||
/**
|
||||
* 公网出带宽最大值,单位为 Mbit/s。取值范围:0~100。 默认值:0。
|
||||
*/
|
||||
private String internetMaxBandwidthOut;
|
||||
|
||||
/*
|
||||
*网络计费类型。取值范围:
|
||||
/**
|
||||
* 网络计费类型。取值范围:
|
||||
* PayByBandwidth: 按固定带宽计费。
|
||||
* PayByTraffic: 按使用流量计费。
|
||||
* 默认值:PayByTraffic。
|
||||
* */
|
||||
*/
|
||||
private String internetChargeType;
|
||||
|
||||
/*
|
||||
*系统盘大小
|
||||
* */
|
||||
/**
|
||||
* 系统盘大小
|
||||
*/
|
||||
private String size;
|
||||
|
||||
/*
|
||||
*系统盘的云盘种类
|
||||
* */
|
||||
/**
|
||||
* 系统盘的云盘种类
|
||||
*/
|
||||
private String category;
|
||||
|
||||
/*
|
||||
*ECS实例的计费方式
|
||||
/**
|
||||
* ECS实例的计费方式
|
||||
* PrePaid:包年包月
|
||||
* PostPaid:按量付费
|
||||
* */
|
||||
*/
|
||||
private String instanceChargeType;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,112 +18,35 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 阿里云ecs服务器openAPI调用
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/16
|
||||
* @Description: 阿里云ecs服务器openAPI调用
|
||||
*/
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AliYunEcsService {
|
||||
/*
|
||||
*实例规格,用于创建实例
|
||||
* */
|
||||
@Autowired
|
||||
private InstanceSpecification instanceSpecification;
|
||||
|
||||
|
||||
//应用阿里云客户端配置
|
||||
private final AliConfig aliConfig;
|
||||
private final Client client;
|
||||
/**
|
||||
* 实例规格,用于创建实例
|
||||
*/
|
||||
@Autowired
|
||||
private InstanceSpecification instanceSpecification;
|
||||
|
||||
public AliYunEcsService(AliConfig aliConfig, Client client) {
|
||||
this.aliConfig = aliConfig;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/16 20:01
|
||||
* @Description: 获取指定区域的实例ID列表
|
||||
* @Param: []
|
||||
* @Return: java.util.List<java.lang.String>
|
||||
**/
|
||||
public List<String> getIDList() throws Exception {
|
||||
|
||||
java.util.List<String> regionIds = com.aliyun.darabonbastring.Client.split(aliConfig.getRegionId(), ",", 50);
|
||||
|
||||
String regionId = regionIds.get(0);
|
||||
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setPageSize(100)
|
||||
.setRegionId(regionId);
|
||||
DescribeInstancesResponse resp = this.client.describeInstances(describeInstancesRequest);
|
||||
java.util.List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> instances = resp.body.instances.instance;
|
||||
|
||||
log.info(regionId + " 下 ECS 实例列表:");
|
||||
|
||||
//存储结果的List
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : instances) {
|
||||
// log.info("主机名:" + instance.hostName + " 实例ID:" + instance.instanceId + " CPU:" + instance.cpu + " 内存:" + instance.memory + " MB 规格:" + instance.instanceType + " 系统:" + instance.OSType + "(" + instance.OSName + ") 状态:" + instance.status);
|
||||
|
||||
result.add(instance.instanceId);
|
||||
}
|
||||
|
||||
//将查询到的ecs服务器id列表 打印控制台
|
||||
log.info(JSON.toJSONString(result));
|
||||
|
||||
//返回结果
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/16 20:19
|
||||
* @Description: 通过实例ID释放实例 多个实例ID,用英文逗号分隔
|
||||
* @Param: instanceIds 要删除实例ID
|
||||
* @Return:
|
||||
**/
|
||||
public void releaseInstances(String instanceIds) throws Exception {
|
||||
|
||||
// 实例名称,支持使用通配符*进行模糊搜索
|
||||
String instanceName = "*";
|
||||
// 强制删除有删除保护的机器
|
||||
String deleteProtected = "true";
|
||||
// 强制删除运行中的机器
|
||||
String force = "true";
|
||||
|
||||
//判断是否为强制删除
|
||||
if (Common.equalString(deleteProtected, "true")) {
|
||||
DescribeInstancesResponse describeInstancesResp = DescribeInstances(client, aliConfig.getRegionId(), instanceIds, instanceName);
|
||||
instanceIds = "";
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : describeInstancesResp.body.instances.instance) {
|
||||
instanceIds = instance.instanceId + "," + instanceIds;
|
||||
if (instance.deletionProtection) {
|
||||
ModifyInstanceAttribute(client, instance.instanceId);
|
||||
}
|
||||
|
||||
}
|
||||
instanceIds = com.aliyun.darabonbastring.Client.subString(instanceIds, 0, -1);
|
||||
}
|
||||
|
||||
//如果入参为空
|
||||
if (Common.empty(instanceIds)) {
|
||||
com.aliyun.teaconsole.Client.log("--------------------无有效实例可删除--------------------");
|
||||
return;
|
||||
}
|
||||
|
||||
DeleteInstances(client, aliConfig.getRegionId(), instanceIds, force);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* 查询要删除的实例
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/16 20:31
|
||||
* @Description: 查询要删除的实例
|
||||
* @Param: [client, regionId, instanceIds, instanceName]
|
||||
* @Return: DescribeInstancesResponse
|
||||
**/
|
||||
|
@ -140,10 +63,11 @@ public class AliYunEcsService {
|
|||
return resp;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* 修改实例的属性 取消 ‘释放保护’
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/16 20:33
|
||||
* @Description: 修改实例的属性 取消 ‘释放保护’
|
||||
* @Param: [client, instatnceId]
|
||||
* @Return: void
|
||||
**/
|
||||
|
@ -155,10 +79,11 @@ public class AliYunEcsService {
|
|||
com.aliyun.teaconsole.Client.log("--------------------" + instatnceId + "释放保护取消成功--------------------");
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* 执行释放实例
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/16 20:35
|
||||
* @Description: 执行释放实例
|
||||
* @Param: [client, regionId, instanceIds, force]
|
||||
* @Return: void
|
||||
**/
|
||||
|
@ -172,48 +97,6 @@ public class AliYunEcsService {
|
|||
com.aliyun.teaconsole.Client.log(Common.toJSONString(Common.toMap(resp)));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/16 21:44
|
||||
* @Description: 创建并运行实例
|
||||
* @Param: []
|
||||
* @Return: java.lang.String
|
||||
**/
|
||||
public String createAndRunInstance() throws Exception {
|
||||
|
||||
//获取实例规格
|
||||
// 地域Id
|
||||
String regionId = aliConfig.getRegionId();
|
||||
// 镜像 ID,启动实例时选择的镜像资源。
|
||||
String imageId = instanceSpecification.getImageId();
|
||||
// 实例规格
|
||||
String instanceType = instanceSpecification.getInstanceType();
|
||||
// 新创建实例所属于的安全组 ID。
|
||||
String securityGroupId = instanceSpecification.getSecurityGroupId();
|
||||
// 虚拟交换机 ID。
|
||||
String vSwitchId = instanceSpecification.getVSwitchId();
|
||||
// 公网出带宽最大值,单位为 Mbit/s。取值范围:0~100。 默认值:0。
|
||||
Integer internetMaxBandwidthOut = com.aliyun.darabonbanumber.Client.parseInt(instanceSpecification.getInternetMaxBandwidthOut());
|
||||
// 网络计费类型。取值范围:
|
||||
// PayByBandwidth: 按固定带宽计费。
|
||||
// PayByTraffic: 按使用流量计费。
|
||||
// 默认值:PayByTraffic。
|
||||
String internetChargeType = instanceSpecification.getInternetChargeType();
|
||||
// 系统盘大小
|
||||
String size = instanceSpecification.getSize();
|
||||
// 系统盘的云盘种类
|
||||
String category = instanceSpecification.getCategory();
|
||||
// ECS实例的计费方式
|
||||
// PrePaid:包年包月
|
||||
// PostPaid:按量付费
|
||||
String instanceChargeType = instanceSpecification.getInstanceChargeType();
|
||||
|
||||
|
||||
// 批量创建实例
|
||||
return RunInstances(client, regionId, imageId, instanceType, securityGroupId, vSwitchId, internetMaxBandwidthOut, internetChargeType, size, category, instanceChargeType);
|
||||
}
|
||||
|
||||
/**
|
||||
* RunInstances 通过备选实例规格创建ECS实例最佳实践
|
||||
* 该场景中,在调用RunInstances创建ECS实例时判断是否发生库存不足等错误,如果发生错误,将调用DescribeRecommendInstanceType查询备选实例,然后通过备选实例规格重新创建ECS实例。
|
||||
|
@ -260,11 +143,129 @@ public class AliYunEcsService {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定区域的实例ID列表
|
||||
*
|
||||
* @Date: 2024/4/19 20:02
|
||||
* @Param: []
|
||||
* @Return: java.util.List<java.lang.String>
|
||||
**/
|
||||
public List<String> getIDList() throws Exception {
|
||||
|
||||
/*
|
||||
java.util.List<String> regionIds = com.aliyun.darabonbastring.Client.split(aliConfig.getRegionId(), ",", 50);
|
||||
|
||||
String regionId = regionIds.get(0);
|
||||
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setPageSize(100)
|
||||
.setRegionId(regionId);
|
||||
DescribeInstancesResponse resp = this.client.describeInstances(describeInstancesRequest);
|
||||
java.util.List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> instances = resp.body.instances.instance;
|
||||
|
||||
log.info(regionId + " 下 ECS 实例列表:");
|
||||
|
||||
//存储结果的List
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : instances) {
|
||||
// log.info("主机名:" + instance.hostName + " 实例ID:" + instance.instanceId + " CPU:" + instance.cpu + " 内存:" + instance.memory + " MB 规格:" + instance.instanceType + " 系统:" + instance.OSType + "(" + instance.OSName + ") 状态:" + instance.status);
|
||||
|
||||
result.add(instance.instanceId);
|
||||
}
|
||||
|
||||
//将查询到的ecs服务器id列表 打印控制台
|
||||
log.info(JSON.toJSONString(result));
|
||||
|
||||
//返回结果
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过实例ID释放实例 多个实例ID,用英文逗号分隔
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/16 20:19
|
||||
* @Description:
|
||||
* @Param: instanceIds 要删除实例ID
|
||||
**/
|
||||
public void releaseInstances(String instanceIds) throws Exception {
|
||||
|
||||
// 实例名称,支持使用通配符*进行模糊搜索
|
||||
String instanceName = "*";
|
||||
// 强制删除有删除保护的机器
|
||||
String deleteProtected = "true";
|
||||
// 强制删除运行中的机器
|
||||
String force = "true";
|
||||
|
||||
//判断是否为强制删除
|
||||
if (Common.equalString(deleteProtected, "true")) {
|
||||
DescribeInstancesResponse describeInstancesResp = DescribeInstances(client, aliConfig.getRegionId(), instanceIds, instanceName);
|
||||
instanceIds = "";
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : describeInstancesResp.body.instances.instance) {
|
||||
instanceIds = instance.instanceId + "," + instanceIds;
|
||||
if (instance.deletionProtection) {
|
||||
ModifyInstanceAttribute(client, instance.instanceId);
|
||||
}
|
||||
|
||||
}
|
||||
instanceIds = com.aliyun.darabonbastring.Client.subString(instanceIds, 0, -1);
|
||||
}
|
||||
|
||||
//如果入参为空
|
||||
if (Common.empty(instanceIds)) {
|
||||
com.aliyun.teaconsole.Client.log("--------------------无有效实例可删除--------------------");
|
||||
return;
|
||||
}
|
||||
|
||||
DeleteInstances(client, aliConfig.getRegionId(), instanceIds, force);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建并运行实例
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/16 21:44
|
||||
* @Param: []
|
||||
* @Return: java.lang.String
|
||||
**/
|
||||
public String createAndRunInstance() throws Exception {
|
||||
|
||||
//获取实例规格
|
||||
// 地域Id
|
||||
String regionId = aliConfig.getRegionId();
|
||||
// 镜像 ID,启动实例时选择的镜像资源。
|
||||
String imageId = instanceSpecification.getImageId();
|
||||
// 实例规格
|
||||
String instanceType = instanceSpecification.getInstanceType();
|
||||
// 新创建实例所属于的安全组 ID。
|
||||
String securityGroupId = instanceSpecification.getSecurityGroupId();
|
||||
// 虚拟交换机 ID。
|
||||
String vSwitchId = instanceSpecification.getVSwitchId();
|
||||
// 公网出带宽最大值,单位为 Mbit/s。取值范围:0~100。 默认值:0。
|
||||
Integer internetMaxBandwidthOut = com.aliyun.darabonbanumber.Client.parseInt(instanceSpecification.getInternetMaxBandwidthOut());
|
||||
// 网络计费类型。取值范围:
|
||||
// PayByBandwidth: 按固定带宽计费。
|
||||
// PayByTraffic: 按使用流量计费。
|
||||
// 默认值:PayByTraffic。
|
||||
String internetChargeType = instanceSpecification.getInternetChargeType();
|
||||
// 系统盘大小
|
||||
String size = instanceSpecification.getSize();
|
||||
// 系统盘的云盘种类
|
||||
String category = instanceSpecification.getCategory();
|
||||
// ECS实例的计费方式
|
||||
// PrePaid:包年包月
|
||||
// PostPaid:按量付费
|
||||
String instanceChargeType = instanceSpecification.getInstanceChargeType();
|
||||
|
||||
|
||||
// 批量创建实例
|
||||
return RunInstances(client, regionId, imageId, instanceType, securityGroupId, vSwitchId, internetMaxBandwidthOut, internetChargeType, size, category, instanceChargeType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询一台或多台实例的信息 多台实例用英文逗号拼接
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/16 22:02
|
||||
* @Description: 查询一台或多台实例的信息 多台实例用英文逗号拼接
|
||||
* @Param: [instanceIds] i-uf6chlqotgoc9h173alu
|
||||
**/
|
||||
public List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> queryInstancesInformation(String instanceIds) {
|
||||
|
|
|
@ -5,10 +5,11 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* mqtt服务器信息
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/13
|
||||
* @Description: mqtt服务器信息
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
|
|
@ -12,20 +12,22 @@ import org.springframework.stereotype.Component;
|
|||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* mqtt的工具类
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/15
|
||||
* @Description: mqtt的工具类
|
||||
*/
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MqttUtil {
|
||||
|
||||
/*
|
||||
/**
|
||||
* 通过IP获取指定IP的fluxmq的负载量
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/15 17:26
|
||||
* @Description: 通过IP获取指定IP的fluxmq的负载量
|
||||
* @Param: [IP]
|
||||
* @Return: int
|
||||
**/
|
||||
|
|
|
@ -8,20 +8,22 @@ import org.springframework.stereotype.Component;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 自定义工具类
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/13
|
||||
* @Description: 自定义工具类
|
||||
*/
|
||||
@Component
|
||||
public class UserUtil {
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 将字符串前后的[]进行删除
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/13 9:25
|
||||
* @Description: 将字符串前后的[]进行删除
|
||||
* @Param: [input]
|
||||
* @Return: java.lang.String
|
||||
**/
|
||||
|
@ -32,10 +34,11 @@ public class UserUtil {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* 获取实例注册token令牌
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/13 11:42
|
||||
* @Description: 获取实例注册token令牌
|
||||
* @Param:
|
||||
* @Return:
|
||||
**/
|
||||
|
|
|
@ -8,10 +8,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 负载中心控制层
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/15
|
||||
* @Description: 负载中心控制层
|
||||
*/
|
||||
|
||||
@RestController
|
||||
|
@ -21,10 +22,10 @@ public class LoadCenterController {
|
|||
private LoadCenterService loadCenterService;
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* 获取指定的服务器IP
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/15 14:57
|
||||
* @Description: 获取指定的服务器IP
|
||||
* @Param: []
|
||||
* @Return: com.lyh.common.domain.resp.Result<java.lang.String>
|
||||
**/
|
||||
|
|
|
@ -8,10 +8,11 @@ import org.springframework.stereotype.Component;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 缓存实例IP和负载量
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/18
|
||||
* @Description: 缓存实例IP和负载量
|
||||
*/
|
||||
@Component
|
||||
public class GatewayIpAndLoadCountCache extends GatewayCacheAbs<String> {
|
||||
|
@ -22,8 +23,9 @@ public class GatewayIpAndLoadCountCache extends GatewayCacheAbs<String> {
|
|||
return "gateway:load:";
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 增加缓存数据
|
||||
/**
|
||||
* 增加缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: [gatewayNodeIps]
|
||||
* @Return: void
|
||||
|
@ -33,8 +35,9 @@ public class GatewayIpAndLoadCountCache extends GatewayCacheAbs<String> {
|
|||
redisService.setCacheList(encode(gatewayIpAndLoadCountKey), ipAndLoadCounts);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 获取缓存数据
|
||||
/**
|
||||
* 获取缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: []
|
||||
* @Return: java.util.List<java.lang.String>
|
||||
|
@ -44,8 +47,9 @@ public class GatewayIpAndLoadCountCache extends GatewayCacheAbs<String> {
|
|||
return JSON.parseArray(JSON.toJSONString(cacheList), IpAndLoadCount.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 删除缓存数据
|
||||
/**
|
||||
* 删除缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: []
|
||||
* @Return: void
|
||||
|
|
|
@ -8,10 +8,11 @@ import org.springframework.stereotype.Component;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 缓存IP和权重
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/18
|
||||
* @Description: 缓存IP和权重
|
||||
*/
|
||||
@Component
|
||||
public class GatewayIpAndLoadWeightCache extends GatewayCacheAbs<String> {
|
||||
|
@ -22,8 +23,9 @@ public class GatewayIpAndLoadWeightCache extends GatewayCacheAbs<String> {
|
|||
return "gateway:load:";
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 增加缓存数据
|
||||
/**
|
||||
* 增加缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: [gatewayNodeIps]
|
||||
* @Return: void
|
||||
|
@ -33,8 +35,9 @@ public class GatewayIpAndLoadWeightCache extends GatewayCacheAbs<String> {
|
|||
redisService.setCacheList(encode(gatewayIpAndWeightKey), ipAndWeights);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 获取缓存数据
|
||||
/**
|
||||
* 获取缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: []
|
||||
* @Return: java.util.List<java.lang.String>
|
||||
|
@ -44,8 +47,9 @@ public class GatewayIpAndLoadWeightCache extends GatewayCacheAbs<String> {
|
|||
return JSON.parseArray(JSON.toJSONString(cacheList), IpAndWeight.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 删除缓存数据
|
||||
/**
|
||||
* 删除缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: []
|
||||
* @Return: void
|
||||
|
|
|
@ -6,10 +6,11 @@ import org.springframework.stereotype.Component;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 节点id缓存
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/19
|
||||
* @Description: 节点id缓存
|
||||
*/
|
||||
@Component
|
||||
public class GatewayNodeIdCache extends GatewayCacheAbs<String> {
|
||||
|
@ -20,8 +21,9 @@ public class GatewayNodeIdCache extends GatewayCacheAbs<String> {
|
|||
return "gateway:load:";
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 增加缓存数据
|
||||
/**
|
||||
* 增加缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: [gatewayNodeIps]
|
||||
* @Return: void
|
||||
|
@ -31,8 +33,9 @@ public class GatewayNodeIdCache extends GatewayCacheAbs<String> {
|
|||
redisService.setCacheList(encode(gatewayLoadNodeIdKey), gatewayNodeIds);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 获取缓存数据
|
||||
/**
|
||||
* 获取缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: []
|
||||
* @Return: java.util.List<java.lang.String>
|
||||
|
@ -41,8 +44,9 @@ public class GatewayNodeIdCache extends GatewayCacheAbs<String> {
|
|||
return redisService.getCacheList(encode(gatewayLoadNodeIdKey));
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 删除缓存数据
|
||||
/**
|
||||
* 删除缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: []
|
||||
* @Return: void
|
||||
|
|
|
@ -8,10 +8,11 @@ import org.springframework.stereotype.Component;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 网关节点缓存
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/18
|
||||
* @Description: 网关节点缓存
|
||||
*/
|
||||
|
||||
@Component
|
||||
|
@ -24,10 +25,11 @@ public class GatewayNodeInfoCache extends GatewayCacheAbs<String> {
|
|||
return "gateway:load:";
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* 增加缓存数据
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/18 15:16
|
||||
* @Description: 增加缓存数据
|
||||
* @Param: 节点信息
|
||||
* @Return: void
|
||||
**/
|
||||
|
@ -36,10 +38,11 @@ public class GatewayNodeInfoCache extends GatewayCacheAbs<String> {
|
|||
redisService.setCacheList(encode(gatewayLoadInfoKey), gatewayNodeInfos);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* 获取缓存数据
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/18 15:19
|
||||
* @Description: 获取缓存数据
|
||||
* @Param: 节点id
|
||||
* @Return: 节点信息
|
||||
**/
|
||||
|
@ -49,10 +52,11 @@ public class GatewayNodeInfoCache extends GatewayCacheAbs<String> {
|
|||
return JSON.parseArray(JSON.toJSONString(cacheList), GatewayNodeInfo.class);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* 删除缓存数据
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/18 15:19
|
||||
* @Description: 删除缓存数据
|
||||
* @Param: 节点id
|
||||
* @Return: void
|
||||
**/
|
||||
|
|
|
@ -6,10 +6,11 @@ import org.springframework.stereotype.Component;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 负载节点IP缓存
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/18
|
||||
* @Description: 负载节点IP缓存
|
||||
*/
|
||||
@Component
|
||||
public class GatewayNodeIpCache extends GatewayCacheAbs<String> {
|
||||
|
@ -20,8 +21,9 @@ public class GatewayNodeIpCache extends GatewayCacheAbs<String> {
|
|||
return "gateway:load:";
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 增加缓存数据
|
||||
/**
|
||||
* 增加缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: [gatewayNodeIps]
|
||||
* @Return: void
|
||||
|
@ -31,8 +33,9 @@ public class GatewayNodeIpCache extends GatewayCacheAbs<String> {
|
|||
redisService.setCacheList(encode(gatewayLoadNodeIpKey), gatewayNodeIps);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 获取缓存数据
|
||||
/**
|
||||
* 获取缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: []
|
||||
* @Return: java.util.List<java.lang.String>
|
||||
|
@ -41,8 +44,9 @@ public class GatewayNodeIpCache extends GatewayCacheAbs<String> {
|
|||
return redisService.getCacheList(encode(gatewayLoadNodeIpKey));
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 删除缓存数据
|
||||
/**
|
||||
* 删除缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: []
|
||||
* @Return: void
|
||||
|
|
|
@ -6,10 +6,11 @@ import org.springframework.stereotype.Component;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 节点IP序列缓存
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/18
|
||||
* @Description: 节点IP序列缓存
|
||||
*/
|
||||
@Component
|
||||
public class GatewayNodeOrderCache extends GatewayCacheAbs<String> {
|
||||
|
@ -20,8 +21,9 @@ public class GatewayNodeOrderCache extends GatewayCacheAbs<String> {
|
|||
return "gateway:load:";
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 增加缓存数据
|
||||
/**
|
||||
* 增加缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: [gatewayNodeIps]
|
||||
* @Return: void
|
||||
|
@ -32,8 +34,9 @@ public class GatewayNodeOrderCache extends GatewayCacheAbs<String> {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* @Description: 获取全部缓存数据
|
||||
/**
|
||||
* 获取全部缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: []
|
||||
* @Return: java.util.List<java.lang.String>
|
||||
|
@ -42,8 +45,9 @@ public class GatewayNodeOrderCache extends GatewayCacheAbs<String> {
|
|||
return redisService.getCacheList(encode(gatewayNodeOrderKey));
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 删除缓存数据
|
||||
/**
|
||||
* 删除缓存数据
|
||||
*
|
||||
* @Date: 2024/4/18 21:37
|
||||
* @Param: []
|
||||
* @Return: void
|
||||
|
|
|
@ -4,10 +4,11 @@ import com.lyh.common.redis.service.RedisService;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* 缓存抽象类
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/18
|
||||
* @Description: 缓存抽象类
|
||||
*/
|
||||
|
||||
public abstract class GatewayCacheAbs<K> {
|
||||
|
|
|
@ -6,10 +6,11 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 网关节点信息
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/18
|
||||
* @Description: 网关节点信息
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
|
@ -28,43 +29,43 @@ public class GatewayNodeInfo {
|
|||
* */
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* 实例的ID
|
||||
* */
|
||||
*/
|
||||
private String instanceId;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 名称
|
||||
* */
|
||||
*/
|
||||
private String instanceName;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 状态
|
||||
* */
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 公网IP
|
||||
* */
|
||||
*/
|
||||
private String publicIpAddress;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 私网IP
|
||||
* */
|
||||
*/
|
||||
private String privateIpAddress;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 创建时间
|
||||
* */
|
||||
*/
|
||||
private String creationTime;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 到期时间
|
||||
* */
|
||||
*/
|
||||
private String expiredTime;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 是否可以回收
|
||||
* */
|
||||
*/
|
||||
private Boolean recyclable;
|
||||
}
|
||||
|
|
|
@ -5,16 +5,23 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* IP和对应IP的负载量
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/15
|
||||
* @Description: IP和对应IP的负载量
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class IpAndLoadCount {
|
||||
/**
|
||||
* IP
|
||||
*/
|
||||
private String ip;
|
||||
/**
|
||||
* 负载量
|
||||
*/
|
||||
private Integer loadCount;
|
||||
}
|
||||
|
|
|
@ -5,16 +5,23 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 节点IP和对应的权重
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/15
|
||||
* @Description: //节点IP和对应的权重
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class IpAndWeight {
|
||||
/**
|
||||
* 节点IP
|
||||
*/
|
||||
private String nodeIp;
|
||||
/**
|
||||
* 权重值
|
||||
*/
|
||||
private Integer weight;
|
||||
}
|
||||
|
|
|
@ -18,10 +18,11 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 操作缓存类
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/19
|
||||
* @Description: 操作缓存类
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
|
@ -32,43 +33,48 @@ public class HandleCache {
|
|||
@Autowired
|
||||
private AliYunEcsService aliYunEcsService;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 操作网关节点缓存
|
||||
* */
|
||||
*/
|
||||
@Autowired
|
||||
private GatewayNodeInfoCache gatewayNodeInfoCache;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 操作负载节点IP缓存
|
||||
* */
|
||||
*/
|
||||
@Autowired
|
||||
private GatewayNodeIpCache gatewayNodeIpCache;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 操作负载节点ID缓存
|
||||
* */
|
||||
*/
|
||||
@Autowired
|
||||
private GatewayNodeIdCache gatewayNodeIdCache;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 操作实例IP和负载量缓存
|
||||
* */
|
||||
*/
|
||||
@Autowired
|
||||
private GatewayIpAndLoadCountCache gatewayIpAndLoadCountCache;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 操作实例IP和权重缓存
|
||||
* */
|
||||
*/
|
||||
@Autowired
|
||||
private GatewayIpAndLoadWeightCache gatewayIpAndLoadWeightCache;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 操作实例IP序列缓存
|
||||
* */
|
||||
*/
|
||||
@Autowired
|
||||
private GatewayNodeOrderCache gatewayNodeOrderCache;
|
||||
|
||||
//刷新所有的缓存
|
||||
/**
|
||||
* 刷新所有的缓存
|
||||
* Date: 2024/4/19 20:19
|
||||
* Param: []
|
||||
* Return: void
|
||||
**/
|
||||
@Scheduled(cron = "0/2 * * * * ?")
|
||||
public void refreshAllCache() {
|
||||
this.getNodeIDList();
|
||||
|
@ -80,8 +86,9 @@ public class HandleCache {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* @Description: 获取节点id列表
|
||||
/**
|
||||
* 获取节点id列表
|
||||
*
|
||||
* @Date: 2024/4/19 9:09
|
||||
* @Param: []
|
||||
* @Return: void
|
||||
|
@ -102,8 +109,9 @@ public class HandleCache {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @Description: 获取实例信息列表
|
||||
/**
|
||||
* 获取实例信息列表
|
||||
*
|
||||
* @Date: 2024/4/18 21:18
|
||||
* @Param: []
|
||||
* @Return: void
|
||||
|
@ -185,10 +193,11 @@ public class HandleCache {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* 获取所有实例公网的IP列表
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/17 17:14
|
||||
* @Description: 获取所有实例公网的IP列表
|
||||
* @Param: []
|
||||
* @Return: List<String>
|
||||
**/
|
||||
|
@ -220,10 +229,11 @@ public class HandleCache {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* 通过IP获取各个IP的负载量
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/17 19:41
|
||||
* @Description: 通过IP获取各个IP的负载量
|
||||
* @Param: ecsIPList
|
||||
* @Return: List<IpAndLoadCount>
|
||||
**/
|
||||
|
@ -239,9 +249,9 @@ public class HandleCache {
|
|||
ArrayList<IpAndLoadCount> ipAndLoadCounts = new ArrayList<>();
|
||||
|
||||
//拿到IP后,获取各个IP的负载量
|
||||
nodeIPList.forEach(ip -> {
|
||||
ipAndLoadCounts.add(mqttUtil.getFetchLoad(ip));
|
||||
});
|
||||
nodeIPList.forEach(
|
||||
ip -> ipAndLoadCounts.add(mqttUtil.getFetchLoad(ip))
|
||||
);
|
||||
|
||||
log.info("各个IP的负载量:{}", ipAndLoadCounts);
|
||||
|
||||
|
@ -249,10 +259,11 @@ public class HandleCache {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* 通过IP和对应的负载量,计算出IP对应的权重
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/17 19:49
|
||||
* @Description: 通过IP和对应的负载量,计算出IP对应的权重
|
||||
* @Param: ipAndLoadCountList
|
||||
* @Return: List<IpAndWeight>
|
||||
**/
|
||||
|
@ -268,7 +279,7 @@ public class HandleCache {
|
|||
//求出空负载的总量
|
||||
int emptyLoadCount = 0;
|
||||
for (IpAndLoadCount ipAndLoadCount : ipAndLoadCounts) {
|
||||
//假设使用2/8原则 一个节点最多能有100个连接
|
||||
//假设使用2/8 原则 一个节点最多能有100个连接
|
||||
emptyLoadCount += (80 - ipAndLoadCount.getLoadCount());
|
||||
}
|
||||
|
||||
|
@ -289,10 +300,11 @@ public class HandleCache {
|
|||
gatewayIpAndLoadWeightCache.put(ipAndWeights);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* 通过IP和权重,计算节点IP序列
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/17 20:02
|
||||
* @Description: 通过IP和权重,计算节点IP序列
|
||||
* @Param: []
|
||||
* @Return:
|
||||
**/
|
||||
|
|
|
@ -13,23 +13,24 @@ import org.springframework.stereotype.Component;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 定时任务类
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/13
|
||||
* @Description:
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class Timer {
|
||||
|
||||
/*
|
||||
/**
|
||||
* 阿里云api接口类
|
||||
* */
|
||||
*/
|
||||
private final AliYunEcsService aliYunEcsService;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 操作缓存
|
||||
* */
|
||||
*/
|
||||
private final GatewayIpAndLoadCountCache gatewayIpAndLoadCountCache;
|
||||
|
||||
private final GatewayNodeIdCache gatewayNodeIdCache;
|
||||
|
@ -44,13 +45,14 @@ public class Timer {
|
|||
}
|
||||
|
||||
|
||||
@Scheduled(cron = "0/10 * * * * ?")
|
||||
/*
|
||||
* @Description: 动态扩容
|
||||
/**
|
||||
* 动态扩容
|
||||
*
|
||||
* @Date: 2024/4/19 9:44
|
||||
* @Param: []
|
||||
* @Return: void
|
||||
**/
|
||||
@Scheduled(cron = "0/10 * * * * ?")
|
||||
public void dynamicExpansion() {
|
||||
//先获取所有的负载列表
|
||||
List<IpAndLoadCount> ipAndLoadCounts = gatewayIpAndLoadCountCache.get();
|
||||
|
@ -85,13 +87,14 @@ public class Timer {
|
|||
}
|
||||
|
||||
|
||||
@Scheduled(cron = "0/10 * * * * ?")
|
||||
/* TODO 缩容有问题
|
||||
* @Description: 动态缩容
|
||||
/**
|
||||
* 动态缩容
|
||||
*
|
||||
* @Date: 2024/4/19 9:44
|
||||
* @Param: []
|
||||
* @Return: void
|
||||
**/
|
||||
@Scheduled(cron = "0/10 * * * * ?")
|
||||
public void dynamicReduction() {
|
||||
//求出所有的节点ID
|
||||
List<String> nodeIds = gatewayNodeIdCache.get();
|
||||
|
|
|
@ -3,10 +3,11 @@ package com.lyh.service;
|
|||
import com.lyh.common.domain.resp.Result;
|
||||
|
||||
/**
|
||||
* 业务接口
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/15
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
public interface LoadCenterService {
|
||||
|
|
|
@ -11,31 +11,33 @@ import org.springframework.stereotype.Service;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 负载中心业务实现类
|
||||
*
|
||||
* @ProjectName: LoadCenter
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/4/15
|
||||
* @Description:
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class LoadCenterServiceImpl implements LoadCenterService {
|
||||
/*
|
||||
/**
|
||||
* 操作缓存
|
||||
* */
|
||||
*/
|
||||
@Autowired
|
||||
private HandleCache handleCache;
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* 操作实例IP序列缓存
|
||||
* */
|
||||
*/
|
||||
@Autowired
|
||||
private GatewayNodeOrderCache gatewayNodeOrderCache;
|
||||
|
||||
/*
|
||||
/**
|
||||
* 获取 分配的一个服务器IP
|
||||
*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/4/15 21:49
|
||||
* @Description: 获取 分配的一个服务器IP
|
||||
* @Param: []
|
||||
* @Return: com.lyh.common.domain.resp.Result<java.lang.String>
|
||||
**/
|
||||
|
@ -52,8 +54,6 @@ public class LoadCenterServiceImpl implements LoadCenterService {
|
|||
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ public class Test {
|
|||
**/
|
||||
@org.junit.jupiter.api.Test
|
||||
public void releaseInstances() throws Exception {
|
||||
aliYunEcsService.releaseInstances("i-uf6h4s0jtpvrtgx574s1,");
|
||||
aliYunEcsService.releaseInstances("i-uf6dsbjd5l364ey5wnkd");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue