Files
VisualSapfor/src/Visual_DVM_2021/Passes/SSH/TestingServerSSHPass.java

85 lines
3.1 KiB
Java
Raw Normal View History

package Visual_DVM_2021.Passes.SSH;
import Common.Constants;
import Common.Current;
import Common.Global;
import Common.Utils.Utils;
import GlobalData.Machine.Machine;
import GlobalData.Machine.MachineType;
import GlobalData.RemoteFile.RemoteFile;
import GlobalData.User.User;
import java.util.Date;
public class TestingServerSSHPass extends ConnectionPass {
2024-03-24 02:49:32 +03:00
@Override
public String getButtonText() {
return "";
}
//--
protected RemoteFile userHome;
protected RemoteFile testingHome;
@Override
protected boolean needsAnimation() {
return true;
}
@Override
public void Connect() throws Exception {
2024-03-24 02:49:32 +03:00
userHome = null;
testingHome = null;
//--
2024-03-24 02:49:32 +03:00
machine = new Machine("alex", Global.properties.ServerAddress, Global.properties.ServerUserSHHPort, MachineType.Server);
user = new User(Global.properties.ServerUserName, "mprit_2011");
super.Connect();
//--
userHome = new RemoteFile(user.connection.sftpChannel.getHome(), true);
testingHome = new RemoteFile(userHome, Constants.testingSystemHomeName);
//-
2024-03-24 02:49:32 +03:00
System.out.println("userHome=" + Utils.Brackets(userHome.full_name));
System.out.println("testingHome=" + Utils.Brackets(testingHome.full_name));
}
//--
2024-03-24 02:49:32 +03:00
protected void StartServer() throws Exception {
user.connection.performScript(testingHome, "nohup java -jar TestingSystem.jar &");
RemoteFile StartLog = new RemoteFile(testingHome, Constants.STARTED +
"_by_" +
Current.getAccount().email +
"_" +
new Date().toString()
);
user.connection.writeToFile("+", StartLog);
//--
RemoteFile[] files = new RemoteFile[]{
new RemoteFile(testingHome, Constants.script),
new RemoteFile(testingHome, Constants.out_file),
new RemoteFile(testingHome, Constants.err_file)
};
//-
for (RemoteFile file : files) {
user.connection.tryRM(file);
}
}
protected void ShutdownServer() throws Exception {
//--
2024-03-24 02:49:32 +03:00
RemoteFile INTERRUPT = new RemoteFile(testingHome, Constants.INTERRUPT);
RemoteFile ABORTED = new RemoteFile(testingHome, Constants.ABORTED);
//--
ShowMessage1("Создание файла INTERRUPT..");
user.connection.writeToFile("+", INTERRUPT);
ShowMessage1("Ожидание остановки сервера тестирования");
do {
Utils.sleep(1000);
ShowMessage2("Проверка признака остановки..");
} while (!user.connection.Exists(ABORTED));
//--
ShowMessage2("");
ShowMessage1("Журнализация");
2024-03-24 02:49:32 +03:00
RemoteFile AbortLog = new RemoteFile(testingHome, Constants.ABORTED +
"_by_" +
Current.getAccount().email +
"_" +
new Date().toString()
);
user.connection.sftpChannel.rename(ABORTED.full_name, AbortLog.full_name);
System.out.println("Done");
}
}