рефакторинг. Исправлен баг. если прервать локальную задачу, не удалялся файл interrupt.
This commit is contained in:
2024-01-08 20:37:16 +03:00
parent 5baf2154e2
commit fce61bf55a
26 changed files with 281 additions and 582 deletions

View File

@@ -4,7 +4,7 @@ import Common.Global;
import Common.UI.UI;
import Common.UI.Windows.Dialog.Dialog;
import GlobalData.RemoteFile.RemoteFile;
import files.ConnectionPass;
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
import com.jcraft.jsch.ChannelSftp.LsEntry;
import javax.swing.tree.DefaultMutableTreeNode;
@@ -28,7 +28,7 @@ public class RemoteFileChooser extends Dialog<String, RemoteFileChooserFields> {
session = (ConnectionPass) params[0];
target_is_directory = (boolean) params[1];
try {
Refresh(session.getSftpChannel().pwd());
Refresh(session.user.connection.sftpChannel.pwd());
} catch (Exception ex) {
Global.Log.PrintException(ex);
onCancel(); //закрываем окно.
@@ -45,7 +45,7 @@ public class RemoteFileChooser extends Dialog<String, RemoteFileChooserFields> {
root_file = new RemoteFile(path, true);
root = new DefaultMutableTreeNode(root_file);
//-------------------------------------------------------
Vector<LsEntry> files = session.getSftpChannel().ls(path);
Vector<LsEntry> files = session.user.connection.sftpChannel.ls(path);
Vector<RemoteFile> directories_ = new Vector<>();
Vector<RemoteFile> files_ = new Vector<>();
//отсортировать по принадлежности.
@@ -74,7 +74,7 @@ public class RemoteFileChooser extends Dialog<String, RemoteFileChooserFields> {
}
public void goHome() {
try {
Refresh(session.getSftpChannel().getHome());
Refresh(session.user.connection.sftpChannel.getHome());
} catch (Exception ex) {
Global.Log.PrintException(ex);
onCancel(); //закрываем окно.

View File

@@ -35,9 +35,11 @@ public class MVSRunSupervisor extends ServerRunSupervisor {
String res = "maxtime=" + Utils.DQuotes(mvs_time) + " ./run";
if (!env.isEmpty())
res = env + " " + res;
/*
mvs.enqueueTask(pass.ShellCommand(
"cd " + Utils.DQuotes(getRemoteProject().full_name),
res), task);
*/
}
@Override
protected boolean isTaskActive() {
@@ -45,11 +47,11 @@ public class MVSRunSupervisor extends ServerRunSupervisor {
}
@Override
protected void CheckTask() throws Exception {
mvs.checkTask(pass.ShellCommand(mvs.getCheckTaskCommand(task)), task);
// mvs.checkTask(pass.ShellCommand(mvs.getCheckTaskCommand(task)), task);
}
@Override
protected void AbortTask() throws Exception {
pass.ShellCommand(mvs.getCancelTaskCommand(task));
// pass.ShellCommand(mvs.getCancelTaskCommand(task));
}
@Override
protected void CalculatePerformanceTime() throws Exception {

View File

@@ -10,36 +10,41 @@ public class RemoteCompilationSupervisor extends RemoteTaskSupervisor<Compilatio
@Override
protected void PrepareWorkspace() throws Exception {
//0. если нет папки с его именем создаем.
pass.tryMKDir(getRemoteProject());
pass.SynchronizeProjectSubDirsR(project, project.Home, getRemoteProject(), false);
pass.tryRM(getBinary());
pass.user.connection.MKDIR(getRemoteProject());
pass.user.connection.SynchronizeProjectSubDirsR(project, project.Home, getRemoteProject(), false);
pass.user.connection.tryRM(getBinary());
if (!task.binary_name.isEmpty()) {
RemoteFile old_binary = new RemoteFile(getRemoteProject().full_name, task.binary_name);
pass.tryRM(old_binary);
pass.user.connection.tryRM(old_binary);
}
//отправить мейкфайл.
Makefile makefile = task.getMakefile();
File makefile_text = Utils.CreateTempFile("makefile", makefile.Generate(project));
pass.putSingleFile(makefile_text, new RemoteFile(getRemoteProject().full_name, "Makefile"));
pass.user.connection.putSingleFile(makefile_text, new RemoteFile(getRemoteProject().full_name, "Makefile"));
//очистить все что связано с gcov
//файлы gcda, gcno, gcov
pass.deleteFilesByExtensions(getRemoteProject(), "gcda", "gcno", "gcov");
pass.user.connection.deleteFilesByExtensions(getRemoteProject(), "gcda", "gcno", "gcov");
//очистить служебные файлы.
super.PrepareWorkspace();
}
@Override
protected void StartTask() throws Exception {
//UI.Info("starting task");
task.PID = pass.ShellCommand(
"cd " + Utils.DQuotes(getRemoteProject().full_name),
getStartCommand());
pass.user.connection.performScript(getRemoteProject(), getStartCommand()+" 1>PID");
RemoteFile PID = getPID();
while (!pass.user.connection.Exists(PID)){
System.out.println("PID NOT FOUND");
Utils.sleep(1000);
}
task.PID = pass.user.connection.readFromFile(PID).replace("\n","").replace("\r","");
System.out.println("PID="+Utils.Brackets(task.PID));
task.state = TaskState.Running;
}
@Override
protected void ValidateTaskResults() throws Exception {
if (pass.Exists(getBinary())) {
if (pass.user.connection.Exists(getBinary())) {
RemoteFile renamed_binary = new RemoteFile(getRemoteProject().full_name, Utils.getDateName("spf_" + getBinary().name));
pass.sftpChannel.rename(getBinary().full_name, renamed_binary.full_name);
pass.user.connection.sftpChannel.rename(getBinary().full_name, renamed_binary.full_name);
task.binary_name = renamed_binary.name;
task.state = TaskState.Done;
} else task.state = TaskState.DoneWithErrors;

View File

@@ -5,7 +5,7 @@ import GlobalData.RemoteFile.RemoteFile;
import GlobalData.Tasks.Supervisor.TaskSupervisor;
import GlobalData.Tasks.Task;
import GlobalData.Tasks.TaskState;
import files.ConnectionPass;
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
public abstract class RemoteTaskSupervisor<T extends Task> extends TaskSupervisor<T, ConnectionPass> {
protected RemoteFile getRemoteProjectsPath() {
return new RemoteFile(pass.user.getRemoteProjectsPath(), true);
@@ -16,6 +16,9 @@ public abstract class RemoteTaskSupervisor<T extends Task> extends TaskSuperviso
protected RemoteFile getBinary() {
return new RemoteFile(getRemoteProject().full_name, "0");
}
protected RemoteFile getPID() {
return new RemoteFile(getRemoteProject().full_name, "PID");
}
protected RemoteFile getRemoteTime() {
return new RemoteFile(getRemoteProject().full_name, Constants.time_file);
}
@@ -34,40 +37,48 @@ public abstract class RemoteTaskSupervisor<T extends Task> extends TaskSuperviso
@Override
protected void PrepareWorkspace() throws Exception {
super.PrepareWorkspace(); //локальная подготовка
pass.tryRM(getDONE_file());
pass.tryRM(getTIMEOUT_file());
pass.tryRM(getRemoteOutput());
pass.tryRM(getRemoteErrors());
pass.tryRM(getRemoteTime());
pass.user.connection.tryRM(getDONE_file());
pass.user.connection.tryRM(getPID());
pass.user.connection.tryRM(getTIMEOUT_file());
pass.user.connection.tryRM(getRemoteOutput());
pass.user.connection.tryRM(getRemoteErrors());
pass.user.connection.tryRM(getRemoteTime());
}
@Override
protected void CheckTask() throws Exception {
RemoteFile DONE = new RemoteFile(getRemoteProject(), Constants.DONE);
RemoteFile TIMEOUT = new RemoteFile(getRemoteProject(), Constants.TIMEOUT);
if (pass.Exists(DONE))
if (pass.user.connection.Exists(DONE))
task.state = TaskState.Finished;
else if (pass.Exists(TIMEOUT))
else if (pass.user.connection.Exists(TIMEOUT))
task.state = TaskState.AbortedByTimeout;
}
@Override
protected void AchieveResults() throws Exception {
pass.tryGetSingleFileWithMaxSize(getRemoteOutput(), task.getOutputFile(), 10240);
pass.tryGetSingleFileWithMaxSize(getRemoteErrors(), task.getErrorsFile(), 10240);
pass.user.connection.tryGetSingleFileWithMaxSize(getRemoteOutput(), task.getOutputFile(), 10240);
pass.user.connection.tryGetSingleFileWithMaxSize(getRemoteErrors(), task.getErrorsFile(), 10240);
}
@Override
protected void AbortTask() throws Exception {
pass.ShellCommand("kill -2 " + task.PID);
pass.user.connection.ShellCommand("kill -2 " + task.PID);
}
@Override
protected void CalculatePerformanceTime() throws Exception {
if (pass.tryGetSingleFileWithMaxSize(getRemoteTime(), task.getTimeFile(), 0))
if (pass.user.connection.tryGetSingleFileWithMaxSize(getRemoteTime(), task.getTimeFile(), 0))
task.RefreshTime();
}
public String getStarter() {
return String.join("/", pass.user.workspace, "modules", "starter");
}
public String getLauncher() {
return String.join("/", pass.user.workspace, "modules", "launcher");
}
protected String getStartCommand() {
String res =
String.join(" ",
Utils.DQuotes(pass.getStarter()),
Utils.DQuotes(pass.getLauncher()),
Utils.DQuotes(getStarter()),
Utils.DQuotes(getLauncher()),
String.valueOf(task.maxtime),
Utils.DQuotes(getCoupDeGrace()),
task.getFullCommand()

View File

@@ -16,10 +16,14 @@ public class ServerRunSupervisor extends RemoteTaskSupervisor<RunTask> {
String res = "./run";
String env = String.join(" ", Current.getRunConfiguration().getEnvList());
if (!env.isEmpty()) res = env + " " + res;
task.PID = pass.ShellCommand(
"cd " + Utils.DQuotes(getRemoteProject().full_name),
"ulimit -s unlimited",
res);
pass.user.connection.performScript(getRemoteProject(), "ulimit -s unlimited", res+" 1>PID");
RemoteFile PID = getPID();
while (!pass.user.connection.Exists(PID)){
System.out.println("PID NOT FOUND");
Utils.sleep(1000);
}
task.PID = pass.user.connection.readFromFile(PID).replace("\n","").replace("\r","");
System.out.println("PID="+Utils.Brackets(task.PID));
task.state = TaskState.Running;
}
@Override
@@ -32,21 +36,21 @@ public class ServerRunSupervisor extends RemoteTaskSupervisor<RunTask> {
//-------------------------
//удалить старую статистику если оная есть.
if (!task.last_sts_name.isEmpty()) {
pass.tryRM(new RemoteFile(getRemoteProject().full_name, task.last_sts_name));
pass.user.connection.tryRM(new RemoteFile(getRemoteProject().full_name, task.last_sts_name));
task.UpdateLastStsName("");
}
//-------------------------
String launchScriptText = getLaunchScriptText();
RemoteFile launchScript = new RemoteFile(getRemoteProject().full_name, "run");
pass.sftpChannel.put(
pass.user.connection.sftpChannel.put(
new ByteArrayInputStream(
launchScriptText.getBytes(StandardCharsets.UTF_8)), launchScript.full_name);
pass.sftpChannel.chmod(0777, launchScript.full_name);
pass.user.connection.sftpChannel.chmod(0777, launchScript.full_name);
//-
//отправить usr.par.
if (task.hasDVMPar()) {
File par_text = Utils.CreateTempFile("usr", String.join("\n", task.getRunConfiguration().getParList()));
pass.putSingleFile(par_text, new RemoteFile(getRemoteProject().full_name, "usr.par"));
pass.user.connection.putSingleFile(par_text, new RemoteFile(getRemoteProject().full_name, "usr.par"));
}
}
protected String getLaunchScriptText() {
@@ -62,7 +66,7 @@ public class ServerRunSupervisor extends RemoteTaskSupervisor<RunTask> {
task.parseCleanTime();
//теперь ищем статистику.
//статистика
Vector<ChannelSftp.LsEntry> files = pass.sftpChannel.ls(getRemoteProject().full_name);
Vector<ChannelSftp.LsEntry> files = pass.user.connection.sftpChannel.ls(getRemoteProject().full_name);
for (ChannelSftp.LsEntry file : files) {
if (file.getFilename().endsWith("sts.gz+")) {
task.UpdateLastStsName(file.getFilename());
@@ -71,7 +75,7 @@ public class ServerRunSupervisor extends RemoteTaskSupervisor<RunTask> {
}
if (!task.last_sts_name.isEmpty()) {
RemoteFile remote_sts = new RemoteFile(getRemoteProject().full_name, task.last_sts_name);
task.hasDvmSts = pass.tryGetSingleFileWithMaxSize(remote_sts, task.getLocalStsFile(), 10240);
task.hasDvmSts = pass.user.connection.tryGetSingleFileWithMaxSize(remote_sts, task.getLocalStsFile(), 10240);
}
}
}

View File

@@ -4,7 +4,6 @@ import Common.Current;
import Common.Database.iDBObject;
import GlobalData.Machine.Machine;
import TestingSystem.DVM.UserConnection;
import files.ConnectionPass;
import com.sun.org.glassfish.gmbal.Description;
import java.io.File;
@@ -53,20 +52,21 @@ public class User extends iDBObject {
public File getLocalModulesDir() {
return Paths.get(workspace, "modules").toFile();
}
public File getHeaderCodeFile() {
return Paths.get(workspace, "modules", ConnectionPass.Process_r_header).toFile();
return Paths.get(workspace, "modules", "Process_r.h").toFile();
}
public File getStarterCodeFile() {
return Paths.get(workspace, "modules", ConnectionPass.starter_code).toFile();
return Paths.get(workspace, "modules", "starter.cpp").toFile();
}
public File getStarterFile() {
return Paths.get(workspace, "modules", ConnectionPass.starter).toFile();
return Paths.get(workspace, "modules", "starter").toFile();
}
public File getLauncherCodeFile() {
return Paths.get(workspace, "modules", ConnectionPass.launcher_code).toFile();
return Paths.get(workspace, "modules", "launcher.cpp").toFile();
}
public File getLauncherFile() {
return Paths.get(workspace, "modules", ConnectionPass.launcher).toFile();
return Paths.get(workspace, "modules", "launcher").toFile();
}
//-
@Description("IGNORE")