промежуточный. частичный рефакторинг инициализации. еще не готов.
This commit is contained in:
@@ -4,7 +4,7 @@ import Common.Global;
|
||||
import Common.UI.UI;
|
||||
import Common.UI.Windows.Dialog.Dialog;
|
||||
import GlobalData.RemoteFile.RemoteFile;
|
||||
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
|
||||
import files.ConnectionPass;
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
@@ -5,7 +5,7 @@ import GlobalData.RemoteFile.RemoteFile;
|
||||
import GlobalData.Tasks.Supervisor.TaskSupervisor;
|
||||
import GlobalData.Tasks.Task;
|
||||
import GlobalData.Tasks.TaskState;
|
||||
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
|
||||
import files.ConnectionPass;
|
||||
public abstract class RemoteTaskSupervisor<T extends Task> extends TaskSupervisor<T, ConnectionPass> {
|
||||
protected RemoteFile getRemoteProjectsPath() {
|
||||
return new RemoteFile(pass.user.getRemoteProjectsPath(), true);
|
||||
|
||||
@@ -4,7 +4,7 @@ import Common.Current;
|
||||
import Common.Database.iDBObject;
|
||||
import GlobalData.Machine.Machine;
|
||||
import TestingSystem.DVM.UserConnection;
|
||||
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
|
||||
import files.ConnectionPass;
|
||||
import com.sun.org.glassfish.gmbal.Description;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -16,7 +16,7 @@ import TestingSystem.DVM.DVMTasks.DVMRunTask;
|
||||
import TestingSystem.DVM.DVMTasks.DVMTask;
|
||||
import TestingSystem.Common.TasksPackageState;
|
||||
import Visual_DVM_2021.Passes.All.UnzipFolderPass;
|
||||
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
|
||||
import files.ConnectionPass;
|
||||
import javafx.util.Pair;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import Common.Utils.Utils;
|
||||
import GlobalData.Machine.Machine;
|
||||
import GlobalData.RemoteFile.RemoteFile;
|
||||
import GlobalData.User.User;
|
||||
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
|
||||
import files.ConnectionPass;
|
||||
import com.jcraft.jsch.ChannelSftp;
|
||||
|
||||
import java.io.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 Visual_DVM_2021.Passes.SSH.ConnectionPass;
|
||||
import files.ConnectionPass;
|
||||
import Visual_DVM_2021.Passes.Server.TestingSystemPass;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -5,7 +5,7 @@ import Common.Utils.Utils;
|
||||
import GlobalData.User.User;
|
||||
import GlobalData.User.UserState;
|
||||
import Visual_DVM_2021.Passes.ProcessPass;
|
||||
import Visual_DVM_2021.Passes.SSH.ConnectionPass;
|
||||
import files.ConnectionPass;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -2,68 +2,95 @@ package Visual_DVM_2021.Passes.All;
|
||||
import Common.Current;
|
||||
import Common.Utils.Utils;
|
||||
import GlobalData.RemoteFile.RemoteFile;
|
||||
import Visual_DVM_2021.Passes.SSH.CurrentConnectionPass;
|
||||
import Visual_DVM_2021.Passes.PassException;
|
||||
import Visual_DVM_2021.Passes.SSH.ConnectionPass_2023;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
public class RemoteInitialiseUser extends CurrentConnectionPass<String> {
|
||||
import java.util.Vector;
|
||||
public class RemoteInitialiseUser extends ConnectionPass_2023<RemoteFile> {
|
||||
RemoteFile modulesDirectory;
|
||||
@Override
|
||||
protected boolean needsInitialize() {
|
||||
return false;
|
||||
protected boolean needsAnimation() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
protected boolean canStart(Object... args) {
|
||||
return Current.Check(Log, Current.User);
|
||||
}
|
||||
@Override
|
||||
protected void Connect() throws Exception {
|
||||
machine = Current.getMachine();
|
||||
user = Current.getUser();
|
||||
super.Connect();
|
||||
}
|
||||
void put_resource(String res_name, RemoteFile dst_directory) throws Exception {
|
||||
user.connection.putSingleFile(Utils.CreateTempResourceFile(res_name), new RemoteFile(dst_directory, res_name));
|
||||
}
|
||||
void compileModule(String module_name) throws Exception{
|
||||
user.connection.performScript(modulesDirectory,
|
||||
"g++ " +
|
||||
Utils.DQuotes(module_name + ".cpp") + " -o "+ Utils.DQuotes(module_name));
|
||||
RemoteFile binary = new RemoteFile(modulesDirectory, module_name);
|
||||
if (!user.connection.Exists(binary)){
|
||||
throw new PassException("Не удалось собрать модуль "+Utils.Brackets(module_name));
|
||||
}else {
|
||||
user.connection.sftpChannel.chmod(0777, binary.full_name);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void ServerAction() throws Exception {
|
||||
String workspace_name = Utils.getDateName("visual_sapfor_workspace");
|
||||
target = Utils.toU(Paths.get(sftpChannel.getHome(), workspace_name).toString());
|
||||
ShowMessage1("Создание рабочих папок...");
|
||||
ShowMessage1("Создание рабочего пространства...");
|
||||
target = new RemoteFile(user.connection.sftpChannel.getHome(), workspace_name);
|
||||
user.connection.sftpChannel.mkdir(target.full_name);
|
||||
Vector<RemoteFile> subdirectories = new Vector<>();
|
||||
subdirectories.add(new RemoteFile(target, "projects"));
|
||||
subdirectories.add(modulesDirectory = new RemoteFile(target, "modules"));
|
||||
subdirectories.add(new RemoteFile(target, "tests"));
|
||||
//-------------------------------------
|
||||
sftpChannel.mkdir(target);
|
||||
sftpChannel.cd(target);
|
||||
sftpChannel.mkdir(projects);
|
||||
sftpChannel.mkdir(modules);
|
||||
sftpChannel.mkdir(compilers);
|
||||
sftpChannel.mkdir(tests);
|
||||
//------------------------------------
|
||||
sftpChannel.cd(modules);
|
||||
ShowMessage1("Закачка модулей...");
|
||||
put_resource(launcher_code);
|
||||
put_resource(starter_code);
|
||||
put_resource(Process_r_header);
|
||||
for (RemoteFile remoteFile : subdirectories)
|
||||
user.connection.sftpChannel.mkdir(remoteFile.full_name);
|
||||
//----------------------------------
|
||||
String [] planner_files = new String[]{
|
||||
"Array.h",
|
||||
|
||||
"CompilationSupervisor.h",
|
||||
"CompilationTask.h",
|
||||
|
||||
"File.h",
|
||||
"Global.h",
|
||||
|
||||
"Planner.cpp",
|
||||
|
||||
"RunSupervisor.h",
|
||||
"RunTask.h",
|
||||
|
||||
"String.h",
|
||||
"Supervisor.h",
|
||||
|
||||
"Task.h",
|
||||
"Text.h",
|
||||
"Utils.h"
|
||||
String[] resourses_names = new String[]{
|
||||
//--
|
||||
"Process_r.h",
|
||||
"starter.cpp",
|
||||
"launcher.cpp",
|
||||
//--
|
||||
"Array.h",
|
||||
"CompilationSupervisor.h",
|
||||
"CompilationTask.h",
|
||||
"File.h",
|
||||
"Global.h",
|
||||
"Planner.cpp",
|
||||
"RunSupervisor.h",
|
||||
"RunTask.h",
|
||||
"String.h",
|
||||
"Supervisor.h",
|
||||
"Task.h",
|
||||
"Text.h",
|
||||
"Utils.h"
|
||||
};
|
||||
for (String p: planner_files){
|
||||
File local_p = Utils.getTempFileName(p);
|
||||
URL u = Utils.class.getResource("/files/Planner/" + p);
|
||||
InputStream i = u.openStream();
|
||||
Files.copy(i, local_p.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
putSingleFile(local_p.getAbsolutePath(), p);
|
||||
ShowMessage1("Закачка модулей...");
|
||||
for (String resource_name : resourses_names) {
|
||||
ShowMessage2(resource_name);
|
||||
File src = Utils.CreateTempResourceFile(resource_name);
|
||||
RemoteFile dst = new RemoteFile(modulesDirectory, resource_name);
|
||||
user.connection.putSingleFile(src, dst);
|
||||
}
|
||||
//-------------------------------------
|
||||
ShowMessage1("Сборка модулей...");
|
||||
String [] modules_names = new String[]{
|
||||
"launcher",
|
||||
"starter",
|
||||
"planner"
|
||||
};
|
||||
for (String module_name: modules_names){
|
||||
ShowMessage2(module_name);
|
||||
compileModule(module_name);
|
||||
}
|
||||
/*
|
||||
|
||||
//канал на исполнение независим, поэтому переход в папку отдельный
|
||||
Command(
|
||||
"cd " + Utils.DQuotes(sftpChannel.pwd()), //нужны ли тут кавычки?
|
||||
@@ -74,8 +101,9 @@ public class RemoteInitialiseUser extends CurrentConnectionPass<String> {
|
||||
"chmod 0777 " + launcher,
|
||||
"chmod 0777 " + planner
|
||||
);
|
||||
*/
|
||||
//--------------------------------------
|
||||
RemoteFile info = new RemoteFile(target, Current.getAccount().email);
|
||||
writeToFile("", info);
|
||||
user.connection.writeToFile("", info);
|
||||
}
|
||||
}
|
||||
|
||||
34
src/Visual_DVM_2021/Passes/SSH/ConnectionPass_2023.java
Normal file
34
src/Visual_DVM_2021/Passes/SSH/ConnectionPass_2023.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package Visual_DVM_2021.Passes.SSH;
|
||||
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> {
|
||||
protected Machine machine = null;
|
||||
protected User user = null;
|
||||
//--
|
||||
protected void Connect() throws Exception{
|
||||
user.connection = null;
|
||||
user.connection = new UserConnection(machine, user);
|
||||
System.out.println("Соединение c " + machine.getURL() + " " + user.login + " успешно установлено.");
|
||||
}
|
||||
void Disconnect(){
|
||||
if (user.connection!=null){
|
||||
user.connection.Disconnect();
|
||||
user.connection = null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void body() throws Exception {
|
||||
Connect();
|
||||
ServerAction();
|
||||
}
|
||||
@Override
|
||||
protected void performFinish() throws Exception {
|
||||
Disconnect();
|
||||
}
|
||||
//--
|
||||
protected void ServerAction() throws Exception{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package Visual_DVM_2021.Passes.SSH;
|
||||
import Common.Current;
|
||||
import files.ConnectionPass;
|
||||
//завязан на текущие машину и юзера
|
||||
public abstract class CurrentConnectionPass<T> extends ConnectionPass<T> {
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package Visual_DVM_2021.Passes.SSH;
|
||||
import Common.Current;
|
||||
import Common.Global;
|
||||
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) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package Visual_DVM_2021.Passes.SSH;
|
||||
package files;
|
||||
import Common.Constants;
|
||||
import Common.Utils.Utils;
|
||||
import Common.Utils.Validators.ShellParser;
|
||||
@@ -8,6 +8,7 @@ import GlobalData.User.User;
|
||||
import ProjectData.Project.db_project_info;
|
||||
import Visual_DVM_2021.Passes.PassException;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
import Visual_DVM_2021.Passes.SSH.WorkspaceNotFoundException;
|
||||
import com.jcraft.jsch.*;
|
||||
import javafx.util.Pair;
|
||||
|
||||
@@ -25,6 +26,7 @@ import java.util.Vector;
|
||||
//http://www.jcraft.com/jsch/
|
||||
//http://developer-remarks.blogspot.com/2013/05/ssh-via-jsch-example.html
|
||||
//https://stackoverflow.com/questions/4194439/sending-commands-to-server-via-jsch-shell-channel
|
||||
//todo вывести его. уже есть UserConnection.
|
||||
public abstract class ConnectionPass<T> extends Pass_2021<T> {
|
||||
//-----------------------------------------------
|
||||
public static final String modules = "modules";
|
||||
Reference in New Issue
Block a user