|
@ -12,7 +12,6 @@ import com.win.system.domain.LinuxAccess; |
|
|
import com.win.system.domain.QadAccess; |
|
|
import com.win.system.domain.QadAccess; |
|
|
import com.win.system.mapper.LinuxAccessMapper; |
|
|
import com.win.system.mapper.LinuxAccessMapper; |
|
|
import com.win.system.mapper.QadAccessMapper; |
|
|
import com.win.system.mapper.QadAccessMapper; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
@ -27,7 +26,6 @@ import java.time.LocalDateTime; |
|
|
* @author win |
|
|
* @author win |
|
|
* @date 2024-03-12 |
|
|
* @date 2024-03-12 |
|
|
*/ |
|
|
*/ |
|
|
@Slf4j |
|
|
|
|
|
@Service |
|
|
@Service |
|
|
public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAccess> implements IService<LinuxAccess> { |
|
|
public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAccess> implements IService<LinuxAccess> { |
|
|
|
|
|
|
|
@ -70,27 +68,27 @@ public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAcce |
|
|
Session session = shellUtil.getShellSession(linuxAccess.getUserName(), linuxAccess.getPassword(), linuxAccess.getIpAddress(), linuxAccess.getPort()); |
|
|
Session session = shellUtil.getShellSession(linuxAccess.getUserName(), linuxAccess.getPassword(), linuxAccess.getIpAddress(), linuxAccess.getPort()); |
|
|
//写入json
|
|
|
//写入json
|
|
|
String result = shellUtil.execute(session, "touch " + linuxAccess.getWorkPath() + traceid + ".json && echo '" + inJson + "'>" + linuxAccess.getWorkPath() + traceid + ".json"); |
|
|
String result = shellUtil.execute(session, "touch " + linuxAccess.getWorkPath() + traceid + ".json && echo '" + inJson + "'>" + linuxAccess.getWorkPath() + traceid + ".json"); |
|
|
log.info("write json result : {}", result); |
|
|
//log.info("write json result : {}", result);
|
|
|
//写入dat.json
|
|
|
//写入dat.json
|
|
|
String datJson = "\"" + linuxAccess.getWorkPath() + traceid + ".json\" \"" + linuxAccess.getQadProgramCode() + "\" \"" + linuxAccess.getOutPath() + traceid+".out.log\" \"" + qadAccess.getUserName() + "\" \"" + qadAccess.getPassword() + "\"\r\n\"" + domain + "\""; |
|
|
String datJson = "\"" + linuxAccess.getWorkPath() + traceid + ".json\" \"" + linuxAccess.getQadProgramCode() + "\" \"" + linuxAccess.getOutPath() + traceid+".out.log\" \"" + qadAccess.getUserName() + "\" \"" + qadAccess.getPassword() + "\"\r\n\"" + domain + "\""; |
|
|
log.info("datJson: {}", datJson); |
|
|
//log.info("datJson: {}", datJson);
|
|
|
result = shellUtil.execute(session, "touch " + linuxAccess.getWorkPath() + traceid + ".dat && echo '" + datJson + "'>" + linuxAccess.getWorkPath() + traceid+".dat"); |
|
|
result = shellUtil.execute(session, "touch " + linuxAccess.getWorkPath() + traceid + ".dat && echo '" + datJson + "'>" + linuxAccess.getWorkPath() + traceid+".dat"); |
|
|
log.info("write dat json result : {}", result); |
|
|
//log.info("write dat json result : {}", result);
|
|
|
//写入执行文件
|
|
|
//写入执行文件
|
|
|
String pJson = "output to " + linuxAccess.getOutPath() + traceid + ".run.log.\r\n" + |
|
|
String pJson = "output to " + linuxAccess.getOutPath() + traceid + ".run.log.\r\n" + |
|
|
"input from " + linuxAccess.getWorkPath() + traceid + ".dat.\r\n" + |
|
|
"input from " + linuxAccess.getWorkPath() + traceid + ".dat.\r\n" + |
|
|
"run " + linuxAccess.getScriptPath() + linuxAccess.getScriptProgram() + ".\r\n" + |
|
|
"run " + linuxAccess.getScriptPath() + linuxAccess.getScriptProgram() + ".\r\n" + |
|
|
"input close.\r\n" + |
|
|
"input close.\r\n" + |
|
|
"output close."; |
|
|
"output close."; |
|
|
log.info("pJson: {}", pJson); |
|
|
//log.info("pJson: {}", pJson);
|
|
|
result = shellUtil.execute(session, "touch " + linuxAccess.getWorkPath() + traceid+".p && echo '"+pJson+"'>" + linuxAccess.getWorkPath() + traceid + ".p"); |
|
|
result = shellUtil.execute(session, "touch " + linuxAccess.getWorkPath() + traceid+".p && echo '"+pJson+"'>" + linuxAccess.getWorkPath() + traceid + ".p"); |
|
|
log.info("write p result : {}", result); |
|
|
//log.info("write p result : {}", result);
|
|
|
//执行QAD脚本
|
|
|
//执行QAD脚本
|
|
|
log.info("command : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p"); |
|
|
//log.info("command : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p");
|
|
|
result = shellUtil.execute(session, linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p"); |
|
|
result = shellUtil.execute(session, linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p"); |
|
|
log.info("execute {} result : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName(), result); |
|
|
//log.info("execute {} result : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName(), result);
|
|
|
result = shellUtil.execute(session, "cat " + linuxAccess.getOutPath() + traceid + ".run.out.json"); |
|
|
result = shellUtil.execute(session, "cat " + linuxAccess.getOutPath() + traceid + ".run.out.json"); |
|
|
log.info("cat execute log : {}", result); |
|
|
//log.info("cat execute log : {}", result);
|
|
|
if(result.indexOf("\"SUCCESS\"") > 0) { |
|
|
if(result.indexOf("\"SUCCESS\"") > 0) { |
|
|
//移动执行结果文件
|
|
|
//移动执行结果文件
|
|
|
shellUtil.execute(session, "mv " + linuxAccess.getOutPath() + traceid + ".run.out.json " + linuxAccess.getSuccessPath() + traceid + ".run.out.json"); |
|
|
shellUtil.execute(session, "mv " + linuxAccess.getOutPath() + traceid + ".run.out.json " + linuxAccess.getSuccessPath() + traceid + ".run.out.json"); |
|
@ -126,17 +124,17 @@ public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAcce |
|
|
"run " + linuxAccess.getScriptPath() + linuxAccess.getScriptProgram() + ".\r\n" + |
|
|
"run " + linuxAccess.getScriptPath() + linuxAccess.getScriptProgram() + ".\r\n" + |
|
|
"input close.\r\n" + |
|
|
"input close.\r\n" + |
|
|
"output close."; |
|
|
"output close."; |
|
|
log.info("pJson: {}", pJson); |
|
|
//log.info("pJson: {}", pJson);
|
|
|
fileOutputStream = new FileOutputStream(linuxAccess.getWorkPath() + traceid + ".p"); |
|
|
fileOutputStream = new FileOutputStream(linuxAccess.getWorkPath() + traceid + ".p"); |
|
|
fileOutputStream.write(pJson.getBytes()); |
|
|
fileOutputStream.write(pJson.getBytes()); |
|
|
fileOutputStream.close(); |
|
|
fileOutputStream.close(); |
|
|
log.info("pJson: {}", pJson); |
|
|
//log.info("pJson: {}", pJson);
|
|
|
//执行QAD脚本
|
|
|
//执行QAD脚本
|
|
|
log.info("command : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p"); |
|
|
//log.info("command : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p");
|
|
|
String result = CommandUtil.exeCommand(linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p"); |
|
|
String result = CommandUtil.exeCommand(linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p"); |
|
|
log.info("execute {} result : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName(), result); |
|
|
//log.info("execute {} result : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName(), result);
|
|
|
result = CommandUtil.exeCommand("cat " + linuxAccess.getOutPath() + traceid + ".run.out.json"); |
|
|
result = CommandUtil.exeCommand("cat " + linuxAccess.getOutPath() + traceid + ".run.out.json"); |
|
|
log.info("cat execute log : {}", result); |
|
|
//log.info("cat execute log : {}", result);
|
|
|
if(result.indexOf("\"SUCCESS\"") > 0) { |
|
|
if(result.indexOf("\"SUCCESS\"") > 0) { |
|
|
//移动执行结果文件
|
|
|
//移动执行结果文件
|
|
|
CommandUtil.exeCommand("mv " + linuxAccess.getOutPath() + traceid + ".run.out.json " + linuxAccess.getSuccessPath() + traceid + ".run.out.json"); |
|
|
CommandUtil.exeCommand("mv " + linuxAccess.getOutPath() + traceid + ".run.out.json " + linuxAccess.getSuccessPath() + traceid + ".run.out.json"); |
|
|