Prechádzať zdrojové kódy

Merge remote-tracking branch 'origin/2.0' into 2.0

zhouhao 2 rokov pred
rodič
commit
6f2003ce16

+ 17 - 20
docker/run-all/docker-compose.yml

@@ -6,7 +6,7 @@ services:
     #    ports:
     #      - "6379:6379"
     volumes:
-      - "redis-volume:/data"
+      - "./data/redis:/data"
     command: redis-server --appendonly yes --requirepass "JetLinks@redis"
     environment:
       - TZ=Asia/Shanghai
@@ -20,8 +20,8 @@ services:
       bootstrap.memory_lock: "true"
       discovery.zen.minimum_master_nodes: 1
       discovery.zen.ping.unicast.hosts: elasticsearch
-    volumes:
-      - elasticsearch-volume:/usr/share/elasticsearch/data
+  #  volumes:
+  #    - ./data/elasticsearch:/usr/share/elasticsearch/data
   #    ports:
   #      - "9200:9200"
   #      - "9300:9300"
@@ -33,14 +33,14 @@ services:
     links:
       - elasticsearch:elasticsearch
     ports:
-      - "5602:5601"
+      - "5601:5601"
     depends_on:
       - elasticsearch
   postgres:
     image: postgres:11-alpine
     container_name: jetlinks-ce-postgres
     volumes:
-      - "postgres-volume:/var/lib/postgresql/data"
+      - "./data/postgres:/var/lib/postgresql/data"
     ports:
       - "5432:5432"
     environment:
@@ -55,22 +55,26 @@ services:
     environment:
       - "API_BASE_PATH=http://jetlinks:8848/" #API根路径
     volumes:
-      - "jetlinks-volume:/usr/share/nginx/html/upload"
+      - "./data/jetlinks-ui:/usr/share/nginx/html/upload"
     links:
       - jetlinks:jetlinks
   jetlinks:
     image: registry.cn-shenzhen.aliyuncs.com/jetlinks/jetlinks-standalone:2.0.0-SNAPSHOT
     container_name: jetlinks-ce
+
     ports:
       - "8848:8848" # API端口
       - "1883-1890:1883-1890" # 预留
       - "8800-8810:8800-8810" # 预留
       - "5060-5061:5060-5061" # 预留
     volumes:
-      - "jetlinks-volume:/application/static/upload"  # 持久化上传的文件
-      - "jetlinks-file-volume:/application/data/files"
-      - "jetlinks-protocol-volume:/application/data/protocols"
+      - "./data/jetlinks:/application/static/upload"  # 持久化上传的文件
+      - "./data/jetlinks/:/application/data/files"
+      - "./data/jetlinks/:/application/data/protocols"
+      - "./entrypoint.sh:/entrypoint.sh"
+    #entrypoint: /entrypoint.sh -d redis:5601,postgres:5432,elasticsearch:9200 'echo "start jetlinks service here"';
     environment:
+     # - "SLEEP_SECOND=4"
       - "JAVA_OPTS=-Duser.language=zh -XX:+UseG1GC"
       - "TZ=Asia/Shanghai"
       - "hsweb.file.upload.static-location=http://127.0.0.1:8848/upload"  #上传的静态文件访问根地址,为ui的地址.
@@ -78,9 +82,9 @@ services:
       - "spring.r2dbc.username=postgres"
       - "spring.r2dbc.password=jetlinks"
       - "spring.data.elasticsearch.client.reactive.endpoints=elasticsearch:9200"
-#        - "spring.data.elasticsearch.client.reactive.username=admin"
-#        - "spring.data.elasticsearch.client.reactive.password=admin"
-#        - "spring.reactor.debug-agent.enabled=false" #设置为false能提升性能
+      #        - "spring.data.elasticsearch.client.reactive.username=admin"
+      #        - "spring.data.elasticsearch.client.reactive.password=admin"
+      #        - "spring.reactor.debug-agent.enabled=false" #设置为false能提升性能
       - "spring.redis.host=redis"
       - "spring.redis.port=6379"
       - "file.manager.storage-base-path=/application/data/files"
@@ -111,11 +115,4 @@ services:
     depends_on:
       - postgres
       - redis
-      - elasticsearch
-volumes:
-  postgres-volume:
-  redis-volume:
-  elasticsearch-volume:
-  jetlinks-volume:
-  jetlinks-file-volume:
-  jetlinks-protocol-volume:
+      - elasticsearch

+ 10 - 0
jetlinks-components/io-component/src/main/java/org/jetlinks/community/io/file/FileInfo.java

@@ -36,6 +36,16 @@ public class FileInfo {
 
     private Map<String, Object> others;
 
+    private String accessUrl;
+
+    public void withBasePath(String apiBashPath) {
+        if (!apiBashPath.endsWith("/")) {
+            apiBashPath = apiBashPath + "/";
+        }
+        accessUrl = apiBashPath + "file/" + id + "?accessKey=" + accessKey().orElse("");
+    }
+
+
     public MediaType mediaType() {
         if (!StringUtils.hasText(extension)) {
             return MediaType.APPLICATION_OCTET_STREAM;

+ 41 - 0
jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/web/ProtocolSupportController.java

@@ -1,11 +1,13 @@
 package org.jetlinks.community.device.web;
 
 import com.alibaba.fastjson.JSON;
+import io.netty.buffer.ByteBufAllocator;
 import io.swagger.v3.oas.annotations.Hidden;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.Getter;
+import org.apache.commons.codec.digest.DigestUtils;
 import org.hswebframework.utils.StringUtils;
 import org.hswebframework.web.api.crud.entity.QueryParamEntity;
 import org.hswebframework.web.authorization.annotation.Authorize;
@@ -21,6 +23,7 @@ import org.jetlinks.community.device.web.protocol.ProtocolInfo;
 import org.jetlinks.community.device.web.protocol.TransportInfo;
 import org.jetlinks.community.device.web.request.ProtocolDecodeRequest;
 import org.jetlinks.community.device.web.request.ProtocolEncodeRequest;
+import org.jetlinks.community.io.file.FileManager;
 import org.jetlinks.community.protocol.TransportDetail;
 import org.jetlinks.core.ProtocolSupport;
 import org.jetlinks.core.ProtocolSupports;
@@ -32,6 +35,9 @@ import org.jetlinks.supports.protocol.management.ProtocolSupportDefinition;
 import org.jetlinks.supports.protocol.management.ProtocolSupportLoader;
 import org.jetlinks.supports.protocol.management.ProtocolSupportLoaderProvider;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.buffer.DataBufferUtils;
+import org.springframework.core.io.buffer.NettyDataBufferFactory;
 import org.springframework.web.bind.annotation.*;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
@@ -39,7 +45,9 @@ import reactor.util.function.Tuple2;
 import reactor.util.function.Tuples;
 
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping("/protocol")
@@ -62,6 +70,9 @@ public class ProtocolSupportController
     @Autowired
     private ProtocolSupportLoader supportLoader;
 
+    @Autowired
+    private FileManager fileManager;
+
     @PostMapping("/{id}/_deploy")
     @SaveAction
     @Operation(summary = "发布协议")
@@ -233,4 +244,34 @@ public class ProtocolSupportController
             .flatMap(ProtocolDetail::of);
     }
 
+
+    @PostMapping("/default-protocol/_save")
+    @SaveAction
+    @Operation(summary = "保存默认协议")
+    public Mono<Void> saveDefaultProtocol() {
+
+        String defaultProtocolName = "JetLinks官方协议";
+        String fileNeme = "jetlinks-official-protocol-3.0-SNAPSHOT.zip";
+        return fileManager
+            .saveFile(fileNeme,
+                      DataBufferUtils.read(new ClassPathResource(fileNeme),
+                                           new NettyDataBufferFactory(ByteBufAllocator.DEFAULT),
+                                           1024))
+            .flatMap(fileInfo -> {
+                Map<String, Object> conf = new HashMap<>();
+                conf.put("fileId", fileInfo.getId());
+                conf.put("provider", "org.jetlinks.protocol.official.JetLinksProtocolSupportProvider");
+                conf.put("location", fileInfo.getAccessUrl());
+                ProtocolSupportEntity entity = new ProtocolSupportEntity();
+                entity.setId(DigestUtils.md5Hex(defaultProtocolName));
+                entity.setType("jar");
+                entity.setName(defaultProtocolName);
+                entity.setState((byte) 1);
+                entity.setDescription("JetLinks官方协议包");
+                entity.setConfiguration(conf);
+                return getService().save(entity);
+            })
+            .then();
+    }
+
 }