Skip to content

Commit e939240

Browse files
authored
Merge pull request #85 from WWP1130/mainformysql
use mysql saving data instead of local file
2 parents df5d3aa + 1d0d55f commit e939240

File tree

17 files changed

+575
-3
lines changed

17 files changed

+575
-3
lines changed

docker-compose.yaml

+22-1
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,30 @@ services:
143143
# count: all # 或者您想要的数量,例如 1
144144
# capabilities: [gpu]
145145

146+
147+
mysql:
148+
image: mysql:8.0.23
149+
container_name: mysql
150+
environment:
151+
MYSQL_ROOT_PASSWORD: 'root'
152+
MYSQL_DATABASE: 'muagent'
153+
MYSQL_USER: 'muagent'
154+
MYSQL_PASSWORD: 'muagent'
155+
ports:
156+
- "3306:3306"
157+
volumes:
158+
- ./examples/mysql/db:/var/lib/mysql
159+
- ./examples/mysql/mysql.cnf:/etc/mysql/conf.d/mysql.cnf
160+
- ./examples/mysql/init:/docker-entrypoint-initdb.d
161+
restart: on-failure
162+
networks:
163+
- ekg-net
164+
146165
runtime:
147166
build:
148167
context: ./runtime
149168
dockerfile: Dockerfile.no-package
150-
image: runtime:0.1.0
169+
image: runtime:0.1.1
151170
container_name: runtime
152171
environment:
153172
USER:
@@ -158,6 +177,8 @@ services:
158177
- ekg-net
159178
volumes:
160179
- ./runtime:/home/user/runtime
180+
depends_on:
181+
- mysql
161182
command: ["bash", "-c", "cd /home/user/runtime && mvn package && java -jar /home/user/runtime/bootstrap/muagent-runtime.jar"]
162183

163184
ekgservice:

