Commit 73c49b51 by huangfusuper

切换fastdfs上传下载文件的方式 经fastdfs修改为集群模式

parent 784f6935
...@@ -54,6 +54,16 @@ myth-job: ...@@ -54,6 +54,16 @@ myth-job:
filestystem: FASTDFS filestystem: FASTDFS
snapshoot-date: 60 #快照的保存时间 单位天 snapshoot-date: 60 #快照的保存时间 单位天
fdfs:
so-timeout: 1500
connect-timeout: 600
pool:
jmx-enabled: false
tracker-list:
- 10.0.120.216:22122
- 10.0.120.217:22122
- 10.0.120.218:22122
myth: myth:
plugin: plugin:
env: ${myth-rpc.registry.env} env: ${myth-rpc.registry.env}
......
...@@ -57,6 +57,15 @@ file: ...@@ -57,6 +57,15 @@ file:
myth-job: myth-job:
filestystem: FASTDFS filestystem: FASTDFS
snapshoot-date: 60 #快照的保存时间 单位天 snapshoot-date: 60 #快照的保存时间 单位天
fdfs:
so-timeout: 1500
connect-timeout: 600
pool:
jmx-enabled: false
tracker-list:
- 10.0.120.216:22122
- 10.0.120.217:22122
- 10.0.120.218:22122
myth: myth:
plugin: plugin:
......
...@@ -52,3 +52,13 @@ file: ...@@ -52,3 +52,13 @@ file:
myth-job: myth-job:
filestystem: FASTDFS filestystem: FASTDFS
snapshoot-date: 60 #快照的保存时间 单位天 snapshoot-date: 60 #快照的保存时间 单位天
fdfs:
so-timeout: 1500
connect-timeout: 600
pool:
jmx-enabled: false
tracker-list:
- 10.0.120.216:22122
- 10.0.120.217:22122
- 10.0.120.218:22122
\ No newline at end of file
...@@ -53,3 +53,13 @@ file: ...@@ -53,3 +53,13 @@ file:
myth-job: myth-job:
filestystem: FASTDFS filestystem: FASTDFS
snapshoot-date: 60 #快照的保存时间 单位天 snapshoot-date: 60 #快照的保存时间 单位天
fdfs:
so-timeout: 1500
connect-timeout: 600
pool:
jmx-enabled: false
tracker-list:
- 10.0.120.216:22122
- 10.0.120.217:22122
- 10.0.120.218:22122
\ No newline at end of file
...@@ -12,7 +12,6 @@ import com.byit.service.RunRecordingService; ...@@ -12,7 +12,6 @@ import com.byit.service.RunRecordingService;
import com.byit.service.mapservice.RunRecordingAndEmailService; import com.byit.service.mapservice.RunRecordingAndEmailService;
import com.byit.util.TimeFormatUtil; import com.byit.util.TimeFormatUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.csource.common.MyException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
...@@ -108,7 +107,7 @@ public class RunRecordingAndEmailServiceImpl implements RunRecordingAndEmailServ ...@@ -108,7 +107,7 @@ public class RunRecordingAndEmailServiceImpl implements RunRecordingAndEmailServ
if(null != jobTaskRunLog.getLogRemotelyPath()){ if(null != jobTaskRunLog.getLogRemotelyPath()){
logStr = new String(fileSystem.downloaderFile(jobTaskRunLog.getLogRemotelyPath()), StandardCharsets.UTF_8); logStr = new String(fileSystem.downloaderFile(jobTaskRunLog.getLogRemotelyPath()), StandardCharsets.UTF_8);
} }
} catch (IOException | MyException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
stringBuilder.append("<tr align='center'>") stringBuilder.append("<tr align='center'>")
......
...@@ -13,9 +13,14 @@ ...@@ -13,9 +13,14 @@
<artifactId>myth-core-common</artifactId> <artifactId>myth-core-common</artifactId>
<dependencies> <dependencies>
<dependency> <!--<dependency>
<groupId>net.oschina.zcx7878</groupId> <groupId>net.oschina.zcx7878</groupId>
<artifactId>fastdfs-client-java</artifactId> <artifactId>fastdfs-client-java</artifactId>
</dependency>-->
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>1.26.1-RELEASE</version>
</dependency> </dependency>
<!-- slf4j --> <!-- slf4j -->
<dependency> <dependency>
......
package com.byit.filesystem; package com.byit.filesystem;
import cn.hutool.core.collection.CollectionUtil; import com.github.tobato.fastdfs.FdfsClientConfig;
import org.csource.common.MyException; import com.github.tobato.fastdfs.domain.MateData;
import org.csource.common.NameValuePair; import com.github.tobato.fastdfs.domain.StorePath;
import org.csource.fastdfs.ClientGlobal; import com.github.tobato.fastdfs.proto.storage.DownloadByteArray;
import org.csource.fastdfs.StorageClient1; import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.ByteArrayInputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -21,74 +21,62 @@ import java.util.Set; ...@@ -21,74 +21,62 @@ import java.util.Set;
*/ */
@Component @Component
@ConditionalOnExpression("'${myth-job.filestystem}'.equals('FASTDFS')") @ConditionalOnExpression("'${myth-job.filestystem}'.equals('FASTDFS')")
@Import(FdfsClientConfig.class)
public class FastDfsFileSystem implements FileSystem { public class FastDfsFileSystem implements FileSystem {
public FastDfsFileSystem() { private final FastFileStorageClient fastFileStorageClient;
try {
ClientGlobal.init("fdfs_client.conf"); public FastDfsFileSystem(FastFileStorageClient fastFileStorageClient) {
} catch (IOException | MyException e) { this.fastFileStorageClient = fastFileStorageClient;
e.printStackTrace();
}
} }
@Override @Override
public String uploadFile(byte[] fileBuffer, String fileExtName, Map<String, String> mateDaTa) throws IOException, MyException { public String uploadFile(byte[] fileBuffer, String fileExtName, Map<String, String> mateDaTas) {
TrackerClient trackerClient = new TrackerClient(); ByteArrayInputStream byteInput = new ByteArrayInputStream(fileBuffer);
TrackerServer trackerServer = trackerClient.getConnection(); Set<MateData> mateDataSet = new HashSet<>(2);
StorageClient1 storageClient1 = new StorageClient1(trackerServer, null); mateDaTas.forEach((key,value) ->{
NameValuePair[] mathList = new NameValuePair[mateDaTa.size()]; MateData mateData = new MateData();
if(CollectionUtil.isNotEmpty(mateDaTa)){ mateData.setName(key);
Set<Map.Entry<String, String>> mateSet = mateDaTa.entrySet(); mateData.setValue(value);
int i = 0; mateDataSet.add(mateData);
for (Map.Entry<String, String> mate : mateSet) { });
mathList[i] = new NameValuePair(mate.getKey(),mate.getValue());
i++; StorePath storePath = fastFileStorageClient.uploadFile(byteInput, fileBuffer.length, fileExtName, mateDataSet);
}
} return storePath.getFullPath();
String fileId = storageClient1.upload_file1(fileBuffer, fileExtName, mathList);
trackerServer.close();
return fileId;
} }
@Override @Override
public byte[] downloaderFile(String remPath) throws IOException, MyException { public byte[] downloaderFile(String remPath) {
TrackerClient trackerClient = new TrackerClient(); DownloadByteArray callback = new DownloadByteArray();
TrackerServer trackerServer = trackerClient.getConnection(); return fastFileStorageClient.downloadFile(getPathGroup(remPath), getPath(remPath), callback);
StorageClient1 storageClient1 = new StorageClient1(trackerServer, null);
byte[] bytes = storageClient1.download_file1(remPath);
trackerServer.close();
return bytes;
} }
@Override @Override
public void fileRemove(String remPath) throws IOException, MyException { public void fileRemove(String remPath) {
TrackerClient trackerClient = new TrackerClient(); fastFileStorageClient.deleteFile(remPath);
TrackerServer trackerServer = trackerClient.getConnection();
StorageClient1 storageClient1 = new StorageClient1(trackerServer, null);
storageClient1.delete_file1(remPath);
trackerServer.close();
} }
@Override @Override
public Map<String, String> getFileMate(String filePath) throws IOException, MyException { public Map<String, String> getFileMate(String filePath) {
TrackerClient trackerClient = new TrackerClient(); Set<MateData> metadataSet = fastFileStorageClient.getMetadata(getPathGroup(filePath), getPath(filePath));
TrackerServer trackerServer = trackerClient.getConnection(); HashMap<String, String> map = new HashMap<>(2);
StorageClient1 storageClient1 = new StorageClient1(trackerServer, null); metadataSet.forEach(mateData -> {
NameValuePair[] metadata1 = storageClient1.get_metadata1(filePath); map.put(mateData.getName(),mateData.getValue());
Map<String,String> map = new HashMap<String,String>(5); });
if(metadata1 != null){ return map;
for (int i = 0; i <metadata1.length ; i++) {
map.put(metadata1[i].getName(),metadata1[i].getValue());
} }
}else{
map.put("filename","filename"+filePath.substring(filePath.lastIndexOf("."),filePath.length())); public static String getPathGroup(String fullPath){
int i = fullPath.indexOf("/");
return fullPath.substring(0, i);
} }
return map; public static String getPath(String fullPath){
int i = fullPath.indexOf("/");
return fullPath.substring(i+1);
} }
public static void main(String[] args) { public static void main(String[] args) {
String filePath = "sadsadsadsadsad.py"; System.out.println(getPath("ddmp/M00/00/09/CgB4Al6mSVSAHi-rAAAABhCiqmE437.log"));
System.out.println(filePath.substring(filePath.lastIndexOf("."), filePath.length()));
} }
} }
package com.byit.filesystem; package com.byit.filesystem;
import org.csource.common.MyException;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
...@@ -17,26 +16,23 @@ public interface FileSystem { ...@@ -17,26 +16,23 @@ public interface FileSystem {
* @param mateDaTA 文件源信息 * @param mateDaTA 文件源信息
* @return 上传路径 * @return 上传路径
* @throws IOException * @throws IOException
* @throws MyException
*/ */
String uploadFile(byte[] fileBuffer, String fileExtName, Map<String, String> mateDaTA) throws IOException, MyException; String uploadFile(byte[] fileBuffer, String fileExtName, Map<String, String> mateDaTA) throws IOException;
/** /**
* 文件下载接口 * 文件下载接口
* @param remPath 远程地址 * @param remPath 远程地址
* @return 文件字节数组 * @return 文件字节数组
* @throws IOException * @throws IOException
* @throws MyException
*/ */
byte[] downloaderFile(String remPath) throws IOException, MyException; byte[] downloaderFile(String remPath) throws IOException;
/** /**
* 文件删除 * 文件删除
* @param remPath 远程地址 * @param remPath 远程地址
* @throws IOException * @throws IOException
* @throws MyException
*/ */
void fileRemove(String remPath) throws IOException, MyException; void fileRemove(String remPath) throws IOException;
/** /**
...@@ -44,9 +40,8 @@ public interface FileSystem { ...@@ -44,9 +40,8 @@ public interface FileSystem {
* @param filePath * @param filePath
* @return * @return
* @throws IOException * @throws IOException
* @throws MyException
*/ */
Map<String,String> getFileMate(String filePath) throws IOException, MyException; Map<String,String> getFileMate(String filePath) throws IOException;
} }
...@@ -17,7 +17,6 @@ import com.byit.pool.RunThreadPool; ...@@ -17,7 +17,6 @@ import com.byit.pool.RunThreadPool;
import com.byit.rpc.remoting.provider.annotation.RpcService; import com.byit.rpc.remoting.provider.annotation.RpcService;
import com.byit.utils.ServiceInfoUtil; import com.byit.utils.ServiceInfoUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.csource.common.MyException;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -145,7 +144,7 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService { ...@@ -145,7 +144,7 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService {
} catch (ProcessFailureException ignored){ } catch (ProcessFailureException ignored){
jobRunResultDto.setReturnResult(ReturnResult.FAIL); jobRunResultDto.setReturnResult(ReturnResult.FAIL);
} catch (IOException | MyException e) { } catch (IOException e) {
jobRunResultDto.setReturnResult(ReturnResult.FAIL); jobRunResultDto.setReturnResult(ReturnResult.FAIL);
e.printStackTrace(); e.printStackTrace();
} }
...@@ -205,7 +204,7 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService { ...@@ -205,7 +204,7 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService {
//写出脚本文件 //写出脚本文件
out.write(scriptByteArray); out.write(scriptByteArray);
return file.getPath(); return file.getPath();
} catch (IOException | MyException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if(out != null){ if(out != null){
......
...@@ -35,3 +35,13 @@ authentication: ...@@ -35,3 +35,13 @@ authentication:
header-name: token header-name: token
expire: 43200 # 外部token有效期为12小时 expire: 43200 # 外部token有效期为12小时
pub-key: client/pub.key # 解密 pub-key: client/pub.key # 解密
fdfs:
so-timeout: 1500
connect-timeout: 600
pool:
jmx-enabled: false
tracker-list:
- 10.0.120.216:22122
- 10.0.120.217:22122
- 10.0.120.218:22122
\ No newline at end of file
...@@ -35,3 +35,13 @@ authentication: ...@@ -35,3 +35,13 @@ authentication:
header-name: token header-name: token
expire: 43200 # 外部token有效期为12小时 expire: 43200 # 外部token有效期为12小时
pub-key: client/pub.key # 解密 pub-key: client/pub.key # 解密
fdfs:
so-timeout: 1500
connect-timeout: 600
pool:
jmx-enabled: false
tracker-list:
- 10.0.120.216:22122
- 10.0.120.217:22122
- 10.0.120.218:22122
\ No newline at end of file
...@@ -36,3 +36,13 @@ authentication: ...@@ -36,3 +36,13 @@ authentication:
header-name: token header-name: token
expire: 43200 # 外部token有效期为12小时 expire: 43200 # 外部token有效期为12小时
pub-key: client/pub.key # 解密 pub-key: client/pub.key # 解密
fdfs:
so-timeout: 1500
connect-timeout: 600
pool:
jmx-enabled: false
tracker-list:
- 10.0.120.216:22122
- 10.0.120.217:22122
- 10.0.120.218:22122
\ No newline at end of file
...@@ -36,3 +36,13 @@ authentication: ...@@ -36,3 +36,13 @@ authentication:
header-name: token header-name: token
expire: 43200 # 外部token有效期为12小时 expire: 43200 # 外部token有效期为12小时
pub-key: client/pub.key # 解密 pub-key: client/pub.key # 解密
fdfs:
so-timeout: 1500
connect-timeout: 600
pool:
jmx-enabled: false
tracker-list:
- 10.0.120.216:22122
- 10.0.120.217:22122
- 10.0.120.218:22122
\ No newline at end of file
package com.byit.job; package com.byit.job;
import com.byit.filesystem.FastDfsFileSystem; import com.byit.filesystem.FastDfsFileSystem;
import org.csource.common.MyException;
import java.io.IOException; import java.io.IOException;
...@@ -12,10 +11,10 @@ import java.io.IOException; ...@@ -12,10 +11,10 @@ import java.io.IOException;
* @date: 2019/11/20 12:18 * @date: 2019/11/20 12:18
**/ **/
public class Mains { public class Mains {
public static void main(String[] args) throws InterruptedException, IOException, MyException { public static void main(String[] args) {
FastDfsFileSystem fastDfsFileSystem = new FastDfsFileSystem(); /*FastDfsFileSystem fastDfsFileSystem = new FastDfsFileSystem(fastFileStorageClient);
byte[] bytes = fastDfsFileSystem.downloaderFile("ddmp/M00/00/00/CgB4Al5wa36ADcUtAAAAiVc2FQ85978.py"); byte[] bytes = fastDfsFileSystem.downloaderFile("ddmp/M00/00/00/CgB4Al5wa36ADcUtAAAAiVc2FQ85978.py");
System.out.println(new String(bytes)); System.out.println(new String(bytes));*/
/*new JobRunServerLauncher("/plugin.xml"); /*new JobRunServerLauncher("/plugin.xml");
JobUtils.jobCache.forEach((key,value) ->{ JobUtils.jobCache.forEach((key,value) ->{
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<module>byit-mybatis-plugin</module> <module>byit-mybatis-plugin</module>
<module>byit-myth-gateway</module> <module>byit-myth-gateway</module>
<module>byit-plugin-core</module> <module>byit-plugin-core</module>
<module>byit-myth-components</module>
</modules> </modules>
<parent> <parent>
...@@ -71,12 +72,20 @@ ...@@ -71,12 +72,20 @@
<springfox-swagger-ui.version>2.9.2</springfox-swagger-ui.version> <springfox-swagger-ui.version>2.9.2</springfox-swagger-ui.version>
<org-apache-commons.version>1.3</org-apache-commons.version> <org-apache-commons.version>1.3</org-apache-commons.version>
<fastdfs-client-java-version>1.27.0.0</fastdfs-client-java-version> <fastdfs-client-java-version>1.27.0.0</fastdfs-client-java-version>
<fastdfs-client-version>1.26.1-RELEASE</fastdfs-client-version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<!-- fastdfs-client 依赖-->
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>${fastdfs-client-version}</version>
</dependency>
<dependency> <dependency>
<groupId>net.oschina.zcx7878</groupId> <groupId>net.oschina.zcx7878</groupId>
<artifactId>fastdfs-client-java</artifactId> <artifactId>fastdfs-client-java</artifactId>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment