package Visual_DVM_2021.Passes.All; import Common.CommonConstants; import Common.Current_; import Common.Utils.Utils_; import Common.Visual.UI_; import _VisualDVM.Current; import Common.Database.Database; import _VisualDVM.Global; import _VisualDVM.Utils; import _VisualDVM.GlobalData.Compiler.CompilerType; import _VisualDVM.GlobalData.Machine.MachineType; import _VisualDVM.GlobalData.Tasks.TaskState; import _VisualDVM.GlobalData.User.UserState; import _VisualDVM.Repository.Server.ServerCode; import _VisualDVM.Repository.Server.ServerExchangeUnit_2021; import _VisualDVM.TestingSystem.Common.Group.Group; import _VisualDVM.TestingSystem.Common.TasksPackageState; import _VisualDVM.TestingSystem.Common.Test.Test; import _VisualDVM.TestingSystem.Common.Test.TestType; import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage; import _VisualDVM.TestingSystem.DVM.DVMPackage.DVMPackage_json; import _VisualDVM.TestingSystem.DVM.DVMTasks.DVMCompilationTask; import _VisualDVM.TestingSystem.DVM.DVMTasks.DVMRunTask; import Common.Passes.AddObjectPass; import Visual_DVM_2021.Passes.PassCode; import Visual_DVM_2021.Passes.Server.TestingSystemPass; import java.util.Vector; public class CloneDVMPackage extends AddObjectPass { Vector srcPackages; Vector inexistingTests; Vector inexistingConfigurations; //- Vector src_ids; Vector 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 = CommonConstants.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.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) 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); } }