提交 2fbac073 authored 作者: zhangshuang's avatar zhangshuang

zs

上级 0d7f231f
...@@ -90,6 +90,11 @@ ...@@ -90,6 +90,11 @@
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>2.6</version> <version>2.6</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.8.1</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-websocket</artifactId> <artifactId>spring-websocket</artifactId>
......
...@@ -27,8 +27,8 @@ public class WebSocketServer { ...@@ -27,8 +27,8 @@ public class WebSocketServer {
public void onOpen(Session session,@PathParam("uuid")String uuid){ public void onOpen(Session session,@PathParam("uuid")String uuid){
this.session = session; this.session = session;
this.uuid = uuid; this.uuid = uuid;
System.out.println(this.uuid + "\t" + this.session);
//session.getOpenSessions(). //session.getOpenSessions().
//System.out.println("第一个" + uuid);
logger.info("uuid:"+uuid); logger.info("uuid:"+uuid);
map.put(uuid,this); map.put(uuid,this);
try { try {
...@@ -70,6 +70,7 @@ public class WebSocketServer { ...@@ -70,6 +70,7 @@ public class WebSocketServer {
public static void sendInfo(String sessionId,String msg,String action,String state,String projectName){ public static void sendInfo(String sessionId,String msg,String action,String state,String projectName){
try { try {
//System.out.println(sessionId);
map.get(sessionId).sendMessage(LocalDateTime.now()+"\t"+projectName+"\t"+action+"\t"+state+"\t"+msg); map.get(sessionId).sendMessage(LocalDateTime.now()+"\t"+projectName+"\t"+action+"\t"+state+"\t"+msg);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -34,6 +34,10 @@ public class Project { ...@@ -34,6 +34,10 @@ public class Project {
private String codeUrl;//当前源码源码路径 private String codeUrl;//当前源码源码路径
private String des;//描述
private String stage;//阶段(源代码、替换后、编译后)
private Integer status = 1;//状态(0:删除 1:未删除) private Integer status = 1;//状态(0:删除 1:未删除)
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
......
...@@ -37,6 +37,6 @@ public class Report { ...@@ -37,6 +37,6 @@ public class Report {
MYSQL,ORACLE,SQLSERVER,POSTGRE MYSQL,ORACLE,SQLSERVER,POSTGRE
} }
public enum Language{ public enum Language{
JAVA,PYTHON,CPP JAVA,PYTHON,CPP,JSP,ONLYVIEW
} }
} }
package com.zjty.adaptationmaster.adaptor.repository;
import com.zjty.adaptationmaster.adaptor.entity.Report;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface ReportDao extends JpaRepository<Report, Integer>, JpaSpecificationExecutor {
}
...@@ -8,6 +8,7 @@ import com.zjty.adaptationmaster.base.response.ServerResponse; ...@@ -8,6 +8,7 @@ import com.zjty.adaptationmaster.base.response.ServerResponse;
import com.zjty.adaptationmaster.adaptor.service.AdaptationService; import com.zjty.adaptationmaster.adaptor.service.AdaptationService;
import com.zjty.adaptationmaster.utils.ApusicDeployer; import com.zjty.adaptationmaster.utils.ApusicDeployer;
import com.zjty.adaptationmaster.utils.FileUtil; import com.zjty.adaptationmaster.utils.FileUtil;
import com.zjty.adaptationmaster.utils.FileZip;
import com.zjty.adaptationmaster.utils.MavenCompiler; import com.zjty.adaptationmaster.utils.MavenCompiler;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -60,11 +61,12 @@ public class AdaptationServiceImpl implements AdaptationService { ...@@ -60,11 +61,12 @@ public class AdaptationServiceImpl implements AdaptationService {
@Transactional @Transactional
@Override @Override
public ServerResponse unZipProject(String path, Project project) { public ServerResponse unZipProject(String path, Project project) {
project = projectDao.getOne(project.getId()); Project project1 = projectDao.getOne(project.getId());
FileUtil fileUtil = new FileUtil(); //FileUtil fileUtil = new FileUtil();
project.setCodeUrl(Const.UPLOAD_LOCATION+File.separator+project.getProjectName()); project1.setCodeUrl(Const.UPLOAD_LOCATION+File.separator+project.getProjectName());
try { try {
fileUtil.unZip(new File(path),project.getCodeUrl()); FileZip.unzip(new File(path),project.getCodeUrl());
project.setStage(project.getStage());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -36,7 +36,7 @@ public class DBMigrateServiceImpl implements DBMigrateService { ...@@ -36,7 +36,7 @@ public class DBMigrateServiceImpl implements DBMigrateService {
private DBRecordDao dbRecordDao; private DBRecordDao dbRecordDao;
//线程池数量,合适的线程数量能让程序更快 //线程池数量,合适的线程数量能让程序更快
private static final int poolSize = 2; private static final int poolSize = 4;
@Value("${highgo.driver}") @Value("${highgo.driver}")
private String highgoDriver; private String highgoDriver;
......
package com.zjty.adaptationmaster.adaptor.service.Impl; package com.zjty.adaptationmaster.adaptor.service.Impl;
import com.zjty.adaptationmaster.adaptor.entity.Project; import com.zjty.adaptationmaster.adaptor.entity.Project;
import com.zjty.adaptationmaster.adaptor.entity.Report;
import com.zjty.adaptationmaster.adaptor.repository.ProjectDao; import com.zjty.adaptationmaster.adaptor.repository.ProjectDao;
import com.zjty.adaptationmaster.adaptor.repository.ReportDao;
import com.zjty.adaptationmaster.adaptor.service.InspectService; import com.zjty.adaptationmaster.adaptor.service.InspectService;
import com.zjty.adaptationmaster.base.response.ServerResponse; import com.zjty.adaptationmaster.base.response.ServerResponse;
import com.zjty.adaptationmaster.utils.Inspector; import com.zjty.adaptationmaster.utils.Inspector;
...@@ -11,16 +13,30 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -11,16 +13,30 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
@Service @Service
public class InspectServiceImpl implements InspectService { public class InspectServiceImpl implements InspectService {
@Autowired @Autowired
private ProjectDao projectDao; private ProjectDao projectDao;
@Autowired
private ReportDao reportDao;
@Transactional @Transactional
@Override @Override
public ServerResponse inspect(Project project) { public ServerResponse inspect(Project project) {
//Project project = projectDao.getOne(projectId); //Project project = projectDao.getOne(projectId);
return ServerResponse.success(new Inspector(project,new HashMap<>(),new HashMap<>()/*,new ArrayList<>()*/).inspect()); Map<String, Report.Language> suffixLanguageMapping = new HashMap<>();
suffixLanguageMapping.put("java",Report.Language.JAVA);
suffixLanguageMapping.put("cpp",Report.Language.CPP);
suffixLanguageMapping.put("py",Report.Language.PYTHON);
suffixLanguageMapping.put("jsp",Report.Language.JSP);
//suffixLanguageMapping.put("html",Report.Language.ONLYVIEW);
Report report = new Inspector(project, suffixLanguageMapping).inspect();
reportDao.save(report);
Project one = projectDao.getOne(project.getId());
one.setReport(report);
return ServerResponse.success(report);
} }
} }
...@@ -40,7 +40,7 @@ public class Const { ...@@ -40,7 +40,7 @@ public class Const {
public static Map<String,Long> transferCountMap = new ConcurrentHashMap<>(); public static Map<String,Long> transferCountMap = new ConcurrentHashMap<>();
public static final String MAVENHOME = "D:\\apache-maven-3.5.4"; public static final String MAVENHOME = "D:\\Program Files\\apache-maven-3.5.4-bin\\apache-maven-3.5.4";
public static final String CTLPATH = "/home/user/Desktop/AAS-V9.0/bin/appctl"; public static final String CTLPATH = "/home/user/AAS-V9.0/bin/appctl.cmd";
public static final String CTLPWD = "Qwert123!@#"; public static final String CTLPWD = "Qwert123!@#";
} }
...@@ -3,12 +3,14 @@ package com.zjty.adaptationmaster.utils; ...@@ -3,12 +3,14 @@ package com.zjty.adaptationmaster.utils;
import com.zjty.adaptationmaster.adaptor.controller.WebSocketServer; import com.zjty.adaptationmaster.adaptor.controller.WebSocketServer;
import com.zjty.adaptationmaster.adaptor.entity.Project; import com.zjty.adaptationmaster.adaptor.entity.Project;
import com.zjty.adaptationmaster.base.entity.ProjectStatueFromMiddleware; import com.zjty.adaptationmaster.base.entity.ProjectStatueFromMiddleware;
import com.zjty.adaptationmaster.base.enums.Const;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -18,7 +20,9 @@ public class ApusicDeployer { ...@@ -18,7 +20,9 @@ public class ApusicDeployer {
private String ctlPath; private String ctlPath;
private String ctlPwd; private String ctlPwd;
public void deploy(Project project,String webSocketName){ public void deploy(Project project,String webSocketName){
String command = ctlPath+" -p '"+ctlPwd+"' install "+project.getProjectName()+" "+project.getReport().getPackagePath(); //String command = ctlPath+" -p "+ Const.CTLPWD +" install "+project.getProjectName()+" "+project.getReport().getPackagePath();
String command = ctlPath +" install "+project.getProjectName()+" "+project.getReport().getPackagePath();
System.out.println(command);
appctl(command,webSocketName,project.getProjectName()); appctl(command,webSocketName,project.getProjectName());
} }
public List<ProjectStatueFromMiddleware> list(){ public List<ProjectStatueFromMiddleware> list(){
...@@ -55,10 +59,15 @@ public class ApusicDeployer { ...@@ -55,10 +59,15 @@ public class ApusicDeployer {
private void appctl(String command,String webSocketName,String projectName){ private void appctl(String command,String webSocketName,String projectName){
try { try {
Process exec = Runtime.getRuntime().exec(command); Process exec = Runtime.getRuntime().exec(command);
String password = "Qwert123!@#";
OutputStream outputStream = exec.getOutputStream();
outputStream.write(password.getBytes());
outputStream.flush();
outputStream.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream()));
String line = null; String line = null;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
WebSocketServer.sendInfo(line, webSocketName, "部署", "running", projectName); WebSocketServer.sendInfo(webSocketName, line, "部署", "running", projectName);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
......
package com.zjty.adaptationmaster.utils; package com.zjty.adaptationmaster.utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.io.FileUtils;
import java.io.*; import java.io.*;
import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@Slf4j
public class FileZip { public class FileZip {
public static void unZipFiles(File zipFile, String descDir)throws IOException public static void unzip(File zipFile, String descDir) {
{ try (ZipArchiveInputStream inputStream = getZipFile(zipFile)) {
File pathFile = new File(descDir); File pathFile = new File(descDir);
if(!pathFile.exists()) if (!pathFile.exists()) {
{ pathFile.mkdirs();
pathFile.mkdirs();
}
//解决zip文件中有中文目录或者中文文件
ZipFile zip = new ZipFile(zipFile, Charset.forName("GBK"));
for(Enumeration entries = zip.entries(); entries.hasMoreElements();)
{
ZipEntry entry = (ZipEntry)entries.nextElement();
String zipEntryName = entry.getName();
InputStream in = zip.getInputStream(entry);
String outPath = (descDir+zipEntryName).replaceAll("\\*", "/");;
//判断路径是否存在,不存在则创建文件路径
File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
if(!file.exists())
{
file.mkdirs();
} }
//判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压 ZipArchiveEntry entry = null;
if(new File(outPath).isDirectory()) while ((entry = inputStream.getNextZipEntry()) != null) {
{ if (entry.isDirectory()) {
continue; File directory = new File(descDir, entry.getName());
directory.mkdirs();
} else {
OutputStream os = null;
try {
os = new BufferedOutputStream(new FileOutputStream(new File(descDir, entry.getName())));
//输出文件路径信息
log.info("解压文件的当前路径为:{}", descDir + entry.getName());
IOUtils.copy(inputStream, os);
} finally {
IOUtils.closeQuietly(os);
}
}
} }
//输出文件路径信息 final File[] files = pathFile.listFiles();
System.out.println(outPath); if (files != null && files.length == 1 && files[0].isDirectory()) {
OutputStream out = new FileOutputStream(outPath); // 说明只有一个文件夹
byte[] buf1 = new byte[1024]; FileUtils.copyDirectory(files[0], pathFile);
int len; //免得删除错误, 删除的文件必须在/data/demand/目录下。
while((len=in.read(buf1))>0) boolean isValid = files[0].getPath().contains("/data/www/");
{ if (isValid) {
out.write(buf1,0,len); FileUtils.forceDelete(files[0]);
}
} }
in.close(); log.info("******************解压完毕********************");
out.close();
} catch (Exception e) {
log.error("[unzip] 解压zip文件出错", e);
} }
zip.close(); //**原博忘记关了,所以我在做完这些操作后想要删除文件时,一直已占用,必须关掉服务器才可以** }
System.out.println("******************解压完毕********************");
private static ZipArchiveInputStream getZipFile(File zipFile) throws Exception {
return new ZipArchiveInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
}
public static void main(String[] args) throws Exception{
String path = "D:\\sqlFile\\uploads\\8599bc6b-e140-493e-8ea6-07eba392adad.zip";
unzip(new File(path), "D:\\sqlFile\\uploads\\test123456789");
} }
} }
...@@ -25,7 +25,7 @@ public class MavenCompiler { ...@@ -25,7 +25,7 @@ public class MavenCompiler {
public void compiler(){ public void compiler(){
InvocationRequest request = new DefaultInvocationRequest(); InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile(new File(project.getReport().getCompileFilePath())); request.setPomFile(new File(project.getReport().getCompileFilePath()));
request.setGoals(Collections.singletonList("compile")); request.setGoals(Collections.singletonList("package"));
Invoker invoker = new DefaultInvoker(); Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(new File(mavenHome)); invoker.setMavenHome(new File(mavenHome));
...@@ -34,7 +34,7 @@ public class MavenCompiler { ...@@ -34,7 +34,7 @@ public class MavenCompiler {
@Override @Override
public void consumeLine(String s) throws IOException { public void consumeLine(String s) throws IOException {
WebSocketServer.sendInfo(webSocketId,s,"编译","running",project.getProjectName()); WebSocketServer.sendInfo(webSocketId,s,"编译","running",project.getProjectName());
//System.out.println(s); System.out.println(s);
} }
}); });
try { try {
......
...@@ -289,6 +289,10 @@ public class Regular { ...@@ -289,6 +289,10 @@ public class Regular {
public static void main(String[] args) { public static void main(String[] args) {
mySqlRegular("D:\\sqlFile\\uploads\\63c6e098-73fd-4999-b289-b3d120a07e87.sql","test11111"); //mySqlRegular("D:\\sqlFile\\uploads\\63c6e098-73fd-4999-b289-b3d120a07e87.sql","test11111");
//
File file = new File("D:\\root\\projects\\adaptationMaster\\uploads\\czq测试系统5\\swiper-4.5.0/target/threem-0.0.1-SNAPSHOT.war");
System.out.println(file.length());
System.out.println(file.getName());
} }
} }
...@@ -28,8 +28,11 @@ spring.jpa.open-in-view=true ...@@ -28,8 +28,11 @@ spring.jpa.open-in-view=true
spring.jpa.properties.javax.persistence.validation.mode=none spring.jpa.properties.javax.persistence.validation.mode=none
# spring-http-文件上传相关配置 # spring-http-文件上传相关配置
spring.servlet.multipart.max-file-size=100MB spring.servlet.multipart.max-file-size=200MB
spring.servlet.multipart.max-request-size=100MB spring.servlet.multipart.max-request-size=200MB
#配置时间格式
spring.jacksondate-format = yyyy-MM-dd HH:mm:ss
spring.thymeleaf.cache=false spring.thymeleaf.cache=false
spring.mvc.static-path-pattern=/** spring.mvc.static-path-pattern=/**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论