11111
parent
aa43f6f142
commit
194214dce1
|
@ -0,0 +1,95 @@
|
||||||
|
package com.muyu.rule.server;
|
||||||
|
|
||||||
|
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.ObjectListing;
|
||||||
|
import com.aliyun.oss.model.OSSObjectSummary;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张承志
|
||||||
|
* @Package:com.muyu.rule.server
|
||||||
|
* @Project:cloud-etl-rule
|
||||||
|
* @name:DownloadOss
|
||||||
|
* @Date:2024/9/3 16:51
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实现项目启动时,把文件下载到服务器里
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
public class DownloadOss implements ApplicationRunner {
|
||||||
|
|
||||||
|
private static final String endPoint = "oss-cn-beijing.aliyuncs.com";
|
||||||
|
private static final String accessKeyId = "LTAI5tRRrrYqiSXddVq7RvqW";
|
||||||
|
private static final String accessKeySecret = "GhEg1LlHTOx4q0rxs1S3pCaSQayCVL";
|
||||||
|
private static final String accessPre = "https://zcz-vfd-1000.oss-cn-beijing.aliyuncs.com/";
|
||||||
|
|
||||||
|
private static String serverPath ="home/code/";
|
||||||
|
|
||||||
|
private static String bucketName = "zcz-vfd-1000";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
|
OSS ossClient = new OSSClientBuilder().build(endPoint, accessKeyId, accessKeySecret);
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
//获取所有的oss存储的信息
|
||||||
|
ObjectListing objectListing = ossClient.listObjects(bucketName);
|
||||||
|
|
||||||
|
|
||||||
|
//循环获取存储中的所有对象
|
||||||
|
while (true) {
|
||||||
|
for (OSSObjectSummary objectSummary : objectListing.getObjectSummaries()) {
|
||||||
|
String key = objectSummary.getKey();
|
||||||
|
downloadFile(ossClient, bucketName, key, serverPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}finally {
|
||||||
|
ossClient.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void downloadFile(OSS ossClient, String bucketName, String key, String serverPath){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//创建服务器项目容器的文件目录路径
|
||||||
|
File serverFile = new File(serverPath, key);
|
||||||
|
//如果目录不存在,则创建目录
|
||||||
|
if (!serverFile.getParentFile().exists()){
|
||||||
|
serverFile.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
//下载文件到项目中
|
||||||
|
OSSObject ossObject = ossClient.getObject(new GetObjectRequest(bucketName, key));
|
||||||
|
|
||||||
|
try(FileOutputStream fos = new FileOutputStream(serverFile);){
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int byteRead;
|
||||||
|
while ((byteRead = ossObject.getObjectContent().read(buffer)) != -1){
|
||||||
|
fos.write(buffer,0,byteRead);
|
||||||
|
}
|
||||||
|
log.info("文件 " +key +"已经下载到" + serverFile.getAbsolutePath());
|
||||||
|
}catch (IOException e){
|
||||||
|
log.error("下载文件失败:"+key);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.muyu.rule.server;
|
||||||
|
|
||||||
|
import com.muyu.rule.common.utils.OssUtil;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张承志
|
||||||
|
* @Package:com.muyu.rule.server
|
||||||
|
* @Project:cloud-etl-rule
|
||||||
|
* @name:DownloadTest
|
||||||
|
* @Date:2024/9/3 17:04
|
||||||
|
*/
|
||||||
|
public class DownloadTest {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
String cc = "fgergtrgrtgregreg";
|
||||||
|
|
||||||
|
byte[] bytes = cc.getBytes();
|
||||||
|
|
||||||
|
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
|
||||||
|
|
||||||
|
String ossPath = "com/zcz/www.java";
|
||||||
|
|
||||||
|
OssUtil.uploadFileInputStreamForBucket("zcz-vfd-1000",ossPath,byteArrayInputStream);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -44,7 +44,7 @@ public class EngineConfig {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
//private String serverPath = "home/";
|
//private String serverPath = "home/";
|
||||||
private String serverPath = "lib/";
|
private String serverPath = "home/";
|
||||||
// private String serverPath = "home/config/source/";
|
// private String serverPath = "home/config/source/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:zhangzhihao
|
* @Author:张承志
|
||||||
* @name:DataSourcesApplication
|
* @name:DataSourcesApplication
|
||||||
* @Date:2024/8/21 14:37
|
* @Date:2024/8/21 14:37
|
||||||
* 不准抄代码,添加注释,清楚每一行代码意思
|
* 不准抄代码,添加注释,清楚每一行代码意思
|
||||||
|
@ -18,4 +18,29 @@ public class EtlRuleApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(EtlRuleApplication.class);
|
SpringApplication.run(EtlRuleApplication.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.muyu.rule.server.basic.engine.value;
|
||||||
|
|
||||||
import com.muyu.rule.common.domain.DataValue;
|
import com.muyu.rule.common.domain.DataValue;
|
||||||
import com.muyu.rule.server.basic.abstracts.DataEngineValueActuator;
|
import com.muyu.rule.server.basic.abstracts.DataEngineValueActuator;
|
||||||
import com.muyu.rule.server.exception.RuleEngineException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:张承志
|
* @Author:张承志
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.muyu.rule.server.load;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load class from byte[] which is compiled in memory.
|
||||||
|
*
|
||||||
|
* @author michael
|
||||||
|
*/
|
||||||
|
class MemoryClassLoader extends URLClassLoader {
|
||||||
|
|
||||||
|
// class name to class bytes:
|
||||||
|
Map<String, byte[]> classBytes = new HashMap<String, byte[]>();
|
||||||
|
|
||||||
|
public MemoryClassLoader(Map<String, byte[]> classBytes) {
|
||||||
|
super(new URL[0], MemoryClassLoader.class.getClassLoader());
|
||||||
|
this.classBytes.putAll(classBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
||||||
|
byte[] buf = classBytes.get(name);
|
||||||
|
if (buf == null) {
|
||||||
|
return super.findClass(name);
|
||||||
|
}
|
||||||
|
classBytes.remove(name);
|
||||||
|
return defineClass(name, buf, 0, buf.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
package com.muyu.rule.server.load;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.FilterOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.CharBuffer;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.tools.FileObject;
|
||||||
|
import javax.tools.ForwardingJavaFileManager;
|
||||||
|
import javax.tools.JavaFileManager;
|
||||||
|
import javax.tools.JavaFileObject;
|
||||||
|
import javax.tools.JavaFileObject.Kind;
|
||||||
|
import javax.tools.SimpleJavaFileObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In-memory java file manager.
|
||||||
|
*
|
||||||
|
* @author michael
|
||||||
|
*/
|
||||||
|
class MemoryJavaFileManager extends ForwardingJavaFileManager<JavaFileManager> {
|
||||||
|
|
||||||
|
// compiled classes in bytes:
|
||||||
|
final Map<String, byte[]> classBytes = new HashMap<String, byte[]>();
|
||||||
|
|
||||||
|
MemoryJavaFileManager(JavaFileManager fileManager) {
|
||||||
|
super(fileManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, byte[]> getClassBytes() {
|
||||||
|
return new HashMap<String, byte[]>(this.classBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush() throws IOException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
classBytes.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JavaFileObject getJavaFileForOutput(JavaFileManager.Location location, String className, Kind kind,
|
||||||
|
FileObject sibling) throws IOException {
|
||||||
|
if (kind == Kind.CLASS) {
|
||||||
|
return new MemoryOutputJavaFileObject(className);
|
||||||
|
} else {
|
||||||
|
return super.getJavaFileForOutput(location, className, kind, sibling);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JavaFileObject makeStringSource(String name, String code) {
|
||||||
|
return new MemoryInputJavaFileObject(name, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MemoryInputJavaFileObject extends SimpleJavaFileObject {
|
||||||
|
|
||||||
|
final String code;
|
||||||
|
|
||||||
|
MemoryInputJavaFileObject(String name, String code) {
|
||||||
|
super(URI.create("string:///" + name), Kind.SOURCE);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharBuffer getCharContent(boolean ignoreEncodingErrors) {
|
||||||
|
return CharBuffer.wrap(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MemoryOutputJavaFileObject extends SimpleJavaFileObject {
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
MemoryOutputJavaFileObject(String name) {
|
||||||
|
super(URI.create("string:///" + name), Kind.CLASS);
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OutputStream openOutputStream() {
|
||||||
|
return new FilterOutputStream(new ByteArrayOutputStream()) {
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
out.close();
|
||||||
|
ByteArrayOutputStream bos = (ByteArrayOutputStream) out;
|
||||||
|
classBytes.put(name, bos.toByteArray());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.muyu.rule.server.load;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张承志
|
||||||
|
* @Package:com.muyu.rule.server.load
|
||||||
|
* @Project:cloud-etl-rule
|
||||||
|
* @name:SpringJavaFileManager
|
||||||
|
* @Date:2024/9/3 19:58
|
||||||
|
*/
|
||||||
|
public class SpringJavaFileManager {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -29,7 +29,6 @@ public class SourceDisposeServiceImpl implements SourceDisposeService {
|
||||||
@Override
|
@Override
|
||||||
public Boolean notEmpty(Object dataSource) {
|
public Boolean notEmpty(Object dataSource) {
|
||||||
|
|
||||||
|
|
||||||
if (dataSource == null || "".equals(dataSource) || "null".equals(dataSource)) {
|
if (dataSource == null || "".equals(dataSource) || "null".equals(dataSource)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -37,48 +36,4 @@ public class SourceDisposeServiceImpl implements SourceDisposeService {
|
||||||
return true;
|
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());
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue