2024-10-09 22:21:57 +03:00
|
|
|
package _VisualDVM.TestingSystem.Common;
|
2024-10-07 14:22:52 +03:00
|
|
|
import Common.CommonConstants;
|
2024-10-14 15:19:13 +03:00
|
|
|
import Common.Utils.Loggable;
|
2024-10-11 00:00:30 +03:00
|
|
|
import Common.Utils.Utils_;
|
2024-10-07 00:58:29 +03:00
|
|
|
import _VisualDVM.Global;
|
2024-10-09 22:21:57 +03:00
|
|
|
import _VisualDVM.GlobalData.Machine.Machine;
|
|
|
|
|
import _VisualDVM.GlobalData.Machine.MachineType;
|
|
|
|
|
import _VisualDVM.GlobalData.User.User;
|
|
|
|
|
import _VisualDVM.Repository.EmailMessage;
|
2024-10-14 15:19:13 +03:00
|
|
|
import _VisualDVM.Repository.RepositoryClient;
|
2024-10-09 22:21:57 +03:00
|
|
|
import _VisualDVM.Repository.Server.ServerCode;
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.TestingPackage.TestingPackage;
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.TestingPackageToKill.TestingPackageToKill;
|
2024-10-14 15:19:13 +03:00
|
|
|
import _VisualDVM.Utils;
|
2024-03-25 00:12:24 +03:00
|
|
|
import javafx.util.Pair;
|
2024-04-27 18:44:36 +03:00
|
|
|
import org.apache.commons.io.FileUtils;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
2024-04-27 18:44:36 +03:00
|
|
|
import java.io.File;
|
2023-09-17 22:13:42 +03:00
|
|
|
import java.util.Date;
|
2024-03-21 19:02:08 +03:00
|
|
|
import java.util.Vector;
|
2024-04-26 17:57:58 +03:00
|
|
|
public abstract class TestingPlanner<P extends TestingPackage> extends RepositoryClient {
|
2023-12-14 02:30:56 +03:00
|
|
|
protected P testingPackage;
|
2024-04-27 18:44:36 +03:00
|
|
|
protected File packageLocalWorkspace = null;
|
|
|
|
|
protected String serverName = "";
|
|
|
|
|
protected File supervisorHome = null;
|
|
|
|
|
protected Machine machine = null;
|
|
|
|
|
protected User user = null;
|
2024-10-14 15:19:13 +03:00
|
|
|
//---
|
|
|
|
|
public TestingPlanner() {
|
|
|
|
|
}
|
|
|
|
|
public TestingPlanner(String... args) {
|
|
|
|
|
//---
|
|
|
|
|
String machineAddress = args[0];
|
|
|
|
|
int machinePort = Integer.parseInt(args[1]);
|
|
|
|
|
String userName = args[2];
|
|
|
|
|
String userPassword = args[3];
|
|
|
|
|
String userWorkspace = args[4];
|
|
|
|
|
String testingSystemRoot = args[5];
|
|
|
|
|
serverName = args[6];
|
|
|
|
|
supervisorHome = Utils_.getHomeDirectory(); //при инициализации это текущая папка.
|
|
|
|
|
//---
|
|
|
|
|
Utils_.MainLog = new Loggable() {
|
|
|
|
|
@Override
|
|
|
|
|
public String getLogHomePath() {
|
|
|
|
|
return supervisorHome.getAbsolutePath();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public String getLogName() {
|
|
|
|
|
return Global.mode.toString();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Utils_.MainLog.ClearLog();
|
|
|
|
|
//--
|
|
|
|
|
Utils_.setHomePath(testingSystemRoot);
|
|
|
|
|
Global.CheckTestingSystemDirectories();
|
|
|
|
|
//---
|
|
|
|
|
machine = new Machine(machineAddress, machineAddress, machinePort, MachineType.Server);
|
|
|
|
|
user = new User(userName, userPassword, userWorkspace);
|
|
|
|
|
//---
|
|
|
|
|
Print("machineAddress=" + Utils_.Brackets(machineAddress));
|
|
|
|
|
Print("machinePort=" + Utils_.Brackets(String.valueOf(machinePort)));
|
|
|
|
|
Print("userName=" + Utils_.Brackets(userName));
|
|
|
|
|
Print("userPassword=" + Utils_.Brackets(userPassword));
|
|
|
|
|
Print("userWorkspace=" + Utils_.Brackets(userWorkspace));
|
|
|
|
|
Print("root=" + Utils_.Brackets(Utils_.getHomePath()));
|
|
|
|
|
Print("serverName=" + serverName);
|
|
|
|
|
Print("=====");
|
|
|
|
|
//----
|
2024-10-16 00:40:45 +03:00
|
|
|
Utils.createEmptyFile(CommonConstants.STARTED);
|
2024-10-14 15:19:13 +03:00
|
|
|
}
|
2024-04-27 18:44:36 +03:00
|
|
|
//----
|
2024-09-25 01:27:02 +03:00
|
|
|
protected void UpdatePackageState(TasksPackageState state_in) throws Exception {
|
2023-12-14 02:30:56 +03:00
|
|
|
testingPackage.state = state_in;
|
|
|
|
|
testingPackage.ChangeDate = new Date().getTime();
|
|
|
|
|
ServerCommand(ServerCode.EditObject, testingPackage);
|
2023-12-24 01:36:52 +03:00
|
|
|
switch (testingPackage.state) {
|
|
|
|
|
case Done:
|
2024-09-25 01:27:02 +03:00
|
|
|
case DoneWithErrors:
|
2023-12-24 01:36:52 +03:00
|
|
|
case Aborted:
|
|
|
|
|
case CompilationExecution:
|
|
|
|
|
case RunningExecution:
|
|
|
|
|
EmailPackage();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-12-14 02:30:56 +03:00
|
|
|
}
|
2024-10-03 16:21:11 +03:00
|
|
|
protected void UpdatePackageState() throws Exception {
|
|
|
|
|
testingPackage.ChangeDate = new Date().getTime();
|
|
|
|
|
ServerCommand(ServerCode.EditObject, testingPackage);
|
|
|
|
|
switch (testingPackage.state) {
|
|
|
|
|
case Done:
|
|
|
|
|
case DoneWithErrors:
|
|
|
|
|
case Aborted:
|
|
|
|
|
case CompilationExecution:
|
|
|
|
|
case RunningExecution:
|
|
|
|
|
EmailPackage();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-14 02:30:56 +03:00
|
|
|
void UpdatePackage() throws Exception {
|
|
|
|
|
testingPackage.ChangeDate = new Date().getTime();
|
|
|
|
|
ServerCommand(ServerCode.EditObject, testingPackage);
|
|
|
|
|
}
|
2024-10-03 16:21:11 +03:00
|
|
|
public abstract String packageDescription();
|
2023-12-14 02:30:56 +03:00
|
|
|
void EmailPackage() throws Exception {
|
2023-12-21 18:16:14 +03:00
|
|
|
if (testingPackage.needsEmail == 1) {
|
|
|
|
|
EmailMessage message = new EmailMessage();
|
2024-10-14 15:19:13 +03:00
|
|
|
message.subject = "Состояние пакета тестирования " + packageDescription() + " " +
|
|
|
|
|
Utils_.Brackets(testingPackage.id) + " изменилось на " + Utils_.Brackets(testingPackage.state.getDescription());
|
2023-12-21 18:16:14 +03:00
|
|
|
message.text = testingPackage.description;
|
|
|
|
|
message.targets.add(testingPackage.sender_address);
|
|
|
|
|
ServerCommand(ServerCode.Email, message);
|
|
|
|
|
}
|
2023-12-14 02:30:56 +03:00
|
|
|
}
|
|
|
|
|
//---
|
2024-03-21 19:02:08 +03:00
|
|
|
protected abstract ServerCode getActivePackagesCode();
|
2023-12-14 02:30:56 +03:00
|
|
|
protected abstract ServerCode getCheckIfNeedsKillCode();
|
|
|
|
|
protected abstract TasksPackageState getStateAfterStart();
|
|
|
|
|
protected void InitSessionCredentials() {
|
|
|
|
|
}
|
2023-12-14 18:45:41 +03:00
|
|
|
protected abstract void TestsSynchronize() throws Exception;
|
2024-10-14 15:19:13 +03:00
|
|
|
;
|
2023-12-14 18:45:41 +03:00
|
|
|
protected abstract void PackageWorkspaceCreation() throws Exception;
|
2024-09-25 01:27:02 +03:00
|
|
|
protected void AnalyseResults() throws Exception {
|
|
|
|
|
UpdatePackageState(TasksPackageState.Done);
|
2024-10-14 15:19:13 +03:00
|
|
|
}
|
2023-12-14 18:45:41 +03:00
|
|
|
protected abstract void PackageStart() throws Exception;
|
|
|
|
|
protected abstract boolean CheckNextState() throws Exception;
|
|
|
|
|
protected abstract void DownloadResults() throws Exception;
|
|
|
|
|
protected abstract void Kill() throws Exception;
|
2023-12-14 02:30:56 +03:00
|
|
|
protected boolean Connect() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
protected void Disconnect() {
|
|
|
|
|
}
|
2024-04-24 22:23:50 +03:00
|
|
|
protected void MachineConnectionError() {
|
2024-04-21 00:01:17 +03:00
|
|
|
}
|
2024-04-24 22:23:50 +03:00
|
|
|
protected void PerformPackage(TestingPackage package_in) throws Exception {
|
2024-03-21 19:02:08 +03:00
|
|
|
testingPackage = (P) package_in;
|
|
|
|
|
//--
|
|
|
|
|
Print(testingPackage.id + ":" + testingPackage.state.getDescription());
|
|
|
|
|
//--
|
2024-04-24 22:23:50 +03:00
|
|
|
if (testingPackage.connectionErrosCount >= 10) {
|
|
|
|
|
Print(testingPackage.id + " had 10 connection errors. stop");
|
2024-04-08 01:30:46 +03:00
|
|
|
UpdatePackageState(TasksPackageState.ConnectionError);
|
2024-04-21 00:01:17 +03:00
|
|
|
MachineConnectionError();
|
2024-04-24 22:23:50 +03:00
|
|
|
} else {
|
2024-04-08 01:30:46 +03:00
|
|
|
//--
|
|
|
|
|
InitSessionCredentials();
|
|
|
|
|
if (testingPackage.state.equals(TasksPackageState.Analysis)) {
|
2024-09-25 01:27:02 +03:00
|
|
|
AnalyseResults(); //todo ввести состояние DoneWithErrors
|
2024-04-08 01:30:46 +03:00
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
if (Connect()) {
|
|
|
|
|
int ptk_id = (int) ServerCommand(getCheckIfNeedsKillCode(), testingPackage.id);
|
2024-10-07 14:22:52 +03:00
|
|
|
if (ptk_id != CommonConstants.Nan) {
|
2024-04-08 01:30:46 +03:00
|
|
|
Print("package " + testingPackage.id + " NEEDS TO KILL");
|
|
|
|
|
Kill();
|
|
|
|
|
UpdatePackageState(TasksPackageState.Aborted);
|
|
|
|
|
ServerCommand(ServerCode.DeleteObjectByPK, new Pair(TestingPackageToKill.class, ptk_id));
|
|
|
|
|
} else {
|
2024-04-21 00:01:17 +03:00
|
|
|
//--
|
2024-10-14 15:19:13 +03:00
|
|
|
System.out.println(testingPackage.id + ":" + testingPackage.state.getDescription());
|
2024-04-21 00:01:17 +03:00
|
|
|
switch (testingPackage.state) {
|
|
|
|
|
case TestsSynchronize:
|
|
|
|
|
TestsSynchronize();
|
|
|
|
|
UpdatePackageState(TasksPackageState.PackageWorkspaceCreation);
|
|
|
|
|
break;
|
|
|
|
|
case PackageWorkspaceCreation:
|
|
|
|
|
PackageWorkspaceCreation();
|
|
|
|
|
UpdatePackageState(TasksPackageState.PackageStart);
|
|
|
|
|
break;
|
|
|
|
|
case PackageStart:
|
|
|
|
|
PackageStart();
|
|
|
|
|
testingPackage.StartDate = new Date().getTime();
|
|
|
|
|
UpdatePackageState(getStateAfterStart());
|
|
|
|
|
break;
|
|
|
|
|
case RunningEnd:
|
|
|
|
|
DownloadResults();
|
|
|
|
|
UpdatePackageState(TasksPackageState.Analysis);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (CheckNextState()) UpdatePackage();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//--
|
2024-04-08 01:30:46 +03:00
|
|
|
}
|
2024-03-21 19:02:08 +03:00
|
|
|
} else {
|
2024-04-08 01:30:46 +03:00
|
|
|
testingPackage.connectionErrosCount++;
|
|
|
|
|
UpdatePackage();
|
2023-09-17 22:13:42 +03:00
|
|
|
}
|
2024-04-08 01:30:46 +03:00
|
|
|
} catch (Exception ex) {
|
|
|
|
|
Print("Ошибка сеанса. Соединение будет разорвано.");
|
2024-04-15 22:09:10 +03:00
|
|
|
ex.printStackTrace();
|
2024-04-08 01:30:46 +03:00
|
|
|
Print(ex.getMessage());
|
|
|
|
|
//
|
|
|
|
|
testingPackage.connectionErrosCount++;
|
|
|
|
|
UpdatePackage();
|
|
|
|
|
} finally {
|
2024-04-10 00:29:36 +03:00
|
|
|
Disconnect();
|
2023-09-17 22:13:42 +03:00
|
|
|
}
|
|
|
|
|
}
|
2024-03-21 19:02:08 +03:00
|
|
|
}
|
|
|
|
|
//--
|
|
|
|
|
testingPackage.destructor();
|
|
|
|
|
testingPackage = null;
|
|
|
|
|
System.gc();
|
|
|
|
|
//--
|
|
|
|
|
}
|
2024-04-26 17:57:58 +03:00
|
|
|
@Override
|
|
|
|
|
public void perform() throws Exception {
|
|
|
|
|
testingPackage = null;
|
|
|
|
|
Vector<P> activePackages = (Vector<P>) ServerCommand(getActivePackagesCode());
|
|
|
|
|
for (P activePackage : activePackages)
|
|
|
|
|
PerformPackage(activePackage);
|
2023-09-17 22:13:42 +03:00
|
|
|
}
|
2024-04-27 18:44:36 +03:00
|
|
|
protected void Finalize(String reason) {
|
|
|
|
|
Print(reason);
|
2024-10-16 00:40:45 +03:00
|
|
|
File stateFile = new File(supervisorHome, CommonConstants.ABORTED);
|
2024-04-27 18:44:36 +03:00
|
|
|
try {
|
|
|
|
|
FileUtils.writeStringToFile(stateFile, reason);
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
//---------------------------------------------
|
|
|
|
|
public String getPlanner() {
|
|
|
|
|
return String.join("/", user.workspace, "modules", "planner");
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
void CheckLocal() {
|
|
|
|
|
local = false;
|
|
|
|
|
try {
|
|
|
|
|
InetAddress address = InetAddress.getByName(machine.address);
|
|
|
|
|
InetAddress localAddress = InetAddress.getByName("alex-freenas.ddns.net");
|
|
|
|
|
Print("machine ip=" + Utils.Brackets(address.getHostAddress()));
|
|
|
|
|
Print("server ip=" + Utils.Brackets(localAddress.getHostAddress()));
|
|
|
|
|
local = localAddress.getHostAddress().equals(address.getHostAddress());
|
|
|
|
|
//todo в этом случае отдельный режим без ssh
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
Global.Log.PrintException(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
2023-09-17 22:13:42 +03:00
|
|
|
}
|