рефакторинг бекапов. бекапы для тестирования. бекапы по кнопке

++
This commit is contained in:
2025-03-08 02:42:21 +03:00
parent e428d621ac
commit c4157fc30b
18 changed files with 275 additions and 149 deletions

20
.idea/workspace.xml generated
View File

@@ -7,8 +7,24 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment=""> <list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/_VisualDVM/Passes/All/ComponentsServerBackUp.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/_VisualDVM/Passes/All/TestingServerBackUp.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/_VisualDVM/Repository/Server/BackUpsChecker.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/_VisualDVM/Repository/Server/RepositoryServerClient.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/icons/BackUp.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/properties" beforeDir="false" afterPath="$PROJECT_DIR$/properties" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/ComponentsServer/ComponentsServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/ComponentsServer/ComponentsServer.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Constants.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Constants.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Global.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Global.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/_VisualDVM/Global.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Global.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/MainModule.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/MainModule.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Passes/PassCode.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Passes/PassCode.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Repository/Server/RepositoryServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Repository/Server/RepositoryServer.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Repository/Server/ServerCode.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Repository/Server/ServerCode.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/Common/TestingClient.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/Common/TestingClient.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/Common/TestingMenuBar.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/Common/TestingMenuBar.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/Common/TestingServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/Common/TestingServer.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Visual/Windows/CallbackForm.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Visual/Windows/CallbackForm.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -87,7 +103,7 @@
<property name="UI_DESIGNER_EDITOR_MODE.UIDesignerToolWindowManager.SHOW" value="true" /> <property name="UI_DESIGNER_EDITOR_MODE.UIDesignerToolWindowManager.SHOW" value="true" />
<property name="UI_DESIGNER_EDITOR_MODE.UIDesignerToolWindowManager.WIDTH" value="509" /> <property name="UI_DESIGNER_EDITOR_MODE.UIDesignerToolWindowManager.WIDTH" value="509" />
<property name="extract.method.default.visibility" value="public" /> <property name="extract.method.default.visibility" value="public" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/icons/versions" /> <property name="last_opened_file_path" value="$PROJECT_DIR$/src/icons" />
<property name="project.structure.last.edited" value="Libraries" /> <property name="project.structure.last.edited" value="Libraries" />
<property name="project.structure.proportion" value="0.15" /> <property name="project.structure.proportion" value="0.15" />
<property name="project.structure.side.proportion" value="0.27322906" /> <property name="project.structure.side.proportion" value="0.27322906" />
@@ -100,9 +116,9 @@
<recent name="controls.Trees" /> <recent name="controls.Trees" />
</key> </key>
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\misha\Documents\visual_sapfor_2023\src\icons" />
<recent name="C:\Users\misha\Documents\visual_sapfor_2023\src\icons\versions" /> <recent name="C:\Users\misha\Documents\visual_sapfor_2023\src\icons\versions" />
<recent name="C:\Users\misha\Documents\visual_sapfor_2023\libs" /> <recent name="C:\Users\misha\Documents\visual_sapfor_2023\libs" />
<recent name="C:\Users\misha\Documents\visual_sapfor_2023\src\icons" />
<recent name="C:\Users\misha\Documents\visual_sapfor_2023\src\icons\Transformations" /> <recent name="C:\Users\misha\Documents\visual_sapfor_2023\src\icons\Transformations" />
<recent name="C:\Users\misha\Documents\visual_sapfor_2023\src\Common\icons" /> <recent name="C:\Users\misha\Documents\visual_sapfor_2023\src\Common\icons" />
</key> </key>

View File

