2023-09-17 22:13:42 +03:00
|
|
|
package GlobalData.Tasks.Supervisor.Remote;
|
2023-10-04 22:01:09 +03:00
|
|
|
import Common.Constants;
|
2023-09-17 22:13:42 +03:00
|
|
|
import Common.Utils.Utils;
|
|
|
|
|
import GlobalData.RemoteFile.RemoteFile;
|
|
|
|
|
import GlobalData.Tasks.Supervisor.TaskSupervisor;
|
|
|
|
|
import GlobalData.Tasks.Task;
|
|
|
|
|
import GlobalData.Tasks.TaskState;
|
2023-12-20 02:47:47 +03:00
|
|
|
import files.ConnectionPass;
|
2023-09-17 22:13:42 +03:00
|
|
|
public abstract class RemoteTaskSupervisor<T extends Task> extends TaskSupervisor<T, ConnectionPass> {
|
|
|
|
|
protected RemoteFile getRemoteProjectsPath() {
|
|
|
|
|
return new RemoteFile(pass.user.getRemoteProjectsPath(), true);
|
|
|
|
|
}
|
|
|
|
|
protected RemoteFile getRemoteProject() {
|
|
|
|
|
return new RemoteFile(getRemoteProjectsPath().full_name, project.getUniqKey(), true);
|
|
|
|
|
}
|
|
|
|
|
protected RemoteFile getBinary() {
|
|
|
|
|
return new RemoteFile(getRemoteProject().full_name, "0");
|
|
|
|
|
}
|
|
|
|
|
protected RemoteFile getRemoteTime() {
|
2023-10-04 22:01:09 +03:00
|
|
|
return new RemoteFile(getRemoteProject().full_name, Constants.time_file);
|
2023-09-17 22:13:42 +03:00
|
|
|
}
|
|
|
|
|
protected RemoteFile getRemoteOutput() {
|
2023-10-04 22:01:09 +03:00
|
|
|
return new RemoteFile(getRemoteProject().full_name, Constants.out_file);
|
2023-09-17 22:13:42 +03:00
|
|
|
}
|
|
|
|
|
protected RemoteFile getRemoteErrors() {
|
2023-10-04 22:01:09 +03:00
|
|
|
return new RemoteFile(getRemoteProject().full_name, Constants.err_file);
|
2023-09-17 22:13:42 +03:00
|
|
|
}
|
|
|
|
|
public RemoteFile getDONE_file() {
|
2023-10-04 22:01:09 +03:00
|
|
|
return new RemoteFile(getRemoteProject().full_name, Constants.DONE);
|
2023-09-17 22:13:42 +03:00
|
|
|
}
|
|
|
|
|
public RemoteFile getTIMEOUT_file() {
|
2023-10-04 22:01:09 +03:00
|
|
|
return new RemoteFile(getRemoteProject().full_name, Constants.TIMEOUT);
|
2023-09-17 22:13:42 +03:00
|
|
|
}
|
|
|
|
|
@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());
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void CheckTask() throws Exception {
|
2023-12-04 14:42:36 +03:00
|
|
|
RemoteFile DONE = new RemoteFile(getRemoteProject(), Constants.DONE);
|
|
|
|
|
RemoteFile TIMEOUT = new RemoteFile(getRemoteProject(), Constants.TIMEOUT);
|
|
|
|
|
if (pass.Exists(DONE))
|
2023-09-17 22:13:42 +03:00
|
|
|
task.state = TaskState.Finished;
|
2023-12-04 14:42:36 +03:00
|
|
|
else if (pass.Exists(TIMEOUT))
|
2023-09-17 22:13:42 +03:00
|
|
|
task.state = TaskState.AbortedByTimeout;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void AchieveResults() throws Exception {
|
2023-12-04 14:42:36 +03:00
|
|
|
pass.tryGetSingleFileWithMaxSize(getRemoteOutput(), task.getOutputFile(), 10240);
|
|
|
|
|
pass.tryGetSingleFileWithMaxSize(getRemoteErrors(), task.getErrorsFile(), 10240);
|
2023-09-17 22:13:42 +03:00
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void AbortTask() throws Exception {
|
|
|
|
|
pass.ShellCommand("kill -2 " + task.PID);
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
protected void CalculatePerformanceTime() throws Exception {
|
2023-12-04 14:42:36 +03:00
|
|
|
if (pass.tryGetSingleFileWithMaxSize(getRemoteTime(), task.getTimeFile(), 0))
|
2023-09-17 22:13:42 +03:00
|
|
|
task.RefreshTime();
|
|
|
|
|
}
|
|
|
|
|
protected String getStartCommand() {
|
|
|
|
|
String res =
|
|
|
|
|
String.join(" ",
|
|
|
|
|
Utils.DQuotes(pass.getStarter()),
|
|
|
|
|
Utils.DQuotes(pass.getLauncher()),
|
|
|
|
|
String.valueOf(task.maxtime),
|
|
|
|
|
Utils.DQuotes(getCoupDeGrace()),
|
|
|
|
|
task.getFullCommand()
|
|
|
|
|
);
|
|
|
|
|
System.out.println(res);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
}
|