Files
VisualSapfor/src/Visual_DVM_2021/Passes/All/CloneDVMPackage.java

223 lines
9.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package Visual_DVM_2021.Passes.All;
import Common_old.Constants;
import Common_old.Current;
import Common.Database.Database;
import _VisualDVM.Global;
import Common_old.UI.UI;
import Common_old.Utils.Utils;
import GlobalData.Compiler.CompilerType;
import GlobalData.Machine.MachineType;
import GlobalData.Tasks.TaskState;
import GlobalData.User.UserState;
import Repository.Server.ServerCode;
import Repository.Server.ServerExchangeUnit_2021;
import TestingSystem.Common.Group.Group;
import TestingSystem.Common.TasksPackageState;
import TestingSystem.Common.Test.Test;
import TestingSystem.Common.Test.TestType;
import TestingSystem.DVM.DVMPackage.DVMPackage;
import TestingSystem.DVM.DVMPackage.DVMPackage_json;
import TestingSystem.DVM.DVMTasks.DVMCompilationTask;
import TestingSystem.DVM.DVMTasks.DVMRunTask;
import Visual_DVM_2021.Passes.AddObjectPass;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Server.TestingSystemPass;
import java.util.Vector;
public class CloneDVMPackage extends AddObjectPass<DVMPackage> {
Vector<DVMPackage> srcPackages;
Vector<String> inexistingTests;
Vector<String> inexistingConfigurations;
//-
Vector<Integer> src_ids;
Vector<DVMPackage_json> src_jsons;
//-
public CloneDVMPackage() {
super(DVMPackage.class);
}
@Override
public String getIconPath() {
return "/icons/MultiFiles.png";
}
@Override
protected Database getDb() {
return Global.testingServer.db;
}
protected void createTarget() {
target = new DVMPackage();
target.id = Constants.Nan;
//-
target.sender_name = Current.getAccount().name;
target.sender_address = Current.getAccount().email;
//-
target.machine_name = Current.getMachine().name;
target.machine_address = Current.getMachine().address;
target.machine_port = Current.getMachine().port;
//-
target.user_name = Current.getUser().login;
target.user_password = Current.getUser().password;
target.user_workspace = Current.getUser().workspace;
//--
target.drv = Current.getCompiler().call_command;
target.version = Current.getCompiler().getVersionInfo();
//--
target.kernels = 1; //Global.properties.TestingKernels;
target.needsEmail = Global.properties.EmailOnTestingProgress ? 1 : 0;
//--
target.tasksCount = 0;
//--
target.package_json = new DVMPackage_json();
}
protected void CloneTasks(DVMPackage_json src_json, DVMPackage_json dst_json) throws Exception {
for (DVMCompilationTask src_compilationTask : src_json.compilationTasks) {
if (Global.testingServer.db.tests.containsKey(src_compilationTask.test_id)
) {
Group group = Global.testingServer.db.groups.get(src_compilationTask.group_id);
Test test = Global.testingServer.db.tests.get(src_compilationTask.test_id);
//--
DVMCompilationTask compilationTask = new DVMCompilationTask();
//--
compilationTask.group_id = group.id;
compilationTask.group_description = group.description;
compilationTask.language = src_compilationTask.language;
//--
compilationTask.test_id = test.id;
compilationTask.test_description = test.description;
compilationTask.test_type = group.type;
//--
compilationTask.maxtime = src_compilationTask.maxtime;
//--
compilationTask.flags = src_compilationTask.flags;
compilationTask.kernels = 1;
//---
for (DVMRunTask src_runTask : src_compilationTask.runTasks) {
DVMRunTask runTask = new DVMRunTask();
//--
runTask.group_id = group.id;
runTask.group_description = group.description;
runTask.language = src_runTask.language;
//--
runTask.test_id = test.id;
runTask.test_description = test.description;
runTask.test_type = group.type;
//--
runTask.compilation_maxtime = src_runTask.compilation_maxtime;
runTask.compilation_state = TaskState.Waiting;
runTask.maxtime = src_runTask.maxtime;
//--
runTask.cube = src_runTask.cube;
runTask.min_dim = src_runTask.min_dim;
runTask.max_dim = src_runTask.max_dim;
runTask.matrix = src_runTask.matrix;
runTask.environments = src_runTask.environments;
runTask.usr_par = src_runTask.usr_par;
runTask.args = test.args;
//--
runTask.flags = src_runTask.flags;
runTask.kernels = (group.type == TestType.Performance) ? target.kernels :
Math.min(Utils.getMatrixProcessors(src_runTask.matrix), target.kernels);
compilationTask.runTasks.add(runTask);
}
//--
dst_json.compilationTasks.add(compilationTask);
//-
} else {
inexistingTests.add(String.valueOf(src_compilationTask.test_id));
}
}
}
@Override
protected boolean canStart(Object... args) throws Exception {
srcPackages = new Vector<>();
if (!Current.getAccount().CheckRegistered(Log))
return false;
//----
srcPackages = Global.testingServer.db.dvmPackages.getCheckedOrCurrent();
if (srcPackages.isEmpty()){
Log.Writeln_("Не отмечено или не выбрано ни одного пакета DVM");
return false;
}
//-
if (!Current.Check(Log, Current.Machine, Current.User, Current.Compiler))
return false;
//---
if (!Current.getMachine().type.equals(MachineType.Server)) {
Log.Writeln_("Тестирование поддерживается только на одиночном удалённом сервере.");
return false;
}
if (!Current.getUser().state.equals(UserState.ready_to_work)) {
Log.Writeln_("Пользователь не готов к работе. Выполните инициализацию пользователя!");
return false;
}
if (!Current.getCompiler().type.equals(CompilerType.dvm)) {
Log.Writeln_("Тестирование поддерживается только для DVM компиляторов.");
return false;
}
if (!Current.getCompiler().versionLoaded)
passes.get(PassCode_2021.ShowCompilerVersion).Do(Current.getCompiler(), false);
//-
for (DVMPackage dvmPackage : Global.testingServer.db.dvmPackages.Data.values()) {
if (dvmPackage.state.equals(TasksPackageState.Draft)) {
Log.Writeln_("Может существовать только один пакет, готовящийся к публикации.");
return false;
}
}
//--
src_ids = new Vector<>();
src_jsons = new Vector<>();
for (DVMPackage src : srcPackages) {
if (src.state.equals(TasksPackageState.Draft)) {
Log.Writeln_("Пакет " + Utils.Brackets(src.id) + " является черновиком.");
return false;
}
src_ids.add(src.id);
}
//--
TestingSystemPass getJsonsPass = new TestingSystemPass() {
@Override
public String getDescription() {
return "Получить информацию о задачах исходных пакетов";
}
@Override
protected void ServerAction() throws Exception {
Command(new ServerExchangeUnit_2021(ServerCode.GetDVMPackagesJson, null, src_ids));
src_jsons.addAll((Vector<DVMPackage_json>) response.object);
}
};
if (!getJsonsPass.Do())
return false;
//--
createTarget();
//--
inexistingTests = new Vector<>();
inexistingConfigurations = new Vector<>(); //не нужно.
//--
for (DVMPackage_json srcJson: src_jsons){
CloneTasks(srcJson, target.package_json);
}
///-
//инициализируем идентификаторы задач.
for (DVMCompilationTask compilationTask : target.package_json.compilationTasks) {
//--
compilationTask.id = target.package_json.getMaxTaskId();
//-
for (DVMRunTask runTask : compilationTask.runTasks) {
runTask.id = target.package_json.getMaxTaskId();
runTask.dvmcompilationtask_id = compilationTask.id;
target.tasksCount++;
}
}
return inexistingTests.isEmpty() || UI.Question(inexistingTests.size() + " тестов отсутствует. Продолжить");
}
@Override
protected void body() throws Exception {
//черновик не вставляется в бд. идет только как элемент списка.
Global.testingServer.db.dvmPackages.Data.put(target.id, target);
}
@Override
protected void showDone() throws Exception {
super.showDone();
Global.testingServer.db.dvmRunTasks.ShowDVMPackage(target);
}
}