examples/mysql/init/init.sql

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
-- MySQL dump 10.13 Distrib 8.0.23, for Linux (x86_64)
2+
--
3+
-- Host: localhost Database: muagent
4+
-- ------------------------------------------------------
5+
-- Server version 8.0.23
6+
7+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10+
/*!50503 SET NAMES utf8mb4 */;
11+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12+
/*!40103 SET TIME_ZONE='+00:00' */;
13+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17+
18+
--
19+
-- Current Database: `muagent`
20+
--
21+
22+
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `muagent` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
23+
24+
USE `muagent`;
25+
26+
--
27+
-- Table structure for table `tool`
28+
--
29+
30+
DROP TABLE IF EXISTS `tool`;
31+
/*!40101 SET @saved_cs_client = @@character_set_client */;
32+
/*!50503 SET character_set_client = utf8mb4 */;
33+
CREATE TABLE `tool` (
34+
`id` BIGINT AUTO_INCREMENT,
35+
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
36+
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
37+
`tool_key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL UNIQUE,
38+
`description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
39+
`tool_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
40+
`operator_create` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
41+
`operator_modified` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
42+
`version` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
43+
`owner` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
44+
`tool_json` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
45+
PRIMARY KEY (`id`)
46+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
47+
/*!40101 SET character_set_client = @saved_cs_client */;
48+
49+
--
50+
-- Dumping data for table `tool`
51+
--
52+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
53+
54+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
55+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
56+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
57+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
58+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
59+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
60+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
61+
62+
-- Dump completed on 2024-11-22 9:26:00

examples/mysql/mysql.cnf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[mysqld]
2+
character-set-server=utf8mb4
3+
collation-server=utf8mb4_unicode_ci
4+
5+
[client]
6+
default-character-set=utf8mb4
7+
8+
[mysql]
9+
default-character-set=utf8mb4

runtime/bootstrap/src/main/java/com/alipay/muagent/bootstrap/BootstrapApplication.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.alipay.muagent.bootstrap;
22

33
import com.alipay.muagent.util.LoggerUtil;
4+
import org.mybatis.spring.annotation.MapperScan;
45
import org.slf4j.Logger;
56
import org.slf4j.LoggerFactory;
67
import org.springframework.boot.SpringApplication;
@@ -10,6 +11,7 @@
1011

1112
@SpringBootApplication
1213
@ComponentScan(basePackages = {"com.alipay.muagent"})
14+
@MapperScan("com.alipay.muagent.service.mybatisplus.mapper")
1315
public class BootstrapApplication {
1416

1517
private static final Logger LOGGER = LoggerFactory.getLogger(BootstrapApplication.class);

runtime/bootstrap/src/main/resources/config/application.properties

+11
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,14 @@ spring.application.name=runtime
22

33
logging.path=./logs
44

5+
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
6+
spring.datasource.url=jdbc:mysql://mysql:3306/muagent?allowPublicKeyRetrieval=true&characterEncoding=utf-8&&useSSL=false&serverTimezone=UTC
7+
spring.datasource.username=root
8+
spring.datasource.password=root
9+
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
10+
11+
mybatis-plus.mapper-locations=classpath:mapper/*.xml
12+
mybatis-plus.type-aliases-package=com.alipay.muagent.model
13+
14+
#配置读取tool的方式:local|mysql
15+
runtime.tool.datatype=mysql

runtime/model/pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
<groupId>org.projectlombok</groupId>
3434
<artifactId>lombok</artifactId>
3535
</dependency>
36+
37+
<!-- MyBatis Plus -->
38+
<dependency>
39+
<groupId>com.baomidou</groupId>
40+
<artifactId>mybatis-plus-boot-starter</artifactId>
41+
</dependency>
42+
3643
</dependencies>
3744

3845
</project>

runtime/model/src/main/java/com/alipay/muagent/model/tool/meta/ProtocolSchema.java

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
package com.alipay.muagent.model.tool.meta;
66

7-
import com.google.gson.annotations.JsonAdapter;
87
import lombok.Data;
98

109
/**

runtime/pom.xml

+23-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,29 @@
7979
<artifactId>disruptor</artifactId>
8080
<version>3.4.4</version>
8181
</dependency>
82-
82+
<!-- MyBatis Plus -->
83+
<dependency>
84+
<groupId>com.baomidou</groupId>
85+
<artifactId>mybatis-plus-boot-starter</artifactId>
86+
<version>3.5.5</version>
87+
<exclusions>
88+
<exclusion>
89+
<groupId>org.mybatis</groupId>
90+
<artifactId>mybatis-spring</artifactId>
91+
</exclusion>
92+
</exclusions>
93+
</dependency>
94+
<dependency>
95+
<groupId>org.mybatis</groupId>
96+
<artifactId>mybatis-spring</artifactId>
97+
<version>3.0.3</version>
98+
</dependency>
99+
<!-- MySQL Connector -->
100+
<dependency>
101+
<groupId>mysql</groupId>
102+
<artifactId>mysql-connector-java</artifactId>
103+
<version>8.0.23</version>
104+
</dependency>
83105
</dependencies>
84106
</dependencyManagement>
85107

runtime/service/pom.xml

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@
4343
<groupId>org.codehaus.groovy</groupId>
4444
<artifactId>groovy</artifactId>
4545
</dependency>
46+
47+
<!-- MyBatis Plus -->
48+
<dependency>
49+
<groupId>com.baomidou</groupId>
50+
<artifactId>mybatis-plus-boot-starter</artifactId>
51+
</dependency>
52+
<!-- MySQL Connector -->
53+
<dependency>
54+
<groupId>mysql</groupId>
55+
<artifactId>mysql-connector-java</artifactId>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>org.mybatis</groupId>
60+
<artifactId>mybatis-spring</artifactId>
61+
</dependency>
4662
</dependencies>
4763

4864
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.alipay.muagent.service.mybatisplus.dto;
2+
3+
import java.util.function.Function;
4+
5+
/**
6+
* @author chenjue.wwp
7+
* @version : LocalToolLoader.java, v 0.1 2024年12月10日 下午7:23 chenjue.wwp Exp $
8+
*/
9+
public class Converter<T, U> {
10+
11+
private final Function<T, U> fromDto;
12+
private final Function<U, T> fromEntity;
13+
14+
/**
15+
* @param fromDto entity function
16+
* @param fromEntity domain function
17+
*/
18+
public Converter(final Function<T, U> fromDto, final Function<U, T> fromEntity) {
19+
this.fromDto = fromDto;
20+
this.fromEntity = fromEntity;
21+
}
22+
23+
/**
24+
* @param dto DTO entity
25+
* @return T -> U
26+
*/
27+
public final U convertFromDto(final T dto) {
28+
if (dto == null) {
29+
throw new RuntimeException("dto is null");
30+
}
31+
return fromDto.apply(dto);
32+
}
33+
34+
/**
35+
* @param entity domain entity
36+
* @return U -> T
37+
*/
38+
public final T convertFromEntity(final U entity) {
39+
if (entity == null) {
40+
throw new RuntimeException("entity is null");
41+
}
42+
return fromEntity.apply(entity);
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Alipay.com Inc.
3+
* Copyright (c) 2004-2024 All Rights Reserved.
4+
*/
5+
package com.alipay.muagent.service.mybatisplus.dto;
6+
7+
import com.alipay.muagent.model.tool.meta.Tool;
8+
import com.alipay.muagent.util.GsonUtils;
9+
10+
/**
11+
* @author chenjue.wwp
12+
* @version $Id: ToolConverter.java, v 0.1 2024-11-22 14:43 Exp $$
13+
*/
14+
public class ToolConverter extends Converter<ToolDO, Tool> {
15+
16+
private static final ToolConverter INSTANCE = new ToolConverter();
17+
public static ToolConverter getInstance() {
18+
return INSTANCE;
19+
}
20+
21+
/**
22+
* Constructor.
23+
*/
24+
public ToolConverter() {
25+
super(toolDO -> {
26+
ToolJson toolJson = GsonUtils.fromString(ToolJson.class, toolDO.getToolJson());
27+
Tool tool = new Tool();
28+
tool.setId(toolDO.getId());
29+
tool.setGmtCreate(toolDO.getGmtCreate());
30+
tool.setGmtModified(toolDO.getGmtModified());
31+
tool.setToolKey(toolDO.getToolKey());
32+
tool.setDescription(toolDO.getDescription());
33+
tool.setToolName(toolDO.getToolName());
34+
tool.setOperatorCreate(toolDO.getOperatorCreate());
35+
tool.setGmtModified(toolDO.getGmtModified());
36+
tool.setVersion(toolDO.getVersion());
37+
tool.setOwner(toolDO.getOwner());
38+
if (toolJson != null) {
39+
tool.setToolDefinition(toolJson.getToolDefinition());
40+
tool.setRequestGroovy(toolJson.getRequestGroovy());
41+
tool.setResponseGroovy(toolJson.getResponseGroovy());
42+
tool.setManifestSchema(toolJson.getManifestSchema());
43+
tool.setToolProtocol(toolJson.getToolProtocol());
44+
tool.setApiSchema(toolJson.getApiSchema());
45+
}
46+
return tool;
47+
}, tool -> {
48+
ToolDO toolDO = new ToolDO();
49+
toolDO.setId(tool.getId());
50+
toolDO.setGmtCreate(tool.getGmtCreate());
51+
toolDO.setGmtModified(tool.getGmtModified());
52+
toolDO.setToolKey(tool.getToolKey());
53+
toolDO.setDescription(tool.getDescription());
54+
toolDO.setToolName(tool.getToolName());
55+
toolDO.setToolName(tool.getToolName());
56+
toolDO.setOperatorCreate(tool.getOperatorCreate());
57+
toolDO.setGmtModified(tool.getGmtModified());
58+
toolDO.setVersion(tool.getVersion());
59+
toolDO.setOwner(tool.getOwner());
60+
ToolJson toolJson = new ToolJson();
61+
toolJson.setToolDefinition(tool.getToolDefinition());
62+
toolJson.setRequestGroovy(tool.getRequestGroovy());
63+
toolJson.setResponseGroovy(tool.getResponseGroovy());
64+
toolJson.setManifestSchema(tool.getManifestSchema());
65+
toolJson.setToolProtocol(tool.getToolProtocol());
66+
toolJson.setApiSchema(tool.getApiSchema());
67+
toolDO.setToolJson(GsonUtils.toString(toolJson));
68+
return toolDO;
69+
});
70+
}
71+
}

0 commit comments

Comments
 (0)