@@ -4,7 +4,7 @@
"ServerUserPassword": "mprit_2011", "ServerUserPassword": "mprit_2011",
"OfferRegistrationOnStart": true, "OfferRegistrationOnStart": true,
"Workspace": "E:\\Tests", "Workspace": "E:\\Tests",
"ProjectsSearchDirectory": "E:\\Tests\\Downloads", "ProjectsSearchDirectory": "E:\\Tests\\Downloads\\sadp110_1741361715\\sadp110\\v1\\v1",
"DocumentsDirectory": "C:\\Users\\misha\\Documents\\_testing_system", "DocumentsDirectory": "C:\\Users\\misha\\Documents\\_testing_system",
"VisualiserPath": "C:\\Users\\misha\\Downloads", "VisualiserPath": "C:\\Users\\misha\\Downloads",
"Sapfor_FPath": "E:\\_sapfor_x64\\Components\\Sapfor_F", "Sapfor_FPath": "E:\\_sapfor_x64\\Components\\Sapfor_F",
@@ -26,7 +26,7 @@
"Kernels": 8, "Kernels": 8,
"LocalMakePathWindows": "C:\\MinGW\\msys\\1.0\\bin\\make.exe", "LocalMakePathWindows": "C:\\MinGW\\msys\\1.0\\bin\\make.exe",
"CheckTestingIntervalSeconds": 10, "CheckTestingIntervalSeconds": 10,
"AutoCheckTesting": true, "AutoCheckTesting": false,
"EmailOnTestingProgress": true, "EmailOnTestingProgress": true,
"CompleteCompilationOptions": false, "CompleteCompilationOptions": false,
"CompleteRunEnvironments": false, "CompleteRunEnvironments": false,

View File

@@ -1,5 +1,6 @@
package _VisualDVM.ComponentsServer; package _VisualDVM.ComponentsServer;
import Common.Database.Objects.DBObject; import Common.Database.Objects.DBObject;
import Common.Database.Objects.riDBObject;
import Common.Database.RepositoryRefuseException; import Common.Database.RepositoryRefuseException;
import Common.Utils.Utils_; import Common.Utils.Utils_;
import _VisualDVM.ComponentsServer.BugReport.BugReport; import _VisualDVM.ComponentsServer.BugReport.BugReport;
@@ -39,68 +40,6 @@ import java.util.Date;
import java.util.Vector; import java.util.Vector;
public class ComponentsServer extends RepositoryServer<BugReportsDatabase> { public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
public CredentialsDatabase credentials_db = null; public CredentialsDatabase credentials_db = null;
//--
public static ZipFolderPass zip = new ZipFolderPass();
public static UnzipFolderPass unzip = new UnzipFolderPass();
public static ArchivesBackupPass backupSession = new ArchivesBackupPass();
//-
public static Vector<Pair<Machine, User>> storages = new Vector<>(
Arrays.asList(new Pair<>(new Machine("titan",
"dvmh.keldysh.ru",
22, MachineType.Server),
new User("dvmuser1", "mprit_2011")) // todo с этим паролем что-то сделать.
));
//-
protected Thread backUp = new Thread(() -> {
while (true) {
try {
//-------------------------------------
Calendar rightNow = Calendar.getInstance();
int year = rightNow.get(Calendar.YEAR);
int month = rightNow.get(Calendar.MONTH);
int day = rightNow.get(Calendar.DAY_OF_MONTH);
int hour = rightNow.get(Calendar.HOUR_OF_DAY);
int minute = rightNow.get(Calendar.MINUTE);
if ((hour == Global.componentsServerProperties.BackupHour) && (minute == Global.componentsServerProperties.BackupMinute)) {
//определить имя папки с багом.
String backUpName = year + "_" + (month + 1) + "_" + (day);
File todayBackUp = Paths.get(Global.DataBackUpsDirectory.getAbsolutePath(), backUpName).toFile();
File todayBackUpArchive = Paths.get(Global.DataBackUpsDirectory.getAbsolutePath(), backUpName + ".zip").toFile();
//-
File bugsDBBackUp = Paths.get(todayBackUp.getAbsolutePath(), db.getFile().getName()).toFile();
File bugsArchives = Paths.get(todayBackUp.getAbsolutePath(), "Bugs.zip").toFile();
//-
// Чистка старых бекапов на самом сервере.
Utils.keepNewFiles(todayBackUp.getParentFile(), 2);
if (!todayBackUpArchive.exists()) {
FileUtils.forceMkdir(todayBackUp);
Files.copy(db.getFile().toPath(), bugsDBBackUp.toPath());
//-
zip.Do("Bugs", bugsArchives.getAbsolutePath());
zip.Do(todayBackUp.getAbsolutePath(), todayBackUpArchive.getAbsolutePath());
Utils_.forceDeleteWithCheck(todayBackUp);
//-
for (Pair<Machine, User> cred : storages) {
backupSession.Do(cred.getKey(), cred.getValue(), todayBackUpArchive);
}
//bonus backup
//todo оформить как у планировщика, так как это нить, напрямую сервер трогать нельзя.
if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
EmailMessage message = new EmailMessage("db backup", "копия баз данных журнала ошибок");
message.addAttachement(db.getFile());
for (String address : Constants.admins_mails) {
Email(message, address);
}
}
}
}
//-------------------------------------
Thread.sleep(60000);
} catch (Exception ex) {
Utils_.MainLog.PrintException(ex);
}
}
});
public ComponentsServer() { public ComponentsServer() {
super(BugReportsDatabase.class); super(BugReportsDatabase.class);
} }
@@ -113,6 +52,10 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
return Constants.ComponentsServerPort; return Constants.ComponentsServerPort;
} }
@Override @Override
protected void extraBackup(File todayBackUp) {
zip.Do("Bugs",new File (todayBackUp, "Bugs.zip").getAbsolutePath());
}
@Override
protected void beforePublishAction(DBObject object) throws Exception { protected void beforePublishAction(DBObject object) throws Exception {
if (object instanceof BugReport) { if (object instanceof BugReport) {
BugReport bugReport = (BugReport) object; BugReport bugReport = (BugReport) object;
@@ -151,10 +94,6 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
@Override
protected void startAdditionalThreads() {
backUp.start();
}
//- //-
void DVMConvertProject() throws Exception { void DVMConvertProject() throws Exception {
String[] args = request.arg.split("\n"); String[] args = request.arg.split("\n");

View File

@@ -3,7 +3,7 @@ import Common.Utils.Vector_;
import java.util.Vector; import java.util.Vector;
public class Constants { public class Constants {
public static final int version = 1200; public static final int version = 1201;
public static final int planner_version = 12; public static final int planner_version = 12;
public static final int testingMaxKernels = 64; public static final int testingMaxKernels = 64;
//-- //--

View File

@@ -39,7 +39,7 @@ public class Global {
public static File KeysDirectory; public static File KeysDirectory;
public static File DataDirectory; public static File DataDirectory;
public static File BugReportsDirectory; public static File BugReportsDirectory;
public static File BackUpsDirectory; public static File BackUpsDirectory; //бекапы компонентов на локальной машине.
public static File TempDirectory; public static File TempDirectory;
public static File ProjectsDirectory; public static File ProjectsDirectory;
public static File CompilationTasksDirectory; public static File CompilationTasksDirectory;
@@ -48,7 +48,7 @@ public class Global {
public static File RepoDirectory; public static File RepoDirectory;
public static File TestsDirectory; public static File TestsDirectory;
public static File PerformanceAnalyzerDirectory; public static File PerformanceAnalyzerDirectory;
public static File DataBackUpsDirectory; public static File DataBackUpsDirectory; //бекапы данных сервера.
public static File DVMPackagesDirectory; public static File DVMPackagesDirectory;
public static File SapforsDirectory; public static File SapforsDirectory;
public static File SapforPackagesDirectory; public static File SapforPackagesDirectory;
@@ -61,8 +61,8 @@ public class Global {
public static Visualiser visualiser = null; public static Visualiser visualiser = null;
public static Visualizer_2 visualizer_2 = null; public static Visualizer_2 visualizer_2 = null;
public static void CheckVisualiserDirectories() { public static void CheckVisualiserDirectories() {
Utils_.CheckDirectory(ComponentsDirectory = new File(Utils_.getHomeDirectory(), Constants.ComponentsDirectoryName));
Utils_.CheckAndCleanDirectory(TempDirectory = new File(Utils_.getHomeDirectory(), Constants.TempDirectoryName)); Utils_.CheckAndCleanDirectory(TempDirectory = new File(Utils_.getHomeDirectory(), Constants.TempDirectoryName));
Utils_.CheckDirectory(ComponentsDirectory = new File(Utils_.getHomeDirectory(), Constants.ComponentsDirectoryName));
Utils_.CheckDirectory(DataDirectory = new File(Utils_.getHomeDirectory(), Constants.DataDirectoryName)); Utils_.CheckDirectory(DataDirectory = new File(Utils_.getHomeDirectory(), Constants.DataDirectoryName));
//- //-
Utils_.CheckDirectory(RepoDirectory = new File(Utils_.getHomeDirectory(), Constants.RepoDirectoryName)); Utils_.CheckDirectory(RepoDirectory = new File(Utils_.getHomeDirectory(), Constants.RepoDirectoryName));
@@ -84,17 +84,18 @@ public class Global {
} }
} }
public static void CheckServerDirectories() { public static void CheckServerDirectories() {
Utils_.CheckDirectory(ComponentsDirectory = new File(Utils_.getHomeDirectory(), Constants.ComponentsDirectoryName));
Utils_.CheckAndCleanDirectory(TempDirectory = new File(Utils_.getHomeDirectory(), Constants.TempDirectoryName)); Utils_.CheckAndCleanDirectory(TempDirectory = new File(Utils_.getHomeDirectory(), Constants.TempDirectoryName));
Utils_.CheckDirectory(ComponentsDirectory = new File(Utils_.getHomeDirectory(), Constants.ComponentsDirectoryName));
Utils_.CheckDirectory(DataDirectory = new File(Utils_.getHomeDirectory(), Constants.DataDirectoryName)); Utils_.CheckDirectory(DataDirectory = new File(Utils_.getHomeDirectory(), Constants.DataDirectoryName));
//-
Utils_.CheckDirectory(BugReportsDirectory = new File(Utils_.getHomeDirectory(), Constants.BugsDirectoryName));
Utils_.CheckDirectory(DataBackUpsDirectory = new File(Utils_.getHomeDirectory(), Constants.DataBackUpsDirectoryName)); Utils_.CheckDirectory(DataBackUpsDirectory = new File(Utils_.getHomeDirectory(), Constants.DataBackUpsDirectoryName));
//--
Utils_.CheckDirectory(BugReportsDirectory = new File(Utils_.getHomeDirectory(), Constants.BugsDirectoryName));
Utils_.CheckDirectory(KeysDirectory = new File(Utils_.getHomeDirectory(), Constants.KeyDirectoryName)); Utils_.CheckDirectory(KeysDirectory = new File(Utils_.getHomeDirectory(), Constants.KeyDirectoryName));
} }
public static void CheckTestingSystemDirectories() { public static void CheckTestingSystemDirectories() {
Utils_.CheckAndCleanDirectory(TempDirectory = new File(Utils_.getHomeDirectory(), Constants.TempDirectoryName)); Utils_.CheckAndCleanDirectory(TempDirectory = new File(Utils_.getHomeDirectory(), Constants.TempDirectoryName));
Utils_.CheckDirectory(DataDirectory = new File(Utils_.getHomeDirectory(), Constants.DataDirectoryName)); Utils_.CheckDirectory(DataDirectory = new File(Utils_.getHomeDirectory(), Constants.DataDirectoryName));
Utils_.CheckDirectory(DataBackUpsDirectory = new File(Utils_.getHomeDirectory(), Constants.DataBackUpsDirectoryName));
//- //-
Utils_.CheckDirectory(TestsDirectory = new File(Utils_.getHomeDirectory(), Constants.TestsDirectoryName)); Utils_.CheckDirectory(TestsDirectory = new File(Utils_.getHomeDirectory(), Constants.TestsDirectoryName));
Utils_.CheckDirectory(RepoDirectory = new File(Utils_.getHomeDirectory(), Constants.RepoDirectoryName)); Utils_.CheckDirectory(RepoDirectory = new File(Utils_.getHomeDirectory(), Constants.RepoDirectoryName));

View File

@@ -28,10 +28,12 @@ public class MainModule extends MainModule_<GlobalDatabase, MainUI> {
PassCode.ShutdownComponentsServer, PassCode.ShutdownComponentsServer,
PassCode.StartComponentsServer, PassCode.StartComponentsServer,
PassCode.PublishComponentsServer, PassCode.PublishComponentsServer,
PassCode.ComponentsServerBackUp,
// //
PassCode.ShutdownTestingServer, PassCode.ShutdownTestingServer,
PassCode.StartTestingServer, PassCode.StartTestingServer,
PassCode.PublishTestingServer, PassCode.PublishTestingServer,
PassCode.TestingServerBackUp,
PassCode.CreateTestsGroupFromSelectedVersions, PassCode.CreateTestsGroupFromSelectedVersions,
PassCode.RefreshDVMPackageResults, PassCode.RefreshDVMPackageResults,
PassCode.ConvertCorrectnessTests PassCode.ConvertCorrectnessTests

View File

@@ -0,0 +1,14 @@
package _VisualDVM.Passes.All;
import _VisualDVM.Global;
import _VisualDVM.Passes.Server.ComponentsServerPass;
import _VisualDVM.Repository.Server.ServerCode;
public class ComponentsServerBackUp extends ComponentsServerPass {
@Override
public String getIconPath() {
return "/icons/BackUp.png";
}
@Override
protected boolean canStart(Object... args) throws Exception {
return Global.mainModule.getAccount().isAdmin()&&SendRequest(ServerCode.CreateBackUp,"", true);
}
}

View File

@@ -0,0 +1,14 @@
package _VisualDVM.Passes.All;
import _VisualDVM.Global;
import _VisualDVM.Passes.Server.TestingServerPass;
import _VisualDVM.Repository.Server.ServerCode;
public class TestingServerBackUp extends TestingServerPass {
@Override
public String getIconPath() {
return "/icons/BackUp.png";
}
@Override
protected boolean canStart(Object... args) throws Exception {
return Global.mainModule.getAccount().isAdmin()&&SendRequest(ServerCode.CreateBackUp,"", true);
}
}

View File

@@ -354,12 +354,18 @@ public enum PassCode implements PassCode_ {
PublishUserAccount, PublishUserAccount,
EditUserAccount, EditUserAccount,
DeleteUserAccount, DeleteUserAccount,
GetDVMPackageCredetials GetDVMPackageCredetials,
ComponentsServerBackUp,
TestingServerBackUp
; ;
//-- //--
@Override @Override
public String getDescription() { public String getDescription() {
switch (this) { switch (this) {
case ComponentsServerBackUp:
return "Создание резервной копии данных сервера компонент";
case TestingServerBackUp:
return "Создание резервной копии данных сервера компонент";
case GetDVMPackageCredetials: case GetDVMPackageCredetials:
return "Получение входных данных пакета тестирования DVM"; return "Получение входных данных пакета тестирования DVM";
case PublishUserAccount: case PublishUserAccount:

View File

@@ -0,0 +1,21 @@
package _VisualDVM.Repository.Server;
import java.util.Calendar;
public class BackUpsChecker extends RepositoryServerClient {
RepositoryServer server;
@Override
protected RepositoryServer getServer() {
return server;
}
public BackUpsChecker(RepositoryServer server_in) {
server = server_in;
}
@Override
protected void perform() throws Exception {
Calendar rightNow = Calendar.getInstance();
int hour = rightNow.get(Calendar.HOUR_OF_DAY);
int minute = rightNow.get(Calendar.MINUTE);
if ((hour == 0) && (minute == 0)) {
ServerCommand(ServerCode.CreateBackUp,false);
}
}
}

View File

@@ -6,10 +6,15 @@ import Common.Database.RepositoryRefuseException;
import Common.Utils.InterruptThread; import Common.Utils.InterruptThread;
import Common.Utils.Utils_; import Common.Utils.Utils_;
import _VisualDVM.Constants; import _VisualDVM.Constants;
import _VisualDVM.Global;
import _VisualDVM.Passes.All.ArchivesBackupPass;
import _VisualDVM.Passes.All.UnzipFolderPass;
import _VisualDVM.Passes.All.ZipFolderPass;
import _VisualDVM.Passes.Server.RepositoryPass; import _VisualDVM.Passes.Server.RepositoryPass;
import _VisualDVM.Repository.EmailMessage; import _VisualDVM.Repository.EmailMessage;
import _VisualDVM.Utils; import _VisualDVM.Utils;
import javafx.util.Pair; import javafx.util.Pair;
import org.apache.commons.io.FileUtils;
import sun.misc.SignalHandler; import sun.misc.SignalHandler;
import javax.activation.DataHandler; import javax.activation.DataHandler;
@@ -23,10 +28,8 @@ import javax.mail.internet.MimeMultipart;
import java.io.*; import java.io.*;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.util.Date; import java.nio.file.Files;
import java.util.LinkedHashMap; import java.util.*;
import java.util.Properties;
import java.util.Vector;
public abstract class RepositoryServer<D extends Database> { public abstract class RepositoryServer<D extends Database> {
protected static FileWriter Log; protected static FileWriter Log;
protected static boolean printOn = true; protected static boolean printOn = true;
@@ -43,15 +46,40 @@ public abstract class RepositoryServer<D extends Database> {
//- //-
protected ServerCode code; protected ServerCode code;
protected long count = 0; //для отладки. protected long count = 0; //для отладки.
BackUpsChecker backUpsChecker = null;
/*
public static Vector<Pair<Machine, User>> storages = new Vector<>(
Arrays.asList(new Pair<>(new Machine("titan",
"dvmh.keldysh.ru",
22, MachineType.Server),
new User("dvmuser1", "mprit_2011"))
));
//-
*/
protected Thread interruptThread = new InterruptThread(10000, protected Thread interruptThread = new InterruptThread(10000,
() -> { () -> {
System.exit(0); System.exit(0);
return null; return null;
}); });
protected Thread backUpsThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
backUpsChecker.Perform();
Utils_.sleep(60000);
}
}
});
Class<D> d_class; Class<D> d_class;
//-----------RECURSION -> //-----------RECURSION ->
SignalHandler signalHandler = signal -> { SignalHandler signalHandler = signal -> {
}; };
//--
public static ZipFolderPass zip = new ZipFolderPass();
public static UnzipFolderPass unzip = new UnzipFolderPass();
public static ArchivesBackupPass backupSession = new ArchivesBackupPass();
//--
public RepositoryServer(Class<D> d_class_in) { public RepositoryServer(Class<D> d_class_in) {
d_class = d_class_in; d_class = d_class_in;
} }
@@ -160,7 +188,11 @@ public abstract class RepositoryServer<D extends Database> {
DiagnosticSignalHandler.install("TERM", signalHandler); DiagnosticSignalHandler.install("TERM", signalHandler);
DiagnosticSignalHandler.install("INT", signalHandler); DiagnosticSignalHandler.install("INT", signalHandler);
DiagnosticSignalHandler.install("ABRT", signalHandler); DiagnosticSignalHandler.install("ABRT", signalHandler);
//--
interruptThread.start(); interruptThread.start();
backUpsChecker = new BackUpsChecker(this);
backUpsThread.start();
//--
startAdditionalThreads(); startAdditionalThreads();
server = new ServerSocket(getPort()); server = new ServerSocket(getPort());
StartAction(); StartAction();
@@ -198,6 +230,9 @@ public abstract class RepositoryServer<D extends Database> {
case Email: case Email:
Email(); Email();
break; break;
case CreateBackUp:
CreateBackUp();
break;
case EditObject: case EditObject:
EditObject(); EditObject();
break; break;
@@ -324,6 +359,53 @@ public abstract class RepositoryServer<D extends Database> {
} }
void Email() throws Exception { void Email() throws Exception {
Email((EmailMessage) request.object, request.arg); Email((EmailMessage) request.object, request.arg);
}
void CreateBackUp() throws Exception {
//определить имя папки с багом.
boolean force = (boolean) request.object;
//--
Calendar rightNow = Calendar.getInstance();
int year = rightNow.get(Calendar.YEAR);
int month = rightNow.get(Calendar.MONTH);
int day = rightNow.get(Calendar.DAY_OF_MONTH);
//--
String backUpName = year + "_" + (month + 1) + "_" + (day);
File todayBackUp = new File(Global.DataBackUpsDirectory, backUpName);
File todayBackUpArchive = new File(Global.DataBackUpsDirectory, backUpName + ".zip");
if (force&&todayBackUpArchive.exists())
Utils_.forceDeleteWithCheck(todayBackUpArchive);
//-
// Чистка старых бекапов на самом сервере.
Utils.keepNewFiles(todayBackUp.getParentFile(), 2);
if (!todayBackUpArchive.exists()) {
FileUtils.forceMkdir(todayBackUp);
//--
File dbBackUp = new File(todayBackUp, db.getFile().getName());
Files.copy(db.getFile().toPath(), dbBackUp.toPath());
//--перегружаемая часть.
extraBackup(todayBackUp);
//--- общая часть.
zip.Do(todayBackUp.getAbsolutePath(), todayBackUpArchive.getAbsolutePath());
Utils_.forceDeleteWithCheck(todayBackUp);
//-
// for (Pair<Machine, User> cred : storages) {
// backupSession.Do(cred.getKey(), cred.getValue(), todayBackUpArchive);
// }
//bonus backup
if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
EmailMessage message = new EmailMessage(getClass().getSimpleName()+" BackUp",
"Резервная копия файлов");
message.addAttachement(todayBackUpArchive);
for (String address : Constants.admins_mails) {
Email(message, address);
}
}
}
};
protected void extraBackup(File todayBackUp){
} }
//---- //----
void PublishObject() throws Exception { void PublishObject() throws Exception {

View File

@@ -0,0 +1,77 @@
package _VisualDVM.Repository.Server;
import Common.Passes.PassException;
import Common.Utils.Utils_;
import _VisualDVM.Global;
import _VisualDVM.Passes.Server.RepositoryPass;
import _VisualDVM.TestingSystem.Common.TestingServer;
import java.io.FileWriter;
import java.io.Serializable;
import java.util.Date;
public abstract class RepositoryServerClient<T extends RepositoryServer> {
protected abstract T getServer();
protected int getSleepMillis() {
return 2000;
}
//---
protected boolean isPrintOn() {
return true;
}
protected void Print(String message) {
try {
if (isPrintOn()) {
FileWriter testLog = new FileWriter(getClass().getSimpleName() + "_Log.txt", true);
String dmessage = Utils_.Brackets(new Date()) + " " + message;
testLog.write(dmessage + "\n");
testLog.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
//--
protected Object ServerCommand(ServerCode code_in, String arg, Serializable object_in) throws Exception {
RepositoryPass<T,Object> pass = new RepositoryPass<T, Object>(getServer()) {
@Override
public String getDescription() {
return "";
}
@Override
protected void ServerAction() throws Exception {
Command(new SafeServerExchangeUnit(code_in, arg, object_in));
target = server_response.object;
}
@Override
protected boolean validate() {
return Log.isEmpty();
}
@Override
protected int getTimeout() {
return 0;
}
};
if (!pass.Do()) {
ServerConnectionError(code_in, pass.Log.toString());
}
return pass.target;
}
protected Object ServerCommand(ServerCode code_in, Serializable object_in) throws Exception {
return ServerCommand(code_in, "", object_in);
}
protected Object ServerCommand(ServerCode code_in) throws Exception {
return ServerCommand(code_in, "", null);
}
protected void ServerConnectionError(ServerCode code_in, String logText) throws Exception {
throw new PassException(Utils_.Brackets(new Date().toString()) + " Ошибка взаимодействия с сервером " + code_in);
}
protected abstract void perform() throws Exception;
public void Perform() {
try {
perform();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
Utils_.sleep(getSleepMillis());
}
}
}

View File

@@ -68,9 +68,12 @@ public enum ServerCode {
EditUserAccount, EditUserAccount,
PublishUserAccount, PublishUserAccount,
DeleteUserAccount, DeleteUserAccount,
GetDVMPackageCredentials; GetDVMPackageCredentials,
CreateBackUp;
public String getDescription(){ public String getDescription(){
switch (this){ switch (this){
case CreateBackUp:
return "Создание резервной копии данных сервера";
case GetDVMPackageCredentials: case GetDVMPackageCredentials:
return "Получение входных данных пакета тестирования DVM на сервере"; return "Получение входных данных пакета тестирования DVM на сервере";
case DeleteUserAccount: case DeleteUserAccount:

View File

@@ -3,76 +3,16 @@ import Common.Passes.PassException;
import Common.Utils.Utils_; import Common.Utils.Utils_;
import _VisualDVM.Global; import _VisualDVM.Global;
import _VisualDVM.Passes.Server.RepositoryPass; import _VisualDVM.Passes.Server.RepositoryPass;
import _VisualDVM.Repository.Server.RepositoryServerClient;
import _VisualDVM.Repository.Server.SafeServerExchangeUnit; import _VisualDVM.Repository.Server.SafeServerExchangeUnit;
import _VisualDVM.Repository.Server.ServerCode; import _VisualDVM.Repository.Server.ServerCode;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
public abstract class TestingClient { public abstract class TestingClient extends RepositoryServerClient<TestingServer> {
//-- @Override
protected int getSleepMillis() { protected TestingServer getServer() {
return 2000; return Global.testingServer;
}
//---
protected boolean isPrintOn() {
return true;
}
protected void Print(String message) {
try {
if (isPrintOn()) {
FileWriter testLog = new FileWriter(getClass().getSimpleName() + "_Log.txt", true);
String dmessage = Utils_.Brackets(new Date()) + " " + message;
testLog.write(dmessage + "\n");
testLog.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
//--
protected Object ServerCommand(ServerCode code_in, String arg, Serializable object_in) throws Exception {
RepositoryPass<TestingServer,Object> pass = new RepositoryPass<TestingServer, Object>(Global.testingServer) {
@Override
public String getDescription() {
return "";
}
@Override
protected void ServerAction() throws Exception {
Command(new SafeServerExchangeUnit(code_in, arg, object_in));
target = server_response.object;
}
@Override
protected boolean validate() {
return Log.isEmpty();
}
@Override
protected int getTimeout() {
return 0;
}
};
if (!pass.Do()) {
ServerConnectionError(code_in, pass.Log.toString());
}
return pass.target;
}
protected Object ServerCommand(ServerCode code_in, Serializable object_in) throws Exception {
return ServerCommand(code_in, "", object_in);
}
protected Object ServerCommand(ServerCode code_in) throws Exception {
return ServerCommand(code_in, "", null);
}
protected void ServerConnectionError(ServerCode code_in, String logText) throws Exception {
throw new PassException(Utils_.Brackets(new Date().toString()) + " Ошибка взаимодействия с сервером " + code_in);
}
public abstract void perform() throws Exception;
public void Perform() {
try {
perform();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
Utils_.sleep(getSleepMillis());
}
} }
} }

View File

@@ -86,7 +86,10 @@ public class TestingMenuBar extends VisualiserMenuBar {
}); });
addSeparator(); addSeparator();
serverAdminLabel = addLabel(" управление сервером "); serverAdminLabel = addLabel(" управление сервером ");
addPasses(PassCode.StartTestingServer, PassCode.ShutdownTestingServer, PassCode.PublishTestingServer); addPasses(PassCode.StartTestingServer,
PassCode.ShutdownTestingServer,
PassCode.PublishTestingServer,
PassCode.TestingServerBackUp);
} }
public void ShowAutoCheckTesting() { public void ShowAutoCheckTesting() {
autorefreshButton.setIcon(Utils_.getIcon(Global.normalProperties.AutoCheckTesting ? "/Common/icons/Pick.png" : "/Common/icons/NotPick.png")); autorefreshButton.setIcon(Utils_.getIcon(Global.normalProperties.AutoCheckTesting ? "/Common/icons/Pick.png" : "/Common/icons/NotPick.png"));

View File

@@ -85,6 +85,13 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
@Override
protected void extraBackup(File todayBackUp) {
zip.Do("Tests", new File (todayBackUp, "Tests.zip").getAbsolutePath());
zip.Do("Sapfors", new File (todayBackUp, "Sapfors.zip").getAbsolutePath());
zip.Do("DVMPackages", new File (todayBackUp, "DVMPackages.zip").getAbsolutePath());
zip.Do("SapforPackages", new File (todayBackUp, "SapforPackages.zip").getAbsolutePath());
}
public static void TimerOn() { public static void TimerOn() {
checkTimer = new Timer(Global.normalProperties.CheckTestingIntervalSeconds * 1000, e -> { checkTimer = new Timer(Global.normalProperties.CheckTestingIntervalSeconds * 1000, e -> {
Global.mainModule.getPass(PassCode.ActualizePackages).Do(); Global.mainModule.getPass(PassCode.ActualizePackages).Do();

View File

@@ -264,6 +264,7 @@ public class CallbackForm implements FormWithSplitters, CallbackWindow {
accountTools.add(Global.mainModule.getPass(PassCode.StartComponentsServer).createButton()); accountTools.add(Global.mainModule.getPass(PassCode.StartComponentsServer).createButton());
accountTools.add(Global.mainModule.getPass(PassCode.ShutdownComponentsServer).createButton()); accountTools.add(Global.mainModule.getPass(PassCode.ShutdownComponentsServer).createButton());
accountTools.add(Global.mainModule.getPass(PassCode.PublishComponentsServer).createButton()); accountTools.add(Global.mainModule.getPass(PassCode.PublishComponentsServer).createButton());
accountTools.add(Global.mainModule.getPass(PassCode.ComponentsServerBackUp).createButton());
} }
public void LockMyOnly() { public void LockMyOnly() {
if (!BugReportsMyOnlyFilter.isSelected()) { if (!BugReportsMyOnlyFilter.isSelected()) {

BIN
src/icons/BackUp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB