Compare commits
3 Commits
7e2ad67a64
...
b9529234e9
Author | SHA1 | Date |
---|---|---|
|
b9529234e9 | |
|
0ed0f872e9 | |
|
add31c49fa |
|
@ -82,31 +82,37 @@
|
|||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>ecs20140526</artifactId>
|
||||
<version>5.1.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-openapi</artifactId>
|
||||
<version>0.3.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-console</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-util</artifactId>
|
||||
<version>0.2.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>cloudapi20160714</artifactId>
|
||||
<version>3.10.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>aliyun-repo</id>
|
||||
<url>https://maven.aliyun.com/repository/public</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.vehiclegateway.instance;
|
||||
|
||||
import com.aliyun.cloudapi20160714.models.DescribeInstancesRequest;
|
||||
import com.aliyun.cloudapi20160714.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @ClassName acquireInstance
|
||||
* @Description 描述
|
||||
* @Author YiBo.Liu
|
||||
* @Date 2024/9/29 17:24
|
||||
*/
|
||||
@Component
|
||||
public class AcquireInstance {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,16 +1,26 @@
|
|||
package com.muyu.vehiclegateway.instance;
|
||||
|
||||
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.ecs20140526.models.RunInstancesRequest;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName GenerateInstance
|
||||
* @Description 描述
|
||||
|
@ -22,11 +32,15 @@ import org.springframework.stereotype.Component;
|
|||
@Tag(name = "程序启动创建ECS服务器实例")
|
||||
public class GenerateInstance implements ApplicationRunner {
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 启动自动创建实例
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void generateInstance() throws Exception {
|
||||
public List<String> generateInstance() throws Exception {
|
||||
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
Client client = CreateClient.createClient();
|
||||
|
@ -38,7 +52,7 @@ public class GenerateInstance implements ApplicationRunner {
|
|||
// 设置地域ID
|
||||
.setRegionId("cn-shanghai")
|
||||
// 设置镜像ID
|
||||
.setImageId("m-uf64hrlxa0rbmyd7ovvq")
|
||||
.setImageId("m-uf63thq7h50ng72jpoq2")
|
||||
// 设置实例类型
|
||||
.setInstanceType("ecs.t6-c1m1.large")
|
||||
// 设置安全组ID
|
||||
|
@ -80,6 +94,36 @@ public class GenerateInstance implements ApplicationRunner {
|
|||
System.out.println(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
}
|
||||
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-shanghai");
|
||||
|
||||
//创建运行时选择对象,用于配置运行时的选项参数
|
||||
RuntimeOptions runtimeOptions = new RuntimeOptions();
|
||||
|
||||
//获取实例列表
|
||||
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtimeOptions);
|
||||
|
||||
//提取实例ID集合
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
|
||||
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()) {
|
||||
list.add(instance.getInstanceId());
|
||||
list.add(instance.getPublicIpAddress().ipAddress.get(0));
|
||||
list.add(instance.getStatus());
|
||||
|
||||
log.info("实例id为:"+instance.getInstanceId());
|
||||
log.info("实例ip为:"+instance.getPublicIpAddress().ipAddress.get(0));
|
||||
log.info("实例状态为:"+instance.getStatus());
|
||||
|
||||
}
|
||||
|
||||
redisService.setCacheList("shili",list);
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-vehicleGateway"/>
|
||||
<property name="log.path" value="logs/cloud-vehicle-gateway"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-vehicleGateway"/>
|
||||
<property name="log.path" value="logs/cloud-vehicle-gateway"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-vehicleGateway"/>
|
||||
<property name="log.path" value="logs/cloud-vehicle-gateway"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
|
30
pom.xml
30
pom.xml
|
@ -43,6 +43,12 @@
|
|||
<knife4j-openapi3.version>4.1.0</knife4j-openapi3.version>
|
||||
<xxl-job-core.version>2.4.1</xxl-job-core.version>
|
||||
<swagger.an.jakarta.verison>2.2.8</swagger.an.jakarta.verison>
|
||||
<ecs20140526.version>5.1.8</ecs20140526.version>
|
||||
<tea-openapi.version>0.3.2</tea-openapi.version>
|
||||
<tea-console.version>0.0.1</tea-console.version>
|
||||
<tea-util.version>0.2.21</tea-util.version>
|
||||
<cloudapi20160714.version>3.10.1</cloudapi20160714.version>
|
||||
|
||||
<kafka.clients.verison>3.0.0</kafka.clients.verison>
|
||||
<iotdb-session.verison>1.3.1</iotdb-session.verison>
|
||||
</properties>
|
||||
|
@ -186,27 +192,12 @@
|
|||
<version>${transmittable-thread-local.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- swagger3文档 -->
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations-jakarta</artifactId>
|
||||
<version>${swagger.an.jakarta.verison}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Kafka客户端 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.kafka</groupId>
|
||||
<artifactId>kafka-clients</artifactId>
|
||||
<version>${kafka.clients.verison}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- IotDB会话-->
|
||||
<dependency>
|
||||
<groupId>org.apache.iotdb</groupId>
|
||||
<artifactId>iotdb-session</artifactId>
|
||||
<version>${iotdb-session.verison}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 核心模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
|
@ -298,14 +289,7 @@
|
|||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- kafka模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-kafka</artifactId>
|
||||
<version>${muyu.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 企业业务平台 - 公共模块 -->
|
||||
<!-- 企业业务平台 - 公告模块 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-modules-enterprise-common</artifactId>
|
||||
|
|
Loading…
Reference in New Issue