新增虚拟机信息同步到调度器

segment2.0
beeajax 2 years ago
parent 27a4404a05
commit fd55f7cfae

@ -1,21 +1,18 @@
package com.docus.server.controller; package com.docus.server.controller;
import com.docus.server.api.scheduling.management.FileApi;
import com.docus.server.service.IFileUploadService; import com.docus.server.service.IFileUploadService;
import org.springframework.core.io.ByteArrayResource; import io.swagger.annotations.Api;
import org.springframework.http.HttpEntity; import io.swagger.annotations.ApiImplicitParam;
import org.springframework.http.HttpHeaders; import io.swagger.annotations.ApiImplicitParams;
import org.springframework.http.HttpMethod; import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/** /**
* API * API
@ -23,37 +20,27 @@ import java.io.IOException;
* @author AutoGenerator * @author AutoGenerator
* @since 2023-07-15 * @since 2023-07-15
*/ */
@Api(value = "通用文件上传下载接口", tags = "通用文件上传下载接口")
@RestController @RestController
public class FileController implements FileApi { @RequestMapping("/sch/file")
public class FileController {
@Resource @Resource
private IFileUploadService iFileUploadService; private IFileUploadService iFileUploadService;
@Resource
private RestTemplate restTemplate;
@Override @ApiOperation("文件下载")
@GetMapping("/download")
// @Override
public void downloadFile(String filePath, HttpServletResponse response) throws Exception { public void downloadFile(String filePath, HttpServletResponse response) throws Exception {
iFileUploadService.downloadFile(filePath, response); iFileUploadService.downloadFile(filePath, response);
} }
@Override @ApiOperation("文件上传")
public void uploadFile(MultipartFile[] multipartFiles, String pathKey) throws Exception { @PostMapping("/upload")
iFileUploadService.uploadFile(multipartFiles, pathKey); @ApiImplicitParams({
} @ApiImplicitParam(name = "files", value = "文件", required = true, dataTypeClass = MultipartFile.class)
})
@Override // @Override
public void downLoadFromUrl(String urlStr, String fileName, String savePath) throws Exception { public void uploadFile(MultipartFile[] files, String pathKey) throws Exception {
iFileUploadService.downLoadFromUrl(urlStr, fileName, savePath); iFileUploadService.uploadFile(files, pathKey);
}
@Override
public ResponseEntity<ByteArrayResource> downloadFile(@RequestParam String url) throws IOException {
HttpEntity<String> request = new HttpEntity<>(new HttpHeaders());
ResponseEntity<byte[]> response = restTemplate.exchange(url, HttpMethod.GET, request, byte[].class);
ByteArrayResource resource = new ByteArrayResource(response.getBody());
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + "your_file_name")
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.contentLength(resource.contentLength())
.body(resource);
} }
} }

