2023-11-19 02:12:44 +03:00
|
|
|
|
package TestingSystem.Common;
|
2023-11-14 20:08:19 +03:00
|
|
|
|
import Common.Constants;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import Common.Database.SQLITE.SQLiteDatabase;
|
2024-04-07 21:30:11 +03:00
|
|
|
|
import Common.Global;
|
|
|
|
|
|
import Common.Utils.Utils;
|
|
|
|
|
|
import GlobalData.Account.Account;
|
|
|
|
|
|
import Repository.Component.Sapfor.Sapfor;
|
|
|
|
|
|
import Repository.RepositoryRefuseException;
|
|
|
|
|
|
import TestingSystem.Common.Group.Group;
|
2023-11-19 02:12:44 +03:00
|
|
|
|
import TestingSystem.Common.Group.GroupsDBTable;
|
2024-04-07 21:30:11 +03:00
|
|
|
|
import TestingSystem.Common.Test.Test;
|
2023-11-19 02:12:44 +03:00
|
|
|
|
import TestingSystem.Common.Test.TestDBTable;
|
2023-12-15 02:34:30 +03:00
|
|
|
|
import TestingSystem.Common.TestingPackageToKill.TestingPackagesToKillDBTable;
|
2023-12-14 02:30:56 +03:00
|
|
|
|
import TestingSystem.DVM.Configuration.ConfigurationDBTable;
|
|
|
|
|
|
import TestingSystem.DVM.DVMPackage.DVMPackage;
|
|
|
|
|
|
import TestingSystem.DVM.DVMPackage.DVMPackageDBTable;
|
2023-12-16 16:52:17 +03:00
|
|
|
|
import TestingSystem.DVM.DVMTasks.DVMRunTasksSet;
|
2023-12-14 02:30:56 +03:00
|
|
|
|
import TestingSystem.SAPFOR.SapforConfiguration.SapforConfigurationDBTable;
|
|
|
|
|
|
import TestingSystem.SAPFOR.SapforConfigurationCommand.SapforConfigurationCommandsDBTable;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
import TestingSystem.SAPFOR.SapforPackage.SapforPackage;
|
2023-12-15 18:38:05 +03:00
|
|
|
|
import TestingSystem.SAPFOR.SapforPackage.SapforPackageDBTable;
|
2024-04-07 21:30:11 +03:00
|
|
|
|
import TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
|
2024-05-07 01:06:47 +03:00
|
|
|
|
import TestingSystem.SAPFOR.ServerSapfor.ServerSapforState;
|
2023-12-14 02:30:56 +03:00
|
|
|
|
import TestingSystem.SAPFOR.ServerSapfor.ServerSapforsDBTable;
|
2024-04-07 21:30:11 +03:00
|
|
|
|
import Visual_DVM_2021.Passes.All.ZipFolderPass;
|
2023-11-19 02:12:44 +03:00
|
|
|
|
import Visual_DVM_2021.Passes.PassCode_2021;
|
2024-04-07 21:30:11 +03:00
|
|
|
|
import javafx.util.Pair;
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
|
2024-04-07 21:30:11 +03:00
|
|
|
|
import java.io.File;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
import java.nio.file.Paths;
|
2024-03-21 19:02:08 +03:00
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
|
import java.util.Vector;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
public class TestsDatabase extends SQLiteDatabase {
|
2024-04-26 20:28:50 +03:00
|
|
|
|
|
2024-09-14 00:18:27 +03:00
|
|
|
|
public ConfigurationDBTable dvm_configurations;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
public TestDBTable tests;
|
|
|
|
|
|
public GroupsDBTable groups;
|
2023-12-11 18:29:15 +03:00
|
|
|
|
public DVMPackageDBTable dvmPackages;
|
2023-12-15 18:38:05 +03:00
|
|
|
|
public SapforPackageDBTable sapforPackages;
|
2023-09-17 22:13:42 +03:00
|
|
|
|
//--
|
2023-12-15 02:34:30 +03:00
|
|
|
|
public TestingPackagesToKillDBTable testingPackagesToKill;
|
|
|
|
|
|
//--
|
2023-09-17 22:13:42 +03:00
|
|
|
|
public SapforConfigurationDBTable sapforConfigurations;
|
|
|
|
|
|
public SapforConfigurationCommandsDBTable sapforConfigurationCommands;
|
2023-10-04 00:25:36 +03:00
|
|
|
|
//----
|
2023-10-03 15:07:17 +03:00
|
|
|
|
public ServerSapforsDBTable serverSapfors;
|
2023-12-16 15:34:29 +03:00
|
|
|
|
//---
|
|
|
|
|
|
public DVMRunTasksSet dvmRunTasks = new DVMRunTasksSet(); //задачи текущего пакета тестирования DVM
|
2024-04-21 23:23:57 +03:00
|
|
|
|
//--
|
2023-09-17 22:13:42 +03:00
|
|
|
|
public TestsDatabase() {
|
2023-11-14 20:08:19 +03:00
|
|
|
|
super(Paths.get(System.getProperty("user.dir"), "Data", Constants.tests_db_name + ".sqlite").toFile());
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void initAllTables() throws Exception {
|
2024-09-14 00:18:27 +03:00
|
|
|
|
addTable(dvm_configurations = new ConfigurationDBTable());
|
2023-09-17 22:13:42 +03:00
|
|
|
|
addTable(groups = new GroupsDBTable());
|
|
|
|
|
|
addTable(tests = new TestDBTable());
|
2023-12-11 18:29:15 +03:00
|
|
|
|
addTable(dvmPackages = new DVMPackageDBTable());
|
2023-12-15 18:38:05 +03:00
|
|
|
|
addTable(sapforPackages = new SapforPackageDBTable());
|
2023-12-15 02:34:30 +03:00
|
|
|
|
addTable(testingPackagesToKill = new TestingPackagesToKillDBTable());
|
2023-09-17 22:13:42 +03:00
|
|
|
|
//-
|
|
|
|
|
|
addTable(sapforConfigurations = new SapforConfigurationDBTable());
|
|
|
|
|
|
addTable(sapforConfigurationCommands = new SapforConfigurationCommandsDBTable());
|
2023-10-03 15:07:17 +03:00
|
|
|
|
addTable(serverSapfors = new ServerSapforsDBTable());
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
@Override
|
2023-11-16 16:20:20 +03:00
|
|
|
|
public PassCode_2021 getSynchronizePassCode() {
|
|
|
|
|
|
return PassCode_2021.SynchronizeTests;
|
|
|
|
|
|
}
|
2024-03-21 19:02:08 +03:00
|
|
|
|
public Vector<SapforPackage> getFirstActiveSapforPackagesCopies() {
|
|
|
|
|
|
Vector<SapforPackage> res = new Vector<>();
|
|
|
|
|
|
Vector<SapforPackage> packages = new Vector<>();
|
|
|
|
|
|
SapforPackage activePackage = null;
|
|
|
|
|
|
//1. получить активные пакеты.
|
|
|
|
|
|
for (SapforPackage p : sapforPackages.Data.values()) {
|
|
|
|
|
|
switch (p.state) {
|
|
|
|
|
|
case Done:
|
|
|
|
|
|
case Aborted:
|
|
|
|
|
|
case Draft:
|
2024-04-08 01:30:46 +03:00
|
|
|
|
case ConnectionError:
|
2024-03-21 19:02:08 +03:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
packages.add(p);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//2. отсортировать по приоритету.
|
|
|
|
|
|
packages.sort(new Comparator<SapforPackage>() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public int compare(SapforPackage o1, SapforPackage o2) {
|
|
|
|
|
|
return Integer.compare(o1.state.ordinal(), o2.state.ordinal());
|
2023-12-14 02:30:56 +03:00
|
|
|
|
}
|
2024-03-21 19:02:08 +03:00
|
|
|
|
});
|
|
|
|
|
|
if (!packages.isEmpty()) {
|
|
|
|
|
|
activePackage = packages.lastElement();
|
|
|
|
|
|
if (activePackage.state.equals(TasksPackageState.Queued)) {
|
|
|
|
|
|
activePackage.state = TasksPackageState.TestsSynchronize;
|
2023-12-14 02:30:56 +03:00
|
|
|
|
try {
|
2024-03-21 19:02:08 +03:00
|
|
|
|
Update(activePackage);
|
2023-12-14 02:30:56 +03:00
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-21 19:02:08 +03:00
|
|
|
|
res.add(new SapforPackage(activePackage));
|
|
|
|
|
|
; //копия чтобы не было конфликта доступа с нитью планировщика.
|
2023-12-14 02:30:56 +03:00
|
|
|
|
}
|
2024-03-21 19:02:08 +03:00
|
|
|
|
return res;
|
2023-12-14 02:30:56 +03:00
|
|
|
|
}
|
2024-03-21 19:02:08 +03:00
|
|
|
|
public Vector<DVMPackage> getFirstActiveDVMPackagesCopies() {
|
|
|
|
|
|
Vector<DVMPackage> res = new Vector<>();
|
|
|
|
|
|
//--
|
|
|
|
|
|
LinkedHashMap<String, Vector<DVMPackage>> packagesByMachines = new LinkedHashMap<>();
|
|
|
|
|
|
//----
|
|
|
|
|
|
//1. Получить список активных пакетов по машинам.
|
|
|
|
|
|
for (DVMPackage dvmPackage : dvmPackages.Data.values()) {
|
|
|
|
|
|
switch (dvmPackage.state) {
|
|
|
|
|
|
case Done:
|
|
|
|
|
|
case Aborted:
|
|
|
|
|
|
case Draft:
|
2024-04-08 01:30:46 +03:00
|
|
|
|
case ConnectionError:
|
2024-03-21 19:02:08 +03:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
//активен.
|
|
|
|
|
|
Vector<DVMPackage> packages = null;
|
|
|
|
|
|
//--
|
|
|
|
|
|
if (packagesByMachines.containsKey(dvmPackage.machine_address)) {
|
|
|
|
|
|
packages = packagesByMachines.get(dvmPackage.machine_address);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
packages = new Vector<>();
|
|
|
|
|
|
packagesByMachines.put(dvmPackage.machine_address, packages);
|
|
|
|
|
|
}
|
|
|
|
|
|
packages.add(dvmPackage);
|
|
|
|
|
|
break;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
}
|
2024-03-21 19:02:08 +03:00
|
|
|
|
}
|
|
|
|
|
|
//2. Выбрать для каждой машины наиболее приоритетный пакет.
|
|
|
|
|
|
for (String machine : packagesByMachines.keySet()) {
|
|
|
|
|
|
Vector<DVMPackage> packages = packagesByMachines.get(machine);
|
|
|
|
|
|
if (!packages.isEmpty()) {
|
|
|
|
|
|
packages.sort(new Comparator<DVMPackage>() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public int compare(DVMPackage o1, DVMPackage o2) {
|
|
|
|
|
|
return Integer.compare(o1.state.ordinal(), o2.state.ordinal());
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
//-
|
|
|
|
|
|
DVMPackage activePackage = packages.lastElement();
|
|
|
|
|
|
if (activePackage.state.equals(TasksPackageState.Queued)) {
|
|
|
|
|
|
activePackage.state = TasksPackageState.TestsSynchronize;
|
|
|
|
|
|
try {
|
|
|
|
|
|
Update(activePackage);
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
}
|
2023-12-16 03:57:01 +03:00
|
|
|
|
}
|
2024-03-21 19:02:08 +03:00
|
|
|
|
res.add(new DVMPackage(activePackage)); //копия чтобы не было конфликта доступа с нитью планировщика.
|
2023-12-16 03:57:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-21 19:02:08 +03:00
|
|
|
|
return res;
|
2023-12-16 03:57:01 +03:00
|
|
|
|
}
|
2024-04-07 21:30:11 +03:00
|
|
|
|
//--
|
|
|
|
|
|
public void SaveTestFromSingleFile(ServerSapfor sapfor, Group group, Test test, File file) throws Exception {
|
|
|
|
|
|
File testDirectory = new File(Global.TestsDirectory, String.valueOf(test.id));
|
|
|
|
|
|
Utils.CheckAndCleanDirectory(testDirectory);
|
|
|
|
|
|
File testFile = Paths.get(testDirectory.getAbsolutePath(), file.getName()).toFile();
|
|
|
|
|
|
FileUtils.copyFile(file, testFile);
|
|
|
|
|
|
//----
|
|
|
|
|
|
//архивация.
|
|
|
|
|
|
File archive = test.getArchive();
|
|
|
|
|
|
if (archive.exists())
|
|
|
|
|
|
FileUtils.forceDelete(archive);
|
|
|
|
|
|
//----------->>
|
|
|
|
|
|
ZipFolderPass zip = new ZipFolderPass();
|
|
|
|
|
|
zip.Do(testDirectory.getAbsolutePath(), archive.getAbsolutePath());
|
|
|
|
|
|
//---
|
|
|
|
|
|
//Определение размерности
|
|
|
|
|
|
switch (group.language) {
|
|
|
|
|
|
case fortran:
|
|
|
|
|
|
// временная папка для анализа. чтобы не засорять нормальную.
|
|
|
|
|
|
File tempProject = Utils.getTempFileName("test");
|
|
|
|
|
|
FileUtils.forceMkdir(tempProject);
|
|
|
|
|
|
FileUtils.copyDirectory(testDirectory, tempProject);
|
|
|
|
|
|
//--
|
|
|
|
|
|
if (Sapfor.getMinMaxDim(Sapfor.getTempCopy(new File(sapfor.call_command)), tempProject, test)) {
|
|
|
|
|
|
Update(test);
|
|
|
|
|
|
} else
|
|
|
|
|
|
throw new RepositoryRefuseException("Не удалось определить размерность теста " + Utils.Brackets(test.description));
|
|
|
|
|
|
break;
|
|
|
|
|
|
case c:
|
|
|
|
|
|
test.max_dim = Utils.getCTestMaxDim(testFile);
|
|
|
|
|
|
Update(test);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//---
|
|
|
|
|
|
public void CreateTestFromSingleFile(Account account, ServerSapfor sapfor, Group group, File file, String testDescription) throws Exception {
|
|
|
|
|
|
Test test = new Test();
|
|
|
|
|
|
test.description = testDescription;
|
|
|
|
|
|
test.sender_name = account.name;
|
|
|
|
|
|
test.sender_address = account.email;
|
|
|
|
|
|
test.group_id = group.id;
|
|
|
|
|
|
test.files = file.getName();
|
|
|
|
|
|
Insert(test);
|
|
|
|
|
|
//->>
|
|
|
|
|
|
SaveTestFromSingleFile(sapfor, group, test, file);
|
|
|
|
|
|
}
|
|
|
|
|
|
public void RefreshGroup(Account account, ServerSapfor sapfor, Pair<Group, Vector<File>> groupData) throws Exception {
|
|
|
|
|
|
Group group = groupData.getKey();
|
|
|
|
|
|
Vector<File> files = groupData.getValue();
|
|
|
|
|
|
//--
|
2024-04-15 22:09:10 +03:00
|
|
|
|
Group oldGroup = groups.getGroupByDescription(group.language, group.description);
|
2024-04-07 21:30:11 +03:00
|
|
|
|
if (oldGroup == null) {
|
|
|
|
|
|
Insert(group);
|
|
|
|
|
|
for (File file : files) {
|
|
|
|
|
|
String testDescription = Utils.getNameWithoutExtension(file.getName()) + "_" + group.language.getDVMCompile();
|
|
|
|
|
|
CreateTestFromSingleFile(account, sapfor, group, file, testDescription);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
for (File file : files) {
|
|
|
|
|
|
String testDescription = Utils.getNameWithoutExtension(file.getName()) + "_" + group.language.getDVMCompile();
|
|
|
|
|
|
Test oldTest = tests.getTestByDescription(oldGroup.id, testDescription);
|
|
|
|
|
|
if (oldTest == null) {
|
|
|
|
|
|
CreateTestFromSingleFile(account, sapfor, oldGroup, file, testDescription);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
SaveTestFromSingleFile(sapfor, group, oldTest, file);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-15 22:09:10 +03:00
|
|
|
|
public Vector<DVMPackage> getFirstActiveDVMPackageCopyForMachineURL(String arg) {
|
|
|
|
|
|
Vector<DVMPackage> res = new Vector<>();
|
|
|
|
|
|
Vector<DVMPackage> machinePackages = new Vector<>();
|
|
|
|
|
|
//--
|
|
|
|
|
|
//1. Получить список активных пакетов для машины.
|
|
|
|
|
|
for (DVMPackage dvmPackage : dvmPackages.Data.values()) {
|
|
|
|
|
|
switch (dvmPackage.state) {
|
|
|
|
|
|
case Done:
|
|
|
|
|
|
case Aborted:
|
|
|
|
|
|
case Draft:
|
|
|
|
|
|
case ConnectionError:
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
if (dvmPackage.getMachine().getURL().equals(arg))
|
|
|
|
|
|
machinePackages.add(dvmPackage);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!machinePackages.isEmpty()) {
|
|
|
|
|
|
machinePackages.sort(new Comparator<DVMPackage>() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public int compare(DVMPackage o1, DVMPackage o2) {
|
|
|
|
|
|
return Integer.compare(o1.state.ordinal(), o2.state.ordinal());
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
//-
|
|
|
|
|
|
DVMPackage activePackage = machinePackages.lastElement();
|
|
|
|
|
|
if (activePackage.state.equals(TasksPackageState.Queued)) {
|
|
|
|
|
|
activePackage.state = TasksPackageState.TestsSynchronize;
|
|
|
|
|
|
try {
|
|
|
|
|
|
Update(activePackage);
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-05-07 01:06:47 +03:00
|
|
|
|
res.add(new DVMPackage(activePackage));
|
2024-04-15 22:09:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
return res;
|
2024-04-13 20:09:26 +03:00
|
|
|
|
}
|
2024-05-07 01:06:47 +03:00
|
|
|
|
public ServerSapfor getSapforCopyForCompilation() {
|
|
|
|
|
|
for (ServerSapfor serverSapfor: serverSapfors.Data.values()){
|
|
|
|
|
|
if (serverSapfor.state.equals(ServerSapforState.Queued)){
|
|
|
|
|
|
return new ServerSapfor(serverSapfor);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2024-05-08 01:56:17 +03:00
|
|
|
|
public Integer getInstalledSapforMaxVersion() {
|
|
|
|
|
|
int max_version=Constants.Nan;
|
|
|
|
|
|
|
|
|
|
|
|
for (ServerSapfor sapfor : serverSapfors.Data.values()) {
|
|
|
|
|
|
if (sapfor.state.equals(ServerSapforState.Done)) {
|
|
|
|
|
|
int version=Constants.Nan;
|
|
|
|
|
|
try {
|
|
|
|
|
|
version = Integer.parseInt(sapfor.version);
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (version > max_version) max_version = version;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return max_version;
|
|
|
|
|
|
}
|
2024-05-17 01:33:39 +03:00
|
|
|
|
|
|
|
|
|
|
public boolean hasActiveSapfors(){
|
|
|
|
|
|
for (ServerSapfor serverSapfor: serverSapfors.Data.values()){
|
|
|
|
|
|
if (serverSapfor.state.isActive())
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2024-09-10 01:50:44 +03:00
|
|
|
|
public void UnselectAllGTC(){
|
|
|
|
|
|
groups.CheckAll(false);
|
|
|
|
|
|
tests.CheckAll(false);
|
2024-09-14 00:18:27 +03:00
|
|
|
|
dvm_configurations.CheckAll(false);
|
2024-09-10 01:50:44 +03:00
|
|
|
|
}
|
2023-09-17 22:13:42 +03:00
|
|
|
|
}
|