From 48b6ec7eb3a4e2f2d4d04428fc74a46d5dbdcf1b Mon Sep 17 00:00:00 2001 From: xiwa Date: Wed, 30 Mar 2022 01:59:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=AE=AF=E7=BB=84=E4=BB=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + components/.DS_Store | Bin 6148 -> 6148 bytes data/elasticsearch/nodes/0/_state/_3.cfe | Bin 278 -> 0 bytes data/elasticsearch/nodes/0/_state/_3.cfs | Bin 1274 -> 0 bytes data/elasticsearch/nodes/0/_state/_3.si | Bin 378 -> 0 bytes .../nodes/0/_state/manifest-0.st | Bin 109 -> 0 bytes data/elasticsearch/nodes/0/_state/node-0.st | Bin 89 -> 0 bytes data/elasticsearch/nodes/0/_state/segments_5 | Bin 245 -> 0 bytes data/elasticsearch/nodes/0/_state/write.lock | 0 data/elasticsearch/nodes/0/node.lock | 0 .../manager/config/ElasticSearchConfig.java | 0 .../controller/ProtocolController.java | 58 ++++++-- .../model/protocol/ProtocolComponent.java | 4 +- .../cc/iotkit/comps/ComponentClassLoader.java | 0 .../src/main/resources/component.spi | 0 .../src/main/resources/component.js | 137 +++++++++--------- .../src/main/resources/component.spi | 0 17 files changed, 113 insertions(+), 88 deletions(-) mode change 100644 => 100755 components/.DS_Store delete mode 100644 data/elasticsearch/nodes/0/_state/_3.cfe delete mode 100644 data/elasticsearch/nodes/0/_state/_3.cfs delete mode 100644 data/elasticsearch/nodes/0/_state/_3.si delete mode 100644 data/elasticsearch/nodes/0/_state/manifest-0.st delete mode 100644 data/elasticsearch/nodes/0/_state/node-0.st delete mode 100644 data/elasticsearch/nodes/0/_state/segments_5 delete mode 100644 data/elasticsearch/nodes/0/_state/write.lock delete mode 100644 data/elasticsearch/nodes/0/node.lock mode change 100644 => 100755 manager/src/main/java/cc/iotkit/manager/config/ElasticSearchConfig.java mode change 100644 => 100755 protocol-gateway/component-server/src/main/java/cc/iotkit/comps/ComponentClassLoader.java mode change 100644 => 100755 protocol-gateway/emqx-component/src/main/resources/component.spi mode change 100644 => 100755 protocol-gateway/mqtt-component/src/main/resources/component.spi diff --git a/.gitignore b/.gitignore index 8da0c3c1..d9c4d48c 100755 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ target *.iml *.yml log +components +data diff --git a/components/.DS_Store b/components/.DS_Store old mode 100644 new mode 100755 index 612370d1330a9cfae3ada62dc7c11631f71ed1a3..d35af10813ea88294ea88c8f5c1aae3821a506f4 GIT binary patch delta 586 zcmZoMXfc=|#>B!ku~2NHo}wrV0|Nsi1A_nqLo!1ugE@l*gD!*F#)r$9LqRes3}y@_ zK$waw3shstU<_1e!eGjf1ZIImEEv*&Vu=h!K(Q3C3JV4UAkPw{sw}uDFDE}QePTyU zy$aA8kYx}HErE)4fg*`O2(sJ+C~g5Hb%7dFfJP>P4K)R_je)96fJP<)MGZl8Qh9Mf zQcivn(4k+G3UV@wOAHKdFfuW-u(GjpaB^{Ta`SO>#|CHQmj{<5mXsDdB^JdC$kYdC zrlck%7KLY~lw^dY=DFsimZj$T7x^TXq!vYkREOl}=KvKz*ojGDnW^RR0wT`&c_oRN zd8tKU10iO_glFcZ>&Xz`)7D881*TQC)3p zYOJGRY-~`gqfl*bZlI%JVr*7h%gMIjfQYH+H6A_;4F!XgQ1=*9=D7&o(X@N)oD%EpJ^nJ4p$7_x#~(JCJ*u~2NHo}wrt0|NsP3otOGGNdphGbAzSG8jxORG*y861iD~Lzrb_ jg8=hpb`E|Hpq|Zw9N(EI^NScVGEBDNk=`65vVs`^%)SyF diff --git a/data/elasticsearch/nodes/0/_state/_3.cfe b/data/elasticsearch/nodes/0/_state/_3.cfe deleted file mode 100644 index cf99088bf5625d865d7b89fabca7ebe890759c25..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 278 zcmcD&o+B>qQ<|KbmuhO@oS$2eUz(TVnpaYknOe*M1T&9(IKDFS&sz=7)5~-XV}CJl zu;`_wRDh&_Ko3GOIPk|q%&;(tH_%JTPlk%;L1{mbrd%jz50st<6wHGPGDblKSD~0x zk_nY(Vu8wsf=nubaF`+?G-ErOrUHmK^8*OY;DIWin*tGM(SXVyI-oK61(eNDd+lv6 E09fZbod5s; diff --git a/data/elasticsearch/nodes/0/_state/_3.cfs b/data/elasticsearch/nodes/0/_state/_3.cfs deleted file mode 100644 index 4d78d2464bca17efdfe4c3ec9f14f85be378fc4a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1274 zcmah|&ubGw6rS0nsjaYxmKM?CLB#eDNuf=O2Machu0|;&Aw-a{*`372-JP&INt58A zAk-GYOO&7o5f6eO2%bIEB6uixD`Nfv4=Q^qZ6fN-{-B$*)(6X*<$dqlZ|8k)?u$A$ zlB`HbM>COmtd(&^m*XN40gb00txvCWzkW;%ZN3Um-R^)niXL^)voi?=sj?~PGO7u3 z?LhqcMDrUfu+ZP1PqO}#ZvXTmHi@E_%&eghWW=#VL9qXm!yY;xN&49uZ-ZNmZR`Lw zH;^qq*v|!)*Uxe6BlH=j4?DAnI0=BcW$(0?y<&9!#r~>Wgi8=Yzq+sQE)6nu#~pRi zh<#UrUc@G4=JpBWf}~zXfP>(V8{GIJGVCtzniAO1L~@~Mrz76A{0nAQibbUcBOoZ# zVX{B=m;vxB&At3EX)C>~V(D($Kq!q2&5SD&p*^8~rM__lrb{X=h-x4NA$PBbbfoqC zJ0m^qs*I%wHjwNXCLx-{HQ4?Mfe?Jg!Ex@47o*39EWX8EoE#qLtZHj0Lb?#k33uwLoK_~+%9*IePYI3Lr6-aPm6x!lDTE;Tti?CI ziiEKtE4oN1Z|6Q`)HWVdaw>NZPfvPLDeYvWd^8ciZt;Sc7P1X7lU4FJ>kGN1-KO0j zN)jp)i$`)_haYe8c1Np<*&evSJgPB4RD;EvJGoQ<|Kbmug`aoSL4SnpfhPmzK`}1T&9(IKDFS&sz=7)5~-XV}F6fIDnWF z#9&0`fcT7DO!>tezKO{S{=o_n+*yfbiF#$Jc`5ltLjFaG$vLSC&iO?J`9+B(nfZA< zQ0by#AcxaX&qB{2-pI_5A0nI!)CiX0GBVWz3hO2r8u8_T9SM_Rwa~NFGhojz)=Ml( z&S0ysFpD=c5dmv2D$Og&%uR)<JCys=(!CL54UPAi5`sf_Z_kTVZ1$uCMxam!52 qNhx;AFUn0U(aX(GN#$~K4GxJ94sdmKVK|^M`2{H8KtOS#qZI(z>u)Fk diff --git a/data/elasticsearch/nodes/0/_state/manifest-0.st b/data/elasticsearch/nodes/0/_state/manifest-0.st deleted file mode 100644 index 030f9cbe09eade2c5fa41802ec7ca16ee9e3ac1f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 109 zcmcD&o+Hj$T#{Il%D}+D2*OsHT&%yklS_+=Qu9jUOHzw+4@^nUDJ=%F;=u~z%TkMq tGxPHfbf%}~r4}WY0NDp8Wag!$R>UJjihun4eL!RK3!sr;pmG1sCIFIlD$W1^ diff --git a/data/elasticsearch/nodes/0/_state/node-0.st b/data/elasticsearch/nodes/0/_state/node-0.st deleted file mode 100644 index a819c66f42c5335dada71a9525e4aec2c24bd285..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 89 zcmcD&o+Hj$T#{Il%D}+D2*OsHT&%y^^72zs<1zeDFQX|3Cj$pi1_UHofCM8@ zfGOS>P2n#NpVH*iyi^PG|4;zZ0As^wkQgJH&OabQ1{R*Y{FK!AvecsD%=|odb3;=D zBTGxsoW$ai_{8Mo)Pj=K6qqcdAy0B?Q4!F|@g=E6xr~PFV7-|sV#)DlZZ6)Qi6Nfh cRf(bDnel#=u94*jG$y|QTLL7WWS?UJ01?Sx(*OVf diff --git a/data/elasticsearch/nodes/0/_state/write.lock b/data/elasticsearch/nodes/0/_state/write.lock deleted file mode 100644 index e69de29b..00000000 diff --git a/data/elasticsearch/nodes/0/node.lock b/data/elasticsearch/nodes/0/node.lock deleted file mode 100644 index e69de29b..00000000 diff --git a/manager/src/main/java/cc/iotkit/manager/config/ElasticSearchConfig.java b/manager/src/main/java/cc/iotkit/manager/config/ElasticSearchConfig.java old mode 100644 new mode 100755 diff --git a/manager/src/main/java/cc/iotkit/manager/controller/ProtocolController.java b/manager/src/main/java/cc/iotkit/manager/controller/ProtocolController.java index 9fabe171..dee6ae4a 100755 --- a/manager/src/main/java/cc/iotkit/manager/controller/ProtocolController.java +++ b/manager/src/main/java/cc/iotkit/manager/controller/ProtocolController.java @@ -1,6 +1,7 @@ package cc.iotkit.manager.controller; import cc.iotkit.common.exception.BizException; +import cc.iotkit.common.utils.JsonUtil; import cc.iotkit.common.utils.ReflectUtil; import cc.iotkit.comp.CompConfig; import cc.iotkit.comp.mqtt.MqttComponent; @@ -56,21 +57,29 @@ public class ProtocolController { @Autowired private ComponentManager componentManager; - private Path getFilePath(String comId, String type) { - return Paths.get(String.format("%s/%s/%s", componentDir, comId, type)) + private Path getFilePath(String comId) { + return Paths.get(String.format("%s/%s", componentDir, comId)) .toAbsolutePath().normalize(); } @PostMapping("/uploadJar") - public String uploadJar(@RequestParam("file") MultipartFile file) { + public String uploadJar(@RequestParam("file") MultipartFile file, String id) { if (file == null) { throw new BizException("file is null"); } log.info("saving upload jar file:{}", file.getName()); String fileName = StringUtils.cleanPath(file.getOriginalFilename()); try { - String id = UUID.randomUUID().toString(); - Path jarFilePath = getFilePath(id, "jar"); + if (StringUtils.hasLength(id)) { + Optional optComponent = protocolComponentRepository.findById(id); + if (!optComponent.isPresent()) { + throw new BizException("the protocol component does not exists"); + } + dataOwnerService.checkOwner(optComponent.get()); + } else { + id = UUID.randomUUID().toString(); + } + Path jarFilePath = getFilePath(id); Files.createDirectories(jarFilePath); Path targetLocation = jarFilePath.resolve(fileName); Files.copy(file.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING); @@ -86,7 +95,7 @@ public class ProtocolController { if (!StringUtils.hasLength(id)) { throw new BizException("component id is blank"); } - Path jarPath = getFilePath(id, "jar"); + Path jarPath = getFilePath(id); if (!jarPath.resolve(component.getJarFile()).toFile().exists()) { throw new BizException("component jar file does not exist"); } @@ -115,7 +124,7 @@ public class ProtocolController { if (!StringUtils.hasLength(id)) { throw new BizException("component id is blank"); } - Path jarPath = getFilePath(id, "jar"); + Path jarPath = getFilePath(id); if (!jarPath.resolve(component.getJarFile()).toFile().exists()) { throw new BizException("component jar file does not exist"); } @@ -139,18 +148,39 @@ public class ProtocolController { } } - @PostMapping("/saveComponentScript") - public void saveComponentScript(@RequestBody ProtocolComponent component) { - Optional optComponent = protocolComponentRepository.findById(component.getId()); + @GetMapping("/getComponentScript/{id}") + public String getComponentScript(@PathVariable("id") String id) { + Optional optComponent = protocolComponentRepository.findById(id); if (!optComponent.isPresent()) { throw new BizException("the component does not exists"); } + ProtocolComponent component = optComponent.get(); dataOwnerService.checkOwner(component); - ProtocolComponent oldComponent = optComponent.get(); - oldComponent.setScriptFile(component.getScriptFile()); try { -// gatewayService.saveFunction(oldGateway.getUuid(), oldGateway.getId(), -// "new (function (){" + oldGateway.getScript() + "})()", functionJar); + Path path = getFilePath(id); + File file = path.resolve(ProtocolComponent.SCRIPT_FILE_NAME).toFile(); + return FileUtils.readFileToString(file, "UTF-8"); + } catch (Throwable e) { + log.error("read component script file error", e); + return ""; + } + } + + @PostMapping("/saveComponentScript/{id}") + public void saveComponentScript( + @PathVariable("id") String id, + @RequestBody String script) { + Optional optComponent = protocolComponentRepository.findById(id); + if (!optComponent.isPresent()) { + throw new BizException("the component does not exists"); + } + ProtocolComponent oldComponent = optComponent.get(); + dataOwnerService.checkOwner(oldComponent); + try { + Path path = getFilePath(id); + File file = path.resolve(ProtocolComponent.SCRIPT_FILE_NAME).toFile(); + script = JsonUtil.parse(script, String.class); + FileUtils.writeStringToFile(file, script, "UTF-8", false); protocolComponentRepository.save(oldComponent); } catch (Throwable e) { throw new BizException("save protocol component script error", e); diff --git a/model/src/main/java/cc/iotkit/model/protocol/ProtocolComponent.java b/model/src/main/java/cc/iotkit/model/protocol/ProtocolComponent.java index 40ee8bf7..97b1aa0c 100755 --- a/model/src/main/java/cc/iotkit/model/protocol/ProtocolComponent.java +++ b/model/src/main/java/cc/iotkit/model/protocol/ProtocolComponent.java @@ -12,6 +12,8 @@ public class ProtocolComponent implements Owned { public static final String STATE_STOPPED = "stopped"; public static final String STATE_RUNNING = "running"; + public static final String SCRIPT_FILE_NAME = "component.js"; + @Id private String id; @@ -28,8 +30,6 @@ public class ProtocolComponent implements Owned { private String config; - private String scriptFile; - private String state; private Long createAt; diff --git a/protocol-gateway/component-server/src/main/java/cc/iotkit/comps/ComponentClassLoader.java b/protocol-gateway/component-server/src/main/java/cc/iotkit/comps/ComponentClassLoader.java old mode 100644 new mode 100755 diff --git a/protocol-gateway/emqx-component/src/main/resources/component.spi b/protocol-gateway/emqx-component/src/main/resources/component.spi old mode 100644 new mode 100755 diff --git a/protocol-gateway/mqtt-component/src/main/resources/component.js b/protocol-gateway/mqtt-component/src/main/resources/component.js index b9c8a840..cd505874 100755 --- a/protocol-gateway/mqtt-component/src/main/resources/component.js +++ b/protocol-gateway/mqtt-component/src/main/resources/component.js @@ -1,84 +1,77 @@ -new (function () { - !function(n){"use strict";function d(n,t){var r=(65535&n)+(65535&t);return(n>>16)+(t>>16)+(r>>16)<<16|65535&r}function f(n,t,r,e,o,u){return d((u=d(d(t,n),d(e,u)))<>>32-o,r)}function l(n,t,r,e,o,u,c){return f(t&r|~t&e,n,t,o,u,c)}function g(n,t,r,e,o,u,c){return f(t&e|r&~e,n,t,o,u,c)}function v(n,t,r,e,o,u,c){return f(t^r^e,n,t,o,u,c)}function m(n,t,r,e,o,u,c){return f(r^(t|~e),n,t,o,u,c)}function c(n,t){var r,e,o,u;n[t>>5]|=128<>>9<<4)]=t;for(var c=1732584193,f=-271733879,i=-1732584194,a=271733878,h=0;h>5]>>>e%32&255);return t}function a(n){var t=[];for(t[(n.length>>2)-1]=void 0,e=0;e>5]|=(255&n.charCodeAt(e/8))<>>4&15)+r.charAt(15&t);return e}function r(n){return unescape(encodeURIComponent(n))}function o(n){return i(c(a(n=r(n)),8*n.length))}function u(n,t){return function(n,t){var r,e=a(n),o=[],u=[];for(o[15]=u[15]=void 0,16>16)+(t>>16)+(r>>16)<<16|65535&r}function f(n,t,r,e,o,u){return d((u=d(d(t,n),d(e,u)))<>>32-o,r)}function l(n,t,r,e,o,u,c){return f(t&r|~t&e,n,t,o,u,c)}function g(n,t,r,e,o,u,c){return f(t&e|r&~e,n,t,o,u,c)}function v(n,t,r,e,o,u,c){return f(t^r^e,n,t,o,u,c)}function m(n,t,r,e,o,u,c){return f(r^(t|~e),n,t,o,u,c)}function c(n,t){var r,e,o,u;n[t>>5]|=128<>>9<<4)]=t;for(var c=1732584193,f=-271733879,i=-1732584194,a=271733878,h=0;h>5]>>>e%32&255);return t}function a(n){var t=[];for(t[(n.length>>2)-1]=void 0,e=0;e>5]|=(255&n.charCodeAt(e/8))<>>4&15)+r.charAt(15&t);return e}function r(n){return unescape(encodeURIComponent(n))}function o(n){return i(c(a(n=r(n)),8*n.length))}function u(n,t){return function(n,t){var r,e=a(n),o=[],u=[];for(o[15]=u[15]=void 0,16