промежуточный. проверка инициализации при тестировании..
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package TestingSystem.DVM;
|
||||
import Common.Constants;
|
||||
import Common.Current;
|
||||
import Common.Global;
|
||||
import Common.Utils.Utils;
|
||||
import GlobalData.Machine.Machine;
|
||||
@@ -32,7 +33,13 @@ public class UserConnection {
|
||||
PipedInputStream pout = null;
|
||||
InputStreamReader fromServer = null;
|
||||
//---
|
||||
public UserConnection(Machine machine, User user) throws Exception {
|
||||
Machine machine = null;
|
||||
User user = null;
|
||||
//---
|
||||
public UserConnection(Machine machine_in, User user_in) throws Exception {
|
||||
machine = machine_in;
|
||||
user = user_in;
|
||||
//--
|
||||
session = (jsch = new JSch()).getSession(user.login, machine.address, machine.port);
|
||||
session.setPassword(user.password);
|
||||
session.setConfig("StrictHostKeyChecking", "no");
|
||||
@@ -101,19 +108,6 @@ public class UserConnection {
|
||||
jsch = null;
|
||||
System.gc();
|
||||
}
|
||||
//--
|
||||
//todo из за мусора результатом пользоваться в общем случае невозможно.
|
||||
//следует перенаправлять вывод в какой нибудь временный файл на сервере.
|
||||
/*
|
||||
public String ShellCommand(String command) throws Exception {
|
||||
StringBuilder result = new StringBuilder();
|
||||
pin.write((command + "\r\n").getBytes());
|
||||
ShellParser.ReadInvitation(fromServer); //первое приглашение после эхо. возможен мусор.
|
||||
result.append(ShellParser.getCommandResult(fromServer)); //возможный результат и второе приглашение.
|
||||
String[] data = result.toString().split("\n");
|
||||
return (data.length > 0) ? data[data.length - 1] : result.toString();
|
||||
}
|
||||
*/
|
||||
public void getSingleFile(String src, String dst) throws Exception {
|
||||
sftpChannel.get(src, dst);
|
||||
}
|
||||
@@ -467,8 +461,8 @@ public class UserConnection {
|
||||
System.gc();
|
||||
}
|
||||
public void waitForFileCreation(RemoteFile file) throws Exception {
|
||||
while (!Exists(file)){
|
||||
System.out.println(file.full_name +" NOT FOUND");
|
||||
while (!Exists(file)) {
|
||||
System.out.println(file.full_name + " NOT FOUND");
|
||||
Utils.sleep(1000);
|
||||
}
|
||||
}
|
||||
@@ -477,7 +471,7 @@ public class UserConnection {
|
||||
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>"+Utils.DQuotes(outFileName));
|
||||
commands_.add(commands[i] + " 1>" + Utils.DQuotes(outFileName));
|
||||
} else {
|
||||
commands_.add(commands[i]);
|
||||
}
|
||||
@@ -490,12 +484,46 @@ public class UserConnection {
|
||||
//--
|
||||
RemoteFile outFile = new RemoteFile(directory, outFileName);
|
||||
if (Exists(outFile))
|
||||
sftpChannel.rm(outFile.full_name);
|
||||
sftpChannel.rm(outFile.full_name);
|
||||
ShellConnect();
|
||||
pin.write(("nohup " + start_command + " &\r\n").getBytes());
|
||||
|
||||
waitForFileCreation(outFile);
|
||||
ShellDisconnect();
|
||||
return readFromFile(outFile).replace("\n","").replace("\r","");
|
||||
return readFromFile(outFile).replace("\n", "").replace("\r", "");
|
||||
}
|
||||
//--
|
||||
public void CheckUserInitialization() throws Exception {
|
||||
RemoteFile userWorkspace = new RemoteFile(user.workspace, true);
|
||||
if (!Exists(userWorkspace)){
|
||||
System.out.println("создание папки пользователя");
|
||||
sftpChannel.mkdir(userWorkspace.full_name);
|
||||
//--
|
||||
RemoteFile modulesDirectory= new RemoteFile(userWorkspace, "modules");
|
||||
RemoteFile projectsDirectory = new RemoteFile(userWorkspace, "projects");
|
||||
RemoteFile testsDirectory = new RemoteFile(userWorkspace, "tests");
|
||||
//--
|
||||
Vector<RemoteFile> subdirectories = new Vector<>();
|
||||
subdirectories.add(modulesDirectory);
|
||||
subdirectories.add(projectsDirectory);
|
||||
subdirectories.add(testsDirectory);
|
||||
System.out.println("создание рабочих подпапок");
|
||||
for (RemoteFile remoteFile : subdirectories)
|
||||
sftpChannel.mkdir(remoteFile.full_name);
|
||||
//--
|
||||
System.out.println("закачка кода модулей");
|
||||
for (String resource_name : Constants.resourses_names) {
|
||||
System.out.println(resource_name);
|
||||
putResource(modulesDirectory, resource_name);
|
||||
}
|
||||
//-
|
||||
System.out.println("Сборка модулей...");
|
||||
String modules_log = compileModules(modulesDirectory);
|
||||
if (!modules_log.isEmpty())
|
||||
throw new PassException(modules_log);
|
||||
/*
|
||||
RemoteFile info = new RemoteFile(userWorkspace, user.email);
|
||||
user.connection.writeToFile("", info);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user