refactor: baety接口封装

V0.5.x
regan 2023-06-11 20:55:20 +08:00
parent 3632d15485
commit abc796c6e4
31 changed files with 1145 additions and 12 deletions

View File

@ -8,8 +8,8 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
public class Response {
private int code;
private Integer code;
private String message;
private Object data;
private long timestamp;
private String requestId;
}

View File

@ -1,19 +1,15 @@
package cc.iotkit.data.service;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.constant.UserConstants;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.data.dao.IJPACommData;
import cc.iotkit.data.dao.SysDeptRepository;
import cc.iotkit.data.model.QTbSysRoleDept;
import cc.iotkit.data.model.TbSysDept;
import cc.iotkit.data.system.ISysDeptData;
import cc.iotkit.data.util.PredicateBuilder;
import cc.iotkit.model.system.SysDept;
import cn.hutool.core.util.ObjectUtil;
import com.querydsl.core.types.dsl.BooleanTemplate;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -10,6 +10,7 @@
package cc.iotkit.common.web.handler;
import cc.iotkit.common.api.Response;
import cc.iotkit.common.utils.SnowflakeIdGeneratorUtil;
import cn.dev33.satoken.util.SaResult;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
@ -36,20 +37,20 @@ public class ResponseResultHandler implements ResponseBodyAdvice<Object> {
if (body instanceof GlobalExceptionHandler.RequestResult) {
GlobalExceptionHandler.RequestResult requestResult = (GlobalExceptionHandler.RequestResult) body;
return new Response(requestResult.getCode(), requestResult.getMessage(),
"", System.currentTimeMillis());
"", String.valueOf(SnowflakeIdGeneratorUtil.getInstanceSnowflake().nextId()));
} else if (body instanceof SaResult) {
SaResult result = (SaResult) body;
return new Response(result.getCode(), result.getMsg(), result.getData(), System.currentTimeMillis());
return new Response(result.getCode(), result.getMsg(), result.getData(), String.valueOf(SnowflakeIdGeneratorUtil.getInstanceSnowflake().nextId()));
} else if (body instanceof Map) {
Map map = (Map) body;
//spring mvc内部异常
if (map.containsKey("timestamp") && map.containsKey("status") && map.containsKey("error")) {
return new Response((Integer) map.get("status"), (String) map.get("error"),
"", System.currentTimeMillis());
"", String.valueOf(SnowflakeIdGeneratorUtil.getInstanceSnowflake().nextId()));
}
}
return new Response(200, "", body, System.currentTimeMillis());
return new Response(200, "", body, String.valueOf(SnowflakeIdGeneratorUtil.getInstanceSnowflake().nextId()));
}
}

View File

