ночные изменения,+ исправление бага с иконкой сравнения
This commit is contained in:
@@ -2,6 +2,7 @@ package TestingSystem.DVM;
|
||||
import Common.Constants;
|
||||
import Common.Global;
|
||||
import Common.Utils.Utils;
|
||||
import Common.Utils.Validators.ShellParser;
|
||||
import GlobalData.Machine.Machine;
|
||||
import GlobalData.RemoteFile.RemoteFile;
|
||||
import GlobalData.User.User;
|
||||
@@ -42,20 +43,6 @@ public class UserConnection {
|
||||
sftpChannel.connect();
|
||||
//-->
|
||||
//создать канал для команд
|
||||
shellChannel = (ChannelShell) session.openChannel("shell");
|
||||
in = new PipedInputStream();
|
||||
out = new PipedOutputStream();
|
||||
/*
|
||||
shellChannel.setInputStream(in);
|
||||
shellChannel.setOutputStream(out);
|
||||
pin = new PipedOutputStream(in);
|
||||
pout = new PipedInputStream(out);
|
||||
shellChannel.connect();
|
||||
//-
|
||||
fromServer = new InputStreamReader(pout);
|
||||
ShellParser.setUserName(user.login);
|
||||
ShellParser.ReadInvitation(fromServer); //прочитать первое приглашение от машины.
|
||||
*/
|
||||
}
|
||||
public void Disconnect() {
|
||||
if (in != null) {
|
||||
@@ -103,7 +90,6 @@ public class UserConnection {
|
||||
sftpChannel = null;
|
||||
shellChannel = null;
|
||||
execChannel = null;
|
||||
jsch = null;
|
||||
session = null;
|
||||
//---
|
||||
in = null;
|
||||
@@ -112,6 +98,7 @@ public class UserConnection {
|
||||
pin = null;
|
||||
pout = null;
|
||||
fromServer = null;
|
||||
jsch = null;
|
||||
System.gc();
|
||||
}
|
||||
//--
|
||||
@@ -393,8 +380,6 @@ public class UserConnection {
|
||||
public void Command(String... commands) throws Exception {
|
||||
if (commands.length > 0) {
|
||||
String command = String.join("\n", commands);
|
||||
// UI.Print(DebugPrintLevel.Session, command);
|
||||
// UI.Print(DebugPrintLevel.Session, "Creating Exec Channel.");
|
||||
execChannel = (ChannelExec) session.openChannel("exec");
|
||||
execChannel.setErrStream(System.err);
|
||||
execChannel.setCommand(command);
|
||||
@@ -425,4 +410,102 @@ public class UserConnection {
|
||||
writeToFile("cd " + Utils.DQuotes(directory.full_name) + "\n" + String.join("\n", commands), script_file);
|
||||
CommandNoWait(Utils.DQuotes(script_file.full_name));
|
||||
}
|
||||
//-----
|
||||
public void ShellConnect() throws Exception {
|
||||
shellChannel = (ChannelShell) session.openChannel("shell");
|
||||
in = new PipedInputStream();
|
||||
out = new PipedOutputStream();
|
||||
//--
|
||||
shellChannel.setInputStream(in);
|
||||
shellChannel.setOutputStream(out);
|
||||
pin = new PipedOutputStream(in);
|
||||
pout = new PipedInputStream(out);
|
||||
shellChannel.connect();
|
||||
//-
|
||||
fromServer = new InputStreamReader(pout);
|
||||
/*
|
||||
ShellParser.setUserName(user.login);
|
||||
ShellParser.ReadInvitation(fromServer); //прочитать первое приглашение от машины.
|
||||
*/
|
||||
}
|
||||
public void ShellDisconnect() throws Exception {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (Exception exception) {
|
||||
Global.Log.PrintException(exception);
|
||||
}
|
||||
}
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (Exception exception) {
|
||||
Global.Log.PrintException(exception);
|
||||
}
|
||||
}
|
||||
if (pin != null) {
|
||||
try {
|
||||
pin.close();
|
||||
} catch (Exception exception) {
|
||||
Global.Log.PrintException(exception);
|
||||
}
|
||||
}
|
||||
if (pout != null) {
|
||||
try {
|
||||
pout.close();
|
||||
} catch (Exception exception) {
|
||||
Global.Log.PrintException(exception);
|
||||
}
|
||||
}
|
||||
if (fromServer != null) {
|
||||
try {
|
||||
fromServer.close();
|
||||
} catch (Exception exception) {
|
||||
Global.Log.PrintException(exception);
|
||||
}
|
||||
}
|
||||
if (shellChannel != null) shellChannel.disconnect();
|
||||
//--
|
||||
in = null;
|
||||
out = null;
|
||||
pin = null;
|
||||
pout = null;
|
||||
fromServer = null;
|
||||
shellChannel = null;
|
||||
System.gc();
|
||||
}
|
||||
public void ShellCommandNoWait(String command) throws Exception {
|
||||
ShellConnect();
|
||||
pin.write(("nohup " + command + " &\r\n").getBytes());
|
||||
ShellParser.ReadCommand(command, fromServer); //команда
|
||||
System.out.println("+++++++++++++++++");
|
||||
ShellParser.ReadCommand(command, fromServer); //эхо
|
||||
ShellDisconnect();
|
||||
}
|
||||
public String startProcess(RemoteFile directory, String... commands) throws Exception {
|
||||
Vector<String> commands_ = new Vector<>();
|
||||
commands_.add("cd " + Utils.DQuotes(directory.full_name));
|
||||
for (int i = 0; i < commands.length; ++i) {
|
||||
if (i == commands.length - 1) {
|
||||
commands_.add(commands[i] + " 1>PID");
|
||||
} else {
|
||||
commands_.add(commands[i]);
|
||||
}
|
||||
}
|
||||
RemoteFile script_file = new RemoteFile(directory, Constants.script);
|
||||
if (Exists(script_file))
|
||||
sftpChannel.rm(script_file.full_name);
|
||||
writeToFile(String.join("\n", commands_), script_file);
|
||||
String start_command = Utils.DQuotes(script_file.full_name);
|
||||
//--
|
||||
RemoteFile PID = new RemoteFile(directory, "PID");
|
||||
ShellConnect();
|
||||
pin.write(("nohup " + start_command + " &\r\n").getBytes());
|
||||
while (!Exists(PID)){
|
||||
System.out.println("PID NOT FOUND");
|
||||
Utils.sleep(1000);
|
||||
}
|
||||
ShellDisconnect();
|
||||
return readFromFile(PID).replace("\n","").replace("\r","");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user