|
|
@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
|
|
@ -84,6 +85,7 @@ public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAcce |
|
|
|
return AjaxResult.error(HttpStatus.LINUX_ACCESS_ERROR, "linux访问控制不存在"); |
|
|
|
} |
|
|
|
QueryWrapper<QadAccess> qadAccessQueryWrapper = new QueryWrapper<>(); |
|
|
|
qadAccessQueryWrapper.eq("company_code", companyCode); |
|
|
|
qadAccessQueryWrapper.eq("domain", domain); |
|
|
|
QadAccess qadAccess = qadAccessMapper.selectOne(qadAccessQueryWrapper); |
|
|
|
if(qadAccess == null) { |
|
|
@ -93,9 +95,10 @@ public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAcce |
|
|
|
//生成traceid
|
|
|
|
String traceid = jsonObject.getString("traceid"); |
|
|
|
jsonObject.remove("traceid"); |
|
|
|
jsonObject.remove("dataid"); |
|
|
|
jsonObject.remove("company_code"); |
|
|
|
jsonObject.remove("domain"); |
|
|
|
String inJson = "{\"dsDescreteOrder\":"+ jsonObject+"}"; |
|
|
|
String inJson = "{\"" + key + "\":"+ jsonObject+"}"; |
|
|
|
log.info("inJson: {}", inJson); |
|
|
|
//写入json
|
|
|
|
String result = shellUtil.execute(session, "touch " + linuxAccess.getWorkPath() + traceid + ".json && echo '" + inJson + "'>" + linuxAccess.getWorkPath() + traceid + ".json"); |
|
|
@ -141,7 +144,7 @@ public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAcce |
|
|
|
*/ |
|
|
|
public AjaxResult executeCommand(String body, String uri, String key) throws IOException, InterruptedException { |
|
|
|
JSONObject jsonObject = JSONObject.parseObject(body); |
|
|
|
jsonObject = JSONObject.parseObject(jsonObject.getString("dsDescreteOrder")); |
|
|
|
jsonObject = JSONObject.parseObject(jsonObject.getString(key)); |
|
|
|
String domain = jsonObject.getString("domain"); |
|
|
|
if(domain == null || domain.isEmpty()) { |
|
|
|
return AjaxResult.error(HttpStatus.DOMAIN_ERROR, "域不能为空"); |
|
|
@ -158,6 +161,7 @@ public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAcce |
|
|
|
return AjaxResult.error(HttpStatus.LINUX_ACCESS_ERROR, "linux访问控制不存在"); |
|
|
|
} |
|
|
|
QueryWrapper<QadAccess> qadAccessQueryWrapper = new QueryWrapper<>(); |
|
|
|
qadAccessQueryWrapper.eq("company_code", companyCode); |
|
|
|
qadAccessQueryWrapper.eq("domain", domain); |
|
|
|
QadAccess qadAccess = qadAccessMapper.selectOne(qadAccessQueryWrapper); |
|
|
|
if(qadAccess == null) { |
|
|
@ -166,18 +170,19 @@ public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAcce |
|
|
|
//生成traceid
|
|
|
|
String traceid = jsonObject.getString("traceid"); |
|
|
|
jsonObject.remove("traceid"); |
|
|
|
jsonObject.remove("dataid"); |
|
|
|
jsonObject.remove("company_code"); |
|
|
|
jsonObject.remove("domain"); |
|
|
|
String inJson = "{\"dsDescreteOrder\":"+ jsonObject+"}"; |
|
|
|
String inJson = "{\"" + key + "\":"+ jsonObject+"}"; |
|
|
|
log.info("inJson: {}", inJson); |
|
|
|
//写入json
|
|
|
|
String result = CommandUtil.execute("touch " + linuxAccess.getWorkPath() + traceid + ".json && echo '" + inJson + "'>" + linuxAccess.getWorkPath() + traceid + ".json"); |
|
|
|
log.info("write json result : {}", result); |
|
|
|
FileOutputStream fileOutputStream = new FileOutputStream(linuxAccess.getWorkPath() + traceid + ".json"); |
|
|
|
fileOutputStream.write(inJson.getBytes()); |
|
|
|
fileOutputStream.close(); |
|
|
|
//写入dat.json
|
|
|
|
String datJson = "\"" + linuxAccess.getWorkPath() + traceid + ".json\" \"" + linuxAccess.getQadProgramCode() + "\" \"" + linuxAccess.getOutPath() + traceid+".out.log\" \"" + qadAccess.getUserName() + "\" \"" + qadAccess.getPassword() + "\"\r\n\"" + domain + "\""; |
|
|
|
log.info("datJson: {}", datJson); |
|
|
|
result = CommandUtil.execute("touch " + linuxAccess.getWorkPath() + traceid + ".dat && echo '" + datJson + "'>" + linuxAccess.getWorkPath() + traceid+".dat"); |
|
|
|
log.info("write dat json result : {}", result); |
|
|
|
fileOutputStream = new FileOutputStream(linuxAccess.getWorkPath() + traceid + ".dat"); |
|
|
|
fileOutputStream.write(datJson.getBytes()); |
|
|
|
fileOutputStream.close(); |
|
|
|
//写入执行文件
|
|
|
|
String pJson = "output to " + linuxAccess.getOutPath() + traceid + ".run.log.\r\n" + |
|
|
|
"input from " + linuxAccess.getWorkPath() + traceid + ".dat.\r\n" + |
|
|
@ -185,20 +190,22 @@ public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAcce |
|
|
|
"input close.\r\n" + |
|
|
|
"output close."; |
|
|
|
log.info("pJson: {}", pJson); |
|
|
|
result = CommandUtil.execute("touch " + linuxAccess.getWorkPath() + traceid+".p && echo '"+pJson+"'>" + linuxAccess.getWorkPath() + traceid + ".p"); |
|
|
|
log.info("write p result : {}", result); |
|
|
|
fileOutputStream = new FileOutputStream(linuxAccess.getWorkPath() + traceid + ".p"); |
|
|
|
fileOutputStream.write(pJson.getBytes()); |
|
|
|
fileOutputStream.close(); |
|
|
|
log.info("pJson: {}", pJson); |
|
|
|
//执行QAD脚本
|
|
|
|
log.info("command : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p"); |
|
|
|
result = CommandUtil.execute(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); |
|
|
|
result = CommandUtil.execute("cat " + linuxAccess.getOutPath() + traceid + ".run.out.json"); |
|
|
|
result = CommandUtil.exeCommand("cat " + linuxAccess.getOutPath() + traceid + ".run.out.json"); |
|
|
|
log.info("cat execute log : {}", result); |
|
|
|
if(result.indexOf("\"SUCCESS\"") > 0) { |
|
|
|
//移动执行结果文件
|
|
|
|
CommandUtil.execute("mv " + linuxAccess.getOutPath() + traceid + ".run.out.json " + linuxAccess.getSuccessPath() + traceid + ".run.out.json"); |
|
|
|
return AjaxResult.success(traceid); |
|
|
|
CommandUtil.exeCommand("mv " + linuxAccess.getOutPath() + traceid + ".run.out.json " + linuxAccess.getSuccessPath() + traceid + ".run.out.json"); |
|
|
|
return AjaxResult.success(result); |
|
|
|
} |
|
|
|
CommandUtil.execute("mv " + linuxAccess.getOutPath() + traceid + ".run.out.json " + linuxAccess.getErrorPath() + traceid + ".run.out.json"); |
|
|
|
CommandUtil.exeCommand("mv " + linuxAccess.getOutPath() + traceid + ".run.out.json " + linuxAccess.getErrorPath() + traceid + ".run.out.json"); |
|
|
|
return AjaxResult.error(HttpStatus.EXECUTE_FAIL, result); |
|
|
|
} |
|
|
|
|
|
|
|