From 71f54f1488af5272175d4b784e88ea442e6bf600 Mon Sep 17 00:00:00 2001
From: Saisai Liu <1374434128@qq.com>
Date: Wed, 29 May 2024 08:46:28 +0800
Subject: [PATCH] =?UTF-8?q?feat():=E9=87=8D=E6=9E=84springboot=E9=A1=B9?=
=?UTF-8?q?=E7=9B=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 38 ++++++++
.idea/.gitignore | 8 ++
.idea/encodings.xml | 6 ++
.idea/misc.xml | 14 +++
.idea/vcs.xml | 6 ++
pom.xml | 77 ++++++++++++++++
src/main/java/com/mobai/Main.java | 7 ++
.../java/com/mobai/TrainLoadApplication.java | 13 +++
.../controller/FluxGetInfoController.java | 28 ++++++
.../java/com/mobai/domain/ApifoxModel.java | 56 ++++++++++++
src/main/java/com/mobai/domain/CPUInfo.java | 25 ++++++
src/main/java/com/mobai/domain/Constants.java | 12 +++
src/main/java/com/mobai/domain/FlowInfo.java | 28 ++++++
src/main/java/com/mobai/domain/JVMInfo.java | 56 ++++++++++++
src/main/java/com/mobai/domain/MqttInfo.java | 52 +++++++++++
src/main/java/com/mobai/domain/Result.java | 89 +++++++++++++++++++
.../java/com/mobai/mq/fluxmq/FluxMqInit.java | 34 +++++++
.../java/com/mobai/mq/rabbitmq/Custom.java | 35 ++++++++
.../com/mobai/openApi/CreateInstance.java | 55 ++++++++++++
.../com/mobai/openApi/SelectInstences.java | 82 +++++++++++++++++
.../com/mobai/service/FluxGetInfoService.java | 15 ++++
.../mobai/service/FluxGetInfoServiceImpl.java | 63 +++++++++++++
src/test/java/LoginTest.java | 30 +++++++
src/test/java/TestGet.java | 31 +++++++
24 files changed, 860 insertions(+)
create mode 100644 .gitignore
create mode 100644 .idea/.gitignore
create mode 100644 .idea/encodings.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/vcs.xml
create mode 100644 pom.xml
create mode 100644 src/main/java/com/mobai/Main.java
create mode 100644 src/main/java/com/mobai/TrainLoadApplication.java
create mode 100644 src/main/java/com/mobai/controller/FluxGetInfoController.java
create mode 100644 src/main/java/com/mobai/domain/ApifoxModel.java
create mode 100644 src/main/java/com/mobai/domain/CPUInfo.java
create mode 100644 src/main/java/com/mobai/domain/Constants.java
create mode 100644 src/main/java/com/mobai/domain/FlowInfo.java
create mode 100644 src/main/java/com/mobai/domain/JVMInfo.java
create mode 100644 src/main/java/com/mobai/domain/MqttInfo.java
create mode 100644 src/main/java/com/mobai/domain/Result.java
create mode 100644 src/main/java/com/mobai/mq/fluxmq/FluxMqInit.java
create mode 100644 src/main/java/com/mobai/mq/rabbitmq/Custom.java
create mode 100644 src/main/java/com/mobai/openApi/CreateInstance.java
create mode 100644 src/main/java/com/mobai/openApi/SelectInstences.java
create mode 100644 src/main/java/com/mobai/service/FluxGetInfoService.java
create mode 100644 src/main/java/com/mobai/service/FluxGetInfoServiceImpl.java
create mode 100644 src/test/java/LoginTest.java
create mode 100644 src/test/java/TestGet.java
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..c2bae49
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..82dbec8
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..1d0ae8a
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,77 @@
+
+
+ 4.0.0
+
+ com.mobai
+ car_load
+ 1.0-SNAPSHOT
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-dependencies
+ 2.7.15
+ pom
+ import
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-amqp
+
+
+
+ com.alibaba.fastjson2
+ fastjson2
+ 2.0.46
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.13.0
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+ com.aliyun
+ ecs20140526
+ 5.1.8
+
+
+
+
+
diff --git a/src/main/java/com/mobai/Main.java b/src/main/java/com/mobai/Main.java
new file mode 100644
index 0000000..a56227b
--- /dev/null
+++ b/src/main/java/com/mobai/Main.java
@@ -0,0 +1,7 @@
+package com.mobai;
+
+public class Main {
+ public static void main(String[] args) {
+ System.out.println("Hello world!");
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/mobai/TrainLoadApplication.java b/src/main/java/com/mobai/TrainLoadApplication.java
new file mode 100644
index 0000000..5210c93
--- /dev/null
+++ b/src/main/java/com/mobai/TrainLoadApplication.java
@@ -0,0 +1,13 @@
+package com.mobai;
+
+import lombok.extern.log4j.Log4j2;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@Log4j2
+@SpringBootApplication
+public class TrainLoadApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(TrainLoadApplication.class);
+ }
+}
diff --git a/src/main/java/com/mobai/controller/FluxGetInfoController.java b/src/main/java/com/mobai/controller/FluxGetInfoController.java
new file mode 100644
index 0000000..bcdd6aa
--- /dev/null
+++ b/src/main/java/com/mobai/controller/FluxGetInfoController.java
@@ -0,0 +1,28 @@
+package com.mobai.controller;
+
+import com.mobai.domain.Result;
+import com.mobai.service.FluxGetInfoService;
+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.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @ClassName FluxGetInfo
+ * @Description 描述
+ * @Author SaiSai.Liu
+ * @Date 2024/5/28 22:00
+ */
+@RestController
+@Log4j2
+@RequestMapping("fluxmq")
+public class FluxGetInfoController {
+ @Autowired
+ private FluxGetInfoService fluxGetInfoService;
+
+ @GetMapping("getInfo")
+ public Result getInfo(){
+ return fluxGetInfoService.getInfo();
+ }
+}
diff --git a/src/main/java/com/mobai/domain/ApifoxModel.java b/src/main/java/com/mobai/domain/ApifoxModel.java
new file mode 100644
index 0000000..5f49b04
--- /dev/null
+++ b/src/main/java/com/mobai/domain/ApifoxModel.java
@@ -0,0 +1,56 @@
+// ApifoxModel.java
+
+package com.mobai.domain;
+
+@lombok.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;
+}
+
diff --git a/src/main/java/com/mobai/domain/CPUInfo.java b/src/main/java/com/mobai/domain/CPUInfo.java
new file mode 100644
index 0000000..1567619
--- /dev/null
+++ b/src/main/java/com/mobai/domain/CPUInfo.java
@@ -0,0 +1,25 @@
+package com.mobai.domain;
+
+@lombok.Data
+public class CPUInfo {
+ /**
+ * CPU核数
+ */
+ private long cpuNum;
+ /**
+ * 内核态使用率
+ */
+ private String cSys;
+ /**
+ * 空闲率
+ */
+ private String idle;
+ /**
+ * I/O等待
+ */
+ private String iowait;
+ /**
+ * 用户态使用率
+ */
+ private String user;
+}
diff --git a/src/main/java/com/mobai/domain/Constants.java b/src/main/java/com/mobai/domain/Constants.java
new file mode 100644
index 0000000..52133ae
--- /dev/null
+++ b/src/main/java/com/mobai/domain/Constants.java
@@ -0,0 +1,12 @@
+package com.mobai.domain;
+
+/**
+ * @ClassName Constants
+ * @Description 描述
+ * @Author SaiSai.Liu
+ * @Date 2024/5/28 22:05
+ */
+public class Constants {
+ public static final int SUCCESS = 200;
+ public static final int FAIL = 500;
+}
diff --git a/src/main/java/com/mobai/domain/FlowInfo.java b/src/main/java/com/mobai/domain/FlowInfo.java
new file mode 100644
index 0000000..1d704ae
--- /dev/null
+++ b/src/main/java/com/mobai/domain/FlowInfo.java
@@ -0,0 +1,28 @@
+package com.mobai.domain;
+
+/**
+ * 节点状态
+ */
+@lombok.Data
+public class FlowInfo {
+ /**
+ * 上次读取吞吐量
+ */
+ private String lastReadThroughput;
+ /**
+ * 上次写入吞吐量
+ */
+ private String lastWriteThroughput;
+ /**
+ * 读取总吞吐量
+ */
+ private String readBytesHistory;
+ /**
+ * 实写字节
+ */
+ private String realWriteBytes;
+ /**
+ * 写入总吞吐量
+ */
+ private String writeBytesHistory;
+}
diff --git a/src/main/java/com/mobai/domain/JVMInfo.java b/src/main/java/com/mobai/domain/JVMInfo.java
new file mode 100644
index 0000000..9aa4708
--- /dev/null
+++ b/src/main/java/com/mobai/domain/JVMInfo.java
@@ -0,0 +1,56 @@
+package com.mobai.domain;
+
+/**
+ * JVM使用信息
+ */
+@lombok.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;
+}
diff --git a/src/main/java/com/mobai/domain/MqttInfo.java b/src/main/java/com/mobai/domain/MqttInfo.java
new file mode 100644
index 0000000..4f2e4a0
--- /dev/null
+++ b/src/main/java/com/mobai/domain/MqttInfo.java
@@ -0,0 +1,52 @@
+package com.mobai.domain;
+
+/**
+ * MQTT事件信息
+ */
+@lombok.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;
+}
diff --git a/src/main/java/com/mobai/domain/Result.java b/src/main/java/com/mobai/domain/Result.java
new file mode 100644
index 0000000..8ffe5ae
--- /dev/null
+++ b/src/main/java/com/mobai/domain/Result.java
@@ -0,0 +1,89 @@
+package com.mobai.domain;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * 响应信息主体
+ *
+ * @author muyu
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class Result implements Serializable {
+ /**
+ * 成功
+ */
+ public static final int SUCCESS = Constants.SUCCESS;
+ /**
+ * 失败
+ */
+ public static final int FAIL = Constants.FAIL;
+
+
+ private static final long serialVersionUID = 1L;
+ private int code;
+
+ private String msg;
+
+ private T data;
+
+ public static Result success () {
+ return restResult(null, SUCCESS, null);
+ }
+
+ public static Result success (T data) {
+ return restResult(data, SUCCESS, null);
+ }
+
+ public static Result success (T data, String msg) {
+ return restResult(data, SUCCESS, msg);
+ }
+
+ public static Result error () {
+ return restResult(null, FAIL, null);
+ }
+
+ public static Result error (String msg) {
+ return restResult(null, FAIL, msg);
+ }
+
+ public static Result error (T data) {
+ return restResult(data, FAIL, null);
+ }
+
+ public static Result error (T data, String msg) {
+ return restResult(data, FAIL, msg);
+ }
+
+ public static Result error (int code, String msg) {
+ return restResult(null, code, msg);
+ }
+
+ public static Result warn (int code, String msg) {
+ return restResult(null, code, msg);
+ }
+
+ private static Result restResult (T data, int code, String msg) {
+ return Result.builder()
+ .code(code)
+ .data(data)
+ .msg(msg)
+ .build();
+ }
+
+ public static Boolean isError (Result ret) {
+ return !isSuccess(ret);
+ }
+
+ public static Boolean isSuccess (Result ret) {
+ return Result.SUCCESS == ret.getCode();
+ }
+
+}
diff --git a/src/main/java/com/mobai/mq/fluxmq/FluxMqInit.java b/src/main/java/com/mobai/mq/fluxmq/FluxMqInit.java
new file mode 100644
index 0000000..5e1e35e
--- /dev/null
+++ b/src/main/java/com/mobai/mq/fluxmq/FluxMqInit.java
@@ -0,0 +1,34 @@
+package com.mobai.mq.fluxmq;
+
+import okhttp3.*;
+
+import java.io.IOException;
+
+/**
+ * @ClassName FluxMqInit
+ * @Description 描述
+ * @Author SaiSai.Liu
+ * @Date 2024/5/27 9:57
+ */
+public class FluxMqInit {
+ public Response loginFluxMq(){
+ OkHttpClient client = new OkHttpClient().newBuilder()
+ .build();
+ MediaType mediaType = MediaType.parse("application/json");
+ RequestBody body = RequestBody.create(mediaType, "{\r\n \"username\": \"fluxmq\",\r\n \"password\": \"fluxmq\"\r\n}");
+ Request request = new Request.Builder()
+ .url("http://fluxmq.muyu.icu/public/login")
+ .method("POST", body)
+ .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
+ .addHeader("Content-Type", "application/json")
+ .build();
+ Response response = null;
+ try {
+ response = client.newCall(request).execute();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return response;
+ }
+
+}
diff --git a/src/main/java/com/mobai/mq/rabbitmq/Custom.java b/src/main/java/com/mobai/mq/rabbitmq/Custom.java
new file mode 100644
index 0000000..b8d98c2
--- /dev/null
+++ b/src/main/java/com/mobai/mq/rabbitmq/Custom.java
@@ -0,0 +1,35 @@
+package com.mobai.mq.rabbitmq;
+
+import com.rabbitmq.client.Channel;
+import org.springframework.amqp.core.ExchangeTypes;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.Exchange;
+import org.springframework.amqp.rabbit.annotation.Queue;
+import org.springframework.amqp.rabbit.annotation.QueueBinding;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+
+/**
+ * @ClassName Custom
+ * @Description 描述
+ * @Author SaiSai.Liu
+ * @Date 2024/5/26 15:25
+ */
+@Component
+public class Custom {
+
+ @RabbitListener(bindings = @QueueBinding(value = @Queue(value = "send_sms_queue"),
+ exchange = @Exchange(value = "null",type = ExchangeTypes.DIRECT)))
+ public void mqCustom(Object data, Message message, Channel channel){
+ System.out.println(data.toString());
+ try {
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+}
diff --git a/src/main/java/com/mobai/openApi/CreateInstance.java b/src/main/java/com/mobai/openApi/CreateInstance.java
new file mode 100644
index 0000000..d3c561d
--- /dev/null
+++ b/src/main/java/com/mobai/openApi/CreateInstance.java
@@ -0,0 +1,55 @@
+// This file is auto-generated, don't edit it. Thanks.
+package com.mobai.openApi;
+
+import com.aliyun.tea.TeaException;
+
+public class CreateInstance {
+
+ /**
+ * 使用AK&SK初始化账号Client
+ * @return Client
+ * @throws Exception
+ */
+ public static com.aliyun.ecs20140526.Client createClient() throws Exception {
+ // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
+ // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
+ com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
+ // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
+ .setAccessKeyId("LTAI5tKaz3hHJ8pkgF7iem8b")
+ // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
+ .setAccessKeySecret("CApa5sl414bKC8GwD8uBtINuT26Ocj");
+ // Endpoint 请参考 https://api.aliyun.com/product/Ecs
+ config.endpoint = "ecs.cn-zhangjiakou.aliyuncs.com";
+ return new com.aliyun.ecs20140526.Client(config);
+ }
+
+ public static void main(String[] args_) throws Exception {
+ java.util.List args = java.util.Arrays.asList(args_);
+ com.aliyun.ecs20140526.Client client = CreateInstance.createClient();
+ com.aliyun.ecs20140526.models.RunInstancesRequest runInstancesRequest = new com.aliyun.ecs20140526.models.RunInstancesRequest()
+ .setRegionId("cn-zhangjiakou")
+ .setLaunchTemplateName("basic_model")
+ .setLaunchTemplateId("lt-8vb71bkyjwcqmcd98ah4");
+ com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
+ try {
+ // 复制代码运行请自行打印 API 的返回值
+ client.runInstancesWithOptions(runInstancesRequest, runtime);
+ } catch (TeaException error) {
+ // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
+ // 错误 message
+ System.out.println(error.getMessage());
+ // 诊断地址
+ System.out.println(error.getData().get("Recommend"));
+ com.aliyun.teautil.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"));
+ com.aliyun.teautil.Common.assertAsString(error.message);
+ }
+ System.out.println("实例创建成功");
+ }
+}
diff --git a/src/main/java/com/mobai/openApi/SelectInstences.java b/src/main/java/com/mobai/openApi/SelectInstences.java
new file mode 100644
index 0000000..4813124
--- /dev/null
+++ b/src/main/java/com/mobai/openApi/SelectInstences.java
@@ -0,0 +1,82 @@
+// This file is auto-generated, don't edit it. Thanks.
+package com.mobai.openApi;
+
+
+import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
+import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
+import com.aliyun.tea.TeaException;
+import lombok.extern.log4j.Log4j2;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Log4j2
+public class SelectInstences {
+
+ /**
+ * 使用AK&SK初始化账号Client
+ *
+ * @return Client
+ * @throws Exception
+ */
+ public static com.aliyun.ecs20140526.Client createClient() throws Exception {
+ // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
+ // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
+ com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
+ // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
+ .setAccessKeyId("LTAI5t7vsLXtqTJKve7JipnX")
+ // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
+ .setAccessKeySecret("AIyMaSTKQtsB1V5sVqlNAGbQzxgXnS");
+ // Endpoint 请参考 https://api.aliyun.com/product/Ecs
+ config.endpoint = "ecs.cn-zhangjiakou.aliyuncs.com";
+ return new com.aliyun.ecs20140526.Client(config);
+ }
+
+ public static void main(String[] args_) throws Exception {
+ List ips = new ArrayList<>();
+ List args = java.util.Arrays.asList(args_);
+ com.aliyun.ecs20140526.Client client = SelectInstences.createClient();
+ com.aliyun.ecs20140526.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.ecs20140526.models.DescribeInstancesRequest()
+// .setImageId("m-8vb8qnidv34yj3nbirhc")
+ .setRegionId("cn-zhangjiakou");
+ com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
+ try {
+ // 复制代码运行请自行打印 API 的返回值
+ DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
+ DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstances instances = describeInstancesResponse.getBody().getInstances();
+ List instance =
+ instances.getInstance();
+ for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance inst : instance) {
+ List ipAddress = inst
+ .getPublicIpAddress()
+ .getIpAddress();
+ if (ipAddress.isEmpty()){
+ continue;
+ }else {
+ ipAddress.forEach(ip -> ips.add(ip));
+ }
+ }
+ log.info("当前实例ip为{}", ips);
+ } catch (TeaException error) {
+ // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
+ // 错误 message
+ System.out.println(error.getMessage());
+ // 诊断地址
+ System.out.println(error.getData().get("Recommend"));
+ com.aliyun.teautil.Common.assertAsString(error.message);
+ } catch (Exception _error) {
+ TeaException error = new TeaException(_error.getMessage(), _error);
+ // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
+ // 错误 message
+ System.out.println(error.getMessage());
+ // 诊断地址
+ if (error.getData() == null) {
+ System.out.println("error.getData()为空");
+ } else {
+ System.out.println(error.getData().get("Recommend"));
+ }
+
+ com.aliyun.teautil.Common.assertAsString(error.message);
+ }
+ }
+}
diff --git a/src/main/java/com/mobai/service/FluxGetInfoService.java b/src/main/java/com/mobai/service/FluxGetInfoService.java
new file mode 100644
index 0000000..206c4bb
--- /dev/null
+++ b/src/main/java/com/mobai/service/FluxGetInfoService.java
@@ -0,0 +1,15 @@
+package com.mobai.service;
+
+import com.mobai.domain.Result;
+
+/**
+ * @ClassName FluxGetInfoService
+ * @Description 描述
+ * @Author SaiSai.Liu
+ * @Date 2024/5/28 22:01
+ */
+public interface FluxGetInfoService {
+
+ Result getInfo();
+
+}
diff --git a/src/main/java/com/mobai/service/FluxGetInfoServiceImpl.java b/src/main/java/com/mobai/service/FluxGetInfoServiceImpl.java
new file mode 100644
index 0000000..e61d6ff
--- /dev/null
+++ b/src/main/java/com/mobai/service/FluxGetInfoServiceImpl.java
@@ -0,0 +1,63 @@
+package com.mobai.service;
+
+import com.mobai.domain.Result;
+import okhttp3.*;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.IOException;
+
+/**
+ * @ClassName FluxGetInfoServiceImpl
+ * @Description 描述
+ * @Author SaiSai.Liu
+ * @Date 2024/5/28 22:01
+ */
+@Service
+public class FluxGetInfoServiceImpl implements FluxGetInfoService {
+ @Override
+ public Result getInfo() {
+ String url = "http://39.98.50.223:8080/public/";
+ //响应体
+ Response response = null;
+ //登录
+ OkHttpClient client = new OkHttpClient().newBuilder()
+ .build();
+ MediaType mediaType = MediaType.parse("application/json");
+ RequestBody body = RequestBody.create(mediaType, "{\r\n \"username\": \"fluxmq\",\r\n \"password\": \"fluxmq\"\r\n}");
+ RestTemplate restTemplate = new RestTemplate();
+ Request request = null;
+ request = new Request.Builder()
+ .url(url+"login")
+ .method("POST", body)
+ .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
+ .addHeader("Content-Type", "application/json")
+ .build();
+ try {
+ response = client.newCall(request).execute();
+ System.out.println(response);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ //获取信息
+// OkHttpClient client = new OkHttpClient().newBuilder()
+// .build();
+// MediaType mediaType = MediaType.parse("text/plain");
+// RequestBody body = RequestBody.create(mediaType, "");
+ request = new Request.Builder()
+ .url(url + "cluster")
+ .method("GET", null)
+ .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
+ .addHeader("Accesstoken", response.header("accesstoken"))
+ .build();
+
+ try {
+ response = client.newCall(request).execute();
+ System.out.println(response);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return Result.success(response);
+ }
+}
diff --git a/src/test/java/LoginTest.java b/src/test/java/LoginTest.java
new file mode 100644
index 0000000..236adc1
--- /dev/null
+++ b/src/test/java/LoginTest.java
@@ -0,0 +1,30 @@
+import okhttp3.*;
+
+import java.io.IOException;
+
+/**
+ * @ClassName LoginTest
+ * @Description 描述
+ * @Author SaiSai.Liu
+ * @Date 2024/5/28 15:37
+ */
+public class LoginTest {
+ public static void main(String[] args) {
+ OkHttpClient client = new OkHttpClient().newBuilder()
+ .build();
+ MediaType mediaType = MediaType.parse("application/json");
+ RequestBody body = RequestBody.create(mediaType, "{\r\n \"username\": \"fluxmq\",\r\n \"password\": \"fluxmq\"\r\n}");
+ Request request = new Request.Builder()
+ .url("http://fluxmq.muyu.icu/public/login")
+ .method("POST", body)
+ .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
+ .addHeader("Content-Type", "application/json")
+ .build();
+ try {
+ Response response = client.newCall(request).execute();
+ System.out.println(response);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/src/test/java/TestGet.java b/src/test/java/TestGet.java
new file mode 100644
index 0000000..24da9cb
--- /dev/null
+++ b/src/test/java/TestGet.java
@@ -0,0 +1,31 @@
+import okhttp3.*;
+
+import java.io.IOException;
+
+/**
+ * @ClassName TestGet
+ * @Description 描述
+ * @Author SaiSai.Liu
+ * @Date 2024/5/28 15:34
+ */
+public class TestGet {
+ public static void main(String[] args) {
+ OkHttpClient client = new OkHttpClient().newBuilder()
+ .build();
+ MediaType mediaType = MediaType.parse("text/plain");
+ RequestBody body = RequestBody.create(mediaType, "");
+ Request request = new Request.Builder()
+ .url("http://39.98.50.223:8080/public/cluster")
+ .method("GET", null)
+ .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
+ .addHeader("Accesstoken", "")
+ .build();
+ try {
+ Response response = client.newCall(request).execute();
+ System.out.println(response);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}