11111
parent
097b2a2fba
commit
7ad71f5f61
|
@ -0,0 +1,5 @@
|
|||
public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
|
@ -21,7 +21,6 @@ import lombok.experimental.SuperBuilder;
|
|||
@Tag(name = "客户端版本添加请求对象")
|
||||
public class VersionAddReq {
|
||||
|
||||
|
||||
/**
|
||||
* 版本名称
|
||||
*/
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.rule.common.utils;
|
|||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.model.GetObjectRequest;
|
||||
import com.aliyun.oss.model.OSSObject;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
@ -20,17 +21,19 @@ public class OssUtil {
|
|||
/**
|
||||
* Endpoint 存储对象概述 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限 访问路径前缀 存储对象概述
|
||||
*/
|
||||
private static String endPoint = "oss-cn-shanghai.aliyuncs.com";
|
||||
private static String accessKeyId = "LTAI5tDbRqXkC5i3SMrCSDcX";
|
||||
private static String accessKeySecret = "XUzMZoHPLsjNLafHsdQnMElBWZATsu";
|
||||
private static String accessPre = "https://mall-bw.oss-cn-shanghai.aliyuncs.com/";
|
||||
private static String endPoint = "oss-cn-beijing.aliyuncs.com";
|
||||
private static String accessKeyId = "LTAI5tRRrrYqiSXddVq7RvqW";
|
||||
private static String accessKeySecret = "GhEg1LlHTOx4q0rxs1S3pCaSQayCVL";
|
||||
private static String accessPre = "https://zcz-vfd-1000.oss-cn-beijing.aliyuncs.com/";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* bucket名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String bucketName = "mall-bw";
|
||||
private static String bucketName = "zcz-vfd-1000";
|
||||
|
||||
private static OSS ossClient;
|
||||
|
||||
|
@ -159,4 +162,39 @@ public class OssUtil {
|
|||
return getOssDefaultPath() + UUID.randomUUID().toString() + "." + fileSuf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 直接读取OSS中的文件内容
|
||||
*
|
||||
* @param bucketName 存储空间名称
|
||||
* @param objectName OSS中的对象名称
|
||||
* @return 文件内容
|
||||
*/
|
||||
public static String readFileContentFromOSS(String bucketName, String objectName) {
|
||||
// 创建OSSClient实例。
|
||||
OSS ossClient = new OSSClientBuilder().build(endPoint,accessKeyId,accessKeySecret);
|
||||
|
||||
try (OSSObject ossObject = ossClient.getObject(new GetObjectRequest(bucketName, objectName))) {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(ossObject.getObjectContent()));
|
||||
StringBuilder content = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
content.append(line).append("\n");
|
||||
}
|
||||
return content.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "读取失败:" + e.getMessage();
|
||||
} finally {
|
||||
// 关闭OSSClient。
|
||||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
package com.muyu.rule.server;
|
||||
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import com.muyu.rule.common.domain.DataValue;
|
||||
import com.muyu.rule.common.utils.OssUtil;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
|
@ -9,17 +21,50 @@ import com.muyu.rule.common.domain.DataValue;
|
|||
* @name:DataTest
|
||||
* @Date:2024/8/27 9:43
|
||||
*/
|
||||
|
||||
public class DataTest {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Endpoint 存储对象概述 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限 访问路径前缀 存储对象概述
|
||||
*/
|
||||
private static String endPoint = "oss-cn-beijing.aliyuncs.com";
|
||||
private static String accessKeyId = "LTAI5tRRrrYqiSXddVq7RvqW";
|
||||
private static String accessKeySecret = "GhEg1LlHTOx4q0rxs1S3pCaSQayCVL";
|
||||
private static String accessPre = "https://zcz-vfd-1000.oss-cn-beijing.aliyuncs.com/";
|
||||
|
||||
private static String bucketName = "zcz-vfd-1000";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
DataValue describe = new DataValue();
|
||||
String sourceCode ="public class HelloWorld {\n" +
|
||||
" public static void main(String[] args) {\n" +
|
||||
" System.out.println(\"Hello, World!\");\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
|
||||
describe.setKey("name");
|
||||
describe.setType("String");
|
||||
describe.setLabel("姓名");
|
||||
describe.setValue("张三");
|
||||
// 创建OSSClient实例。
|
||||
OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, accessKeySecret);
|
||||
|
||||
// 将字符串转换为字节数组。
|
||||
byte[] contentBytes = sourceCode.getBytes();
|
||||
|
||||
// 创建PutObjectRequest。
|
||||
PutObjectRequest put = new PutObjectRequest(bucketName, "test", new ByteArrayInputStream(contentBytes));
|
||||
|
||||
// 上传字符串到OSS。
|
||||
ossClient.putObject(put);
|
||||
|
||||
// 关闭OSSClient。
|
||||
ossClient.shutdown();
|
||||
//读取
|
||||
String s = OssUtil.readFileContentFromOSS(bucketName, "test");
|
||||
|
||||
System.out.println(s);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package com.muyu.rule.server;
|
||||
|
||||
|
||||
import com.muyu.rule.common.utils.OssUtil;
|
||||
import com.muyu.rule.server.complie.SourceCodeComplier;
|
||||
import com.muyu.rule.server.execution.EngineExecution;
|
||||
import com.muyu.rule.server.load.JavaBinaryClassLoader;
|
||||
import com.muyu.rule.server.pool.container.EngineContainer;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -22,6 +27,24 @@ public class EngineTest {
|
|||
|
||||
EngineConfig engineConfig = new EngineConfig();
|
||||
|
||||
// String string = OssUtil.uploadFileInputStreamForBucket("zcz-vfd-1000", engineConfig.getPack(),"E:\\practical_training\\cloud-etl-rule\\cloud-rule-server\\src\\main\\java\\com\\muyu\\rule\\server\\engine\\Engine_2024_8_23_2347.java");
|
||||
//
|
||||
// try {
|
||||
// InputStream fileInputStream = new FileInputStream("src/main/java/com/muyu/rule/server/engine/Engine_2024_8_23_2347.java");
|
||||
// } catch (FileNotFoundException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
//
|
||||
// System.out.println(string);
|
||||
//
|
||||
// String ossFilePath = OssUtil.getOssFilePath(engineConfig.getPack());
|
||||
//
|
||||
// System.out.println("===>"+ossFilePath);
|
||||
////读取
|
||||
//String s = OssUtil.readFileContentFromOSS("zcz-vfd-1000", engineConfig.getPack());
|
||||
|
||||
// System.out.println(s);
|
||||
|
||||
//扫描原码进行编译+-+-
|
||||
SourceCodeComplier.javaCompilerPath(engineConfig.getLocation());
|
||||
//对class文件进行自定义类加载规则引擎
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.muyu.rule.server;
|
|||
|
||||
import com.muyu.rule.common.domain.DataValue;
|
||||
import com.muyu.rule.server.basic.BasicEngine;
|
||||
import com.muyu.rule.server.basic.engine.ENGINE_VALUE_VFD1000_V1;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -21,7 +20,7 @@ public class Main {
|
|||
|
||||
static {
|
||||
try {
|
||||
Class<?> aClass = Class.forName("com.muyu.rule.server.basic.engine.ENGINE_VALUE_VFD1000_V1");
|
||||
Class<?> aClass = Class.forName("com.muyu.rule.server.basic.engine.value.ENGINE_VALUE_VFD1000_V1");
|
||||
|
||||
try {
|
||||
engineMap.put("ENGINE_VALUE_VFD1000_V1", (BasicEngine<DataValue>) aClass.newInstance());
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.muyu.rule.server.basic.engine.row;
|
||||
|
||||
import com.muyu.rule.common.domain.DataValue;
|
||||
import com.muyu.rule.server.basic.abstracts.DataEngineRowActuator;
|
||||
import com.muyu.rule.server.basic.handler.DataEngineRowHandler;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server.basic.engine.row
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:ENGINE_ROW_HANG_R1
|
||||
* @Date:2024/8/30 11:13
|
||||
*/
|
||||
public class ENGINE_ROW_HANG_R1 extends DataEngineRowActuator {
|
||||
|
||||
|
||||
@Override
|
||||
public void execution() {
|
||||
DataValue[] dataValues = get();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.rule.server.basic.engine;
|
||||
package com.muyu.rule.server.basic.engine.value;
|
||||
|
||||
import com.muyu.rule.common.domain.DataValue;
|
||||
import com.muyu.rule.server.basic.abstracts.DataEngineValueActuator;
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.rule.server.basic.engine;
|
||||
package com.muyu.rule.server.basic.engine.value;
|
||||
|
||||
import com.muyu.rule.common.domain.DataValue;
|
||||
import com.muyu.rule.common.utils.Desensitization;
|
||||
|
@ -17,8 +17,6 @@ public class ENGINE_VALUE_VFD1000_V2 extends DataEngineValueActuator {
|
|||
DataValue dataValue = get();
|
||||
|
||||
String string = Desensitization.mobilePhoneDesensitization((String) dataValue.getValue());
|
||||
|
||||
System.out.println("手机号脱敏的结果是====>"+string);
|
||||
|
||||
}
|
||||
}
|
|
@ -33,7 +33,6 @@ public static void javaCompilerPath(String path){
|
|||
|
||||
javaCampiler(files);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输入编译的文件路径
|
||||
* @param filePath
|
||||
|
|
|
@ -38,10 +38,17 @@ public class RuleEngineVersionController {
|
|||
|
||||
|
||||
@PostMapping("/insertVersion")
|
||||
@Operation(summary = "规则引擎版本",description = "通过传入版本添加的实体类,进行规则引擎的版本添加")
|
||||
@Operation(summary = "增加规则引擎版本",description = "通过传入版本添加的实体类,进行规则引擎的版本添加")
|
||||
public Result insertVersion(@Validated @RequestBody VersionAddReq versionAddReq){
|
||||
|
||||
versionService.save(RuleEngineVersion.addBuild(versionAddReq));
|
||||
boolean save = versionService.save(RuleEngineVersion.addBuild(versionAddReq));
|
||||
if (true==save){
|
||||
//添加成功则把增加的代码进行java编译,进行热加载
|
||||
versionService.HotLoadClass(versionAddReq.getClassName(),versionAddReq.getVersionClazz());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
@ -76,12 +83,11 @@ public class RuleEngineVersionController {
|
|||
|
||||
|
||||
/**
|
||||
* 上传
|
||||
* 将源码写入到OSS中
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
|
||||
|
||||
@PostMapping("/deposit")
|
||||
public Result deposit(@RequestBody VersionAddReq ver ){
|
||||
|
||||
|
@ -96,7 +102,13 @@ public class RuleEngineVersionController {
|
|||
}
|
||||
|
||||
|
||||
@PostMapping("/readByOss/{className}")
|
||||
public Result readByOss(@PathVariable String className){
|
||||
|
||||
Object o= versionService.readByOss(className);
|
||||
|
||||
return Result.success(o);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -35,4 +35,14 @@ public interface RuleEngineVersionService extends IService<RuleEngineVersion> {
|
|||
*/
|
||||
|
||||
void Upload(String versionClazz,String className);
|
||||
|
||||
/**
|
||||
* 从OSS服务器读取文件的接口
|
||||
* @param className 类名
|
||||
* @return
|
||||
*/
|
||||
Object readByOss(String className);
|
||||
|
||||
void HotLoadClass(String className, String versionClazz);
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import org.springframework.stereotype.Service;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -65,30 +67,45 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineVersionMapper,R
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* bucket名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String bucketName = "zcz-vfd-1000";
|
||||
/**
|
||||
*
|
||||
* @param versionClazz 具体代码
|
||||
* @param versionClazz java源代码
|
||||
* @param className 类的名
|
||||
*/
|
||||
@Override
|
||||
public void Upload(String versionClazz,String className) {
|
||||
|
||||
// 使用ByteArrayInputStream将字符串内容转换为输入流
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(versionClazz.getBytes());
|
||||
|
||||
/**
|
||||
* 将java源码存入OSS
|
||||
*/
|
||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(versionClazz.getBytes());
|
||||
OssUtil.uploadFileInputStreamForBucket(bucketName,className,byteArrayInputStream);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readByOss(String className) {
|
||||
|
||||
String string = OssUtil.readFileContentFromOSS(bucketName, className);
|
||||
|
||||
|
||||
OssUtil.uploadFileInputStreamForBucket("mall-bw",className,inputStream);
|
||||
return string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void HotLoadClass(String className, String versionClazz) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// OssUtil.uploadFileInputStreamForBucket(,"E:\\practical_training\\cloud-etl-rule\\cloud-rule-server\\src\\main\\java\\com\\muyu\\rule\\server\\engine\\");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.rule.server.service.impl;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.rule.common.utils.Desensitization;
|
||||
import com.muyu.rule.server.exception.ActionDiscard;
|
||||
import com.muyu.rule.server.service.SourceDisposeService;
|
||||
|
@ -35,4 +36,49 @@ public class SourceDisposeServiceImpl implements SourceDisposeService {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
// public Result uploadFiles(String content, String fileName) {
|
||||
//
|
||||
// //uploadDir
|
||||
// String host = "12.66.2.3";
|
||||
// int port = 22;
|
||||
// String user = "root";
|
||||
// String password = "Six@211206";
|
||||
// String remoteFilePath = "/home/engine/"+fileName+".java";
|
||||
//
|
||||
// try {
|
||||
// JSch jsch = new JSch();
|
||||
// Session session = jsch.getSession(user, host, port);
|
||||
// session.setPassword(password);
|
||||
//
|
||||
// Properties config = new Properties();
|
||||
// config.put("StrictHostKeyChecking", "no");
|
||||
// session.setConfig(config);
|
||||
//
|
||||
// session.connect();
|
||||
//
|
||||
// Channel channel = session.openChannel("sftp");
|
||||
// channel.connect();
|
||||
//
|
||||
// ChannelSftp channelSftp = (ChannelSftp) channel;
|
||||
//
|
||||
// // 使用ByteArrayInputStream将字符串内容转换为输入流
|
||||
// ByteArrayInputStream inputStream = new ByteArrayInputStream(content.getBytes());
|
||||
//
|
||||
// // 上传文件
|
||||
// channelSftp.put(inputStream, remoteFilePath);
|
||||
//
|
||||
// inputStream.close();
|
||||
//
|
||||
// channelSftp.exit();
|
||||
// session.disconnect();
|
||||
//
|
||||
// return Result.success(null,"字符串已成功上传到SSH服务器!");
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// return Result.error(null,"上传到SSH服务器时出错:" + e.getMessage());
|
||||
//
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue