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