рефакторинг. Исправлен баг. если прервать локальную задачу, не удалялся файл 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.Utils.Utils;
import GlobalData.Machine.Machine;
import GlobalData.RemoteFile.RemoteFile;
import GlobalData.User.User;
import files.ConnectionPass;
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
import com.jcraft.jsch.ChannelSftp;
import java.io.File;
@@ -20,18 +20,14 @@ public class ArchivesBackupPass extends ConnectionPass<File> {
return true;
}
@Override
protected boolean needsInitialize() {
return false;
}
@Override
protected void ServerAction() throws Exception {
String workspace_path = Utils.toU(Paths.get(sftpChannel.getHome(),Global.properties.BackupWorkspace).toString());
String workspace_path = Utils.toU(Paths.get(user.connection.sftpChannel.getHome(), Global.properties.BackupWorkspace).toString());
RemoteFile workspace = new RemoteFile(workspace_path, true);
tryMKDir(workspace);
user.connection.MKDIR(workspace);
RemoteFile dst = new RemoteFile(workspace.full_name, src.getName());
putSingleFile(src, dst);
user.connection.putSingleFile(src, dst);
//-теперь, удалить старые файлы.
Vector<ChannelSftp.LsEntry> raw_files = sftpChannel.ls(workspace.full_name);
Vector<ChannelSftp.LsEntry> raw_files = user.connection.sftpChannel.ls(workspace.full_name);
Vector<RemoteFile> files = new Vector<>();
for (ChannelSftp.LsEntry file : raw_files) {
if (!file.getAttrs().isDir()) {
@@ -44,7 +40,7 @@ public class ArchivesBackupPass extends ConnectionPass<File> {
files.sort((o1, o2) -> (int) (o2.updateTime - o1.updateTime));
for (int i = 2; i < files.size(); ++i) {
System.out.println(files.get(i).full_name + ":" + files.get(i).updateTime);
sftpChannel.rm(files.get(i).full_name);
user.connection.sftpChannel.rm(files.get(i).full_name);
}
//--------------
}

View File

@@ -70,6 +70,7 @@ public class Compile extends Pass_2021<db_project_info> {
subpass = passes.get(PassCode_2021.LinuxLocalCompilation);
break;
case Undefined:
case MVS_cluster:
throw new PassException("Компиляция не реализована для типа машины " + Utils.DQuotes(Current.getMachine().type));
default:
subpass = passes.get(PassCode_2021.RemoteCompilation);

View File

@@ -24,19 +24,19 @@ public class DownloadProject extends CurrentConnectionPass {
System.out.println(Current.getRemoteFile());
remote_archive = new RemoteFile(src.full_name, src.name + ".zip", false);
local_archive = Utils.getTempFileName(remote_archive.name);
if ((getFileKBSize(src.full_name)) <= maxSize) {
if ((user.connection.getFileKBSize(src.full_name)) <= maxSize) {
ShowMessage2("Запаковка папки проекта..");
Command(
user.connection.Command(
"cd " + Utils.DQuotes(src.full_name),
"zip -r " + Utils.DQuotes(remote_archive.full_name) + " ./"
);
// try {
ShowMessage2("Загрузка проекта..");
getSingleFile(remote_archive.full_name, local_archive.getAbsolutePath());
user.connection.getSingleFile(remote_archive.full_name, local_archive.getAbsolutePath());
// } catch (Exception ex) {
// throw new PassException("Ошибка загрузки");
// }
sftpChannel.rm(remote_archive.full_name);
user.connection.sftpChannel.rm(remote_archive.full_name);
} else throw new PassException("Размер проекта превышает " + maxSize + " KB.\n");
} else {
//диалога не вышло, сбрасываем файл.

View File

@@ -8,7 +8,7 @@ import Repository.Server.ServerCode;
import Repository.Server.ServerExchangeUnit_2021;
import TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
import Visual_DVM_2021.Passes.PassCode_2021;
import files.ConnectionPass;
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
import Visual_DVM_2021.Passes.Server.TestingSystemPass;
import java.util.Date;
@@ -39,39 +39,39 @@ public class InstallServerSapfor extends ConnectionPass<Object> {
return true;
}
@Override
protected boolean needsInitialize() {
return false;
}
@Override
protected boolean needsAnimation() {
return true;
}
@Override
protected void ServerAction() throws Exception {
RemoteFile testingSystemHome = new RemoteFile(sftpChannel.pwd(), "_testing_system", true);
RemoteFile testingSystemHome = new RemoteFile(user.connection.sftpChannel.pwd(), "_testing_system", true);
RemoteFile repo = new RemoteFile(testingSystemHome.full_name, "Repo", true);
RemoteFile repoSapforHome = new RemoteFile(repo.full_name + Constants.SAPFOR_REPOSITORY_BIN, true);
//--
ShowMessage1("Синхронизация ветви DVM...");
ShellCommand("cd " + Utils.DQuotes(repo.full_name), "svn checkout " + Constants.REPOSITORY_AUTHENTICATION + " " + Constants.DVM_REPOSITORY + "\n");
user.connection.performScript(repo,
"svn checkout " + Constants.REPOSITORY_AUTHENTICATION + " " + Constants.DVM_REPOSITORY + "\n"
);
ShowMessage1("Синхронизация ветви SAPFOR...");
ShellCommand("cd " + Utils.DQuotes(repo.full_name), "svn checkout " + Constants.REPOSITORY_AUTHENTICATION + " " + Constants.SAPFOR_REPOSITORY + "\n");
user.connection.performScript(repo,
"svn checkout " + Constants.REPOSITORY_AUTHENTICATION + " " + Constants.SAPFOR_REPOSITORY + "\n"
);
ShowMessage1("Сборка SAPFOR...");
//-
RemoteFile repo_bin = new RemoteFile(repoSapforHome.full_name, "Sapfor_F");
if (Exists(repo_bin))
sftpChannel.rm(repo_bin.full_name);
if (user.connection.Exists(repo_bin))
user.connection.sftpChannel.rm(repo_bin.full_name);
//--
performScript(repoSapforHome, "cmake ../", "make -j 4");
user.connection.performScript(repoSapforHome, "cmake ../", "make -j 4");
RemoteFile repoSapfor = new RemoteFile(repoSapforHome, "Sapfor_F");
result = Exists(repoSapfor);
result = user.connection.Exists(repoSapfor);
if (result) {
RemoteFile sapforsDirectory = new RemoteFile(testingSystemHome.full_name, "Sapfors", true);
//создать папку. Для того чтобы скопировать из репозитория.
RemoteFile sapforHome = new RemoteFile(sapforsDirectory.full_name, Utils.getDateName("sapfor"));
tryMKDir(sapforHome);
user.connection.MKDIR(sapforHome);
RemoteFile sapforBin = new RemoteFile(sapforHome, "Sapfor_F");
copy(repo_bin, sapforBin);
user.connection.copy(repo_bin, sapforBin);
//-->>>
serverSapfor = new ServerSapfor();
serverSapfor.home_path = sapforHome.full_name;
@@ -79,9 +79,13 @@ public class InstallServerSapfor extends ConnectionPass<Object> {
serverSapfor.languageName = LanguageName.fortran;
serverSapfor.buildDate = new Date().getTime();
///--->>
String raw = ShellCommand(serverSapfor.getVersionCommand());
String[] data = raw.split(" ");
if (data.length >= 4) serverSapfor.version = data[3].replace(",", "");
RemoteFile version =new RemoteFile(sapforHome, "version.txt");
user.connection.ShellCommand(serverSapfor.getVersionCommand()+" 1>"+Utils.DQuotes(version.full_name));
if (user.connection.Exists(version)){
String raw = user.connection.readFromFile(version);
String[] data = raw.split(" ");
if (data.length >= 4) serverSapfor.version = data[3].replace(",", "");
}
//---
}
}

View File

@@ -5,7 +5,6 @@ import Common.Utils.Utils;
import GlobalData.User.User;
import GlobalData.User.UserState;
import Visual_DVM_2021.Passes.ProcessPass;
import files.ConnectionPass;
import org.apache.commons.io.FileUtils;
import java.io.File;
@@ -38,13 +37,13 @@ public class LocalInitaliseUser extends ProcessPass<User> {
PerformScript(
String.join("\n",
"cd " + Utils.DQuotes(target.getLocalModulesDir()),
"g++ " + ConnectionPass.starter_code + " -o " + ConnectionPass.starter,
"chmod 0777 " + ConnectionPass.starter
"g++ starter -o starter",
"chmod 0777 starter"
));
PerformScript(String.join("\n",
"cd " + Utils.DQuotes(target.getLocalModulesDir()),
"g++ " + ConnectionPass.launcher_code + " -o " + ConnectionPass.launcher,
"chmod 0777 " + ConnectionPass.launcher
"g++ launcher.cpp -o launcher",
"chmod 0777 launcher"
));
}
//-

View File

@@ -4,10 +4,10 @@ import Common.Current;
import Common.Utils.Utils;
import GlobalData.RemoteFile.RemoteFile;
import Visual_DVM_2021.Passes.PassException;
import Visual_DVM_2021.Passes.SSH.ConnectionPass_2023;
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
import java.util.Vector;
public class RemoteInitialiseUser extends ConnectionPass_2023<RemoteFile> {
public class RemoteInitialiseUser extends ConnectionPass<RemoteFile> {
RemoteFile modulesDirectory;
@Override
protected boolean needsAnimation() {

View File

@@ -1,4 +1,6 @@
package Visual_DVM_2021.Passes.All;
import Common.Utils.Utils;
import GlobalData.RemoteFile.RemoteFile;
import Visual_DVM_2021.Passes.SSH.CurrentConnectionPass;
public class RemoteSingleCommand extends CurrentConnectionPass<String> {
String command = "";
@@ -12,6 +14,10 @@ public class RemoteSingleCommand extends CurrentConnectionPass<String> {
}
@Override
protected void ServerAction() throws Exception {
target = ShellCommand(command);
RemoteFile file = new RemoteFile(user.connection.sftpChannel.getHome(), Utils.getDateName("out"));
user.connection.ShellCommand(command+" 1>"+Utils.DQuotes(file.full_name));
if (user.connection.Exists(file)){
target = user.connection.readFromFile(file);
}
}
}

View File

@@ -64,10 +64,13 @@ public class Run extends Pass_2021<db_project_info> {
subpass = passes.get(PassCode_2021.LinuxLocalRun);
break;
case Undefined:
case MVS_cluster:
throw new PassException("Запуск не реализован для типа машины " + Utils.DQuotes(Current.getMachine().type));
/*
case MVS_cluster:
subpass = passes.get(PassCode_2021.MVSRun);
break;
*/
default:
subpass = passes.get(PassCode_2021.ServerRun);
break;

View File

@@ -1,38 +0,0 @@
package Visual_DVM_2021.Passes.OLD;
public class AttachFileToProject {
}
/*
extends ToolBarPass<File> {
VFileChooser fileChooser = new VFileChooser(
"Выбор вложения",
"png",
"jpg",
"bmp",
"zip",
"7z",
"rar"
);
@Override
protected String getIconPath() {
return "/icons/LastOpened.png";
}
@Override
protected boolean CanStart() {
return Current.Check(Log, Current.Project) &&
((target = fileChooser.ShowDialog()) != null) &&
Current.getProject().CheckAttachmentFile(target, Log);
}
@Override
protected void Action() throws Exception {
Utils.CheckDirectory(Current.getProject().getAttachmentsDirectory());
Path src = target.toPath();
Path dst = Paths.get(Current.getProject().getAttachmentsDirectory().getAbsolutePath(), target.getName());
Files.copy(src, dst, StandardCopyOption.REPLACE_EXISTING);
}
@Override
protected void PerformDone() throws Exception {
// UI.getMainWindow().ShowAttachments();
}
}
*/

View File

@@ -1,23 +0,0 @@
package Visual_DVM_2021.Passes.OLD;
public class DeleteAttachments {}
/*
extends ToolBarPass {
@Override
protected String getIconPath() {
return "/icons/Delete.png";
}
@Override
protected boolean CanStart() {
return Current.Check(Log, Current.Project) && UI.Warning("Удалить все вложения текущего проекта");
}
@Override
protected void Action() throws Exception {
Utils.CleanDirectory(Current.getProject().getAttachmentsDirectory());
}
@Override
protected void PerformFinish() {
// UI.getMainWindow().ShowAttachments();
}
}
*/

View File

@@ -3,9 +3,9 @@ import GlobalData.Machine.Machine;
import GlobalData.User.User;
import TestingSystem.DVM.UserConnection;
import Visual_DVM_2021.Passes.Pass_2021;
public class ConnectionPass_2023<T> extends Pass_2021<T> {
public class ConnectionPass<T> extends Pass_2021<T> {
protected Machine machine = null;
protected User user = null;
public User user = null;
//--
protected void Connect() throws Exception{
user.connection = null;

View File

@@ -1,6 +1,5 @@
package Visual_DVM_2021.Passes.SSH;
import Common.Current;
import files.ConnectionPass;
//завязан на текущие машину и юзера
public abstract class CurrentConnectionPass<T> extends ConnectionPass<T> {
@Override

View File

@@ -1,8 +1,9 @@
package Visual_DVM_2021.Passes.SSH;
import Common.Current;
import Common.Global;
import Common.Utils.Utils;
import GlobalData.RemoteFile.RemoteFile;
import GlobalData.Tasks.Supervisor.Remote.RemoteTaskSupervisor;
import files.ConnectionPass;
public abstract class TaskConnectionPass<S extends RemoteTaskSupervisor> extends ConnectionPass {
public S supervisor; //инициализация идет в конструкторе потомка.
public TaskConnectionPass(Class<S> s_class) {
@@ -21,6 +22,14 @@ public abstract class TaskConnectionPass<S extends RemoteTaskSupervisor> extends
machine = supervisor.task.getMachine();
user = supervisor.task.getUser();
super.Connect();
RemoteFile userWorkspace = new RemoteFile(user.workspace, true);
if (!user.connection.Exists(userWorkspace))
throw new WorkspaceNotFoundException(
"Рабочее пространство пользователя " + Utils.Brackets(user.login)
+ " на машине " + Utils.Brackets(machine.getURL())
+ "\n" + Utils.Brackets(user.workspace) + "\е найдено.\n" +
"Требуется выполнить повторную инициализацию пользователя."
);
}
@Override
protected void ServerAction() throws Exception {

View File

@@ -4,10 +4,6 @@ import Common.UI.UI;
public class SapforPass extends SilentSapforPass {
//отличается наличием журнала и сообщений
@Override
protected void performPreparation() throws Exception {
// target.CleanInterruptFile();
}
@Override
protected void performFinish() throws Exception {
target.db.BeginTransaction();
try {

View File

@@ -19,6 +19,10 @@ public class SilentSapforPass extends CurrentProjectPass {
return super.canStart(args) && ((sapfor = Current.getSapfor()) != null);
}
@Override
protected void performPreparation() throws Exception {
target.CleanInterruptFile();
}
@Override
protected boolean validate() {
switch (sapfor.getErrorCode()) {
case Sapfor.empty_code: