автоматический поиск версии сапфора для установки на сервере.
This commit is contained in:
@@ -6,7 +6,6 @@ import Common.Utils.Utils;
|
||||
import GlobalData.Account.Account;
|
||||
import ProjectData.LanguageName;
|
||||
import Repository.Component.Sapfor.Sapfor;
|
||||
import Repository.EmailMessage;
|
||||
import Repository.RepositoryRefuseException;
|
||||
import Repository.RepositoryServer;
|
||||
import Repository.Server.ServerCode;
|
||||
@@ -26,6 +25,7 @@ import TestingSystem.SAPFOR.SapforConfigurationCommand.SapforConfigurationComman
|
||||
import TestingSystem.SAPFOR.SapforPackage.SapforPackage;
|
||||
import TestingSystem.SAPFOR.SapforTestingPlanner;
|
||||
import TestingSystem.SAPFOR.ServerSapfor.ServerSapfor;
|
||||
import TestingSystem.SAPFOR.ServerSapfor.ServerSapforState;
|
||||
import Visual_DVM_2021.Passes.All.DownloadRepository;
|
||||
import Visual_DVM_2021.Passes.All.ZipFolderPass;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
@@ -33,10 +33,13 @@ import Visual_DVM_2021.Passes.Pass_2021;
|
||||
import javafx.util.Pair;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Vector;
|
||||
public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
public String name = "?";
|
||||
public static MachineProcessSet machinesProcesses = new MachineProcessSet();
|
||||
@@ -110,24 +113,11 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
//-->>>
|
||||
@Override
|
||||
protected void beforePublishAction(DBObject object) throws Exception {
|
||||
if (object instanceof ServerSapfor){
|
||||
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 " +
|
||||
Utils.DQuotes(Global.TempDirectory.getAbsolutePath()) +
|
||||
" 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);
|
||||
if (object instanceof ServerSapfor) {
|
||||
int current_version = getSapforActualVersion();
|
||||
int max_installed_version = db.getInstalledSapforMaxVersion();
|
||||
if (max_installed_version==current_version)
|
||||
throw new RepositoryRefuseException("Актуальная версия SAPFOR "+max_installed_version+" уже установлена");
|
||||
if (max_installed_version == current_version)
|
||||
throw new RepositoryRefuseException("Актуальная версия SAPFOR " + max_installed_version + " уже установлена");
|
||||
}
|
||||
}
|
||||
public TestingServer() {
|
||||
@@ -230,10 +220,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
Print("Загрузить пакет SAPFOR");
|
||||
DownloadSapforPackage();
|
||||
break;
|
||||
case InstallServerSapfor:
|
||||
Print("Установить текущую версию SAPFOR для тестирования");
|
||||
InstallServerSapfor();
|
||||
break;
|
||||
case ReplaceTestCode:
|
||||
Print("Заменить код теста");
|
||||
ReplaceTestCode();
|
||||
@@ -355,11 +341,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = db.getFirstActiveSapforPackagesCopies();
|
||||
}
|
||||
//---
|
||||
void GetSapforForCompilation() throws Exception {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = db.getSapforCopyForCompilation();
|
||||
}
|
||||
void GetSapforMaxVersion() throws Exception {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = db.getInstalledSapforMaxVersion();
|
||||
@@ -455,122 +436,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
else
|
||||
throw new RepositoryRefuseException("Не удалось заархивировать пакет тестирования SAPFOR с ключом " + sapforPackage_id);
|
||||
}
|
||||
private void InstallServerSapfor() throws Exception {
|
||||
int max_version = Constants.Nan;
|
||||
int current_version = Constants.Nan;
|
||||
//--
|
||||
for (ServerSapfor sapfor : db.serverSapfors.Data.values()) {
|
||||
int version = -1;
|
||||
try {
|
||||
version = Integer.parseInt(sapfor.version);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
if (version > max_version) max_version = version;
|
||||
}
|
||||
System.out.println("max Sapfor version is " + max_version);
|
||||
//--
|
||||
File testingSystemHome = new File(Global.Home);
|
||||
File repo = new File(testingSystemHome, "Repo");
|
||||
File repoSapforHome = Paths.get(repo.getAbsolutePath(), Constants.SAPFOR_REPOSITORY_BIN).toFile();
|
||||
File repo_bin = new File(repoSapforHome, "Sapfor_F");
|
||||
File repo_out = new File(repoSapforHome, Constants.out_file);
|
||||
File repo_err = new File(repoSapforHome, Constants.err_file);
|
||||
//--
|
||||
System.out.println("Синхронизация ветви DVM...");
|
||||
Utils.startScript(repo, repo, "dvm_checkout",
|
||||
"svn checkout " +
|
||||
Constants.REPOSITORY_AUTHENTICATION +
|
||||
" " + Constants.DVM_REPOSITORY + " 1>dvm_out.txt 2>dvm_err.txt\n").waitFor();
|
||||
System.out.println("Синхронизация ветви SAPFOR...");
|
||||
Utils.startScript(repo, repo, "spf_checkout",
|
||||
"svn checkout " +
|
||||
Constants.REPOSITORY_AUTHENTICATION +
|
||||
" " + Constants.SAPFOR_REPOSITORY + " 1>spf_out.txt 2>spf_err.txt\n").waitFor();
|
||||
//--
|
||||
if (repo_bin.exists())
|
||||
FileUtils.forceDelete(repo_bin);
|
||||
//-
|
||||
File versionFile = Paths.get(repo.getAbsolutePath(), "/sapfor/experts/Sapfor_2017/_src/Utils/version.h").toFile();
|
||||
if (versionFile.exists()) {
|
||||
List<String> data = FileUtils.readLines(versionFile);
|
||||
for (String s : data) {
|
||||
if (s.startsWith("#define VERSION_SPF ")) {
|
||||
String[] version_data = s.split("\"");
|
||||
if (version_data.length > 0) {
|
||||
String version_s = version_data[1];
|
||||
//-
|
||||
try {
|
||||
current_version = Integer.parseInt(version_s);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
//-
|
||||
if (current_version == max_version) {
|
||||
throw new RepositoryRefuseException("Версия SAPFOR " + max_version + " уже собрана!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//--
|
||||
System.out.println("Сборка SAPFOR...");
|
||||
Utils.startScript(repoSapforHome, repoSapforHome, "build_sapfor",
|
||||
"cmake ../ 1>" +
|
||||
Constants.out_file +
|
||||
" 2>" +
|
||||
Constants.err_file +
|
||||
"\nmake -j 14 1>>" +
|
||||
Constants.out_file +
|
||||
" 2>>" +
|
||||
Constants.err_file +
|
||||
"\n").waitFor();
|
||||
//--
|
||||
System.out.println("DONE");
|
||||
File repoSapfor = new File(repoSapforHome, "Sapfor_F");
|
||||
System.out.println("Result file is " + Utils.Brackets(repoSapfor.getAbsolutePath()));
|
||||
//---
|
||||
File sapforsDirectory = new File(testingSystemHome, "Sapfors");
|
||||
File sapforHome = new File(sapforsDirectory, Utils.getDateName("sapfor"));
|
||||
sapforHome.mkdir();
|
||||
File sapforOut = new File(sapforHome, Constants.out_file);
|
||||
File sapforErr = new File(sapforHome, Constants.err_file);
|
||||
//--
|
||||
System.out.println(repoSapfor.getAbsolutePath());
|
||||
System.out.println(repo_out.getAbsolutePath());
|
||||
System.out.println(repo_err.getAbsolutePath());
|
||||
System.out.println("====================");
|
||||
//--
|
||||
if (repo_out.exists())
|
||||
FileUtils.copyFile(repo_out, sapforOut);
|
||||
if (repo_err.exists())
|
||||
FileUtils.copyFile(repo_err, sapforErr);
|
||||
//--
|
||||
if (repoSapfor.exists()) {
|
||||
System.out.println("assembly found!");
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
//создать папку. Для того чтобы скопировать из репозитория.
|
||||
File sapforBin = new File(sapforHome, "Sapfor_F");
|
||||
FileUtils.copyFile(repo_bin, sapforBin);
|
||||
sapforBin.setExecutable(true, false);
|
||||
// //-->>>
|
||||
ServerSapfor serverSapfor = new ServerSapfor();
|
||||
serverSapfor.home_path = sapforHome.getAbsolutePath();
|
||||
serverSapfor.call_command = sapforBin.getAbsolutePath();
|
||||
serverSapfor.languageName = LanguageName.fortran;
|
||||
serverSapfor.buildDate = new Date().getTime();
|
||||
response.object = serverSapfor;
|
||||
serverSapfor.version = String.valueOf(current_version);
|
||||
//---
|
||||
// EmailSapforAssembly(current_version, true);
|
||||
//---
|
||||
} else {
|
||||
//---
|
||||
EmailSapforAssembly(current_version, false);
|
||||
//---
|
||||
throw new RepositoryRefuseException("Бинарный файл SAPFOR не найден!");
|
||||
}
|
||||
}
|
||||
private void ReplaceTestCode() throws Exception {
|
||||
Test test = (Test) request.object;
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
@@ -596,21 +461,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
} else db.Update(test); //обновить список файлов и размерность.
|
||||
}
|
||||
}
|
||||
private void EmailSapforAssembly(int version, boolean done) throws Exception {
|
||||
String version_s = (version == Constants.Nan) ? "?" : String.valueOf(version);
|
||||
String status = done ? "Успешно" : "С ошибками";
|
||||
//-
|
||||
File out = Paths.get(Global.RepoDirectory.getAbsolutePath(), Constants.SAPFOR_REPOSITORY_BIN, Constants.out_file).toFile();
|
||||
File err = Paths.get(Global.RepoDirectory.getAbsolutePath(), Constants.SAPFOR_REPOSITORY_BIN, Constants.err_file).toFile();
|
||||
Vector<String> targets = new Vector<>(Arrays.asList(Global.admins_mails));
|
||||
EmailMessage message = new EmailMessage(
|
||||
"Выполнена сборка системы SAPFOR",
|
||||
"Версия: " + version_s + "\n" + "Статус: " + status,
|
||||
targets
|
||||
);
|
||||
//-
|
||||
Email(message, out, err);
|
||||
}
|
||||
private void GetDVMPackagesJson() throws Exception {
|
||||
Vector<Integer> packages_ids = (Vector<Integer>) request.object;
|
||||
Vector<DVMPackage_json> jsons = new Vector<>();
|
||||
@@ -687,7 +537,7 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
}
|
||||
void GetSapforActualVersion() throws Exception {
|
||||
response = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
File versionFile = new File(Global.TempDirectory,"version.h");
|
||||
File versionFile = new File(Global.TempDirectory, "version.h");
|
||||
if (versionFile.exists())
|
||||
FileUtils.forceDelete(versionFile);
|
||||
//1. Получить версию из репозитория.
|
||||
@@ -702,8 +552,43 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
|
||||
throw new RepositoryRefuseException("Не удалось загрузить текущую версию SAPFOR из репозитория!");
|
||||
int current_version = Sapfor.readVersionFromCode(versionFile);
|
||||
int max_installed_version = db.getInstalledSapforMaxVersion();
|
||||
if (max_installed_version==current_version)
|
||||
throw new RepositoryRefuseException("Версия "+max_installed_version+" уже установлена");
|
||||
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 " +
|
||||
Utils.DQuotes(Global.TempDirectory.getAbsolutePath()) +
|
||||
" 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 = new ServerExchangeUnit_2021(ServerCode.OK);
|
||||
response.object = serverSapfor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user