@ -52,8 +52,8 @@ public class SchVirtualLogController implements SchVirtualLogApi {
* @return * @return
*/ */
@Override @Override
public boolean add(AddSchVirtualLogDTO addSchVirtualLogDTO) { public void add(AddSchVirtualLogDTO addSchVirtualLogDTO) {
return iSchVirtualLogService.add(addSchVirtualLogDTO); iSchVirtualLogService.add(addSchVirtualLogDTO);
} }
/** /**
@ -63,8 +63,8 @@ public class SchVirtualLogController implements SchVirtualLogApi {
* @return * @return
*/ */
@Override @Override
public boolean edit(EditSchVirtualLogDTO editSchVirtualLogDTO) { public void edit(EditSchVirtualLogDTO editSchVirtualLogDTO) {
return iSchVirtualLogService.edit(editSchVirtualLogDTO); iSchVirtualLogService.edit(editSchVirtualLogDTO);
} }
/** /**

@ -11,6 +11,4 @@ public interface IFileUploadService {
List<UploadFileVO> uploadFile(MultipartFile[] multipartFiles, String pathKey) throws Exception; List<UploadFileVO> uploadFile(MultipartFile[] multipartFiles, String pathKey) throws Exception;
void downloadFile(String filePath, HttpServletResponse response); void downloadFile(String filePath, HttpServletResponse response);
void downLoadFromUrl(String urlStr, String fileName, String savePath) throws Exception;
} }

@ -7,32 +7,17 @@ import com.docus.infrastructure.web.exception.ExceptionCode;
import com.docus.server.service.IFileUploadService; import com.docus.server.service.IFileUploadService;
import com.docus.server.vo.scheduling.management.schcollectorversionfile.UploadFileVO; import com.docus.server.vo.scheduling.management.schcollectorversionfile.UploadFileVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.httpclient.util.URIUtil;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.security.cert.CertificateException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
@ -50,8 +35,6 @@ public class FileUploadServiceImpl implements IFileUploadService {
private static DateTimeFormatter ymdDtf = DateTimeFormatter.ofPattern("yyyyMMdd"); private static DateTimeFormatter ymdDtf = DateTimeFormatter.ofPattern("yyyyMMdd");
private String userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36";
@Override @Override
public List<UploadFileVO> uploadFile(MultipartFile[] multipartFiles, String pathKey) throws Exception { public List<UploadFileVO> uploadFile(MultipartFile[] multipartFiles, String pathKey) throws Exception {
@ -137,155 +120,6 @@ public class FileUploadServiceImpl implements IFileUploadService {
} }
} }
/**
*
*/
private final HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
@Override
public void downLoadFromUrl(String urlStr, String fileName, String savePath) throws Exception {
long start = System.currentTimeMillis();
urlStr = urlStr.replace("\\", "/");
urlStr = URIUtil.encodePathQuery(urlStr);
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
try {
boolean useHttps = urlStr.toLowerCase().startsWith("https");
if (useHttps) {
HttpsURLConnection https = (HttpsURLConnection) conn;
trustAllHosts(https);
https.setHostnameVerifier(DO_NOT_VERIFY);
}
//设置超时间为3秒
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", userAgent);
conn.setRequestProperty("Accept-Encoding", "identity");
conn.setConnectTimeout(8 * 1000);
conn.setReadTimeout(8 * 1000);
conn = reload(conn);
long length = conn.getContentLength();
if (length < 0) {
String values = conn.getHeaderField("Content-Length");
if (values != null && !values.isEmpty()) {
length = Long.parseLong(values);
}
}
InputStream inputStream = null;
if (conn.getResponseCode() >= 400) {
throw new Exception("文件不存在");
} else {
inputStream = conn.getInputStream();
}
//获取自己数组
byte[] getData = readInputStream(inputStream);
//文件保存位置
File saveDir = new File(savePath);
if (!saveDir.exists()) {
saveDir.mkdir();
}
File file = new File(saveDir + File.separator + fileName);
FileOutputStream fos = new FileOutputStream(file);
fos.write(getData);
if (fos != null) {
fos.close();
}
if (inputStream != null) {
inputStream.close();
}
long end = System.currentTimeMillis();
log.info("info:" + url + " download success;用时:" + (end - start) + "ms");
} catch (Exception ex) {
throw ex;
} finally {
// 断开连接,释放资源
conn.disconnect();
}
}
/**
* 302
*
* @param uc
* @return
* @throws Exception
*/
private HttpURLConnection reload(HttpURLConnection uc) throws Exception {
HttpURLConnection huc = uc;
if (huc.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP
|| huc.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM) {// 302, 301
String url = huc.getHeaderField("Location");
url = url.replace("\\", "/");
return reload((HttpURLConnection) new URL(url).openConnection());
}
return uc;
}
/**
* java
*/
private final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[]{};
}
}};
/**
*
*
* @param connection
* @return
*/
private SSLSocketFactory trustAllHosts(HttpsURLConnection connection) {
SSLSocketFactory oldFactory = connection.getSSLSocketFactory();
try {
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
SSLSocketFactory newFactory = sc.getSocketFactory();
connection.setSSLSocketFactory(newFactory);
} catch (Exception e) {
e.printStackTrace();
}
return oldFactory;
}
/**
*
*
* @param inputStream
* @return
* @throws IOException
*/
public byte[] readInputStream(InputStream inputStream) throws IOException {
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
return bos.toByteArray();
}
private void valid(MultipartFile multipartFile) { private void valid(MultipartFile multipartFile) {
if (multipartFile.isEmpty()) { if (multipartFile.isEmpty()) {
throw new ApiException(ExceptionCode.ParamIllegal.getCode(), "上传失败,请选择文件!"); throw new ApiException(ExceptionCode.ParamIllegal.getCode(), "上传失败,请选择文件!");

@ -3,7 +3,7 @@ api.base-package=com.docus.server
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://db.docus.cn:3306/docus-collector-scheduling?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai spring.datasource.url=jdbc:mysql://db.docus.cn:3306/docus-collector-scheduling?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
spring.datasource.username=docus spring.datasource.username=root
spring.datasource.password=docus702 spring.datasource.password=root
mybatis-plus.type-enums-package=com.docus.server.enums mybatis-plus.type-enums-package=com.docus.server.enums

@ -13,8 +13,8 @@ spring:
#公司病案的文件服务数据库 #公司病案的文件服务数据库
master: master:
url: jdbc:log4jdbc:mysql://db.docus.cn:3306/docus-collector-scheduling?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai url: jdbc:log4jdbc:mysql://db.docus.cn:3306/docus-collector-scheduling?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
username: docus username: root
password: docus702 password: root
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
servlet: servlet:
@ -23,7 +23,7 @@ spring:
max-request-size: 200MB max-request-size: 200MB
redis: redis:
host: redis.docus.cn host: redis.docus.cn
password: JSdocus@702 # password: JSdocus@702
cloud: cloud:
nacos: nacos:
discovery: discovery:
@ -60,7 +60,7 @@ netty:
all-idle-time-seconds: 0 all-idle-time-seconds: 0
file: file:
uploadFolder: D://docus/ uploadFolder: /Users/linruifeng/workspace/
docus: docus:
redisKeyExpiration: true redisKeyExpiration: true

@ -6,7 +6,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
@EnableAsync @EnableAsync
@EnableFeignClients(basePackages = {"com.docus.core.excel.feign", "com.docus.server.api.taskdistribute"}) @EnableFeignClients(basePackages = {"com.docus.core.excel.feign", "com.docus.server.api"})
@SpringBootApplication(scanBasePackages = {"com.docus"}) @SpringBootApplication(scanBasePackages = {"com.docus"})
public class TerminalBootstrap { public class TerminalBootstrap {
public static void main(String[] args) { public static void main(String[] args) {

@ -0,0 +1,52 @@
package com.docus.server.common;
import com.alibaba.fastjson.JSONObject;
import com.docus.server.api.scheduling.management.SchVirtualLogApi;
import com.docus.server.common.utils.SystemInfoUtils;
import com.docus.server.dto.scheduling.management.schvirtuallog.AddSchVirtualLogDTO;
import com.xxl.job.core.util.IpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
@Component
@Slf4j
public class SchVirtualLogTask {
@Resource
private SchVirtualLogApi schVirtualLogApi;
//定时任务
// 5 * * * * ? 在每分钟的5秒执行
@Scheduled(cron = "${docus.vm-task-cron}")
public void runTask() {
try {
log.info("收集虚拟机信息定时任务: 开始执行");
JSONObject info = SystemInfoUtils.getInfo();
AddSchVirtualLogDTO addSchVirtualLogDTO = new AddSchVirtualLogDTO();
addSchVirtualLogDTO.setCpuUtilization((String) ((JSONObject) info.get("cpuInfo")).get("cSys"));
addSchVirtualLogDTO.setMemoryTotal((String) ((JSONObject) info.get("memInfo")).get("total"));
addSchVirtualLogDTO.setMemoryAllowance((String) ((JSONObject) info.get("memInfo")).get("free"));
addSchVirtualLogDTO.setUplinkRate((String) ((JSONObject) info.get("networkInfo")).get("txPercent"));
addSchVirtualLogDTO.setDescendingRate((String) ((JSONObject) info.get("networkInfo")).get("rxPercent"));
addSchVirtualLogDTO.setIp(IpUtil.getIp());
addSchVirtualLogDTO.setClientTime(new Date());
addSchVirtualLogDTO.setDiskJson(info.get("sysFileInfo").toString());
schVirtualLogApi.add(addSchVirtualLogDTO);
System.out.println(info);
log.info("收集虚拟机信息定时任务: 执行完毕");
} catch (Exception e) {
log.error("收集虚拟机信息定时任务执行出错", e);
}
}
}

@ -13,8 +13,8 @@ spring:
#公司病案的文件服务数据库 #公司病案的文件服务数据库
master: master:
url: jdbc:log4jdbc:mysql://db.docus.cn:3306/docus-collector-scheduling?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai url: jdbc:log4jdbc:mysql://db.docus.cn:3306/docus-collector-scheduling?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
username: docus username: root
password: docus702 password: root
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
servlet: servlet:
@ -23,7 +23,7 @@ spring:
max-request-size: 200MB max-request-size: 200MB
redis: redis:
host: redis.docus.cn host: redis.docus.cn
password: JSdocus@702 # password: JSdocus@702
cloud: cloud:
nacos: nacos:
discovery: discovery:
@ -67,7 +67,7 @@ netty:
all-idle-time-seconds: 0 all-idle-time-seconds: 0
file: file:
uploadFolder: D://docus/ uploadFolder: /Users/linruifeng/workspace/
docus: docus:
redisKeyExpiration: true vm-task-cron: 0/15 * * * * ?

@ -1,5 +1,6 @@
package com.docus.server; package com.docus.server;
import cn.hutool.core.util.ZipUtil;
import com.docus.server.common.download.downLoader.HttpDownloader; import com.docus.server.common.download.downLoader.HttpDownloader;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -16,10 +17,19 @@ public class FileController {
@Test @Test
void test() throws Exception { void test() throws Exception {
HttpDownloader httpDownloader = new HttpDownloader(null); HttpDownloader httpDownloader = new HttpDownloader(null);
String url = "http://192.168.16.110:9113/sch/file/download2?filePath=collector_packages/20230718/64cdaf49-f45e-4435-b6a3-3466165e7e3b/docus-collector-scheduling.tar.gz"; String url = "http://127.0.0.1:9113/sch/file/download?filePath=collector_packages/20230727/78c002bc-7674-4dfe-9247-ae594d03ccdf/docus-collector-scheduling.tar.gz";
String fileName = "test.tar.gz"; String fileName = "collector.tar.gz";
String savePath = "h:\\test"; String savePath = "/Users/linruifeng/Desktop/collector_packages";
httpDownloader.downLoadFromUrl(url, fileName, savePath); httpDownloader.downLoadFromUrl(url, fileName, savePath);
} }
public static void main(String[] args) throws Exception {
test1();
}
public static void test1() throws Exception {
ZipUtil.unzip("/Users/linruifeng/Desktop/collector_packages/collector.zip", "/Users/linruifeng/Desktop/collector_packages");
// ZipUtil.unGzip(new GZIPInputStream(new FileInputStream(new File("/Users/linruifeng/Desktop/collector_packages/index.tar.gz"))));
// FileUtils.unTarGz("/Users/linruifeng/Desktop/collector_packages/", "/Users/linruifeng/Desktop/collector_packages/test");
}
} }

@ -0,0 +1,162 @@
package com.docus.server;
import org.apache.tools.tar.TarInputStream;
import java.io.*;
import java.util.zip.GZIPInputStream;
/**
* @program: JavaCode
* @ClassName FileUtils
* @description:
* @author: ltcz99
* @create: 2023-04-16
* @Version 1.0
**/
public class FileUtils {
/**
* tar.gz
*
* @param sourceDir
* @param destDir
*/
public static void unTarGz(String sourceDir, String destDir) throws Exception {
File outFile = new File(sourceDir);
File[] files = outFile.listFiles();
try {
//创建输出目录
createDirectory(destDir, null);
TarInputStream tarIn;
int index = 1;
for (File file : files) {
if (file.getName().contains("tar.gz")) {
tarIn = new TarInputStream(new GZIPInputStream(
new BufferedInputStream(new FileInputStream(file))),
1024 * 2);
String outFileName = destDir + "/" + file.getName();
OutputStream out = new FileOutputStream(new File(outFileName));
int length = 0;
byte[] b = new byte[2048];
while ((length = tarIn.read(b)) != -1) {
out.write(b, 0, length);
}
out.close();
tarIn.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* gz
*
* @param sourceDir
* @param destDir
*/
public static void unGzipFile(String sourceDir, String destDir) {
//创建输出目录
createDirectory(destDir, null);
File sourceFile = new File(sourceDir);
File[] files = sourceFile.listFiles();
try {
int index = 1;
for (File file : files) {
if (file.getName().contains("gz")) {
FileInputStream fin = new FileInputStream(file);
//建立gzip解压工作流
GZIPInputStream gzin = new GZIPInputStream(fin);
//建立解压文件输出流
File tmpFile = new File(destDir + "/" + index++ + ".log");
FileOutputStream fout = new FileOutputStream(tmpFile);
int length;
byte[] buf = new byte[2048];
while ((length = gzin.read(buf, 0, buf.length)) != -1) {
fout.write(buf, 0, length);
}
gzin.close();
fout.close();
fin.close();
}
}
} catch (Exception ex) {
System.err.println(ex);
}
}
/**
*
*
* @param sourceLogPath
* @param destLogPath
*/
public static void readFileToDestLogPath(String sourceLogPath, String destLogPath) {
File sourceFile = new File(sourceLogPath);
File[] files = sourceFile.listFiles();
for (File file : files) {
String fileName = destLogPath + "/" + file.getName();
File destFile = new File(fileName);
if (file.getName().contains("log") && !fileName.contains("gz")) {
try {
if (destFile.exists()) {
destFile.delete();
}
String logFile = sourceFile + "/" + file.getName();
FileInputStream fis = new FileInputStream(logFile);
FileOutputStream fos = new FileOutputStream(destFile);
BufferedInputStream bis = new BufferedInputStream(fis);
BufferedOutputStream bos = new BufferedOutputStream(fos);
int len = 0;
while ((len = bis.read()) != -1) {
bos.write(len);
}
bos.flush();
// 关闭资源
fis.close();
bis.close();
fos.close();
bos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
/**
*
*
* @param outputDir
* @param subDir
*/
public static void createDirectory(String outputDir, String subDir) {
File file = new File(outputDir);
//子目录不为空
if (!(subDir == null || subDir.trim().equals(""))) {
file = new File(outputDir + "/" + subDir);
}
if (!file.exists()) {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
file.mkdirs();
}
}
public static void main(String[] args) throws Exception {
String sourceDir = "/Users/ltcz99/Downloads/templog";
String destDir = "/Users/ltcz99/Downloads/unzip/";
//解压.gz文件到指定的文件件下面
unGzipFile(sourceDir, destDir);
// 解压tar.gz文件到指定的文件夹下面
unTarGz(sourceDir, destDir);
//读取特定的文件到指定的文件夹下面
readFileToDestLogPath(sourceDir, destDir);
}
}

@ -1,51 +1,36 @@
package com.docus.server.api.scheduling.management; //package com.docus.server.api.scheduling.management;
//
import io.swagger.annotations.Api; //import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; //import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; //import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; //import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient; //import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.core.io.ByteArrayResource; //import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity; //import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.GetMapping; //
import org.springframework.web.bind.annotation.PostMapping; //import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping; //
import org.springframework.web.bind.annotation.RequestParam; //
import org.springframework.web.multipart.MultipartFile; ///**
// * 文件上传下载 API
import javax.servlet.http.HttpServletResponse; // *
// * @author AutoGenerator
// * @since 2023-07-15
/** // */
* API //@Api(value = "通用文件上传下载接口", tags = "通用文件上传下载接口")
* //@FeignClient(value = "collector-scheduling-management", contextId = "collector-scheduling-management.FileApi")
* @author AutoGenerator //@RequestMapping("/sch/file")
* @since 2023-07-15 //public interface FileApi {
*/ //
@Api(value = "通用文件上传下载接口", tags = "通用文件上传下载接口") // @ApiOperation("文件下载")
@FeignClient(value = "collector-scheduling-management", contextId = "collector-scheduling-management.FileApi") // @GetMapping("/download")
@RequestMapping("/sch/file") // void downloadFile(@RequestParam(value = "filePath") String filePath, HttpServletResponse response) throws Exception;
public interface FileApi { //
// @ApiOperation("文件上传")
@ApiOperation("文件下载") // @PostMapping("/upload")
@GetMapping("/download0") // @ApiImplicitParams({
void downLoadFromUrl(@RequestParam(value = "urlStr") String urlStr, // @ApiImplicitParam(name = "files", value = "文件", required = true, dataTypeClass = MultipartFile.class)
@RequestParam(value = "fileName") String fileName, // })
@RequestParam(value = "savePath") String savePath) throws Exception; // void uploadFile(@RequestPart MultipartFile[] files, String pathKey) throws Exception;
//
@ApiOperation("文件下载") //}
@GetMapping("/download1")
ResponseEntity<ByteArrayResource> downloadFile(@RequestParam(value = "filePath") String filePath) throws Exception;
@ApiOperation("文件下载")
@GetMapping("/download2")
void downloadFile(@RequestParam(value = "filePath") String filePath, HttpServletResponse response) throws Exception;
@ApiOperation("文件上传")
@PostMapping("/upload")
@ApiImplicitParams({
@ApiImplicitParam(name = "files", value = "文件", required = true, dataTypeClass = MultipartFile.class)
})
void uploadFile(MultipartFile[] multipartFiles, String pathKey) throws Exception;
}

@ -57,7 +57,7 @@ public interface SchVirtualLogApi {
*/ */
@ApiOperation("新增") @ApiOperation("新增")
@PostMapping("/add") @PostMapping("/add")
boolean add(@RequestBody AddSchVirtualLogDTO addSchVirtualLogDTO); void add(@RequestBody AddSchVirtualLogDTO addSchVirtualLogDTO);
/** /**
* *
@ -67,7 +67,7 @@ public interface SchVirtualLogApi {
*/ */
@ApiOperation("编辑") @ApiOperation("编辑")
@PutMapping("/edit") @PutMapping("/edit")
boolean edit(@RequestBody EditSchVirtualLogDTO editSchVirtualLogDTO); void edit(@RequestBody EditSchVirtualLogDTO editSchVirtualLogDTO);
/** /**
* *

@ -22,10 +22,10 @@ public class AddSchVirtualLogDTO implements Serializable {
private String cpuUtilization; private String cpuUtilization;
@ApiModelProperty(value = "物理内存总量单位MB") @ApiModelProperty(value = "物理内存总量单位MB")
private Double memoryTotal; private String memoryTotal;
@ApiModelProperty(value = "物理内存余量单位MB") @ApiModelProperty(value = "物理内存余量单位MB")
private Double memoryAllowance; private String memoryAllowance;
@ApiModelProperty(value = "当前网络上行速率(KBPS)") @ApiModelProperty(value = "当前网络上行速率(KBPS)")
private String uplinkRate; private String uplinkRate;

@ -3,23 +3,18 @@ package com.docus.server.dto.scheduling.management.schvirtuallog;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import com.docus.server.enums.*;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
/** /**
* * 使 EditDTO
* 使 EditDTO *
* * @author AutoGenerator
* @author AutoGenerator * @since 2023-07-15
* @since 2023-07-15 */
*/
@Data @Data
@ApiModel(value="EditSchVirtualLogDTO对象", description="虚拟机使用情况") @ApiModel(value = "EditSchVirtualLogDTO对象", description = "虚拟机使用情况")
public class EditSchVirtualLogDTO implements Serializable { public class EditSchVirtualLogDTO implements Serializable {
@ApiModelProperty(value = "终端id") @ApiModelProperty(value = "终端id")
@ -29,10 +24,10 @@ public class EditSchVirtualLogDTO implements Serializable {
private String cpuUtilization; private String cpuUtilization;
@ApiModelProperty(value = "物理内存总量单位MB") @ApiModelProperty(value = "物理内存总量单位MB")
private Double memoryTotal; private String memoryTotal;
@ApiModelProperty(value = "物理内存余量单位MB") @ApiModelProperty(value = "物理内存余量单位MB")
private Double memoryAllowance; private String memoryAllowance;
@ApiModelProperty(value = "当前网络上行速率(KBPS)") @ApiModelProperty(value = "当前网络上行速率(KBPS)")
private String uplinkRate; private String uplinkRate;

@ -35,11 +35,11 @@ public class SchVirtualLog implements Serializable {
@ApiModelProperty(value = "物理内存总量单位MB") @ApiModelProperty(value = "物理内存总量单位MB")
@TableField("memory_total") @TableField("memory_total")
private Double memoryTotal; private String memoryTotal;
@ApiModelProperty(value = "物理内存余量单位MB") @ApiModelProperty(value = "物理内存余量单位MB")
@TableField("memory_allowance") @TableField("memory_allowance")
private Double memoryAllowance; private String memoryAllowance;
@ApiModelProperty(value = "当前网络上行速率(KBPS)") @ApiModelProperty(value = "当前网络上行速率(KBPS)")
@TableField("uplink_rate") @TableField("uplink_rate")

@ -255,7 +255,11 @@
<artifactId>commons-httpclient</artifactId> <artifactId>commons-httpclient</artifactId>
<version>3.1</version> <version>3.1</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.5</version>
</dependency>
</dependencies> </dependencies>
<profiles> <profiles>

Loading…
Cancel
Save