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.Database.Objects.DBObject;
|
2025-02-05 01:14:41 +03:00
|
|
|
|
import Common.Database.Objects.riDBObject;
|
2024-10-17 17:22:33 +03:00
|
|
|
|
import Common.Database.RepositoryRefuseException;
|
2024-10-14 15:19:13 +03:00
|
|
|
|
import Common.Utils.TextLog;
|
2024-10-11 00:00:30 +03:00
|
|
|
|
import Common.Utils.Utils_;
|
2025-02-11 21:28:35 +03:00
|
|
|
|
import Common.Utils.Vector_;
|
2025-02-18 16:21:20 +03:00
|
|
|
|
import _VisualDVM.ComponentsServer.Component.Sapfor.Sapfor;
|
2025-02-18 20:14:14 +03:00
|
|
|
|
import _VisualDVM.ComponentsServer.UserAccount.AccountRole;
|
|
|
|
|
|
import _VisualDVM.ComponentsServer.UserAccount.UserAccount;
|
2024-10-09 22:01:19 +03:00
|
|
|
|
import _VisualDVM.Constants;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
import _VisualDVM.Global;
|
2025-02-13 23:07:18 +03:00
|
|
|
|
import _VisualDVM.GlobalData.Tasks.TaskState;
|
2024-10-14 15:19:13 +03:00
|
|
|
|
import _VisualDVM.Passes.All.DownloadRepository;
|
|
|
|
|
|
import _VisualDVM.Passes.All.ZipFolderPass;
|
|
|
|
|
|
import _VisualDVM.Passes.PassCode;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.ProjectData.LanguageName;
|
|
|
|
|
|
import _VisualDVM.Repository.EmailMessage;
|
2025-02-18 16:21:20 +03:00
|
|
|
|
import _VisualDVM.Repository.Server.RepositoryServer;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.Repository.Server.ServerCode;
|
|
|
|
|
|
import _VisualDVM.Repository.Server.ServerExchangeUnit_2021;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Group.Group;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.MachineProcess.MachineProcess;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.MachineProcess.MachineProcessSet;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Test.Test;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.Test.TestType;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.Common.TestingPackageToKill.TestingPackageToKill;
|
2024-11-15 00:44:23 +03:00
|
|
|
|
import _VisualDVM.TestingSystem.DVM.DVMConfiguration.DVMConfiguration;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage;
|
2024-11-15 02:08:42 +03:00
|
|
|
|
import _VisualDVM.TestingSystem.DVM.DVMSettings.DVMSettings;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.TestingSystem.DVM.DVMTestingChecker;
|
2025-02-21 01:57:15 +03:00
|
|
|
|
import _VisualDVM.TestingSystem.DVM.PackageCredentials.DVMPackageCredentials;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforPackage_json;
|
2025-02-11 21:28:35 +03:00
|
|
|
|
import _VisualDVM.TestingSystem.SAPFOR.Json.SapforVersion_json;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.SAPFOR.SapforPackage.SapforPackage;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.SAPFOR.SapforSettings.SapforSettings;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.SAPFOR.SapforSettingsCommand.SapforSettingsCommand;
|
2025-02-11 21:28:35 +03:00
|
|
|
|
import _VisualDVM.TestingSystem.SAPFOR.SapforTask.SapforTask;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.TestingSystem.SAPFOR.SapforTestingPlanner;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
|
|
|
|
|
|
import _VisualDVM.TestingSystem.SAPFOR.ServerSapfor.ServerSapforState;
|
2024-10-14 15:19:13 +03:00
|
|
|
|
import _VisualDVM.Utils;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import javafx.util.Pair;
|
2023-11-19 00:25:37 +03:00
|
|
|
|
import org.apache.commons.io.FileUtils;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
|
2024-05-21 17:36:03 +03:00
|
|
|
|
import javax.swing.*;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import java.io.File;
|
|
|
|
|
|
import java.nio.file.Paths;
|
2024-05-21 17:36:03 +03:00
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
|
import java.util.Vector;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
public class TestingServer extends RepositoryServer<TestsDatabase> {
|
2024-05-05 23:20:12 +03:00
|
|
|
|
public static MachineProcessSet machinesProcesses = new MachineProcessSet();
|
2024-10-14 15:19:13 +03:00
|
|
|
|
//------>>>
|
|
|
|
|
|
public static Timer checkTimer = null;
|
|
|
|
|
|
public String name = "?";
|
|
|
|
|
|
DVMTestingChecker dvmTestingChecker = new DVMTestingChecker();
|
|
|
|
|
|
SapforTestingPlanner sapforTestingPlanner = new SapforTestingPlanner();
|
2025-02-21 01:57:15 +03:00
|
|
|
|
//-->
|
|
|
|
|
|
MachinesDatabase machines_db;
|
|
|
|
|
|
//-->
|
2024-10-14 15:19:13 +03:00
|
|
|
|
protected Thread testingThread = new Thread(() -> {
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
dvmTestingChecker.Perform();
|
|
|
|
|
|
sapforTestingPlanner.Perform();
|
|
|
|
|
|
Utils_.sleep(5000);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
public TestingServer() {
|
|
|
|
|
|
super(TestsDatabase.class);
|
|
|
|
|
|
name = Utils_.getDateName("testingServer");
|
|
|
|
|
|
}
|
2025-02-21 01:57:15 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
public void StartAction() throws Exception {
|
|
|
|
|
|
try {
|
|
|
|
|
|
machines_db = new MachinesDatabase();
|
|
|
|
|
|
machines_db.Activate();
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-10-14 15:19:13 +03:00
|
|
|
|
public static void TimerOn() {
|
2025-01-18 01:36:02 +03:00
|
|
|
|
checkTimer = new Timer(Global.normalProperties.CheckTestingIntervalSeconds * 1000, e -> {
|
2024-10-14 15:19:13 +03:00
|
|
|
|
Global.mainModule.getPass(PassCode.ActualizePackages).Do();
|
|
|
|
|
|
});
|
|
|
|
|
|
checkTimer.start();
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void TimerOff() {
|
|
|
|
|
|
if (checkTimer != null)
|
|
|
|
|
|
checkTimer.stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void ResetTimer() {
|
|
|
|
|
|
TimerOff();
|
|
|
|
|
|
TimerOn();
|
|
|
|
|
|
}
|
2023-12-16 03:57:01 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
public void afterPublishAction(DBObject object) throws Exception {
|
2023-12-16 16:52:17 +03:00
|
|
|
|
if (object instanceof Test) {
|
2023-12-16 03:57:01 +03:00
|
|
|
|
Test test = (Test) object;
|
|
|
|
|
|
if (!test.unpackProjectOnServer()) {
|
|
|
|
|
|
db.Delete(test);
|
|
|
|
|
|
throw new RepositoryRefuseException(
|
|
|
|
|
|
"Не удалось прикрепить проект к тесту с id " + test.id
|
|
|
|
|
|
+ "\nТест будет удален"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2024-09-25 01:27:02 +03:00
|
|
|
|
} else if (object instanceof DVMPackage) {
|
2023-12-16 03:57:01 +03:00
|
|
|
|
DVMPackage dvmPackage = (DVMPackage) object;
|
|
|
|
|
|
//--
|
2024-10-14 12:54:52 +03:00
|
|
|
|
Utils_.CheckAndCleanDirectory(dvmPackage.getLocalWorkspace());
|
2023-12-16 03:57:01 +03:00
|
|
|
|
//--
|
|
|
|
|
|
dvmPackage.saveJson();
|
|
|
|
|
|
dvmPackage.package_json = null; // объект больше не нужен.
|
2024-04-26 20:28:50 +03:00
|
|
|
|
//--
|
2025-02-21 01:57:15 +03:00
|
|
|
|
//Занести учетные данные пакета в базу о машинах. это основной поток, нить не нужна. арг это пароль
|
|
|
|
|
|
DVMPackageCredentials credentials = new DVMPackageCredentials(dvmPackage, request.arg);
|
|
|
|
|
|
machines_db.Insert(credentials);
|
|
|
|
|
|
//--
|
2024-09-25 01:27:02 +03:00
|
|
|
|
} else if (object instanceof SapforPackage) {
|
2024-03-07 18:56:47 +03:00
|
|
|
|
((SapforPackage) object).init();
|
2023-12-16 03:57:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-09-14 00:18:27 +03:00
|
|
|
|
@Override
|
2025-02-11 21:28:35 +03:00
|
|
|
|
protected void afterCloneAction(riDBObject src, riDBObject dst) throws Exception {
|
|
|
|
|
|
if (src instanceof SapforSettings) {
|
2025-02-05 01:14:41 +03:00
|
|
|
|
Vector<PassCode> codes = new Vector<>();
|
|
|
|
|
|
for (SapforSettingsCommand command : db.sapforSettingsCommands.Data.values())
|
|
|
|
|
|
if (command.sapforsettings_id == src.id) codes.add(command.passCode);
|
|
|
|
|
|
//--
|
|
|
|
|
|
for (PassCode code : codes) {
|
|
|
|
|
|
SapforSettingsCommand command = new SapforSettingsCommand();
|
|
|
|
|
|
command.sapforsettings_id = dst.id;
|
|
|
|
|
|
command.passCode = code;
|
|
|
|
|
|
db.Insert(command);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
2024-11-15 00:44:23 +03:00
|
|
|
|
protected void afterEditAction(DBObject object) throws Exception {
|
|
|
|
|
|
if (object instanceof Group) {
|
|
|
|
|
|
Group group = (Group) object;
|
|
|
|
|
|
//-
|
|
|
|
|
|
for (DVMConfiguration dvmConfiguration : db.dvmConfigurations.Data.values()) {
|
2024-11-15 02:08:42 +03:00
|
|
|
|
if (dvmConfiguration.tryUpdateGroup(group)) {
|
2024-11-15 00:44:23 +03:00
|
|
|
|
db.Update(dvmConfiguration);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (SapforConfiguration sapforConfiguration : db.sapforConfigurations.Data.values()) {
|
2024-11-15 02:08:42 +03:00
|
|
|
|
if (sapforConfiguration.tryUpdateGroup(group)) {
|
|
|
|
|
|
db.Update(sapforConfiguration);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-11 21:28:35 +03:00
|
|
|
|
} else if (object instanceof DVMSettings) {
|
2024-11-15 02:08:42 +03:00
|
|
|
|
DVMSettings dvmSettings = (DVMSettings) object;
|
|
|
|
|
|
//-
|
|
|
|
|
|
for (DVMConfiguration dvmConfiguration : db.dvmConfigurations.Data.values()) {
|
|
|
|
|
|
if (dvmConfiguration.tryUpdateSettings(dvmSettings)) {
|
|
|
|
|
|
db.Update(dvmConfiguration);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-11 21:28:35 +03:00
|
|
|
|
} else if (object instanceof SapforSettings) {
|
2024-11-15 02:08:42 +03:00
|
|
|
|
SapforSettings sapforSettings = (SapforSettings) object;
|
|
|
|
|
|
for (SapforConfiguration sapforConfiguration : db.sapforConfigurations.Data.values()) {
|
|
|
|
|
|
if (sapforConfiguration.tryUpdateSettings(sapforSettings)) {
|
2024-11-15 00:44:23 +03:00
|
|
|
|
db.Update(sapforConfiguration);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
2025-02-13 20:27:01 +03:00
|
|
|
|
protected void afterDeleteAction(DBObject object) throws Exception {
|
2023-12-16 03:57:01 +03:00
|
|
|
|
if (object instanceof Test) {
|
|
|
|
|
|
Test test = (Test) object;
|
2024-10-14 12:54:52 +03:00
|
|
|
|
Utils_.forceDeleteWithCheck(test.getArchive());
|
|
|
|
|
|
Utils_.forceDeleteWithCheck(test.getServerPath());
|
2024-11-16 21:10:17 +03:00
|
|
|
|
//--
|
|
|
|
|
|
for (DVMConfiguration dvmConfiguration : db.dvmConfigurations.Data.values()) {
|
|
|
|
|
|
if (dvmConfiguration.tryDeleteTest(test)) {
|
|
|
|
|
|
db.Update(dvmConfiguration);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (SapforConfiguration sapforConfiguration : db.sapforConfigurations.Data.values()) {
|
|
|
|
|
|
if (sapforConfiguration.tryDeleteTest(test)) {
|
|
|
|
|
|
db.Update(sapforConfiguration);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//--
|
2025-02-11 21:28:35 +03:00
|
|
|
|
} else if (object instanceof Group) {
|
2023-12-16 03:57:01 +03:00
|
|
|
|
Group group = (Group) object;
|
2024-11-16 21:32:27 +03:00
|
|
|
|
LinkedHashMap<Integer, Test> groupTests = db.getMapByFKi(group, Test.class);
|
2024-11-15 01:17:52 +03:00
|
|
|
|
//--
|
|
|
|
|
|
for (DVMConfiguration dvmConfiguration : db.dvmConfigurations.Data.values()) {
|
2024-11-15 02:08:42 +03:00
|
|
|
|
if (dvmConfiguration.tryDeleteGroup(group)) {
|
2024-11-16 21:32:27 +03:00
|
|
|
|
dvmConfiguration.tryDeleteTests(groupTests);
|
2024-11-15 01:17:52 +03:00
|
|
|
|
db.Update(dvmConfiguration);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (SapforConfiguration sapforConfiguration : db.sapforConfigurations.Data.values()) {
|
2024-11-15 02:08:42 +03:00
|
|
|
|
if (sapforConfiguration.tryDeleteGroup(group)) {
|
2024-11-16 21:32:27 +03:00
|
|
|
|
sapforConfiguration.tryDeleteTests(groupTests);
|
2024-11-15 01:17:52 +03:00
|
|
|
|
db.Update(sapforConfiguration);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//--
|
2024-11-16 21:32:27 +03:00
|
|
|
|
for (Test group_test : groupTests.values()) {
|
|
|
|
|
|
db.Delete(group_test);
|
|
|
|
|
|
Utils_.forceDeleteWithCheck(group_test.getArchive());
|
|
|
|
|
|
Utils_.forceDeleteWithCheck(group_test.getServerPath());
|
|
|
|
|
|
}
|
|
|
|
|
|
//--
|
2023-12-16 03:57:01 +03:00
|
|
|
|
} else if (object instanceof ServerSapfor) {
|
2024-10-14 12:54:52 +03:00
|
|
|
|
Utils_.forceDeleteWithCheck(
|
2023-12-16 03:57:01 +03:00
|
|
|
|
new File(
|
|
|
|
|
|
((ServerSapfor) object).home_path
|
|
|
|
|
|
)
|
|
|
|
|
|
);
|
2024-10-14 15:19:13 +03:00
|
|
|
|
} else if (object instanceof DVMPackage) {
|
2023-12-16 03:57:01 +03:00
|
|
|
|
DVMPackage dvmPackage = (DVMPackage) object;
|
|
|
|
|
|
File workspace = dvmPackage.getLocalWorkspace();
|
2024-10-14 12:54:52 +03:00
|
|
|
|
Utils_.forceDeleteWithCheck(workspace);
|
2025-02-21 01:57:15 +03:00
|
|
|
|
//--
|
|
|
|
|
|
DVMPackageCredentials credentials = machines_db.dvmPackagesCredentials.getForPackageId(dvmPackage.id);
|
|
|
|
|
|
if (credentials != null)
|
|
|
|
|
|
machines_db.Delete(credentials);
|
|
|
|
|
|
//--
|
2023-12-16 03:57:01 +03:00
|
|
|
|
} else if (object instanceof SapforPackage) {
|
|
|
|
|
|
SapforPackage sapforPackage = (SapforPackage) object;
|
2024-11-16 22:03:10 +03:00
|
|
|
|
//--
|
2025-02-11 21:28:35 +03:00
|
|
|
|
for (SapforConfiguration sapforConfiguration : db.sapforConfigurations.Data.values()) {
|
|
|
|
|
|
if (sapforConfiguration.ethalon_id == sapforPackage.id) {
|
|
|
|
|
|
sapforConfiguration.ethalon_id = CommonConstants.Nan;
|
2024-11-16 22:03:10 +03:00
|
|
|
|
db.Update(sapforConfiguration);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//--
|
2023-12-16 03:57:01 +03:00
|
|
|
|
File workspace = sapforPackage.getLocalWorkspace();
|
2024-10-14 12:54:52 +03:00
|
|
|
|
Utils_.forceDeleteWithCheck(workspace);
|
2024-11-15 02:08:42 +03:00
|
|
|
|
} else if (object instanceof DVMSettings) {
|
|
|
|
|
|
DVMSettings dvmSettings = (DVMSettings) object;
|
|
|
|
|
|
for (DVMConfiguration dvmConfiguration : db.dvmConfigurations.Data.values()) {
|
|
|
|
|
|
if (dvmConfiguration.tryDeleteSettings(dvmSettings)) {
|
|
|
|
|
|
db.Update(dvmConfiguration);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-09-27 22:50:47 +03:00
|
|
|
|
} else if (object instanceof SapforSettings) {
|
2024-11-15 02:08:42 +03:00
|
|
|
|
//--
|
2024-09-27 22:50:47 +03:00
|
|
|
|
SapforSettings sapforSettings = (SapforSettings) object;
|
2024-11-15 02:08:42 +03:00
|
|
|
|
for (SapforConfiguration sapforConfiguration : db.sapforConfigurations.Data.values()) {
|
|
|
|
|
|
if (sapforConfiguration.tryDeleteSettings(sapforSettings)) {
|
|
|
|
|
|
db.Update(sapforConfiguration);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//--
|
2024-09-27 22:50:47 +03:00
|
|
|
|
Vector<SapforSettingsCommand> commands = new Vector<>();
|
|
|
|
|
|
for (SapforSettingsCommand command : db.sapforSettingsCommands.Data.values()) {
|
2024-10-14 15:19:13 +03:00
|
|
|
|
if (command.sapforsettings_id == sapforSettings.id)
|
2024-09-27 22:50:47 +03:00
|
|
|
|
commands.add(command);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (SapforSettingsCommand command : commands) {
|
|
|
|
|
|
db.Delete(command);
|
|
|
|
|
|
}
|
2023-12-16 03:57:01 +03:00
|
|
|
|
}
|
2024-11-15 02:08:42 +03:00
|
|
|
|
//-
|
2023-12-16 03:57:01 +03:00
|
|
|
|
}
|
2025-02-13 16:20:48 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
public String getServerHomeName() {
|
|
|
|
|
|
return "_testing_system";
|
|
|
|
|
|
}
|
2023-12-16 03:57:01 +03:00
|
|
|
|
//-->>>
|
2024-05-16 01:26:03 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
protected void beforePublishAction(DBObject object) throws Exception {
|
2024-05-21 17:36:03 +03:00
|
|
|
|
if (object instanceof ServerSapfor) {
|
|
|
|
|
|
int current_version = getSapforActualVersion();
|
2024-05-16 01:26:03 +03:00
|
|
|
|
int max_installed_version = db.getInstalledSapforMaxVersion();
|
2024-05-21 17:36:03 +03:00
|
|
|
|
if (max_installed_version == current_version)
|
|
|
|
|
|
throw new RepositoryRefuseException("Актуальная версия SAPFOR " + max_installed_version + " уже установлена");
|
2024-05-16 01:26:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-09-17 22:13:42 +03:00
|
|
|
|
@Override
|
|
|
|
|
|
public int getPort() {
|
2025-02-11 21:28:35 +03:00
|
|
|
|
return Constants.TestingServerPort;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
2023-10-03 15:07:17 +03:00
|
|
|
|
protected void startAdditionalThreads() {
|
2023-12-16 16:52:17 +03:00
|
|
|
|
testingThread.start();
|
2023-10-03 15:07:17 +03:00
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void PerformAutoSapforTesting() throws Exception {
|
|
|
|
|
|
TextLog Log = new TextLog();
|
|
|
|
|
|
SapforPackage autoPackage = tryAutoSapforTesting(Log);
|
|
|
|
|
|
EmailMessage message = Log.isEmpty() ?
|
|
|
|
|
|
new EmailMessage(
|
|
|
|
|
|
"Запущено автоматическое тестирование версии " + request.arg + " системы SAPFOR",
|
|
|
|
|
|
"Пакет " + Utils_.Brackets(autoPackage.id)) :
|
|
|
|
|
|
new EmailMessage(
|
|
|
|
|
|
"Не удалось запустить автоматическое тестирование версии " + request.arg + " системы SAPFOR",
|
|
|
|
|
|
Log.toString()
|
|
|
|
|
|
);
|
|
|
|
|
|
for (String address : Constants.admins_mails) {
|
|
|
|
|
|
Email(message, address);
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void DownloadTest() throws Exception {
|
|
|
|
|
|
int test_id = Integer.parseInt(request.arg);
|
|
|
|
|
|
if (db.tests.containsKey(test_id)) {
|
|
|
|
|
|
Test test = db.tests.get(test_id);
|
|
|
|
|
|
response = new ServerExchangeUnit_2021(ServerCode.OK, "", Utils_.fileToBytes(test.getArchive()));
|
|
|
|
|
|
} else
|
|
|
|
|
|
throw new RepositoryRefuseException("Теста с именем " + request.arg + " не существует");
|
|
|
|
|
|
}
|
|
|
|
|
|
void ReceiveTestsDatabase() throws Exception {
|
|
|
|
|
|
response.object = Utils_.fileToBytes(db.getFile());
|
|
|
|
|
|
}
|
2023-11-23 01:00:08 +03:00
|
|
|
|
Pair<Group, Vector<File>> ConvertDirectoryToGroup(File src, LanguageName languageName, TestType
|
2025-02-18 20:14:14 +03:00
|
|
|
|
testType, UserAccount account) throws Exception {
|
2023-11-19 00:25:37 +03:00
|
|
|
|
Group object = new Group();
|
|
|
|
|
|
Vector<File> groupFiles = null; //транспорт.
|
|
|
|
|
|
//->>
|
|
|
|
|
|
object.description = src.getName();
|
|
|
|
|
|
object.language = languageName;
|
|
|
|
|
|
object.type = testType;
|
|
|
|
|
|
object.sender_name = account.name;
|
|
|
|
|
|
object.sender_address = account.email;
|
|
|
|
|
|
//-->>
|
|
|
|
|
|
File[] files = src.listFiles(pathname ->
|
|
|
|
|
|
pathname.isFile()
|
|
|
|
|
|
&& !pathname.getName().equals("settings")
|
|
|
|
|
|
&& !pathname.getName().equals("test-analyzer.sh")
|
2024-10-11 00:00:30 +03:00
|
|
|
|
&& Utils_.getExtension(pathname).startsWith(languageName.getDVMCompile()));
|
2023-11-19 00:25:37 +03:00
|
|
|
|
if (files != null) {
|
|
|
|
|
|
groupFiles = new Vector<>(Arrays.asList(files));
|
|
|
|
|
|
groupFiles.sort(Comparator.comparing(File::getName));
|
|
|
|
|
|
}
|
|
|
|
|
|
//->>
|
|
|
|
|
|
return new Pair<>(object, groupFiles);
|
|
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void RefreshDVMTests() throws Exception {
|
2025-02-22 16:48:19 +03:00
|
|
|
|
UserAccount account = new UserAccount("server", Constants.MailAddress);
|
2025-02-15 23:30:48 +03:00
|
|
|
|
ServerSapfor serverSapfor = db.serverSapfors.getLastDoneVersion();
|
2023-11-19 00:25:37 +03:00
|
|
|
|
DownloadRepository downloadRepository = new DownloadRepository();
|
|
|
|
|
|
if (!downloadRepository.Do())
|
|
|
|
|
|
throw new RepositoryRefuseException("Не удалось обновить репозиторий");
|
|
|
|
|
|
//-->>
|
|
|
|
|
|
Vector<Pair<Group, Vector<File>>> groups = new Vector<>();
|
|
|
|
|
|
File testsSrc = Paths.get(
|
|
|
|
|
|
Global.RepoDirectory.getAbsolutePath(),
|
|
|
|
|
|
"dvm", "tools", "tester", "trunk", "test-suite").toFile();
|
|
|
|
|
|
LanguageName[] supportedLanguages = new LanguageName[]{LanguageName.fortran, LanguageName.c};
|
|
|
|
|
|
for (LanguageName languageName : supportedLanguages) {
|
|
|
|
|
|
for (TestType testType : TestType.values()) {
|
|
|
|
|
|
File groupsSrc = null;
|
|
|
|
|
|
switch (testType) {
|
|
|
|
|
|
case Correctness:
|
|
|
|
|
|
String languageSrcName = null;
|
|
|
|
|
|
switch (languageName) {
|
|
|
|
|
|
case fortran:
|
|
|
|
|
|
languageSrcName = "Fortran";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case c:
|
|
|
|
|
|
languageSrcName = "C";
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (languageSrcName != null) {
|
|
|
|
|
|
groupsSrc = Paths.get(testsSrc.getAbsolutePath(), "Correctness", languageSrcName).toFile();
|
|
|
|
|
|
File[] groupsDirs = groupsSrc.listFiles(File::isDirectory);
|
|
|
|
|
|
if (groupsDirs != null) {
|
|
|
|
|
|
for (File groupDir : groupsDirs)
|
|
|
|
|
|
groups.add(ConvertDirectoryToGroup(groupDir, languageName, testType, account));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case Performance:
|
|
|
|
|
|
File groupDir = Paths.get(testsSrc.getAbsolutePath(), "Performance").toFile();
|
|
|
|
|
|
groups.add(ConvertDirectoryToGroup(groupDir, languageName, testType, account));
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
groups.sort(Comparator.comparing(o -> o.getKey().description));
|
|
|
|
|
|
//-теперь создать тесты.
|
|
|
|
|
|
//--
|
2024-04-07 21:30:11 +03:00
|
|
|
|
for (Pair<Group, Vector<File>> p : groups)
|
2025-02-15 23:30:48 +03:00
|
|
|
|
db.RefreshGroup(account, serverSapfor, p);
|
2023-11-19 00:25:37 +03:00
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void GetFirstActiveSapforPackages() throws Exception {
|
2024-03-21 19:02:08 +03:00
|
|
|
|
response.object = db.getFirstActiveSapforPackagesCopies();
|
2023-12-16 03:57:01 +03:00
|
|
|
|
}
|
2024-05-16 01:26:03 +03:00
|
|
|
|
void GetSapforMaxVersion() throws Exception {
|
2024-05-08 01:56:17 +03:00
|
|
|
|
response.object = db.getInstalledSapforMaxVersion();
|
|
|
|
|
|
}
|
2023-12-14 23:00:50 +03:00
|
|
|
|
void UpdateActiveDVMPackages() throws Exception {
|
2023-12-15 14:55:16 +03:00
|
|
|
|
Vector<Pair<Integer, Long>> keys_pairs = (Vector<Pair<Integer, Long>>) request.object;
|
2023-12-14 23:00:50 +03:00
|
|
|
|
Vector<DVMPackage> res = new Vector<>();
|
|
|
|
|
|
//--
|
2023-12-15 14:55:16 +03:00
|
|
|
|
for (Pair<Integer, Long> p : keys_pairs) {
|
2023-12-14 23:00:50 +03:00
|
|
|
|
if (db.dvmPackages.containsKey(p.getKey())) {
|
2023-12-15 14:55:16 +03:00
|
|
|
|
DVMPackage actual = db.dvmPackages.get(p.getKey());
|
|
|
|
|
|
if (actual.ChangeDate != p.getValue())
|
|
|
|
|
|
res.add(new DVMPackage(actual));
|
2023-12-14 23:00:50 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
response.object = res;
|
|
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void UpdateActiveSapforPackages() {
|
2023-12-16 03:57:01 +03:00
|
|
|
|
Vector<Pair<Integer, Long>> keys_pairs = (Vector<Pair<Integer, Long>>) request.object;
|
|
|
|
|
|
Vector<SapforPackage> res = new Vector<>();
|
|
|
|
|
|
//--
|
|
|
|
|
|
for (Pair<Integer, Long> p : keys_pairs) {
|
|
|
|
|
|
if (db.sapforPackages.containsKey(p.getKey())) {
|
|
|
|
|
|
SapforPackage actual = db.sapforPackages.get(p.getKey());
|
|
|
|
|
|
if (actual.ChangeDate != p.getValue())
|
|
|
|
|
|
res.add(new SapforPackage(actual));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
response.object = res;
|
|
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void DVMPackageNeedsKill() {
|
2024-10-07 14:22:52 +03:00
|
|
|
|
response.object = CommonConstants.Nan;
|
2023-12-15 02:34:30 +03:00
|
|
|
|
int packageId = (int) request.object;
|
|
|
|
|
|
for (TestingPackageToKill packageToKill : db.testingPackagesToKill.Data.values()) {
|
|
|
|
|
|
if ((packageToKill.packageId == packageId) && (packageToKill.type == 0)) {
|
2023-12-18 15:44:48 +03:00
|
|
|
|
response.object = packageToKill.id;
|
2023-12-15 02:34:30 +03:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void SapforPackageNeedsKill() throws Exception {
|
2024-10-07 14:22:52 +03:00
|
|
|
|
response.object = CommonConstants.Nan;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
int packageId = (int) request.object;
|
|
|
|
|
|
for (TestingPackageToKill packageToKill : db.testingPackagesToKill.Data.values()) {
|
|
|
|
|
|
if ((packageToKill.packageId == packageId) && (packageToKill.type == 1)) {
|
2023-12-18 15:44:48 +03:00
|
|
|
|
response.object = packageToKill.id;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void DownloadDVMPackages() throws Exception {
|
2023-12-17 19:19:59 +03:00
|
|
|
|
Vector<Integer> ids = (Vector<Integer>) request.object;
|
|
|
|
|
|
Vector<Pair<Integer, Pair<byte[], byte[]>>> res = new Vector<>();
|
|
|
|
|
|
for (int dvmPackage_id : ids) {
|
|
|
|
|
|
if (!db.dvmPackages.containsKey(dvmPackage_id))
|
|
|
|
|
|
throw new RepositoryRefuseException("Не найдено пакета тестирования DVM с ключом " + dvmPackage_id);
|
|
|
|
|
|
DVMPackage dvmPackage = db.dvmPackages.get(dvmPackage_id);
|
|
|
|
|
|
File workspace = dvmPackage.getLocalWorkspace();
|
|
|
|
|
|
File results_zip = new File(workspace, "results.zip");
|
|
|
|
|
|
File package_json = dvmPackage.getJsonFile();
|
2024-10-11 00:00:30 +03:00
|
|
|
|
res.add(new Pair<>(dvmPackage_id, new Pair(Utils_.fileToBytes(results_zip), Utils_.fileToBytes(package_json))));
|
2023-12-17 19:19:59 +03:00
|
|
|
|
}
|
|
|
|
|
|
response.object = res;
|
|
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void DownloadSapforPackage() throws Exception {
|
2023-12-18 00:04:44 +03:00
|
|
|
|
int sapforPackage_id = (int) request.object;
|
|
|
|
|
|
if (!db.sapforPackages.containsKey(sapforPackage_id))
|
|
|
|
|
|
throw new RepositoryRefuseException("Не найдено пакета тестирования SAPFOR с ключом " + sapforPackage_id);
|
|
|
|
|
|
SapforPackage sapforPackage = db.sapforPackages.get(sapforPackage_id);
|
|
|
|
|
|
File workspace = sapforPackage.getLocalWorkspace();
|
|
|
|
|
|
File results_zip = Utils.getTempFileName("results");
|
|
|
|
|
|
ZipFolderPass zipFolderPass = new ZipFolderPass();
|
|
|
|
|
|
zipFolderPass.Do(workspace.getAbsolutePath(), results_zip.getAbsolutePath());
|
|
|
|
|
|
if (results_zip.exists())
|
2024-10-11 00:00:30 +03:00
|
|
|
|
response.object = Utils_.fileToBytes(results_zip);
|
2023-12-18 15:44:48 +03:00
|
|
|
|
else
|
|
|
|
|
|
throw new RepositoryRefuseException("Не удалось заархивировать пакет тестирования SAPFOR с ключом " + sapforPackage_id);
|
2023-12-18 00:04:44 +03:00
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void ReplaceTestCode() throws Exception {
|
2024-03-02 01:44:03 +03:00
|
|
|
|
Test test = (Test) request.object;
|
|
|
|
|
|
if (!test.unpackProjectOnServer()) {
|
|
|
|
|
|
db.Delete(test);
|
|
|
|
|
|
throw new RepositoryRefuseException(
|
|
|
|
|
|
"Не удалось прикрепить проект к тесту с id " + test.id
|
|
|
|
|
|
+ "\nТест будет удален"
|
|
|
|
|
|
);
|
2024-03-02 22:32:42 +03:00
|
|
|
|
} else db.Update(test); //обновить список файлов и размерность.
|
|
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void ReplaceTestsCodes() throws Exception {
|
2024-03-05 16:49:57 +03:00
|
|
|
|
Vector<Test> tests = (Vector<Test>) request.object;
|
2024-03-07 18:56:47 +03:00
|
|
|
|
for (Test test : tests) {
|
2024-03-05 16:49:57 +03:00
|
|
|
|
if (!test.unpackProjectOnServer()) {
|
|
|
|
|
|
db.Delete(test);
|
|
|
|
|
|
throw new RepositoryRefuseException(
|
|
|
|
|
|
"Не удалось прикрепить проект к тесту с id " + test.id
|
|
|
|
|
|
+ "\nТест будет удален"
|
|
|
|
|
|
);
|
|
|
|
|
|
} else db.Update(test); //обновить список файлов и размерность.
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void GetServerName() throws Exception {
|
2024-04-23 22:48:02 +03:00
|
|
|
|
response.object = name;
|
|
|
|
|
|
}
|
2024-04-15 22:09:10 +03:00
|
|
|
|
//--
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void GetFirstActiveDVMPackageForMachineURL() {
|
2024-04-15 22:09:10 +03:00
|
|
|
|
response.object = db.getFirstActiveDVMPackageCopyForMachineURL(request.arg);
|
|
|
|
|
|
}
|
2024-05-05 23:20:12 +03:00
|
|
|
|
void StartNecessaryMachines() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
Vector<String> aborted = new Vector<>();
|
|
|
|
|
|
for (MachineProcess process : machinesProcesses.Data.values()) {
|
|
|
|
|
|
if (process.isAborted()) {
|
|
|
|
|
|
aborted.add(process.id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//---
|
|
|
|
|
|
for (String key : aborted) {
|
|
|
|
|
|
machinesProcesses.Data.remove(key);
|
|
|
|
|
|
}
|
|
|
|
|
|
//---
|
|
|
|
|
|
LinkedHashMap<String, MachineProcess> processes_to_start = new LinkedHashMap<>();
|
|
|
|
|
|
//1. Получить список всех пакетов, которые активны, и взять из них машины.
|
|
|
|
|
|
for (DVMPackage dvmPackage : db.dvmPackages.Data.values()) {
|
|
|
|
|
|
if (dvmPackage.state.isActive()) {
|
|
|
|
|
|
//-
|
|
|
|
|
|
if (!machinesProcesses.hasProcessForPackage(dvmPackage)) {
|
2025-02-21 01:57:15 +03:00
|
|
|
|
DVMPackageCredentials credentials = machines_db.dvmPackagesCredentials.getForPackageId(dvmPackage.id);
|
|
|
|
|
|
if (credentials != null) {
|
|
|
|
|
|
MachineProcess new_process = new MachineProcess(dvmPackage, credentials);
|
|
|
|
|
|
//получить пароль.
|
|
|
|
|
|
processes_to_start.put(new_process.getUniqueKey(), new_process);
|
|
|
|
|
|
}
|
2024-05-05 23:20:12 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//запуск.
|
|
|
|
|
|
for (MachineProcess process : processes_to_start.values()) {
|
|
|
|
|
|
process.Start();
|
|
|
|
|
|
if (Utils.checkFileCreation(process.getStartedFile())) {
|
|
|
|
|
|
machinesProcesses.Data.put(process.id, process);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-16 01:26:03 +03:00
|
|
|
|
void GetSapforActualVersion() throws Exception {
|
2024-05-21 17:36:03 +03:00
|
|
|
|
File versionFile = new File(Global.TempDirectory, "version.h");
|
2024-05-16 01:26:03 +03:00
|
|
|
|
if (versionFile.exists())
|
|
|
|
|
|
FileUtils.forceDelete(versionFile);
|
|
|
|
|
|
//1. Получить версию из репозитория.
|
|
|
|
|
|
Utils.startScript(Global.TempDirectory,
|
|
|
|
|
|
Global.TempDirectory,
|
|
|
|
|
|
"get_version",
|
|
|
|
|
|
"wget --user dvmhuser --password dvmh2013 -P " +
|
2024-10-11 00:00:30 +03:00
|
|
|
|
Utils_.DQuotes(Global.TempDirectory.getAbsolutePath()) +
|
2024-05-16 01:26:03 +03:00
|
|
|
|
" http://svn.dvm-system.org/svn/dvmhrepo/sapfor/experts/Sapfor_2017/_src/Utils/version.h"
|
|
|
|
|
|
).waitFor();
|
|
|
|
|
|
if (!versionFile.exists())
|
|
|
|
|
|
throw new RepositoryRefuseException("Не удалось загрузить текущую версию SAPFOR из репозитория!");
|
|
|
|
|
|
int current_version = Sapfor.readVersionFromCode(versionFile);
|
|
|
|
|
|
int max_installed_version = db.getInstalledSapforMaxVersion();
|
2024-05-21 17:36:03 +03:00
|
|
|
|
if (max_installed_version == current_version)
|
|
|
|
|
|
throw new RepositoryRefuseException("Версия " + max_installed_version + " уже установлена");
|
|
|
|
|
|
}
|
|
|
|
|
|
//---
|
|
|
|
|
|
int getSapforActualVersion() throws Exception {
|
|
|
|
|
|
File versionFile = new File(Global.TempDirectory, "version.h");
|
|
|
|
|
|
if (versionFile.exists())
|
|
|
|
|
|
FileUtils.forceDelete(versionFile);
|
|
|
|
|
|
//1. Получить версию из репозитория.
|
|
|
|
|
|
Utils.startScript(Global.TempDirectory,
|
|
|
|
|
|
Global.TempDirectory,
|
|
|
|
|
|
"get_version",
|
|
|
|
|
|
"wget --user dvmhuser --password dvmh2013 -P " +
|
2024-10-11 00:00:30 +03:00
|
|
|
|
Utils_.DQuotes(Global.TempDirectory.getAbsolutePath()) +
|
2024-05-21 17:36:03 +03:00
|
|
|
|
" http://svn.dvm-system.org/svn/dvmhrepo/sapfor/experts/Sapfor_2017/_src/Utils/version.h"
|
|
|
|
|
|
).waitFor();
|
|
|
|
|
|
if (!versionFile.exists())
|
|
|
|
|
|
throw new RepositoryRefuseException("Не удалось загрузить текущую версию SAPFOR из репозитория!");
|
|
|
|
|
|
return Sapfor.readVersionFromCode(versionFile);
|
|
|
|
|
|
}
|
|
|
|
|
|
void GetSapforForCompilation() throws Exception {
|
|
|
|
|
|
//1. Проверить наличие заказов от пользователя
|
|
|
|
|
|
ServerSapfor serverSapfor = db.getSapforCopyForCompilation();
|
|
|
|
|
|
if (serverSapfor == null) {
|
|
|
|
|
|
//2 если нет. проверить есть ли свежие версии.
|
|
|
|
|
|
int max_version = db.getInstalledSapforMaxVersion();
|
|
|
|
|
|
int current_version = getSapforActualVersion();
|
|
|
|
|
|
if (current_version > max_version) {
|
|
|
|
|
|
serverSapfor = new ServerSapfor();
|
|
|
|
|
|
serverSapfor.sender_name = "server";
|
|
|
|
|
|
serverSapfor.sender_address = Constants.MailAddress;
|
|
|
|
|
|
serverSapfor.state = ServerSapforState.Queued;
|
|
|
|
|
|
db.Insert(serverSapfor);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
response.object = serverSapfor;
|
2024-05-16 01:26:03 +03:00
|
|
|
|
}
|
2024-10-03 16:21:11 +03:00
|
|
|
|
SapforPackage tryAutoSapforTesting(TextLog Log) throws Exception {
|
2024-09-24 20:22:41 +03:00
|
|
|
|
//--
|
2025-02-18 20:14:14 +03:00
|
|
|
|
UserAccount account = new UserAccount();
|
2024-09-25 01:27:02 +03:00
|
|
|
|
account.name = "server";
|
|
|
|
|
|
account.email = Constants.MailAddress;
|
2025-02-21 01:57:15 +03:00
|
|
|
|
account.role = AccountRole.Admin;
|
2024-09-24 20:22:41 +03:00
|
|
|
|
//-
|
|
|
|
|
|
int sapforId = Integer.parseInt(request.arg);
|
2024-09-25 01:27:02 +03:00
|
|
|
|
if (!db.serverSapfors.containsKey(sapforId)) {
|
|
|
|
|
|
Log.Writeln_("Версия SAPFOR " + sapforId + " не существует.");
|
2024-10-03 16:21:11 +03:00
|
|
|
|
return null;
|
2024-09-24 20:22:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
ServerSapfor sapfor = db.serverSapfors.get(sapforId);
|
2024-09-25 01:27:02 +03:00
|
|
|
|
if (!sapfor.state.equals(ServerSapforState.Done)) {
|
|
|
|
|
|
Log.Writeln_("Выбранная версия SAPFOR " + sapforId + " не собрана!");
|
2024-10-03 16:21:11 +03:00
|
|
|
|
return null;
|
2024-09-24 20:22:41 +03:00
|
|
|
|
}
|
2024-09-25 01:27:02 +03:00
|
|
|
|
Vector<SapforConfiguration> configurations = db.sapforConfigurations.getAutoConfigurations();
|
|
|
|
|
|
if (configurations.isEmpty()) {
|
|
|
|
|
|
Log.Writeln_("Не найдено конфигураций для автоматического тестирования!");
|
2024-10-03 16:21:11 +03:00
|
|
|
|
return null;
|
2024-09-24 20:22:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
SapforPackage target = new SapforPackage(account,
|
|
|
|
|
|
sapfor,
|
|
|
|
|
|
configurations,
|
|
|
|
|
|
1,
|
|
|
|
|
|
Log);
|
|
|
|
|
|
//-
|
2024-09-25 01:27:02 +03:00
|
|
|
|
if (target.tasksCount == 0) {
|
|
|
|
|
|
Log.Writeln_("Не сформировано ни одной новой задачи.");
|
2024-10-03 16:21:11 +03:00
|
|
|
|
return null;
|
2024-09-25 01:27:02 +03:00
|
|
|
|
}
|
2024-09-24 20:22:41 +03:00
|
|
|
|
beforePublishAction(target);
|
|
|
|
|
|
db.InsertS(target);
|
|
|
|
|
|
afterPublishAction(target);
|
|
|
|
|
|
//--
|
2024-10-03 16:21:11 +03:00
|
|
|
|
return target;
|
2024-09-24 20:22:41 +03:00
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
Vector<String> getSapforTaskResults(SapforTask task) throws Exception {
|
2025-02-11 21:28:35 +03:00
|
|
|
|
Vector<String> res = new Vector<>();
|
|
|
|
|
|
//--
|
|
|
|
|
|
if (!task.variants.isEmpty()) {
|
|
|
|
|
|
for (SapforVersion_json version_json : task.variants) {
|
|
|
|
|
|
res.add(version_json.version);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (!task.versions.isEmpty()) {
|
|
|
|
|
|
res.add(task.versions.lastElement().version);
|
2025-02-10 16:14:48 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-11 21:28:35 +03:00
|
|
|
|
return res;
|
|
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void JoinSapforPackageToGroup() throws Exception {
|
2025-02-11 21:28:35 +03:00
|
|
|
|
String[] packed = request.arg.split("\n");
|
|
|
|
|
|
int groupId = Integer.parseInt(packed[0]);
|
|
|
|
|
|
int packageId = Integer.parseInt(packed[1]);
|
|
|
|
|
|
if (!db.sapforPackages.containsKey(packageId))
|
|
|
|
|
|
throw new RepositoryRefuseException("Пакета с ключом " + packageId + " не существует!");
|
|
|
|
|
|
if (!db.groups.containsKey(groupId))
|
|
|
|
|
|
throw new RepositoryRefuseException("Группы с ключом " + groupId + " не существует!");
|
|
|
|
|
|
//--
|
|
|
|
|
|
SapforPackage sapforPackage = db.sapforPackages.get(packageId);
|
|
|
|
|
|
Group group = db.groups.get(groupId);
|
|
|
|
|
|
//--
|
|
|
|
|
|
SapforPackage_json json = Utils_.jsonFromFile(sapforPackage.getJsonFile(), SapforPackage_json.class);
|
|
|
|
|
|
LinkedHashMap<String, File> versions = new LinkedHashMap<>();
|
2025-02-14 00:13:00 +03:00
|
|
|
|
LinkedHashMap<String, String> descriptions = new LinkedHashMap<>();
|
2025-02-11 21:28:35 +03:00
|
|
|
|
for (SapforTask task : json.tasks) {
|
2025-02-13 23:07:18 +03:00
|
|
|
|
if (task.state.equals(TaskState.Done)) {
|
|
|
|
|
|
File task_root = Paths.get(
|
|
|
|
|
|
sapforPackage.getLocalWorkspace().getAbsolutePath(),
|
|
|
|
|
|
String.valueOf(task.set_id),
|
|
|
|
|
|
String.valueOf(task.sapfor_configuration_id)
|
|
|
|
|
|
).toFile();
|
|
|
|
|
|
for (String path : getSapforTaskResults(task)) {
|
|
|
|
|
|
File versionProject = Paths.get(task_root.getAbsolutePath(), path).toFile();
|
|
|
|
|
|
Vector<String> name_parts = new Vector_<>(
|
|
|
|
|
|
String.valueOf(task.id),
|
|
|
|
|
|
task.test_description,
|
|
|
|
|
|
versionProject.getName()
|
|
|
|
|
|
);
|
2025-02-14 00:13:00 +03:00
|
|
|
|
String name = String.join("_", name_parts);
|
|
|
|
|
|
versions.put(name, versionProject);
|
|
|
|
|
|
//--
|
|
|
|
|
|
String[] data = task.codes.split(" ");
|
|
|
|
|
|
Vector<String> codes_ = new Vector<>();
|
|
|
|
|
|
for (String datum : data) {
|
|
|
|
|
|
PassCode code = PassCode.valueOf(datum);
|
|
|
|
|
|
codes_.add(code.getDescription());
|
|
|
|
|
|
//--
|
|
|
|
|
|
descriptions.put(name, String.join("\n", codes_));
|
|
|
|
|
|
}
|
2025-02-13 23:07:18 +03:00
|
|
|
|
}
|
2025-02-11 21:28:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
ZipFolderPass zip = new ZipFolderPass();
|
|
|
|
|
|
//создание тестов.
|
2025-02-11 23:03:18 +03:00
|
|
|
|
Vector<Test> tests = new Vector<>();
|
2025-02-14 00:13:00 +03:00
|
|
|
|
for (String name : versions.keySet()) {
|
|
|
|
|
|
File src = versions.get(name);
|
2025-02-13 01:43:23 +03:00
|
|
|
|
File[] files = src.listFiles(pathname -> !pathname.isDirectory());
|
|
|
|
|
|
if (files != null && files.length > 0) {
|
2025-02-11 21:28:35 +03:00
|
|
|
|
//--
|
|
|
|
|
|
Vector<String> filesNames = new Vector<>();
|
2025-02-13 01:43:23 +03:00
|
|
|
|
for (File file : files)
|
2025-02-11 21:28:35 +03:00
|
|
|
|
filesNames.add(file.getName());
|
|
|
|
|
|
//--
|
|
|
|
|
|
Test test = new Test();
|
|
|
|
|
|
test.group_id = group.id;
|
2025-02-14 00:13:00 +03:00
|
|
|
|
test.description = name;
|
2025-02-11 21:28:35 +03:00
|
|
|
|
test.files = String.join("\n", filesNames);
|
2025-02-12 14:22:11 +03:00
|
|
|
|
test.sender_address = group.sender_address;
|
|
|
|
|
|
test.sender_name = group.sender_name;
|
2025-02-14 00:13:00 +03:00
|
|
|
|
test.extended_description = descriptions.get(name);
|
2025-02-11 21:28:35 +03:00
|
|
|
|
db.Insert(test);
|
|
|
|
|
|
//---
|
|
|
|
|
|
File testProject = new File(Global.TestsDirectory, String.valueOf(test.id));
|
|
|
|
|
|
File testArchive = new File(Global.TestsDirectory, test.id + ".zip");
|
|
|
|
|
|
//---
|
|
|
|
|
|
if (testProject.exists())
|
|
|
|
|
|
FileUtils.forceDelete(testProject);
|
|
|
|
|
|
if (testArchive.exists())
|
|
|
|
|
|
FileUtils.forceDelete(testArchive);
|
|
|
|
|
|
//---
|
2025-02-11 23:08:27 +03:00
|
|
|
|
FileUtils.copyDirectory(src, testProject);
|
2025-02-11 21:28:35 +03:00
|
|
|
|
//---
|
|
|
|
|
|
if (!zip.Do(testProject.getAbsolutePath(), testArchive.getAbsolutePath())) {
|
|
|
|
|
|
db.Delete(test);
|
|
|
|
|
|
throw new RepositoryRefuseException("Не удалось переписать архив проекта");
|
|
|
|
|
|
}
|
2025-02-11 23:03:18 +03:00
|
|
|
|
tests.add(test);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//определение размерности тестов
|
|
|
|
|
|
ServerSapfor serverSapfor = db.serverSapfors.getLastDoneVersion();
|
2025-02-13 01:43:23 +03:00
|
|
|
|
if (serverSapfor != null) {
|
2025-02-11 23:03:18 +03:00
|
|
|
|
File sapfor_copy = Sapfor.getTempCopy(new File(serverSapfor.call_command));
|
2025-02-13 01:43:23 +03:00
|
|
|
|
for (Test test : tests) {
|
2025-02-11 23:32:28 +03:00
|
|
|
|
try {
|
|
|
|
|
|
Sapfor.getMinMaxDim(sapfor_copy, test.getServerPath(), test);
|
|
|
|
|
|
db.Update(test);
|
|
|
|
|
|
Utils.deleteFilesByExtensions(test.getServerPath(),
|
|
|
|
|
|
"proj", "dep", "jar"
|
|
|
|
|
|
);
|
|
|
|
|
|
File visualiser_data = new File(test.getServerPath(), Constants.data);
|
|
|
|
|
|
FileUtils.forceDelete(visualiser_data);
|
2025-02-13 01:43:23 +03:00
|
|
|
|
} catch (Exception ex) {
|
2025-02-11 23:32:28 +03:00
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
}
|
2025-02-11 21:28:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-11 23:32:28 +03:00
|
|
|
|
//-"sh"
|
2025-02-10 16:14:48 +03:00
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void ReplaceDVMPackageJson() throws Exception {
|
2025-02-12 22:49:20 +03:00
|
|
|
|
Pair<DVMPackage, byte[]> p = (Pair<DVMPackage, byte[]>) request.object;
|
|
|
|
|
|
DVMPackage src = p.getKey();
|
|
|
|
|
|
byte[] packed_file = p.getValue();
|
|
|
|
|
|
//todo написать стандартное исключение на несуществование объекта с ключом
|
|
|
|
|
|
if (!db.dvmPackages.containsKey(src.id))
|
2025-02-13 01:43:23 +03:00
|
|
|
|
throw new RepositoryRefuseException("не существует пакета с ключом " + src.id);
|
2025-02-12 22:49:20 +03:00
|
|
|
|
DVMPackage dst = db.dvmPackages.get(src.id);
|
|
|
|
|
|
dst.SynchronizeFields(src);
|
|
|
|
|
|
db.Update(dst);
|
|
|
|
|
|
Utils_.bytesToFile(packed_file, dst.getJsonFile());
|
2025-02-12 14:22:11 +03:00
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
void DetectTestsMinMaxDim() throws Exception {
|
2025-02-13 01:43:23 +03:00
|
|
|
|
Vector<Object> keys = (Vector<Object>) request.object;
|
|
|
|
|
|
for (Object key : keys) {
|
|
|
|
|
|
if (!db.tests.containsKey(key))
|
|
|
|
|
|
throw new RepositoryRefuseException("не существует пакета с ключом " + key);
|
|
|
|
|
|
}
|
|
|
|
|
|
//определение размерности тестов
|
|
|
|
|
|
ServerSapfor serverSapfor = db.serverSapfors.getLastDoneVersion();
|
|
|
|
|
|
if (serverSapfor != null) {
|
|
|
|
|
|
File sapfor_copy = Sapfor.getTempCopy(new File(serverSapfor.call_command));
|
|
|
|
|
|
for (Object key : keys) {
|
|
|
|
|
|
Test test = db.tests.get(key);
|
|
|
|
|
|
Group group = db.groups.get(test.group_id);
|
|
|
|
|
|
if (group.language.equals(LanguageName.fortran)) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
Sapfor.getMinMaxDim(sapfor_copy, test.getServerPath(), test);
|
|
|
|
|
|
db.Update(test);
|
|
|
|
|
|
Utils.deleteFilesByExtensions(test.getServerPath(),
|
|
|
|
|
|
"proj", "dep", "jar"
|
|
|
|
|
|
);
|
|
|
|
|
|
File visualiser_data = new File(test.getServerPath(), Constants.data);
|
|
|
|
|
|
FileUtils.forceDelete(visualiser_data);
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-21 01:57:15 +03:00
|
|
|
|
void GetDVMPackageCredentials() throws Exception {
|
|
|
|
|
|
int package_id = (int) request.object;
|
|
|
|
|
|
if (!db.dvmPackages.containsKey(package_id))
|
|
|
|
|
|
throw new RepositoryRefuseException("Не найден пакет с ключом " + Utils_.Brackets(package_id));
|
|
|
|
|
|
DVMPackageCredentials res = machines_db.dvmPackagesCredentials.getForPackageId(package_id);
|
|
|
|
|
|
if (res == null)
|
|
|
|
|
|
throw new RepositoryRefuseException("Не найдено учетных данных для пакета " + Utils_.Brackets(package_id));
|
|
|
|
|
|
response.object = res;
|
|
|
|
|
|
}
|
2025-02-13 22:43:04 +03:00
|
|
|
|
//--
|
|
|
|
|
|
@Override
|
2025-02-14 02:09:55 +03:00
|
|
|
|
protected void Session() throws Exception {
|
2025-02-13 22:43:04 +03:00
|
|
|
|
switch (code) {
|
2025-02-21 01:57:15 +03:00
|
|
|
|
case GetDVMPackageCredentials:
|
|
|
|
|
|
GetDVMPackageCredentials();
|
|
|
|
|
|
break;
|
2025-02-13 22:43:04 +03:00
|
|
|
|
case PerformAutoSapforTesting:
|
|
|
|
|
|
PerformAutoSapforTesting();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case DownloadTest:
|
|
|
|
|
|
DownloadTest();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ReceiveTestsDatabase:
|
|
|
|
|
|
ReceiveTestsDatabase();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case RefreshDVMTests:
|
|
|
|
|
|
RefreshDVMTests();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case DVMPackageNeedsKill:
|
|
|
|
|
|
DVMPackageNeedsKill();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case UpdateActiveDVMPackages:
|
|
|
|
|
|
UpdateActiveDVMPackages();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case GetFirstActiveSapforPackages:
|
|
|
|
|
|
GetFirstActiveSapforPackages();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case SapforPackageNeedsKill:
|
|
|
|
|
|
SapforPackageNeedsKill();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case UpdateActiveSapforPackages:
|
|
|
|
|
|
UpdateActiveSapforPackages();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case DownloadDVMPackages:
|
|
|
|
|
|
DownloadDVMPackages();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case DownloadSapforPackage:
|
|
|
|
|
|
DownloadSapforPackage();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ReplaceTestCode:
|
|
|
|
|
|
ReplaceTestCode();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ReplaceTestsCodes:
|
|
|
|
|
|
ReplaceTestsCodes();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case GetFirstActiveDVMPackageForMachineURL:
|
|
|
|
|
|
GetFirstActiveDVMPackageForMachineURL();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case GetServerName:
|
|
|
|
|
|
GetServerName();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case StartNecessaryMachines:
|
|
|
|
|
|
StartNecessaryMachines();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case GetSapforForCompilation:
|
|
|
|
|
|
GetSapforForCompilation();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case GetMaxSapforVersion:
|
|
|
|
|
|
GetSapforMaxVersion();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case JoinSapforVersionsToGroup:
|
|
|
|
|
|
JoinSapforPackageToGroup();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case ReplaceDVMPackageResults:
|
|
|
|
|
|
ReplaceDVMPackageJson();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case DetectTestsMinMaxDim:
|
|
|
|
|
|
DetectTestsMinMaxDim();
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new RepositoryRefuseException("Неподдерживаемый код: " + code);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
2024-03-02 22:32:42 +03:00
|
|
|
|
|