diff --git a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/Response.java b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/Response.java index ad915510..b8b10585 100644 --- a/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/Response.java +++ b/iot-common/iot-common-core/src/main/java/cc/iotkit/common/api/Response.java @@ -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; } diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDeptDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDeptDataImpl.java index ebc38a95..2c6d26f9 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDeptDataImpl.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDeptDataImpl.java @@ -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; diff --git a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/ResponseResultHandler.java b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/ResponseResultHandler.java index 6b40a0d4..33f68ca9 100644 --- a/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/ResponseResultHandler.java +++ b/iot-common/iot-common-web/src/main/java/cc/iotkit/common/web/handler/ResponseResultHandler.java @@ -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 { 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())); } } diff --git a/iot-module/iot-baetyl/pom.xml b/iot-module/iot-baetyl/pom.xml new file mode 100644 index 00000000..703a9d05 --- /dev/null +++ b/iot-module/iot-baetyl/pom.xml @@ -0,0 +1,172 @@ + + + 4.0.0 + + iot-module + cc.iotkit + ${revision} + + + iot-baetyl + + + 此模块为边缘计算模块云端控制SDK + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.bouncycastle + bcprov-jdk15on + + + + com.aliyun.oss + aliyun-sdk-oss + + + + joda-time + joda-time + + + + it.ozimov + embedded-redis + + + slf4j-simple + org.slf4j + + + + + + cc.iotkit + iot-common-model + + + + cc.iotkit + iot-common-core + + + + cc.iotkit + iot-rule-engine + + + + cc.iotkit + iot-component-server + + + + cc.iotkit + iot-component-converter + + + + cc.iotkit + iot-virtual-device + + + + cc.iotkit + iot-message-core + + + + cc.iotkit + iot-temporal-service + + + + cc.iotkit + iot-data-serviceImpl-rdb + + + + cc.iotkit + iot-data-serviceImpl-cache + + + + cc.iotkit + iot-common-web + + + + cc.iotkit + iot-common-doc + + + cc.iotkit + iot-common-satoken + + + + cc.iotkit + iot-common-excel + + + cc.iotkit + iot-common-log + + + io.github.linpeilie + mapstruct-plus-spring-boot-starter + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + utf8 + + + org.projectlombok + lombok + ${lombok.version} + + + io.github.linpeilie + mapstruct-plus-processor + ${mapstruct-plus.version} + + + org.projectlombok + lombok-mapstruct-binding + 0.2.0 + + + + + + + + + diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/IBaetylService.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/IBaetylService.java new file mode 100644 index 00000000..97103279 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/IBaetylService.java @@ -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); +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/config/BaetylProperties.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/config/BaetylProperties.java new file mode 100644 index 00000000..30b4cebd --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/config/BaetylProperties.java @@ -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; +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/constant/BaetylConstant.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/constant/BaetylConstant.java new file mode 100644 index 00000000..879b6773 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/constant/BaetylConstant.java @@ -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"; + + } + + + + + + } + + + +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/controller/BartylController.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/controller/BartylController.java new file mode 100644 index 00000000..02ea93c0 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/controller/BartylController.java @@ -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 request) { + return configService.getNodeAppsByName(request.getData()); + } + + @ApiOperation("修改 core 配置(core 自升级)") + @PostMapping("/updateCoreConfigByName") + public UpdateCoreConfigByNameVo updateCoreConfigByName(@Validated @RequestBody Request request) { + return configService.updateCoreConfigByName(request.getData()); + } + + @ApiOperation("创建节点") + @PostMapping("/creatNode") + public CreateNodeVo creatNode(@Validated @RequestBody Request request) { + return configService.creatNode(request.getData()); + } + + @ApiOperation("删除节点") + @PostMapping("/deleteNodeByName") + public Boolean deleteNodeByName(@Validated @RequestBody Request request) { + return configService.deleteNodeByName(request.getData()); + } + + @ApiOperation("批量查询节点") + @PostMapping("/getNodesBatch") + public GetNodesBatchVo getNodesBatch(@Validated @RequestBody Request request) { + return configService.getNodesBatch(request.getData()); + } + + @ApiOperation("更新节点属性") + @PostMapping("/updateNodeProperties") + public UpdateNodePropertiesVo updateNodeProperties(@Validated @RequestBody Request request) { + return configService.updateNodeProperties(request.getData()); + } + + @ApiOperation("查询节点") + @PostMapping("/getNodeByName") + public GetNodeByNameVo getNodeByName(@Validated @RequestBody Request request) { + return configService.getNodeByName(request.getData()); + } + + @ApiOperation("修改节点") + @PostMapping("/updateNode") + public UpdateNodeVo updateNode(@Validated @RequestBody Request request) { + return configService.updateNode(request.getData()); + } + + @ApiOperation("查询节点状态信息") + @PostMapping("/getNodeStats") + public GetNodeStatsVo getNodeStats(@Validated @RequestBody Request request) { + return configService.getNodeStats(request.getData()); + } + + @ApiOperation("罗列当前节点 core 版本号") + @PostMapping("/getNodeCoreVersion") + public GetNodeCoreVersionVo getNodeCoreVersion(@Validated @RequestBody Request request) { + return configService.getNodeCoreVersion(request.getData()); + } + + @ApiOperation("罗列节点") + @PostMapping("/getNodes") + public GetNodesVo getNodes(@Validated @RequestBody Request request) { + return configService.getNodes(request.getData()); + } + +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/CreateNodeBo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/CreateNodeBo.java new file mode 100644 index 00000000..ab112cf7 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/CreateNodeBo.java @@ -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 labels; + @ApiModelProperty(value = "map[string]string 用来保存品牌等属性信息") + private Map 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; + +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/GetNodesBo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/GetNodesBo.java new file mode 100644 index 00000000..f59db4f6 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/GetNodesBo.java @@ -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; +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateCoreConfigByNameBo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateCoreConfigByNameBo.java new file mode 100644 index 00000000..186729ee --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateCoreConfigByNameBo.java @@ -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; + } + + + +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateNodeBo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateNodeBo.java new file mode 100644 index 00000000..53832803 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateNodeBo.java @@ -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 labels; + @ApiModelProperty(value = "map[string]string 用来保存品牌等属性信息") + private Map annotations; + @ApiModelProperty(value = "描述信息") + private String description; + @ApiModelProperty(value = "可选官方应用,支持 baetyl-function、baetyl-rule") + private String[] sysApps; + + + } + +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateNodePropertiesBo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateNodePropertiesBo.java new file mode 100644 index 00000000..ff83918f --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/bo/UpdateNodePropertiesBo.java @@ -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; + } + +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/CreateNodeVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/CreateNodeVo.java new file mode 100644 index 00000000..8df626f9 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/CreateNodeVo.java @@ -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; + + +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeAppsByNameVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeAppsByNameVo.java new file mode 100644 index 00000000..0209aa8d --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeAppsByNameVo.java @@ -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 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; + } + + +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeByNameVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeByNameVo.java new file mode 100644 index 00000000..4e8fef2b --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeByNameVo.java @@ -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 +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeCoreVersionVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeCoreVersionVo.java new file mode 100644 index 00000000..f9199e7f --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeCoreVersionVo.java @@ -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; +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeStatsVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeStatsVo.java new file mode 100644 index 00000000..f9616b8b --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodeStatsVo.java @@ -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 +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodesBatchVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodesBatchVo.java new file mode 100644 index 00000000..e37fb734 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodesBatchVo.java @@ -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; + + +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodesVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodesVo.java new file mode 100644 index 00000000..1ea9f295 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/GetNodesVo.java @@ -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 +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateCoreConfigByNameVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateCoreConfigByNameVo.java new file mode 100644 index 00000000..4c349a68 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateCoreConfigByNameVo.java @@ -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; + } + + + +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateNodePropertiesVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateNodePropertiesVo.java new file mode 100644 index 00000000..8b2e71f6 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateNodePropertiesVo.java @@ -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; + } +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateNodeVo.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateNodeVo.java new file mode 100644 index 00000000..292177e3 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/dto/vo/UpdateNodeVo.java @@ -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; + +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/feign/BaetylServiceFeignClient.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/feign/BaetylServiceFeignClient.java new file mode 100644 index 00000000..d32296ab --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/feign/BaetylServiceFeignClient.java @@ -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); +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/service/BaetylServiceFeignImpl.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/service/BaetylServiceFeignImpl.java new file mode 100644 index 00000000..898e21a8 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/service/BaetylServiceFeignImpl.java @@ -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()); + } +} diff --git a/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/service/BaetylServiceWebclientImpl.java b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/service/BaetylServiceWebclientImpl.java new file mode 100644 index 00000000..613556e7 --- /dev/null +++ b/iot-module/iot-baetyl/src/main/java/cc/iotkit/baetyl/service/BaetylServiceWebclientImpl.java @@ -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 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; + } +} diff --git a/iot-module/pom.xml b/iot-module/pom.xml index 53702e91..01c0e4ca 100644 --- a/iot-module/pom.xml +++ b/iot-module/pom.xml @@ -13,6 +13,7 @@ pom iot-system + iot-baetyl iot-manager iot-rule-engine iot-message-notify diff --git a/iot-starter/pom.xml b/iot-starter/pom.xml index 820e14bd..21f15a4a 100644 --- a/iot-starter/pom.xml +++ b/iot-starter/pom.xml @@ -149,6 +149,10 @@ cc.iotkit iot-system + diff --git a/iot-starter/src/main/java/cc/iotkit/Application.java b/iot-starter/src/main/java/cc/iotkit/Application.java index 45a07d48..7ec4272b 100644 --- a/iot-starter/src/main/java/cc/iotkit/Application.java +++ b/iot-starter/src/main/java/cc/iotkit/Application.java @@ -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) { diff --git a/iot-starter/src/main/resources/application.yml b/iot-starter/src/main/resources/application.yml index 59032554..56d36b39 100644 --- a/iot-starter/src/main/resources/application.yml +++ b/iot-starter/src/main/resources/application.yml @@ -159,4 +159,7 @@ oss: endpoint: xxxxx accessKey: xxxxx secretKey: xxxxx - buckName: xxxx \ No newline at end of file + buckName: xxxx +baetyl: + api-type: feign + service-url: http://116.168.30.140:30004 \ No newline at end of file diff --git a/pom.xml b/pom.xml index bd2f99dd..de3db218 100755 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ 2.0.9 1.1.0.Final 1.18.26 - + 2.1.1.RELEASE @@ -66,6 +66,13 @@ ${beanutils.version} + + + org.springframework.cloud + spring-cloud-starter-openfeign + ${openfeign.version} + + com.fasterxml.jackson.core jackson-core @@ -518,6 +525,12 @@ ${project.version} + + cc.iotkit + iot-baetyl + ${project.version} + + cc.iotkit iot-virtual-device