@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>iot-module</artifactId>
<groupId>cc.iotkit</groupId>
<version>${revision}</version>
</parent>
<artifactId>iot-baetyl</artifactId>
<description>
此模块为边缘计算模块云端控制SDK
</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>it.ozimov</groupId>
<artifactId>embedded-redis</artifactId>
<exclusions>
<exclusion>
<artifactId>slf4j-simple</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-common-model</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-common-core</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-rule-engine</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-component-server</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-component-converter</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-virtual-device</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-message-core</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-temporal-service</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-data-serviceImpl-rdb</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-data-serviceImpl-cache</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-common-web</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-common-doc</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-common-satoken</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-common-excel</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-common-log</artifactId>
</dependency>
<dependency>
<groupId>io.github.linpeilie</groupId>
<artifactId>mapstruct-plus-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source> <!-- depending on your project -->
<target>${java.version}</target> <!-- depending on your project -->
<encoding>utf8</encoding>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>io.github.linpeilie</groupId>
<artifactId>mapstruct-plus-processor</artifactId>
<version>${mapstruct-plus.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
<!-- other annotation processors -->
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,28 @@
package cc.iotkit.baetyl;
import cc.iotkit.baetyl.dto.bo.*;
import cc.iotkit.baetyl.dto.vo.*;
public interface IBaetylService {
GetNodeAppsByNameVo getNodeAppsByName(String name);
UpdateCoreConfigByNameVo updateCoreConfigByName(UpdateCoreConfigByNameBo data);
CreateNodeVo creatNode(CreateNodeBo data);
Boolean deleteNodeByName(String data);
GetNodesBatchVo getNodesBatch(String[] data);
UpdateNodePropertiesVo updateNodeProperties(UpdateNodePropertiesBo data);
GetNodeByNameVo getNodeByName(String data);
UpdateNodeVo updateNode(UpdateNodeBo data);
GetNodeStatsVo getNodeStats(String data);
GetNodeCoreVersionVo getNodeCoreVersion(String data);
GetNodesVo getNodes(GetNodesBo data);
}

View File

@ -0,0 +1,20 @@
package cc.iotkit.baetyl.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Data
@Configuration
@ConfigurationProperties(prefix = "baetyl")
public class BaetylProperties {
/**
* baetyl
*/
private String serviceUrl;
/**
* api feign webclient
*/
private String apiType;
}

View File

@ -0,0 +1,82 @@
package cc.iotkit.baetyl.constant;
/***
* -https://baetyl.io/docs/cn/latest/_static/api.html
*/
public class BaetylConstant {
public class Url {
/**
*
*/
public class NodeManagement {
/**
* GET
*/
public static final String GetNodeAppsByName = "/v1/nodes/{name}/apps";
/**
* core core PUT
*/
public static final String UpdateCoreConfigByName = "/v1/nodes/{name}/core/configs";
/**
* POST
*/
public static final String CreatNode = "/v1/nodes";
/**
* DELETE
*/
public static final String DeleteNodeByName = "/v1/nodes/{name}";
/**
* PUT
*/
public static final String GetNodesBatch = "/v1/nodes?batch";
/**
* PUT
*/
public static final String UpdateNodeProperties = "/v1/nodes/{name}/properties";
/**
* GET
*/
public static final String GetNodeByName = "/v1/nodes/{name}";
/**
* PUT
*/
public static final String UpdateNode = "/v1/nodes/{name}";
/**
* GET
*/
public static final String GetNodeStats = "/v1/nodes/{name}/stats";
/**
* core GET
*/
public static final String GetNodeCoreVersion = "/v1/nodes/{name}/core/versions";
/**
* GET
*/
public static final String GetNodes = "/v1/nodes";
/**
* core GET
*/
public static final String GetCoreConfig = "/v1/nodes/{name}/core/configs";
/**
* GET
*/
public static final String GetInstallCommand = "/v1/nodes/:name/init";
/**
* GET
*/
public static final String GetNodeProperties = "/v1/nodes/{name}/properties";
}
}
}

View File

@ -0,0 +1,99 @@
package cc.iotkit.baetyl.controller;
import cc.iotkit.baetyl.IBaetylService;
import cc.iotkit.baetyl.dto.bo.*;
import cc.iotkit.baetyl.dto.vo.*;
import cc.iotkit.common.api.Request;
import cc.iotkit.common.web.core.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* baetyl
*
* @author longjun.tu
*/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/baetyl")
@Api(tags = "边缘计算管理")
public class BartylController extends BaseController {
@Autowired
private IBaetylService configService;
@ApiOperation("查询节点关联的应用")
@PostMapping("/getNodeAppsByName")
public GetNodeAppsByNameVo getNodeAppsByName(@Validated @RequestBody Request<String> request) {
return configService.getNodeAppsByName(request.getData());
}
@ApiOperation("修改 core 配置core 自升级)")
@PostMapping("/updateCoreConfigByName")
public UpdateCoreConfigByNameVo updateCoreConfigByName(@Validated @RequestBody Request<UpdateCoreConfigByNameBo> request) {
return configService.updateCoreConfigByName(request.getData());
}
@ApiOperation("创建节点")
@PostMapping("/creatNode")
public CreateNodeVo creatNode(@Validated @RequestBody Request<CreateNodeBo> request) {
return configService.creatNode(request.getData());
}
@ApiOperation("删除节点")
@PostMapping("/deleteNodeByName")
public Boolean deleteNodeByName(@Validated @RequestBody Request<String> request) {
return configService.deleteNodeByName(request.getData());
}
@ApiOperation("批量查询节点")
@PostMapping("/getNodesBatch")
public GetNodesBatchVo getNodesBatch(@Validated @RequestBody Request<String[]> request) {
return configService.getNodesBatch(request.getData());
}
@ApiOperation("更新节点属性")
@PostMapping("/updateNodeProperties")
public UpdateNodePropertiesVo updateNodeProperties(@Validated @RequestBody Request<UpdateNodePropertiesBo> request) {
return configService.updateNodeProperties(request.getData());
}
@ApiOperation("查询节点")
@PostMapping("/getNodeByName")
public GetNodeByNameVo getNodeByName(@Validated @RequestBody Request<String> request) {
return configService.getNodeByName(request.getData());
}
@ApiOperation("修改节点")
@PostMapping("/updateNode")
public UpdateNodeVo updateNode(@Validated @RequestBody Request<UpdateNodeBo> request) {
return configService.updateNode(request.getData());
}
@ApiOperation("查询节点状态信息")
@PostMapping("/getNodeStats")
public GetNodeStatsVo getNodeStats(@Validated @RequestBody Request<String> request) {
return configService.getNodeStats(request.getData());
}
@ApiOperation("罗列当前节点 core 版本号")
@PostMapping("/getNodeCoreVersion")
public GetNodeCoreVersionVo getNodeCoreVersion(@Validated @RequestBody Request<String> request) {
return configService.getNodeCoreVersion(request.getData());
}
@ApiOperation("罗列节点")
@PostMapping("/getNodes")
public GetNodesVo getNodes(@Validated @RequestBody Request<GetNodesBo> request) {
return configService.getNodes(request.getData());
}
}

View File

@ -0,0 +1,36 @@
package cc.iotkit.baetyl.dto.bo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;
/**
* @author: regan
* @description:
* @date:created in 2023/6/8 16:36
* @modificed by:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CreateNodeBo {
@ApiModelProperty(value = "节点名称",required = true)
private String name;
@ApiModelProperty(value = "map[string]string类型例如 {\"env\":\"test\"}")
private Map<String,String> labels;
@ApiModelProperty(value = "map[string]string 用来保存品牌等属性信息")
private Map<String,String> annotations;
@ApiModelProperty(value = "为空或NVIDIA GPU")
private String accelerator;
@ApiModelProperty(value = "是单机还是集群环境")
private Boolean cluster;
@ApiModelProperty(value = "可选官方应用,支持 baetyl-function、baetyl-rule")
private String[] sysApps;
@ApiModelProperty(value = "描述信息")
private String description;
}

View File

@ -0,0 +1,34 @@
package cc.iotkit.baetyl.dto.bo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author: regan
* @description:
* @date:created in 2023/6/11 18:49
* @modificed by:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GetNodesBo {
@ApiModelProperty(value = "标签查询")
private String selector;
@ApiModelProperty(value = "属性查询")
private String fieldSelector;
@ApiModelProperty(value = "分页限制")
private Integer limit;
@ApiModelProperty(value = "分页继续token由上一次分页查询返回")
private String isContinue;
@ApiModelProperty(value = "查询页码")
private Integer pageNo;
@ApiModelProperty(value = "每页数据数")
private Integer pageSize;
@ApiModelProperty(value = "模糊匹配名称")
private String name;
@ApiModelProperty(value = "子节点标签过滤")
private String nodeSelector;
}

View File

@ -0,0 +1,41 @@
package cc.iotkit.baetyl.dto.bo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author: regan
* @description:
* @date:created in 2023/6/11 18:03
* @modificed by:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UpdateCoreConfigByNameBo {
@ApiModelProperty(value = "节点名称",required = true)
private String name;
@ApiModelProperty(value = "body内容")
private UpdateCoreConfigByNameBoBody body;
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class UpdateCoreConfigByNameBoBody {
@ApiModelProperty(value = "core版本号")
private String version;
@ApiModelProperty(value = "core上报频率")
private Integer frequency;
@ApiModelProperty(value = "core 边缘 API 端口")
private Integer apiport;
}
}

View File

@ -0,0 +1,43 @@
package cc.iotkit.baetyl.dto.bo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;
/**
* @author: regan
* @description:
* @date:created in 2023/6/11 18:35
* @modificed by:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UpdateNodeBo {
@ApiModelProperty(value = "节点名称",required = true)
private String name;
@ApiModelProperty(value = "body内容",required = true)
private UpdateNodeBoBody body;
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class UpdateNodeBoBody {
@ApiModelProperty(value = "map[string]string类型例如 {\"env\":\"test\"}")
private Map<String,String> labels;
@ApiModelProperty(value = "map[string]string 用来保存品牌等属性信息")
private Map<String,String> annotations;
@ApiModelProperty(value = "描述信息")
private String description;
@ApiModelProperty(value = "可选官方应用,支持 baetyl-function、baetyl-rule")
private String[] sysApps;
}
}

View File

@ -0,0 +1,35 @@
package cc.iotkit.baetyl.dto.bo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;
/**
* @author: regan
* @description:
* @date:created in 2023/6/11 17:58
* @modificed by:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UpdateNodePropertiesBo {
@ApiModelProperty(value = "节点名称",required = true)
private String name;
@ApiModelProperty(value = "map[string]string, value必须为 string")
private UpdateNodePropertiesBoBody state;
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class UpdateNodePropertiesBoBody {
@ApiModelProperty(value = "map[string]string, value必须为 string")
private String desire;
}
}

View File

@ -0,0 +1,39 @@
package cc.iotkit.baetyl.dto.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author: regan
* @description:
* @date:created in 2023/6/8 16:36
* @modificed by:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CreateNodeVo {
@ApiModelProperty(value = "节点名称")
private String name;
@ApiModelProperty(value = "命名空间")
private String namespace;
@ApiModelProperty(value = "描述信息")
private String description;
@ApiModelProperty(value = "为空或NVIDIA GPU")
private String accelerator;
@ApiModelProperty(value = "可选官方应用,支持 baetyl-function、baetyl-rule")
private String[] sysApps;
@ApiModelProperty(value = "节点是否已连接")
private Boolean ready;
@ApiModelProperty(value = "创建时间")
private String createTime;
@ApiModelProperty(value = "标签")
private Object labels;
@ApiModelProperty(value = "注解")
private Object annotations;
}

View File

@ -0,0 +1,44 @@
package cc.iotkit.baetyl.dto.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author: regan
* @description:
* @date:created in 2023/6/8 16:36
* @modificed by:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GetNodeAppsByNameVo {
@ApiModelProperty(value = "应用总数")
private Integer total;
@ApiModelProperty(value = "列表选项")
private Object listOptions;
@ApiModelProperty(value = "应用列表")
private List<AppInfoDetails> items;
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class AppInfoDetails{
@ApiModelProperty(value = "应用名称",required = true)
private String name;
@ApiModelProperty(value = "标签选择器",required = true)
private String selector;
@ApiModelProperty(value = "命名空间",required = true)
private String namespace;
@ApiModelProperty(value = "创建时间",required = true)
private String createTime;
}
}

View File

@ -0,0 +1,14 @@
package cc.iotkit.baetyl.dto.vo;
import lombok.Data;
/**
* @author: regan
* @description:
* @date:created in 2023/6/11 18:31
* @modificed by:
*/
@Data
public class GetNodeByNameVo {
// TODO: 2023/6/11
}

View File

@ -0,0 +1,20 @@
package cc.iotkit.baetyl.dto.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author: regan
* @description:
* @date:created in 2023/6/11 18:46
* @modificed by:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GetNodeCoreVersionVo {
@ApiModelProperty(value = "当前节点 core 版本号列表")
private String[] versions;
}

View File

@ -0,0 +1,14 @@
package cc.iotkit.baetyl.dto.vo;
import lombok.Data;
/**
* @author: regan
* @description:
* @date:created in 2023/6/11 18:43
* @modificed by:
*/
@Data
public class GetNodeStatsVo {
// TODO: 2023/6/11
}

View File

@ -0,0 +1,40 @@
package cc.iotkit.baetyl.dto.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author: regan
* @description:
* @date:created in 2023/6/8 16:36
* @modificed by:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GetNodesBatchVo {
// TODO: 2023/6/11 待修改
@ApiModelProperty(value = "节点名称")
private String name;
@ApiModelProperty(value = "命名空间")
private String namespace;
@ApiModelProperty(value = "描述信息")
private String description;
@ApiModelProperty(value = "为空或NVIDIA GPU")
private String accelerator;
@ApiModelProperty(value = "可选官方应用,支持 baetyl-function、baetyl-rule")
private String[] sysApps;
@ApiModelProperty(value = "节点是否已连接")
private Boolean ready;
@ApiModelProperty(value = "创建时间")
private String createTime;
@ApiModelProperty(value = "标签")
private Object labels;
@ApiModelProperty(value = "注解")
private Object annotations;
}

View File

@ -0,0 +1,14 @@
package cc.iotkit.baetyl.dto.vo;
import lombok.Data;
/**
* @author: regan
* @description:
* @date:created in 2023/6/11 18:49
* @modificed by:
*/
@Data
public class GetNodesVo {
// TODO: 2023/6/11
}

View File

@ -0,0 +1,41 @@
package cc.iotkit.baetyl.dto.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author: regan
* @description:
* @date:created in 2023/6/11 18:03
* @modificed by:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UpdateCoreConfigByNameVo {
@ApiModelProperty(value = "节点名称")
private String name;
@ApiModelProperty(value = "body内容")
private UpdateCoreConfigByNameBoBody body;
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class UpdateCoreConfigByNameBoBody {
@ApiModelProperty(value = "core版本号")
private String version;
@ApiModelProperty(value = "core上报频率")
private Integer frequency;
@ApiModelProperty(value = "core 边缘 API 端口")
private Integer apiport;
}
}

View File

@ -0,0 +1,47 @@
package cc.iotkit.baetyl.dto.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;
/**
* @author: regan
* @description:
* @date:created in 2023/6/11 17:58
* @modificed by:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UpdateNodePropertiesVo {
@ApiModelProperty(value = "map[string]string, value必须为 string")
private UpdateNodePropertiesVoBodyState state;
@ApiModelProperty(value = "map[string]string, value必须为 string")
private UpdateNodePropertiesVoBodyMetadata metadata;
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class UpdateNodePropertiesVoBodyState {
@ApiModelProperty(value = "map[string]string, value必须为 string")
private String report;
@ApiModelProperty(value = "map[string]string, value必须为 string")
private String desire;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class UpdateNodePropertiesVoBodyMetadata {
@ApiModelProperty(value = "map[string]string, value必须为 string")
private String report;
@ApiModelProperty(value = "map[string]string, value必须为 string")
private String desire;
}
}

View File

@ -0,0 +1,38 @@
package cc.iotkit.baetyl.dto.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;
/**
* @author: regan
* @description:
* @date:created in 2023/6/11 18:35
* @modificed by:
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UpdateNodeVo {
@ApiModelProperty(value = "节点名称")
private String name;
@ApiModelProperty(value = "命名空间")
private String namespace;
@ApiModelProperty(value = "描述信息")
private String description;
@ApiModelProperty(value = "可选官方应用,支持 baetyl-function、baetyl-rule")
private String[] sysApps;
@ApiModelProperty(value = "节点是否已连接")
private Boolean ready;
@ApiModelProperty(value = "创建时间")
private String createTime;
@ApiModelProperty(value = "标签")
private Object labels;
@ApiModelProperty(value = "注解")
private Object annotations;
}

View File

@ -0,0 +1,48 @@
package cc.iotkit.baetyl.feign;
import cc.iotkit.baetyl.constant.BaetylConstant;
import cc.iotkit.baetyl.dto.bo.CreateNodeBo;
import cc.iotkit.baetyl.dto.bo.UpdateCoreConfigByNameBo;
import cc.iotkit.baetyl.dto.bo.UpdateNodeBo;
import cc.iotkit.baetyl.dto.bo.UpdateNodePropertiesBo;
import cc.iotkit.baetyl.dto.vo.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@ConditionalOnClass(FeignClient.class)
@FeignClient(name = "baetylServiceFeignClient" , contextId = "baetylServiceFeignClient" ,url = "${baetyl.service-url:}")
public interface BaetylServiceFeignClient {
@GetMapping(value = BaetylConstant.Url.NodeManagement.GetNodeAppsByName)
GetNodeAppsByNameVo getNodeAppsByName(@PathVariable(value = "name") String name);
@PutMapping(value = BaetylConstant.Url.NodeManagement.UpdateCoreConfigByName)
UpdateCoreConfigByNameVo updateCoreConfigByName(@PathVariable(value = "name") String name, @RequestBody UpdateCoreConfigByNameBo.UpdateCoreConfigByNameBoBody data);
@PostMapping(value = BaetylConstant.Url.NodeManagement.CreatNode)
CreateNodeVo creatNode(@RequestBody CreateNodeBo data);
@DeleteMapping(value = BaetylConstant.Url.NodeManagement.DeleteNodeByName)
Boolean deleteNodeByName(@PathVariable(value = "name") String name);
@PutMapping(value = BaetylConstant.Url.NodeManagement.GetNodesBatch)
GetNodesBatchVo getNodesBatch(@RequestBody String[] data);
@PutMapping(value = BaetylConstant.Url.NodeManagement.UpdateNodeProperties)
UpdateNodePropertiesVo updateNodeProperties(@PathVariable(value = "name") String name, @RequestBody UpdateNodePropertiesBo.UpdateNodePropertiesBoBody state);
@GetMapping(value = BaetylConstant.Url.NodeManagement.GetNodeByName)
GetNodeByNameVo getNodeByName(@PathVariable(value = "name") String name);
@PutMapping(value = BaetylConstant.Url.NodeManagement.UpdateNode)
UpdateNodeVo updateNode(@PathVariable(value = "name") String name, @RequestBody UpdateNodeBo.UpdateNodeBoBody body);
@GetMapping(value = BaetylConstant.Url.NodeManagement.GetNodeStats)
GetNodeStatsVo getNodeStats(@PathVariable(value = "name") String name);
@GetMapping(value = BaetylConstant.Url.NodeManagement.GetNodeCoreVersion)
GetNodeCoreVersionVo getNodeCoreVersion(@PathVariable(value = "name") String name);
@GetMapping(value = BaetylConstant.Url.NodeManagement.GetNodes)
GetNodesVo getNodes(@RequestParam(value = "selector") String selector, @RequestParam(value = "fieldSelector") String fieldSelector, @RequestParam(value = "limit") Integer limit,
@RequestParam(value = "continue") String isContinue, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize,
@RequestParam(value = "name") String name, @RequestParam(value = "nodeSelector") String nodeSelector);
}

View File

@ -0,0 +1,77 @@
package cc.iotkit.baetyl.service;
import cc.iotkit.baetyl.IBaetylService;
import cc.iotkit.baetyl.dto.bo.*;
import cc.iotkit.baetyl.dto.vo.*;
import cc.iotkit.baetyl.feign.BaetylServiceFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@Slf4j
@ConditionalOnProperty(value = "baetyl.api-type", havingValue = "feign")
@Component
public class BaetylServiceFeignImpl implements IBaetylService {
@Lazy
@Autowired
private BaetylServiceFeignClient client;
@Override
public GetNodeAppsByNameVo getNodeAppsByName(String name) {
return client.getNodeAppsByName(name);
}
@Override
public UpdateCoreConfigByNameVo updateCoreConfigByName(UpdateCoreConfigByNameBo data) {
return client.updateCoreConfigByName(data.getName(),data.getBody());
}
@Override
public CreateNodeVo creatNode(CreateNodeBo data) {
return client.creatNode(data);
}
@Override
public Boolean deleteNodeByName(String data) {
return client.deleteNodeByName(data);
}
@Override
public GetNodesBatchVo getNodesBatch(String[] data) {
return client.getNodesBatch(data);
}
@Override
public UpdateNodePropertiesVo updateNodeProperties(UpdateNodePropertiesBo data) {
return client.updateNodeProperties(data.getName(),data.getState());
}
@Override
public GetNodeByNameVo getNodeByName(String data) {
return client.getNodeByName(data);
}
@Override
public UpdateNodeVo updateNode(UpdateNodeBo data) {
return client.updateNode(data.getName(),data.getBody());
}
@Override
public GetNodeStatsVo getNodeStats(String data) {
return client.getNodeStats(data);
}
@Override
public GetNodeCoreVersionVo getNodeCoreVersion(String data) {
return client.getNodeCoreVersion(data);
}
@Override
public GetNodesVo getNodes(GetNodesBo data) {
return client.getNodes(data.getSelector(),data.getFieldSelector(),data.getLimit(),data.getIsContinue(),data.getPageNo(),data.getPageSize(),
data.getName(),data.getNodeSelector());
}
}

View File

@ -0,0 +1,87 @@
package cc.iotkit.baetyl.service;
import cc.iotkit.baetyl.IBaetylService;
import cc.iotkit.baetyl.constant.BaetylConstant;
import cc.iotkit.baetyl.dto.bo.*;
import cc.iotkit.baetyl.dto.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
@Slf4j
@ConditionalOnProperty(value = "baetyl.api-type", havingValue = "webClient")
@Component
public class BaetylServiceWebclientImpl implements IBaetylService {
@Autowired
private WebClient webClient;
@Override
public GetNodeAppsByNameVo getNodeAppsByName(String name) {
ParameterizedTypeReference<GetNodeAppsByNameVo> responseBodyType = new ParameterizedTypeReference<>() {};
return webClient.get()
.uri(BaetylConstant.Url.NodeManagement.GetNodeAppsByName.replace("{name}",name))
.retrieve()
.bodyToMono(responseBodyType)
.block();
}
// TODO: 2023/6/10 后续有需要则实现
@Override
public UpdateCoreConfigByNameVo updateCoreConfigByName(UpdateCoreConfigByNameBo data) {
return null;
}
@Override
public CreateNodeVo creatNode(CreateNodeBo data) {
return null;
}
@Override
public Boolean deleteNodeByName(String data) {
return null;
}
@Override
public GetNodesBatchVo getNodesBatch(String[] data) {
return null;
}
@Override
public UpdateNodePropertiesVo updateNodeProperties(UpdateNodePropertiesBo data) {
return null;
}
@Override
public GetNodeByNameVo getNodeByName(String data) {
return null;
}
@Override
public UpdateNodeVo updateNode(UpdateNodeBo data) {
return null;
}
@Override
public GetNodeStatsVo getNodeStats(String data) {
return null;
}
@Override
public GetNodeCoreVersionVo getNodeCoreVersion(String data) {
return null;
}
@Override
public GetNodesVo getNodes(GetNodesBo data) {
return null;
}
}

View File

@ -13,6 +13,7 @@
<packaging>pom</packaging>
<modules>
<module>iot-system</module>
<module>iot-baetyl</module>
<module>iot-manager</module>
<module>iot-rule-engine</module>
<module>iot-message-notify</module>

View File

@ -149,6 +149,10 @@
<groupId>cc.iotkit</groupId>
<artifactId>iot-system</artifactId>
</dependency>
<!-- <dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-baetyl</artifactId>
</dependency>-->
<!--打开注释使用rocketmq消息总线-->
<!-- <dependency>-->
<!-- <groupId>cc.iotkit</groupId>-->

View File

@ -14,6 +14,7 @@ import cc.iotkit.config.EmbeddedRedisConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@ -21,6 +22,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@SpringBootApplication(scanBasePackages = {"cc.iotkit"})
@EnableTransactionManagement
@EnableWebMvc
@EnableFeignClients(basePackages = {"cc.iotkit.baetyl.feign"})
public class Application {
public static void main(String[] args) {

View File

@ -159,4 +159,7 @@ oss:
endpoint: xxxxx
accessKey: xxxxx
secretKey: xxxxx
buckName: xxxx
buckName: xxxx
baetyl:
api-type: feign
service-url: http://116.168.30.140:30004

15
pom.xml
View File

@ -45,7 +45,7 @@
<knife4j.version>2.0.9</knife4j.version>
<validateion.version>1.1.0.Final</validateion.version>
<lombok.version>1.18.26</lombok.version>
<openfeign.version>2.1.1.RELEASE</openfeign.version>
</properties>
<dependencyManagement>
@ -66,6 +66,13 @@
<version>${beanutils.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>${openfeign.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
@ -518,6 +525,12 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-baetyl</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-virtual-device</artifactId>