传入主分支,在分支上修改代码
parent
0496291ba7
commit
1d9b299753
|
@ -4,7 +4,7 @@ target/
|
||||||
!**/src/test/**/target/
|
!**/src/test/**/target/
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
### IntelliJ IDEA ###
|
||||||
/.idea
|
.idea/
|
||||||
*.iws
|
*.iws
|
||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -59,8 +59,10 @@
|
||||||
<version>2.0.47</version>
|
<version>2.0.47</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-pool2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 阿里云openAPI创建实例依赖 开始 -->
|
<!-- 阿里云openAPI创建实例依赖 开始 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -0,0 +1,257 @@
|
||||||
|
package com.yao.common.aliy;
|
||||||
|
|
||||||
|
import com.aliyun.ecs20140526.Client;
|
||||||
|
import com.aliyun.ecs20140526.models.*;
|
||||||
|
import com.aliyun.tea.TeaException;
|
||||||
|
import com.aliyun.teautil.Common;
|
||||||
|
import com.aliyun.teautil.models.RuntimeOptions;
|
||||||
|
import com.yao.common.aliy.model.EcsSelectModel;
|
||||||
|
import com.yao.common.config.AlyConfigProperties;
|
||||||
|
import com.yao.common.domain.aliy.InstanceInfo;
|
||||||
|
import com.yao.common.domain.aliy.InstanceRequest;
|
||||||
|
import com.yao.common.redis.service.RedisService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/16
|
||||||
|
* @Description: 阿里云ECS服务器openAPI调用
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class AliYunEcsService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisService redisService;
|
||||||
|
private final AlyConfigProperties alyConfigProperties;
|
||||||
|
private final Client client;
|
||||||
|
|
||||||
|
public AliYunEcsService(AlyConfigProperties alyConfigProperties, Client client) {
|
||||||
|
this.alyConfigProperties = alyConfigProperties;
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
//todo----------------------------------------------------以下是查询代码--------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
* @Description: 根据id和name查询内容
|
||||||
|
*/
|
||||||
|
public List<InstanceInfo> selectList(EcsSelectModel ecsSelectModel) throws Exception {
|
||||||
|
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||||
|
.setRegionId(alyConfigProperties.getRegionId());
|
||||||
|
if (ecsSelectModel.getInstanceNameList() == null || ecsSelectModel.getInstanceNameList().isEmpty()) {
|
||||||
|
describeInstancesRequest.setInstanceName("*");
|
||||||
|
} else {
|
||||||
|
describeInstancesRequest.setInstanceName(Common.toJSONString(ecsSelectModel.getInstanceNameList()));
|
||||||
|
}
|
||||||
|
if (ecsSelectModel.getInstanceIdList() != null || !ecsSelectModel.getInstanceIdList().isEmpty()) {
|
||||||
|
describeInstancesRequest.setInstanceIds(Common.toJSONString(ecsSelectModel.getInstanceIdList()).toString());
|
||||||
|
} else {
|
||||||
|
describeInstancesRequest.setInstanceName(Common.toJSONString(ecsSelectModel.getInstanceNameList()));
|
||||||
|
}
|
||||||
|
describeInstancesRequest.setPageSize(10);
|
||||||
|
|
||||||
|
RuntimeOptions runtime = new RuntimeOptions();
|
||||||
|
|
||||||
|
//初始化返回值
|
||||||
|
List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> instanceList = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 复制代码运行请自行打印 API 的返回值
|
||||||
|
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||||
|
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||||
|
DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances = body.getInstances();
|
||||||
|
//能返回的值
|
||||||
|
instanceList = instances.getInstance();
|
||||||
|
if (instanceList == null || instanceList.isEmpty()) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
return instanceList.stream()
|
||||||
|
.map(instance -> {
|
||||||
|
return InstanceInfo.builder()
|
||||||
|
.instanceId(instance.getInstanceId())
|
||||||
|
.instanceName(instance.getInstanceName())
|
||||||
|
.status(instance.getStatus())
|
||||||
|
.publicIpAddress(instance.getPublicIpAddress().getIpAddress().toString())
|
||||||
|
.privateIpAddress(instance.getVpcAttributes().getPrivateIpAddress().ipAddress.toString())
|
||||||
|
.recyclable(instance.getRecyclable())
|
||||||
|
.creationTime(instance.creationTime)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
}).toList();
|
||||||
|
} catch (TeaException error) {
|
||||||
|
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||||
|
// 错误 message
|
||||||
|
log.error("状态码是:[{}],信息是:[{}],返回的结果是:[{}]", error.getCode(), error.getMessage(), error);
|
||||||
|
} catch (Exception _error) {
|
||||||
|
TeaException error = new TeaException();
|
||||||
|
log.error("code:[{}],信息是:[{}],返回的结果是:[{}]",error.getCode(), error.getMessage(), error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//todo----------------------------------------------------以下是新增代码--------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增实列
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* initialization 初始化公共请求参数
|
||||||
|
*/
|
||||||
|
public List<String> startCreate() throws Exception {
|
||||||
|
// 公网出带宽最大值,单位为 Mbit/s。取值范围:0~100。 默认值:0。
|
||||||
|
Integer internetMaxBandwidthOut = com.aliyun.darabonbanumber.Client.parseInt("5");
|
||||||
|
// 批量创建实例
|
||||||
|
List<String> s = RunInstances(
|
||||||
|
client, alyConfigProperties.getRegionId(), alyConfigProperties.getImageId(), alyConfigProperties.getInstanceType(),
|
||||||
|
alyConfigProperties.getSecurityGroupId(), alyConfigProperties.getVSwitchId(), internetMaxBandwidthOut,
|
||||||
|
alyConfigProperties.getInternetChargeType(), alyConfigProperties.getSize(), alyConfigProperties.getCategory(),
|
||||||
|
alyConfigProperties.getInstanceChargeType());
|
||||||
|
//切割成一个string类型的数据
|
||||||
|
// String id = s.substring(2, s.length()-2).replace("\"", "");
|
||||||
|
EcsSelectModel ecsSelectModel = new EcsSelectModel();
|
||||||
|
ecsSelectModel.setInstanceIdList(s);
|
||||||
|
List<InstanceInfo> list = selectList(ecsSelectModel);
|
||||||
|
list.forEach(
|
||||||
|
item -> {
|
||||||
|
String publicIP = item.getPublicIpAddress().substring(1, item.getPublicIpAddress().length() - 1);
|
||||||
|
item.setPublicIpAddress(publicIP);
|
||||||
|
redisService.setCacheSet("new:real:column", item);
|
||||||
|
log.info("公网IP:" + item.getPublicIpAddress());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RunInstances 通过备选实例规格创建ECS实例最佳实践
|
||||||
|
* 该场景中,在调用RunInstances创建ECS实例时判断是否发生库存不足等错误,如果发生错误,将调用DescribeRecommendInstanceType查询备选实例,然后通过备选实例规格重新创建ECS实例。
|
||||||
|
*/
|
||||||
|
public List<String> RunInstances(Client client, String regionId, String imageId, String instanceType, String securityGroupId, String vSwitchId, Integer internetMaxBandwidthOut,
|
||||||
|
String internetChargeType, String size, String category, String instanceChargeType) throws Exception {
|
||||||
|
RunInstancesResponse responces =null;
|
||||||
|
int i = 0;
|
||||||
|
RunInstancesRequest request1 = new RunInstancesRequest()
|
||||||
|
.setRegionId(regionId)
|
||||||
|
.setImageId(imageId)
|
||||||
|
.setInstanceType(instanceType)
|
||||||
|
.setSecurityGroupId(securityGroupId)
|
||||||
|
.setVSwitchId(vSwitchId)
|
||||||
|
.setInstanceName("MyFirstEcsInstance")
|
||||||
|
.setDescription("MyFirstEcsInstance")
|
||||||
|
.setInternetMaxBandwidthOut(internetMaxBandwidthOut)
|
||||||
|
.setInternetChargeType(internetChargeType)
|
||||||
|
.setInstanceChargeType(instanceChargeType)
|
||||||
|
// 批量创建五台ECS实例,如果不设置该参数,默认创建一台ECS实例。
|
||||||
|
// amount = 5,
|
||||||
|
// 如果缺少库存可以接受的最低创建数量。
|
||||||
|
// minAmount = 2,
|
||||||
|
// 打开预检参数功能,不会实际创建ECS实例,只检查参数正确性、用户权限或者ECS库存等问题。
|
||||||
|
// 实际情况下,设置了DryRun参数后,Amount必须为1,MinAmount必须为空,您可以根据实际需求修改代码。
|
||||||
|
.setDryRun(false)
|
||||||
|
.setSystemDisk(new RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||||
|
.setSize(size)
|
||||||
|
.setCategory(category));
|
||||||
|
try {
|
||||||
|
com.aliyun.teaconsole.Client.log("--------------------批量创建实例开始--------------------");
|
||||||
|
responces = client.runInstances(request1);
|
||||||
|
com.aliyun.teaconsole.Client.log("--------------------创建实例成功,实例ID:" + (responces.body.instanceIdSets.instanceIdSet) + "--------------------");
|
||||||
|
i++;
|
||||||
|
} catch (TeaException error) {
|
||||||
|
com.aliyun.teaconsole.Client.log("--------------------创建实例失败:" + Common.toJSONString(error.message) + "--------------------");
|
||||||
|
} catch (Exception _error) {
|
||||||
|
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||||
|
com.aliyun.teaconsole.Client.log("--------------------创建实例失败:" + Common.toJSONString(error.message) + "--------------------");
|
||||||
|
}
|
||||||
|
return responces.body.instanceIdSets.instanceIdSet;
|
||||||
|
}
|
||||||
|
//todo----------------------------------------------------以下是删除代码----------------------------------------------
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
public DescribeInstancesResponse describeInstances(Client client,String regionId,String instanceIds,String instanceName) {
|
||||||
|
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||||
|
.setRegionId(regionId)
|
||||||
|
.setInstanceName(instanceName);
|
||||||
|
if (!Common.empty(instanceIds)){
|
||||||
|
describeInstancesRequest.instanceIds = Common.toJSONString(com.aliyun.darabonbastring.Client.split(instanceIds, ",", 50));
|
||||||
|
}
|
||||||
|
DescribeInstancesResponse resq = null;
|
||||||
|
try {
|
||||||
|
resq = client.describeInstances(describeInstancesRequest);
|
||||||
|
com.aliyun.teaconsole.Client.log("--------------------查询需要删除的实例--------------------");
|
||||||
|
return resq;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void modifyInstanceAttribute(Client client,String instatnceId) {
|
||||||
|
ModifyInstanceAttributeRequest req = new ModifyInstanceAttributeRequest()
|
||||||
|
.setInstanceId(instatnceId)
|
||||||
|
.setDeletionProtection(false)
|
||||||
|
;
|
||||||
|
try {
|
||||||
|
client.modifyInstanceAttribute(req);
|
||||||
|
com.aliyun.teaconsole.Client.log("--------------------"+instatnceId+"释放保护成功--------------------");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteInstances(Client client, String regionId, String instanceIds, String force) {
|
||||||
|
DeleteInstancesRequest req = new DeleteInstancesRequest()
|
||||||
|
.setRegionId(regionId)
|
||||||
|
.setInstanceId(com.aliyun.darabonbastring.Client.split(instanceIds, ",", 50))
|
||||||
|
.setForce(Common.equalString(force, "true"));
|
||||||
|
DeleteInstancesResponse resp = null;
|
||||||
|
try {
|
||||||
|
resp = client.deleteInstances(req);
|
||||||
|
com.aliyun.teaconsole.Client.log("--------------------实例释放成功--------------------");
|
||||||
|
com.aliyun.teaconsole.Client.log(Common.toJSONString(Common.toMap(resp)));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String delete (String instanceIds) {
|
||||||
|
//实例名称
|
||||||
|
String instanceName = "MyFirstEcsInstance";
|
||||||
|
//强制删除有删除保护的机器
|
||||||
|
String deleteProtected = "true";
|
||||||
|
//强制删除运行中的机器
|
||||||
|
String force = "true";
|
||||||
|
|
||||||
|
if (Common.equalString(deleteProtected,"true")){
|
||||||
|
DescribeInstancesResponse describeInstances = describeInstances(client, alyConfigProperties.getRegionId(), instanceIds, instanceName);
|
||||||
|
instanceIds="";
|
||||||
|
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : describeInstances.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)){
|
||||||
|
try {
|
||||||
|
com.aliyun.teaconsole.Client.log("--------------------无有效实例可删除--------------------");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deleteInstances(client,alyConfigProperties.getRegionId(),instanceIds,force);
|
||||||
|
return instanceIds;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.yao.common.aliy.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/16
|
||||||
|
* @Description: 查询模型
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class EcsSelectModel {
|
||||||
|
|
||||||
|
private List<String> instanceIdList;
|
||||||
|
private List<String> instanceNameList;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.yao.common.config;
|
||||||
|
|
||||||
|
import com.aliyun.ecs20140526.Client;
|
||||||
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/16
|
||||||
|
* @Description: 阿里云配置
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "config.aly")
|
||||||
|
@Data
|
||||||
|
public class AlyConfigProperties {
|
||||||
|
|
||||||
|
private String accessKeyId;
|
||||||
|
private String accessKeySecret;
|
||||||
|
/**
|
||||||
|
* 地域id
|
||||||
|
*/
|
||||||
|
private String regionId;
|
||||||
|
private String imageId;
|
||||||
|
|
||||||
|
/*
|
||||||
|
实列规格
|
||||||
|
*/
|
||||||
|
private String instanceType;
|
||||||
|
/**
|
||||||
|
* 安全组
|
||||||
|
*/
|
||||||
|
private String securityGroupId;
|
||||||
|
/**
|
||||||
|
* 虚拟交换机
|
||||||
|
*/
|
||||||
|
private String vSwitchId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网络计费类型
|
||||||
|
*/
|
||||||
|
private String internetChargeType;
|
||||||
|
/**
|
||||||
|
* 系统盘大小
|
||||||
|
*/
|
||||||
|
private String size;
|
||||||
|
/**
|
||||||
|
* 系统盘的云盘种类
|
||||||
|
*/
|
||||||
|
private String category;
|
||||||
|
//ECS实例的计费方式
|
||||||
|
private String instanceChargeType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param alyConfig
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
* @Description: 创建一个单例
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public Client createEcsClient(AlyConfigProperties alyConfig) throws Exception {
|
||||||
|
Config config = new Config()
|
||||||
|
// 您的AccessKey ID
|
||||||
|
.setAccessKeyId(alyConfig.getAccessKeyId())
|
||||||
|
// 您的AccessKey Secret
|
||||||
|
.setAccessKeySecret(alyConfig.getAccessKeySecret())
|
||||||
|
// 您的可用区ID
|
||||||
|
.setRegionId(alyConfig.getRegionId());
|
||||||
|
return new Client(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,9 +0,0 @@
|
||||||
package com.yao.common.config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: LiJiaYao
|
|
||||||
* @Date: 2024/4/16
|
|
||||||
* @Description: 阿里云配置
|
|
||||||
*/
|
|
||||||
public class Alyconfig {
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package com.yao.common.config;
|
|
||||||
|
|
||||||
import com.aliyun.teaopenapi.models.Config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: LiJiaYao
|
|
||||||
* @Date: 2024/4/13
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
public class ClientService {
|
|
||||||
/*
|
|
||||||
* @Author: LiuYunHu
|
|
||||||
* @Date: 2024/4/13 9:52
|
|
||||||
* @Description: 初始化公共请求参数
|
|
||||||
* @Param:
|
|
||||||
* @Return:
|
|
||||||
**/
|
|
||||||
|
|
||||||
public static com.aliyun.ecs20140526.Client createEcsClient(String regionId) throws Exception {
|
|
||||||
Config config = new Config()
|
|
||||||
// 您的AccessKey ID
|
|
||||||
.setAccessKeyId("LTAI5t7kDVgLdPETn9TXjFaaW")
|
|
||||||
// 您的AccessKey Secret
|
|
||||||
.setAccessKeySecret("79UjUBiwoQgADVyJjrOXa9B4KVJn0lS")
|
|
||||||
// 您的可用区ID
|
|
||||||
.setRegionId(regionId);
|
|
||||||
return new com.aliyun.ecs20140526.Client(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,148 +0,0 @@
|
||||||
package com.yao.common.config;
|
|
||||||
|
|
||||||
import com.aliyun.ecs20140526.Client;
|
|
||||||
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
|
||||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
|
||||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
|
||||||
import com.aliyun.tea.TeaException;
|
|
||||||
import com.aliyun.teautil.Common;
|
|
||||||
import com.aliyun.teautil.models.RuntimeOptions;
|
|
||||||
import com.yao.common.domain.InstanceInfo;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: LiJiaYao
|
|
||||||
* @Date: 2024/4/13
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class GetInstanceProperties {
|
|
||||||
|
|
||||||
static int i = 1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @Author: LiuYunHu
|
|
||||||
* @Date: 2024/4/13 11:01
|
|
||||||
* @Description: 实例ID 用 英文逗号拼接
|
|
||||||
* @Param: [instanceIds] i-uf6chlqotgoc9h173alu
|
|
||||||
* @Return: void
|
|
||||||
**/
|
|
||||||
public static List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> startGet(String instanceIds) throws Exception {
|
|
||||||
// 地域Id
|
|
||||||
String regionId = "cn-shanghai";
|
|
||||||
|
|
||||||
Client client = ClientService.createEcsClient(regionId);
|
|
||||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
|
||||||
.setRegionId(regionId)
|
|
||||||
.setInstanceName("*")
|
|
||||||
.setInstanceIds(com.aliyun.teautil.Common.toJSONString(com.aliyun.darabonbastring.Client.split(instanceIds, ",", 50)))
|
|
||||||
.setPageSize(10);
|
|
||||||
|
|
||||||
RuntimeOptions runtime = new RuntimeOptions();
|
|
||||||
|
|
||||||
//初始化返回值
|
|
||||||
List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> instance = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 复制代码运行请自行打印 API 的返回值
|
|
||||||
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
|
||||||
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
|
||||||
DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances = body.getInstances();
|
|
||||||
//能返回的值
|
|
||||||
instance = instances.getInstance();
|
|
||||||
instance.forEach(item -> {
|
|
||||||
System.out.println("实例{" + i + "}的ID:" + item.getInstanceId());
|
|
||||||
System.out.println("名称:" + item.getInstanceName());
|
|
||||||
System.out.println("地域ID:" + item.getRegionId());
|
|
||||||
System.out.println("状态:" + item.getStatus());
|
|
||||||
System.out.println("类型:" + item.getInstanceType());
|
|
||||||
System.out.println("CPU核心数:" + item.getCpu());
|
|
||||||
System.out.println("内存大小:" + item.getMemory() + "MB");
|
|
||||||
System.out.println("磁盘大小:" + item.getLocalStorageCapacity() + "G");
|
|
||||||
System.out.println("操作系统:" + item.getOSName());
|
|
||||||
System.out.println("网络类型:" + item.getInstanceNetworkType());
|
|
||||||
System.out.println("公网出带宽值:" + item.getInternetMaxBandwidthOut() + "Mbit/s");
|
|
||||||
System.out.println("公网入带宽值:" + item.getInternetMaxBandwidthIn() + "Mbit/s");
|
|
||||||
System.out.println("公网IP:" + item.getPublicIpAddress().getIpAddress().toString());
|
|
||||||
System.out.println("私网IP:" + item.getVpcAttributes().getPrivateIpAddress().ipAddress.toString());
|
|
||||||
System.out.println("专有网络VPCID:" + item.getVpcAttributes().getVpcId());
|
|
||||||
// System.out.println("安全组ID:" + UserUtil.removeBrackets(item.getSecurityGroupIds().getSecurityGroupId().toString()));
|
|
||||||
System.out.println("创建时间:" + item.getCreationTime());
|
|
||||||
System.out.println("到期时间:" + item.getExpiredTime());
|
|
||||||
System.out.println("是否可以回收:" + (item.getRecyclable() ? "是" : "否") + "\n\n");
|
|
||||||
System.out.println("---------------------");
|
|
||||||
i++;
|
|
||||||
});
|
|
||||||
} catch (TeaException error) {
|
|
||||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
|
||||||
// 错误 message
|
|
||||||
System.out.println(error.getMessage());
|
|
||||||
// 诊断地址
|
|
||||||
System.out.println(error.getData().get("Recommend"));
|
|
||||||
Common.assertAsString(error.message);
|
|
||||||
} catch (Exception _error) {
|
|
||||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
|
||||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
|
||||||
// 错误 message
|
|
||||||
System.out.println(error.getMessage());
|
|
||||||
// 诊断地址
|
|
||||||
System.out.println(error.getData().get("Recommend"));
|
|
||||||
Common.assertAsString(error.message);
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static List<InstanceInfo> selectECS(String instanceName) {
|
|
||||||
Client client = null;
|
|
||||||
List<InstanceInfo> instanceInfos = new ArrayList<>(); // 用于存储查询到的实例信息
|
|
||||||
|
|
||||||
try {
|
|
||||||
client = ClientService.createEcsClient("cn-shanghai");
|
|
||||||
com.aliyun.ecs20140526.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.ecs20140526.models.DescribeInstancesRequest()
|
|
||||||
.setRegionId("cn-shanghai")
|
|
||||||
.setInstanceName(instanceName)
|
|
||||||
.setPageSize(10);
|
|
||||||
|
|
||||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
|
||||||
|
|
||||||
|
|
||||||
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
|
||||||
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
|
||||||
DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances = body.getInstances();
|
|
||||||
List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> instanceList = instances.getInstance();
|
|
||||||
|
|
||||||
// 修改 selectECS 方法中 IP 地址的处理部分
|
|
||||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance item : instanceList) {
|
|
||||||
InstanceInfo instanceInfo = new InstanceInfo();
|
|
||||||
instanceInfo.setInstanceId(item.getInstanceId());
|
|
||||||
instanceInfo.setInstanceName(item.getInstanceName());
|
|
||||||
// 将 IP 地址对象转换为字符串,并存储到 InstanceInfo 对象中
|
|
||||||
// 在您的代码中将 IP 地址转换为字符串的部分可以改为以下方式
|
|
||||||
|
|
||||||
|
|
||||||
String publicIpAddress = item.getPublicIpAddress().getIpAddress().toString();
|
|
||||||
// 去掉方括号
|
|
||||||
publicIpAddress = publicIpAddress.substring(1, publicIpAddress.length() - 1);
|
|
||||||
instanceInfo.setPublicIpAddress(publicIpAddress);
|
|
||||||
|
|
||||||
String privateIpAddress = item.getVpcAttributes().getPrivateIpAddress().ipAddress.toString();
|
|
||||||
// 去掉方括号
|
|
||||||
privateIpAddress = privateIpAddress.substring(1, privateIpAddress.length() - 1);
|
|
||||||
instanceInfo.setPrivateIpAddress(privateIpAddress);
|
|
||||||
instanceInfos.add(instanceInfo);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return instanceInfos;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
package com.yao.common.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;
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
package com.yao.common.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;
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package com.yao.common.domain;
|
|
||||||
|
|
||||||
import lombok.Data; /**
|
|
||||||
* 节点状态
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class FlowInfo {
|
|
||||||
/**
|
|
||||||
* 上次读取吞吐量
|
|
||||||
*/
|
|
||||||
private String lastReadThroughput;
|
|
||||||
/**
|
|
||||||
* 上次写入吞吐量
|
|
||||||
*/
|
|
||||||
private String lastWriteThroughput;
|
|
||||||
/**
|
|
||||||
* 读取总吞吐量
|
|
||||||
*/
|
|
||||||
private String readBytesHistory;
|
|
||||||
/**
|
|
||||||
* 实写字节
|
|
||||||
*/
|
|
||||||
private String realWriteBytes;
|
|
||||||
/**
|
|
||||||
* 写入总吞吐量
|
|
||||||
*/
|
|
||||||
private String writeBytesHistory;
|
|
||||||
}
|
|
|
@ -1,58 +0,0 @@
|
||||||
package com.yao.common.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;
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
package com.yao.common.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,24 +1,55 @@
|
||||||
package com.yao.common.domain;
|
package com.yao.common.domain.aliy;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: LiJiaYao
|
* @Author: LiJiaYao
|
||||||
* @Date: 2024/4/15
|
* @Date: 2024/4/15
|
||||||
* @Description:
|
* @Description: 阿里云服务器
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
public class InstanceInfo {
|
public class InstanceInfo {
|
||||||
|
|
||||||
private String instanceId;
|
|
||||||
private String instanceName;
|
|
||||||
private String publicIpAddress; // 将数据类型修改为字符串
|
|
||||||
private String privateIpAddress; // 将数据类型修改为字符串
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例id
|
||||||
|
*/
|
||||||
|
private String instanceId;
|
||||||
|
/**
|
||||||
|
* 实例名称
|
||||||
|
*/
|
||||||
|
private String instanceName;
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
/**
|
||||||
|
* 公网IP
|
||||||
|
*/
|
||||||
|
private String publicIpAddress; // 将数据类型修改为字符串
|
||||||
|
/**
|
||||||
|
* 私网IP
|
||||||
|
*/
|
||||||
|
private String privateIpAddress; // 将数据类型修改为字符串
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private String creationTime;
|
||||||
|
/*
|
||||||
|
是否可以回收
|
||||||
|
*/
|
||||||
|
private boolean recyclable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否可以回收
|
||||||
|
* @param ipAddress
|
||||||
|
*/
|
||||||
|
|
||||||
public void setPublicIpAddress(String ipAddress) {
|
public void setPublicIpAddress(String ipAddress) {
|
||||||
this.publicIpAddress = ipAddress;
|
this.publicIpAddress = ipAddress;
|
|
@ -1,6 +1,7 @@
|
||||||
package com.yao.common.domain;
|
package com.yao.common.domain.aliy;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@ -12,8 +13,9 @@ import java.io.Serializable;
|
||||||
* @Description:
|
* @Description:
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
public class InstanceRequest implements Serializable {
|
public class InstanceRequest implements Serializable {
|
||||||
|
|
||||||
private String publicIpAddress;
|
private String publicIpAddress;
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.yao.common.mqtt;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.yao.common.redis.service.RedisService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/16
|
||||||
|
* @Description: 连接mqttx的配置类
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
public class MqttConnectService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用redis分装好的方法
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private RedisService redisService;
|
||||||
|
|
||||||
|
//todo-----------------------连接mqtt方法-------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 连接mqtt方法
|
||||||
|
*/
|
||||||
|
public Integer connectMqtt(String ip) {
|
||||||
|
//请求路径
|
||||||
|
String URL = "http://" + ip + ":8080/public/cluster";
|
||||||
|
OkHttpClient client = new OkHttpClient();
|
||||||
|
Request request = new Request.Builder().url(URL).get().addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)").addHeader("Accesstoken", "").build();
|
||||||
|
redisService.setCacheSet("ECS", ip);
|
||||||
|
Response response = null;
|
||||||
|
try {
|
||||||
|
response = client.newCall(request).execute();
|
||||||
|
log.info(response);
|
||||||
|
JSONArray jsonArray = JSONArray.parseArray(response.body().string());
|
||||||
|
JSONObject object = jsonArray.getJSONObject(0);
|
||||||
|
JSONObject mqttInfo = object.getJSONObject("mqttInfo");
|
||||||
|
int connectSize = mqttInfo.getIntValue("connectSize");
|
||||||
|
log.info(ip + " 的fluxmq连接数为:" + connectSize);
|
||||||
|
return connectSize;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,7 +34,6 @@ public class RedisConfig extends CachingConfigurerSupport {
|
||||||
// Hash的key也采用StringRedisSerializer的序列化方式
|
// Hash的key也采用StringRedisSerializer的序列化方式
|
||||||
template.setHashKeySerializer(new StringRedisSerializer());
|
template.setHashKeySerializer(new StringRedisSerializer());
|
||||||
template.setHashValueSerializer(serializer);
|
template.setHashValueSerializer(serializer);
|
||||||
|
|
||||||
template.afterPropertiesSet();
|
template.afterPropertiesSet();
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,6 +267,17 @@ public class RedisService {
|
||||||
HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
|
HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
|
||||||
return opsForHash.get(key, hKey);
|
return opsForHash.get(key, hKey);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 获取Hash中的数据
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @param hKey Hash键
|
||||||
|
* @return Hash中的对象
|
||||||
|
*/
|
||||||
|
public <T> T getCacheListValue(final String key, final Long hKey) {
|
||||||
|
ListOperations opsForHash = redisTemplate.opsForList();
|
||||||
|
return (T) opsForHash.index(key,hKey);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取多个Hash中的数据
|
* 获取多个Hash中的数据
|
||||||
|
@ -315,4 +326,5 @@ public class RedisService {
|
||||||
|
|
||||||
return redisTemplate.opsForValue().increment(cursor,l);
|
return redisTemplate.opsForValue().increment(cursor,l);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.yao.gateWay.cache;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/18
|
||||||
|
* @Description: 网关节点
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class GateWayNodeInfo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点id
|
||||||
|
*/
|
||||||
|
private String nodeId;
|
||||||
|
/***
|
||||||
|
* 外网
|
||||||
|
*/
|
||||||
|
private String publicIdAddress;
|
||||||
|
/**
|
||||||
|
* 内网
|
||||||
|
*/
|
||||||
|
private String privateIdAddress;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.yao.gateWay.cache;
|
||||||
|
|
||||||
|
import com.yao.gateWay.cache.abs.GatewayNodeAbstract;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/18
|
||||||
|
* @Description: 网关负载节点缓存
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class GatewayLoadNodeCache extends GatewayNodeAbstract {
|
||||||
|
|
||||||
|
|
||||||
|
private final static String gateWayLoadNodeKey="gateway:load:node";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存负载集合
|
||||||
|
* @param nodeList 节点权重集合
|
||||||
|
*/
|
||||||
|
public void put(List<String> nodeList){
|
||||||
|
redisService.deleteObject(gateWayLoadNodeKey);
|
||||||
|
redisService.setCacheList(gateWayLoadNodeKey,nodeList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有负载节点
|
||||||
|
* @return 所有负载节点集合
|
||||||
|
*/
|
||||||
|
public List<String> get(){
|
||||||
|
return redisService.getCacheList(gateWayLoadNodeKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据下标查询内容
|
||||||
|
* @param index
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getByIndex(Long index){
|
||||||
|
if (index == null || index > 100){
|
||||||
|
throw new RuntimeException("下标违法,0-100");
|
||||||
|
}
|
||||||
|
return redisService.getCacheListValue(gateWayLoadNodeKey,index);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.yao.gateWay.cache;
|
||||||
|
|
||||||
|
import com.yao.gateWay.cache.abs.GatewayNodeAbstract;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/18
|
||||||
|
* @Description: 网关负载序列
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class GatewayLoadSeriesCache extends GatewayNodeAbstract {
|
||||||
|
|
||||||
|
public static final String gatewayLoadSeriesKey = "gateway:load:series";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化
|
||||||
|
* bean创建完成之后执行方法
|
||||||
|
*/
|
||||||
|
@PostConstruct
|
||||||
|
public void init(){
|
||||||
|
redisService.setCacheObject(gatewayLoadSeriesKey,0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前序列值
|
||||||
|
* @return 序列值
|
||||||
|
*/
|
||||||
|
public Long get(){
|
||||||
|
return redisService.getCacheObject(gatewayLoadSeriesKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取自增序列值
|
||||||
|
* @return 自增后的值
|
||||||
|
*/
|
||||||
|
public Long incrementAndGet(){
|
||||||
|
return redisService.increment(gatewayLoadSeriesKey,1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置 刷新
|
||||||
|
*/
|
||||||
|
public void refresh(){
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package com.yao.gateWay.cache;
|
||||||
|
|
||||||
|
import com.yao.gateWay.cache.abs.GatewayNodeAbstract;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/18
|
||||||
|
* @Description: 网关节点缓存
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class GatewayNodeCache extends GatewayNodeAbstract {
|
||||||
|
|
||||||
|
private final static String nodePre= "gateway:node:info:";
|
||||||
|
public String encode (String nodeId){
|
||||||
|
return nodePre+nodeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加缓存信息
|
||||||
|
* @param gateWayNodeInfo 节点信息
|
||||||
|
*/
|
||||||
|
public void add(GateWayNodeInfo gateWayNodeInfo){
|
||||||
|
redisService.setCacheObject(encode(gateWayNodeInfo.getNodeId()),gateWayNodeInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取节点信息
|
||||||
|
* @param nodeId 缓存名称
|
||||||
|
* @return GateWayNodeInfo 节点信息
|
||||||
|
*/
|
||||||
|
public GateWayNodeInfo get(String nodeId){
|
||||||
|
return redisService.getCacheObject(encode(nodeId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除节点信息
|
||||||
|
* @param nodeId 节点id
|
||||||
|
*/
|
||||||
|
public void remove(String nodeId){
|
||||||
|
redisService.deleteObject(encode(nodeId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.yao.gateWay.cache;
|
||||||
|
|
||||||
|
import com.yao.gateWay.cache.abs.GatewayNodeAbstract;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/18
|
||||||
|
* @Description: 网关节点分数
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class GatewayNodeScoreCache extends GatewayNodeAbstract {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.yao.gateWay.cache;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/18
|
||||||
|
* @Description: 网关节点存储vin详情
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class GatewayNodeSetVinCache {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.yao.gateWay.cache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/18
|
||||||
|
* @Description: 网关连接车俩
|
||||||
|
*/
|
||||||
|
public class GatewayVehicleLineNodeCache {
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.yao.gateWay.cache.abs;
|
||||||
|
|
||||||
|
import com.yao.common.redis.service.RedisService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/18
|
||||||
|
* @Description: 缓存抽象
|
||||||
|
*/
|
||||||
|
public abstract class GatewayNodeAbstract {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* redis工具类
|
||||||
|
*/
|
||||||
|
public RedisService redisService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,114 +0,0 @@
|
||||||
package com.yao.server.add;
|
|
||||||
|
|
||||||
import com.aliyun.ecs20140526.Client;
|
|
||||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
|
||||||
import com.aliyun.ecs20140526.models.RunInstancesRequest;
|
|
||||||
import com.aliyun.ecs20140526.models.RunInstancesResponse;
|
|
||||||
import com.aliyun.tea.TeaException;
|
|
||||||
import com.aliyun.teautil.Common;
|
|
||||||
import com.yao.common.config.ClientService;
|
|
||||||
import com.yao.common.config.GetInstanceProperties;
|
|
||||||
import com.yao.common.domain.InstanceInfo;
|
|
||||||
import com.yao.common.domain.InstanceRequest;
|
|
||||||
import com.yao.common.redis.service.RedisService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: LiJiaYao
|
|
||||||
* @Date: 2024/4/12
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
public class Sample {
|
|
||||||
|
|
||||||
|
|
||||||
private static RedisService redisService;
|
|
||||||
static int i = 1;
|
|
||||||
/**
|
|
||||||
* initialization 初始化公共请求参数
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static String startCreate() throws Exception {
|
|
||||||
// 地域Id
|
|
||||||
String regionId = "cn-shanghai";
|
|
||||||
// 镜像 ID,启动实例时选择的镜像资源。
|
|
||||||
String imageId = "m-uf6ii43j71vmvcc84cb9";
|
|
||||||
// 实例规格
|
|
||||||
String instanceType = "ecs.e-c1m1.large";
|
|
||||||
// 新创建实例所属于的安全组 ID。
|
|
||||||
String securityGroupId = "sg-uf61d7chl7g03zmc4rrj";
|
|
||||||
// 虚拟交换机 ID。
|
|
||||||
String vSwitchId = "vsw-uf6w1g7dugq9i83omkes2";
|
|
||||||
// 公网出带宽最大值,单位为 Mbit/s。取值范围:0~100。 默认值:0。
|
|
||||||
Integer internetMaxBandwidthOut = com.aliyun.darabonbanumber.Client.parseInt("5");
|
|
||||||
// 网络计费类型。取值范围:
|
|
||||||
// PayByBandwidth: 按固定带宽计费。
|
|
||||||
// PayByTraffic: 按使用流量计费。
|
|
||||||
// 默认值:PayByTraffic。
|
|
||||||
String internetChargeType = "PayByTraffic";
|
|
||||||
// 系统盘大小
|
|
||||||
String size = "20";
|
|
||||||
// 系统盘的云盘种类
|
|
||||||
String category = "cloud_essd";
|
|
||||||
// ECS实例的计费方式
|
|
||||||
// PrePaid:包年包月
|
|
||||||
// PostPaid:按量付费
|
|
||||||
String instanceChargeType = "PostPaid";
|
|
||||||
Client client = ClientService.createEcsClient(regionId);
|
|
||||||
// 批量创建实例
|
|
||||||
String s = Sample.RunInstances(client, regionId, imageId, instanceType, securityGroupId, vSwitchId, internetMaxBandwidthOut, internetChargeType, size, category, instanceChargeType);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RunInstances 通过备选实例规格创建ECS实例最佳实践
|
|
||||||
* 该场景中,在调用RunInstances创建ECS实例时判断是否发生库存不足等错误,如果发生错误,将调用DescribeRecommendInstanceType查询备选实例,然后通过备选实例规格重新创建ECS实例。
|
|
||||||
*/
|
|
||||||
public static String RunInstances(com.aliyun.ecs20140526.Client client, String regionId, String imageId, String instanceType, String securityGroupId, String vSwitchId, Integer internetMaxBandwidthOut, String internetChargeType, String size, String category, String instanceChargeType) throws Exception {
|
|
||||||
RunInstancesResponse responces =null;
|
|
||||||
RunInstancesRequest request1 = new RunInstancesRequest()
|
|
||||||
.setRegionId(regionId)
|
|
||||||
.setImageId(imageId)
|
|
||||||
.setInstanceType(instanceType)
|
|
||||||
.setSecurityGroupId(securityGroupId)
|
|
||||||
.setVSwitchId(vSwitchId)
|
|
||||||
.setInstanceName("MyFirstEcsInstance")
|
|
||||||
.setDescription("MyFirstEcsInstance")
|
|
||||||
.setInternetMaxBandwidthOut(internetMaxBandwidthOut)
|
|
||||||
.setInternetChargeType(internetChargeType)
|
|
||||||
.setInstanceChargeType(instanceChargeType)
|
|
||||||
// 批量创建五台ECS实例,如果不设置该参数,默认创建一台ECS实例。
|
|
||||||
// amount = 5,
|
|
||||||
// 如果缺少库存可以接受的最低创建数量。
|
|
||||||
// minAmount = 2,
|
|
||||||
// 打开预检参数功能,不会实际创建ECS实例,只检查参数正确性、用户权限或者ECS库存等问题。
|
|
||||||
// 实际情况下,设置了DryRun参数后,Amount必须为1,MinAmount必须为空,您可以根据实际需求修改代码。
|
|
||||||
.setDryRun(false)
|
|
||||||
.setSystemDisk(new RunInstancesRequest.RunInstancesRequestSystemDisk()
|
|
||||||
.setSize(size)
|
|
||||||
.setCategory(category));
|
|
||||||
try {
|
|
||||||
com.aliyun.teaconsole.Client.log("--------------------批量创建实例开始--------------------");
|
|
||||||
responces = client.runInstances(request1);
|
|
||||||
com.aliyun.teaconsole.Client.log("--------------------创建实例成功,实例ID:" + (responces.body.instanceIdSets.instanceIdSet) + "--------------------");
|
|
||||||
List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> list =
|
|
||||||
GetInstanceProperties.startGet(Common.toJSONString(responces.body.instanceIdSets.instanceIdSet));
|
|
||||||
list.forEach(
|
|
||||||
item -> {
|
|
||||||
String so = item.getPublicIpAddress().toString();
|
|
||||||
String instanceId = item.getInstanceId();
|
|
||||||
InstanceRequest instanceRequest = new InstanceRequest(so, instanceId);
|
|
||||||
redisService.setCacheSet("new:real:column", instanceRequest);
|
|
||||||
System.out.println("公网IP:" + item.getPublicIpAddress().getIpAddress().toString());
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} catch (TeaException error) {
|
|
||||||
com.aliyun.teaconsole.Client.log("--------------------创建实例失败:" + com.aliyun.teautil.Common.toJSONString(error.message) + "--------------------");
|
|
||||||
} catch (Exception _error) {
|
|
||||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
|
||||||
com.aliyun.teaconsole.Client.log("--------------------创建实例失败:" + com.aliyun.teautil.Common.toJSONString(error.message) + "--------------------");
|
|
||||||
}
|
|
||||||
return com.aliyun.teautil.Common.toJSONString(responces.body.instanceIdSets.instanceIdSet);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.yao.server.controller;
|
||||||
|
|
||||||
|
import com.yao.common.config.Result;
|
||||||
|
import com.yao.server.service.GatewayLoadService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/18
|
||||||
|
* @Description: 网关控制层
|
||||||
|
*/
|
||||||
|
@RestController("/gateway")
|
||||||
|
@Log4j2
|
||||||
|
public class GatewayController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GatewayLoadService gatewayLoadService;
|
||||||
|
|
||||||
|
@GetMapping("/load/node")
|
||||||
|
public Result<String> loadNode(){
|
||||||
|
return Result.success(gatewayLoadService.loadNode());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,78 +0,0 @@
|
||||||
package com.yao.server.delete;
|
|
||||||
|
|
||||||
|
|
||||||
import com.aliyun.ecs20140526.Client;
|
|
||||||
import com.aliyun.ecs20140526.models.*;
|
|
||||||
import com.aliyun.teaopenapi.models.Config;
|
|
||||||
import com.aliyun.teautil.Common;
|
|
||||||
import com.yao.common.config.ClientService;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: LiJiaYao
|
|
||||||
* @Date: 2024/4/12
|
|
||||||
* @Description:
|
|
||||||
*/
|
|
||||||
public class DeleteSample {
|
|
||||||
|
|
||||||
public static DescribeInstancesResponse describeInstances(Client client,String regionId,String instanceIds,String instanceName) throws Exception {
|
|
||||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
|
||||||
.setRegionId(regionId)
|
|
||||||
.setInstanceName(instanceName);
|
|
||||||
if (!Common.empty(instanceIds)){
|
|
||||||
describeInstancesRequest.instanceIds = com.aliyun.teautil.Common.toJSONString(com.aliyun.darabonbastring.Client.split(instanceIds, ",", 50));
|
|
||||||
}
|
|
||||||
DescribeInstancesResponse resq = client.describeInstances(describeInstancesRequest);
|
|
||||||
com.aliyun.teaconsole.Client.log("--------------------查询需要删除的实例--------------------");
|
|
||||||
return resq;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void modifyInstanceAttribute(Client client,String instatnceId) throws Exception {
|
|
||||||
ModifyInstanceAttributeRequest req = new ModifyInstanceAttributeRequest()
|
|
||||||
.setInstanceId(instatnceId)
|
|
||||||
.setDeletionProtection(false)
|
|
||||||
;
|
|
||||||
client.modifyInstanceAttribute(req);
|
|
||||||
com.aliyun.teaconsole.Client.log("--------------------"+instatnceId+"释放保护成功--------------------");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void deleteInstances(Client client, String regionId, String instanceIds, String force) throws Exception {
|
|
||||||
DeleteInstancesRequest req = new DeleteInstancesRequest()
|
|
||||||
.setRegionId(regionId)
|
|
||||||
.setInstanceId(com.aliyun.darabonbastring.Client.split(instanceIds, ",", 50))
|
|
||||||
.setForce(com.aliyun.teautil.Common.equalString(force, "true"));
|
|
||||||
DeleteInstancesResponse resp = client.deleteInstances(req);
|
|
||||||
com.aliyun.teaconsole.Client.log("--------------------实例释放成功--------------------");
|
|
||||||
com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(com.aliyun.teautil.Common.toMap(resp)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String delete (String instanceIds) throws Exception {
|
|
||||||
//区域id
|
|
||||||
String regionId = "cn-shanghai";
|
|
||||||
//多个实例id,用英文逗号分割
|
|
||||||
//实例名称
|
|
||||||
String instanceName = "MyFirstEcsInstance";
|
|
||||||
//强制删除有删除保护的机器
|
|
||||||
String deleteProtected = "true";
|
|
||||||
//强制删除运行中的机器
|
|
||||||
String force = "true";
|
|
||||||
com.aliyun.ecs20140526.Client client = ClientService.createEcsClient(regionId);
|
|
||||||
|
|
||||||
if (Common.equalString(deleteProtected,"true")){
|
|
||||||
DescribeInstancesResponse describeInstances = DeleteSample.describeInstances(client, regionId, instanceIds, instanceName);
|
|
||||||
instanceIds="";
|
|
||||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : describeInstances.body.instances.instance) {
|
|
||||||
instanceIds = "" + instance.instanceId + "," + instanceIds + "";
|
|
||||||
if (instance.deletionProtection) {
|
|
||||||
DeleteSample.modifyInstanceAttribute(client, instance.instanceId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
instanceIds = com.aliyun.darabonbastring.Client.subString(instanceIds, 0, -1);
|
|
||||||
}
|
|
||||||
if (Common.empty(instanceIds)){
|
|
||||||
com.aliyun.teaconsole.Client.log("--------------------无有效实例可删除--------------------");
|
|
||||||
}
|
|
||||||
DeleteSample.deleteInstances(client,regionId,instanceIds,force);
|
|
||||||
return instanceIds;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.yao.server.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/18
|
||||||
|
* @Description: 网关实现接口
|
||||||
|
*/
|
||||||
|
public interface GatewayLoadService {
|
||||||
|
/**
|
||||||
|
* 负载节点
|
||||||
|
* @return 负载节点
|
||||||
|
*/
|
||||||
|
String loadNode();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.yao.server.service.impl;
|
||||||
|
|
||||||
|
import com.yao.gateWay.cache.GateWayNodeInfo;
|
||||||
|
import com.yao.gateWay.cache.GatewayLoadNodeCache;
|
||||||
|
import com.yao.gateWay.cache.GatewayLoadSeriesCache;
|
||||||
|
import com.yao.gateWay.cache.GatewayNodeCache;
|
||||||
|
import com.yao.server.service.GatewayLoadService;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/18
|
||||||
|
* @Description: 网关实现层
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class GatewayLoadServiceImpl implements GatewayLoadService {
|
||||||
|
|
||||||
|
private final Long nodeLength = 100L;
|
||||||
|
|
||||||
|
//网关负载节点缓存
|
||||||
|
private final GatewayLoadNodeCache gatewayLoadNodeCache;
|
||||||
|
//网关负载序列
|
||||||
|
private final GatewayLoadSeriesCache gatewayLoadSeriesCache;
|
||||||
|
//网关节点缓存
|
||||||
|
private final GatewayNodeCache gatewayNodeCache;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loadNode() {
|
||||||
|
//序列负载下标
|
||||||
|
Long series = gatewayLoadSeriesCache.incrementAndGet();
|
||||||
|
Long seriesLoadIndex = series % nodeLength;
|
||||||
|
//获取对应下表的节点
|
||||||
|
String loadNodeId = gatewayLoadNodeCache.getByIndex(seriesLoadIndex);
|
||||||
|
//获取节点信息
|
||||||
|
GateWayNodeInfo gateWayNodeInfo = gatewayNodeCache.get(loadNodeId);
|
||||||
|
//获取外网ip
|
||||||
|
return gateWayNodeInfo.getPublicIdAddress();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,19 +1,14 @@
|
||||||
package com.yao.server.service.impl;
|
package com.yao.server.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import com.yao.common.config.Constants;
|
import com.yao.common.config.Constants;
|
||||||
import com.yao.common.domain.WorkGateWayNode;
|
import com.yao.common.domain.WorkGateWayNode;
|
||||||
|
import com.yao.common.mqtt.MqttConnectService;
|
||||||
import com.yao.common.redis.service.RedisService;
|
import com.yao.common.redis.service.RedisService;
|
||||||
import com.yao.server.service.LoadService;
|
import com.yao.server.service.LoadService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.Response;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
|
@ -30,6 +25,12 @@ public class LoadServiceImpl implements LoadService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
|
private MqttConnectService mqttConnectService;
|
||||||
|
|
||||||
|
public LoadServiceImpl(MqttConnectService mqttConnectService) {
|
||||||
|
this.mqttConnectService = mqttConnectService;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String load() {
|
public String load() {
|
||||||
//初始化序列
|
//初始化序列
|
||||||
|
@ -49,7 +50,8 @@ public class LoadServiceImpl implements LoadService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
work:while (true) {
|
work:
|
||||||
|
while (true) {
|
||||||
for (WorkGateWayNode workGateWayNode : nodeIdList) {
|
for (WorkGateWayNode workGateWayNode : nodeIdList) {
|
||||||
Integer nodeWeight = workGateWayNode.getWeight();
|
Integer nodeWeight = workGateWayNode.getWeight();
|
||||||
if (nodeWeight > 0) {
|
if (nodeWeight > 0) {
|
||||||
|
@ -69,7 +71,7 @@ public class LoadServiceImpl implements LoadService {
|
||||||
redisService.deleteObject("work:node:gateway");
|
redisService.deleteObject("work:node:gateway");
|
||||||
redisService.setCacheList("work:node:gateway", loadNodeList);
|
redisService.setCacheList("work:node:gateway", loadNodeList);
|
||||||
CountDownLatch countDownLatch = new CountDownLatch(300);
|
CountDownLatch countDownLatch = new CountDownLatch(300);
|
||||||
new Thread(()->{
|
new Thread(() -> {
|
||||||
for (int i = 0; i < Constants.SUM; i++) {
|
for (int i = 0; i < Constants.SUM; i++) {
|
||||||
long cursor = redisService.increment("cursor", 1L);
|
long cursor = redisService.increment("cursor", 1L);
|
||||||
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
|
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
|
||||||
|
@ -79,7 +81,7 @@ public class LoadServiceImpl implements LoadService {
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
new Thread(()->{
|
new Thread(() -> {
|
||||||
for (int i = 0; i < Constants.SUM; i++) {
|
for (int i = 0; i < Constants.SUM; i++) {
|
||||||
long cursor = redisService.increment("cursor", 1L);
|
long cursor = redisService.increment("cursor", 1L);
|
||||||
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
|
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
|
||||||
|
@ -89,7 +91,7 @@ public class LoadServiceImpl implements LoadService {
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
new Thread(()-> {
|
new Thread(() -> {
|
||||||
for (int i = 0; i < Constants.SUM; i++) {
|
for (int i = 0; i < Constants.SUM; i++) {
|
||||||
Long cursor = redisService.increment("cursor", 1L);
|
Long cursor = redisService.increment("cursor", 1L);
|
||||||
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
|
String cacheList = redisService.getCacheList("work:node:gateway", cursor % 100);
|
||||||
|
@ -117,41 +119,18 @@ public class LoadServiceImpl implements LoadService {
|
||||||
} else {
|
} else {
|
||||||
System.out.println("HashMap 为空!");
|
System.out.println("HashMap 为空!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
public ArrayList<WorkGateWayNode> carWorkGatewayNode(){
|
|
||||||
|
public ArrayList<WorkGateWayNode> carWorkGatewayNode() {
|
||||||
Set<String> ip = redisService.getCacheSet("ECS");
|
Set<String> ip = redisService.getCacheSet("ECS");
|
||||||
ArrayList<WorkGateWayNode> list = new ArrayList<>();
|
ArrayList<WorkGateWayNode> list = new ArrayList<>();
|
||||||
for (String s : ip) {
|
for (String s : ip) {
|
||||||
|
Integer connectSize = mqttConnectService.connectMqtt(s);
|
||||||
String ips = s;
|
WorkGateWayNode workGateWayNode = new WorkGateWayNode();
|
||||||
//请求路径
|
workGateWayNode.setWeight(connectSize);
|
||||||
String URL = "http://" + ips + ":8080/public/cluster";
|
workGateWayNode.setNodeId(s);
|
||||||
OkHttpClient client = new OkHttpClient();
|
list.add(workGateWayNode);
|
||||||
Request request = new Request.Builder()
|
|
||||||
.url(URL)
|
|
||||||
.get()
|
|
||||||
.addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
|
|
||||||
.addHeader("Accesstoken", "")
|
|
||||||
.build();
|
|
||||||
Response response = null;
|
|
||||||
try {
|
|
||||||
response = client.newCall(request).execute();
|
|
||||||
log.info(response);
|
|
||||||
JSONArray jsonArray = JSONArray.parseArray(response.body().string());
|
|
||||||
JSONObject object = jsonArray.getJSONObject(0);
|
|
||||||
JSONObject mqttInfo = object.getJSONObject("mqttInfo");
|
|
||||||
Integer connectSize = mqttInfo.getIntValue("connectSize");
|
|
||||||
log.info(ips + " 的fluxmq连接数为:" + connectSize);
|
|
||||||
WorkGateWayNode workGateWayNode = new WorkGateWayNode();
|
|
||||||
workGateWayNode.setWeight(connectSize);
|
|
||||||
workGateWayNode.setNodeId(ips);
|
|
||||||
list.add(workGateWayNode);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
|
@ -171,7 +150,6 @@ public class LoadServiceImpl implements LoadService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//计数
|
//计数
|
||||||
@Log4j2
|
@Log4j2
|
||||||
class SitNode {
|
class SitNode {
|
||||||
|
@ -183,8 +161,8 @@ class SitNode {
|
||||||
sitNodeMap.put(nodeId, orDefault + 1);
|
sitNodeMap.put(nodeId, orDefault + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<String,Integer> show() {
|
public static HashMap<String, Integer> show() {
|
||||||
HashMap<String,Integer> map = new HashMap<>();
|
HashMap<String, Integer> map = new HashMap<>();
|
||||||
sitNodeMap.forEach((key, val) -> {
|
sitNodeMap.forEach((key, val) -> {
|
||||||
map.put(key, val);
|
map.put(key, val);
|
||||||
log.info(key + "-------" + val);
|
log.info(key + "-------" + val);
|
||||||
|
|
|
@ -5,8 +5,6 @@ import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||||
import com.aliyun.tea.TeaException;
|
import com.aliyun.tea.TeaException;
|
||||||
import com.aliyun.teautil.models.RuntimeOptions;
|
import com.aliyun.teautil.models.RuntimeOptions;
|
||||||
import com.yao.common.config.ClientService;
|
|
||||||
import com.yao.common.config.GetInstanceProperties;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -22,28 +20,28 @@ public class QueryIp {
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args_) throws Exception {
|
public static void main(String[] args_) throws Exception {
|
||||||
Client ecsClient = ClientService.createEcsClient("cn-shanghai");
|
// Client ecsClient = ClientService.createEcsClient("cn-shanghai");
|
||||||
com.aliyun.ecs20140526.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.ecs20140526.models.DescribeInstancesRequest()
|
// com.aliyun.ecs20140526.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.ecs20140526.models.DescribeInstancesRequest()
|
||||||
.setRegionId(ecsClient._regionId);
|
// .setRegionId(ecsClient._regionId);
|
||||||
RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DescribeInstancesResponse resp = ecsClient.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
// DescribeInstancesResponse resp = ecsClient.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||||
DescribeInstancesResponseBody body = resp.getBody();
|
// DescribeInstancesResponseBody body = resp.getBody();
|
||||||
DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances = body.getInstances();
|
// DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances = body.getInstances();
|
||||||
com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(instances));
|
// com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(instances));
|
||||||
List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> instance = instances.getInstance();
|
// List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> instance = instances.getInstance();
|
||||||
|
//
|
||||||
instance.forEach(i->{
|
// instance.forEach(i->{
|
||||||
try {
|
// try {
|
||||||
System.out.println("实列id:"+i.getInstanceId());
|
// System.out.println("实列id:"+i.getInstanceId());
|
||||||
List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> list = GetInstanceProperties.startGet(i.getInstanceId());
|
// List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> list = GetInstanceProperties.startGet(i.getInstanceId());
|
||||||
DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instancesInstance = list.get(0);
|
// DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instancesInstance = list.get(0);
|
||||||
System.out.println(instancesInstance.getPublicIpAddress().ipAddress);
|
// System.out.println(instancesInstance.getPublicIpAddress().ipAddress);
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
} catch (TeaException error) {
|
} catch (TeaException error) {
|
||||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||||
// 错误 message
|
// 错误 message
|
||||||
|
|
|
@ -6,7 +6,6 @@ import com.aliyun.ecs20140526.models.DescribeAvailableResourceResponse;
|
||||||
import com.aliyun.tea.TeaException;
|
import com.aliyun.tea.TeaException;
|
||||||
import com.aliyun.tea.TeaModel;
|
import com.aliyun.tea.TeaModel;
|
||||||
import com.aliyun.teaopenapi.models.Config;
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
import com.yao.common.config.ClientService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: LiJiaYao
|
* @Author: LiJiaYao
|
||||||
|
@ -33,9 +32,9 @@ public class Test {
|
||||||
String ioOptimized = "optimized";
|
String ioOptimized = "optimized";
|
||||||
// 实例规格
|
// 实例规格
|
||||||
String instanceType = "ecs.e-c1m1.large";
|
String instanceType = "ecs.e-c1m1.large";
|
||||||
Client client = ClientService.createEcsClient(regionId);
|
// Client client = ClientService.createEcsClient(regionId);
|
||||||
// 查询指定地域下所有可用区的库存供应情况
|
// 查询指定地域下所有可用区的库存供应情况
|
||||||
Test.describeAvailableResource(client, regionId, destinationResource, ioOptimized, instanceType);
|
// Test.describeAvailableResource(client, regionId, destinationResource, ioOptimized, instanceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,24 +1,19 @@
|
||||||
package com.yao.server.timer;
|
package com.yao.server.timer;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
import com.aliyun.teautil.Common;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.yao.common.aliy.AliYunEcsService;
|
||||||
import com.yao.common.config.GetInstanceProperties;
|
import com.yao.common.aliy.model.EcsSelectModel;
|
||||||
import com.yao.common.domain.InstanceInfo;
|
import com.yao.common.domain.aliy.InstanceInfo;
|
||||||
import com.yao.common.domain.InstanceRequest;
|
import com.yao.common.domain.aliy.InstanceRequest;
|
||||||
import com.yao.common.domain.WorkGateWayNode;
|
import com.yao.common.mqtt.MqttConnectService;
|
||||||
import com.yao.common.redis.service.RedisService;
|
import com.yao.common.redis.service.RedisService;
|
||||||
import com.yao.server.add.Sample;
|
|
||||||
import com.yao.server.delete.DeleteSample;
|
|
||||||
import io.netty.util.internal.StringUtil;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import okhttp3.*;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -35,56 +30,49 @@ public class Timer {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
private AliYunEcsService aliYunEcsService;
|
||||||
|
private MqttConnectService mqttConnectService;
|
||||||
|
|
||||||
|
public Timer(AliYunEcsService aliYunEcsService, MqttConnectService mqttConnectService) {
|
||||||
|
this.aliYunEcsService = aliYunEcsService;
|
||||||
|
this.mqttConnectService = mqttConnectService;
|
||||||
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
@Scheduled(cron = "0/10 * * * * ?")
|
@Scheduled(cron = "0/20 * * * * ?")
|
||||||
public void timer() {
|
public void timer() {
|
||||||
redisService.deleteObject("new:real:column");
|
long startTime = System.currentTimeMillis(); // 记录开始时间
|
||||||
List<InstanceInfo> myFirstEcsInstance = GetInstanceProperties.selectECS("MyFirstEcsInstance");
|
long endTime = startTime + 10 * 60 * 1000; // 设置结束时间为10分钟后
|
||||||
for (InstanceInfo instanceInfo : myFirstEcsInstance) {
|
// redisService.deleteObject("new:real:column");
|
||||||
String publicIpAddress = instanceInfo.getPublicIpAddress();
|
Set<InstanceInfo> instance = redisService.getCacheSet("new:real:column");
|
||||||
String instanceId = instanceInfo.getInstanceId();
|
// List<InstanceInfo> myFirstEcsInstance = null;
|
||||||
InstanceRequest instanceRequest = new InstanceRequest(publicIpAddress, instanceId);
|
// try {
|
||||||
redisService.setCacheSet("new:real:column", instanceRequest);
|
// myFirstEcsInstance = aliYunEcsService.selectList(ecsSelectModelName("MyFirstEcsInstance"));
|
||||||
}
|
// for (InstanceInfo instanceInfo : myFirstEcsInstance) {
|
||||||
// Set<InstanceRequest> instance = redisService.getCacheSet("new:real:column");
|
// String publicIpAddress = instanceInfo.getPublicIpAddress();
|
||||||
if (myFirstEcsInstance.isEmpty()) {
|
// String instanceId = instanceInfo.getInstanceId();
|
||||||
if (myFirstEcsInstance.isEmpty()) {
|
// InstanceRequest instanceRequest = new InstanceRequest(publicIpAddress, instanceId);
|
||||||
try {
|
// redisService.setCacheSet("new:real:column", instanceRequest);
|
||||||
Sample.startCreate();
|
// }
|
||||||
} catch (Exception e) {
|
if (instance.isEmpty()) {
|
||||||
throw new RuntimeException(e);
|
// if (myFirstEcsInstance.isEmpty()) {
|
||||||
}
|
try {
|
||||||
|
aliYunEcsService.startCreate();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
for (InstanceInfo s : instance) {
|
||||||
for (InstanceInfo s : myFirstEcsInstance) {
|
Integer connectSize = mqttConnectService.connectMqtt(s.getPublicIpAddress());
|
||||||
String ip = s.getPublicIpAddress();
|
List<String> instanceId = null;
|
||||||
//请求路径
|
|
||||||
String URL = "http://" + ip + ":8080/public/cluster";
|
|
||||||
OkHttpClient client = new OkHttpClient();
|
|
||||||
Request request = new Request.Builder()
|
|
||||||
.url(URL)
|
|
||||||
.get()
|
|
||||||
.addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
|
|
||||||
.addHeader("Accesstoken", "")
|
|
||||||
.build();
|
|
||||||
redisService.setCacheSet("ecsIp", ip);
|
|
||||||
try {
|
|
||||||
Response response = client.newCall(request).execute();
|
|
||||||
log.info(response);
|
|
||||||
JSONArray jsonArray = JSONArray.parseArray(response.body().string());
|
|
||||||
JSONObject object = jsonArray.getJSONObject(0);
|
|
||||||
JSONObject mqttInfo = object.getJSONObject("mqttInfo");
|
|
||||||
int connectSize = mqttInfo.getIntValue("connectSize");
|
|
||||||
log.info(ip + " 的fluxmq连接数为:" + connectSize);
|
|
||||||
String instanceId = null;
|
|
||||||
String deleteInstanceId = null;
|
String deleteInstanceId = null;
|
||||||
if (connectSize >= 10) {
|
if (connectSize >= 80) {
|
||||||
//执行节点扩容
|
//执行节点扩容
|
||||||
//返回实例的ID
|
//返回实例的ID
|
||||||
if (!instanceId.isEmpty()) {
|
if (!instanceId.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
instanceId = Sample.startCreate();
|
instanceId = aliYunEcsService.startCreate();
|
||||||
log.info("扩容成功!");
|
log.info("扩容成功!");
|
||||||
log.info("扩容的节点id为:" + instanceId);
|
log.info("扩容的节点id为:" + instanceId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -92,20 +80,43 @@ public class Timer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (connectSize <= 5) {
|
if (connectSize <= 20 && System.currentTimeMillis() < endTime) {
|
||||||
// if (!deleteInstanceId.isEmpty()) {
|
// if (!deleteInstanceId.isEmpty()) {
|
||||||
try {
|
aliYunEcsService.delete(s.getInstanceId());
|
||||||
deleteInstanceId = DeleteSample.delete(s.getInstanceId());
|
//删除实列以后再去把redis的值删除 再去通知重新上线
|
||||||
log.info("缩容成功!");
|
redisService.deleteCacheMapValue("new:real:column", Common.toJSONString(s));
|
||||||
log.info("锁容的节点id为:" + deleteInstanceId);
|
redisService.setCacheSet("reconnectCar",s.getPublicIpAddress());
|
||||||
} catch (Exception e) {
|
log.info("缩容成功!");
|
||||||
throw new RuntimeException(e);
|
log.info("锁容的节点id为:" + deleteInstanceId);
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* 查出来数据以后把值返回给要查的数据
|
||||||
|
*
|
||||||
|
* @param instance
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
// public EcsSelectModel ecsSelectModel(Set<InstanceInfo> instance) {
|
||||||
|
// List<String> instanceIdList = new ArrayList<>();
|
||||||
|
// for (InstanceInfo req : instance) {
|
||||||
|
// instanceIdList.add(req.getInstanceId());
|
||||||
|
// }
|
||||||
|
// EcsSelectModel ecsSelectModel = new EcsSelectModel();
|
||||||
|
// ecsSelectModel.setInstanceIdList(instanceIdList);
|
||||||
|
// return ecsSelectModel;
|
||||||
|
// }
|
||||||
|
// public EcsSelectModel ecsSelectModelName(String instanceName) {
|
||||||
|
// List<String> instanceIdList = new ArrayList<>();
|
||||||
|
// instanceIdList.add(instanceName);
|
||||||
|
// EcsSelectModel ecsSelectModel = new EcsSelectModel();
|
||||||
|
// ecsSelectModel.setInstanceIdList(instanceIdList);
|
||||||
|
// return ecsSelectModel;
|
||||||
|
// }
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
|
@ -23,3 +23,26 @@ spring:
|
||||||
# 共享配置
|
# 共享配置
|
||||||
shared-configs:
|
shared-configs:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
config:
|
||||||
|
aly:
|
||||||
|
access-key-id: LTAI5t7kDVgLdPETn9TXjFaW
|
||||||
|
access-key-secret: 79UjUBiwoQgADVyJjrOX9B4KVJn0lS
|
||||||
|
# 区域
|
||||||
|
region-id: cn-shanghai
|
||||||
|
# 镜像
|
||||||
|
image-id: m-uf6ii43j71vmvcc84cb9
|
||||||
|
# 实例规格
|
||||||
|
instance-type: ecs.e-c1m1.large
|
||||||
|
# 安全组
|
||||||
|
security-group-id: sg-uf61d7chl7g03zmc4rrj
|
||||||
|
# 虚拟
|
||||||
|
v-switch-id: vsw-uf6w1g7dugq9i83omkes2
|
||||||
|
# 网络计费类型
|
||||||
|
internet-charge-type: PayByTraffic
|
||||||
|
#系统大小
|
||||||
|
size: 20
|
||||||
|
# 系统盘的云盘种类
|
||||||
|
category: cloud_essd
|
||||||
|
# ECS实例的计费方式
|
||||||
|
instance-charge-type: PostPaid
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue