use of org.entando.entando.aps.system.init.model.DataSourceDumpReport in project entando-core by entando.
the class DatabaseControllerTest method startBackup.
@Test
public void startBackup() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String xml = null;
DataSourceDumpReport report = new DataSourceDumpReport(xml);
when(databaseManager.getBackupReport(ArgumentMatchers.anyString())).thenReturn(report);
ResultActions result = mockMvc.perform(post("/database/startBackup").content("{}").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
Mockito.verify(databaseService, Mockito.times(1)).startDatabaseBackup();
}
use of org.entando.entando.aps.system.init.model.DataSourceDumpReport in project entando-core by entando.
the class DatabaseControllerTest method deleteReport.
@Test
public void deleteReport() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String xml = null;
DataSourceDumpReport report = new DataSourceDumpReport(xml);
when(databaseManager.getBackupReport(ArgumentMatchers.anyString())).thenReturn(report);
ResultActions result = mockMvc.perform(delete("/database/report/{reportCode}", new Object[] { "reportCode" }).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
Mockito.verify(databaseService, Mockito.times(1)).deleteDumpReport("reportCode");
}
use of org.entando.entando.aps.system.init.model.DataSourceDumpReport in project entando-core by entando.
the class DatabaseService method getDumpReportDto.
@Override
public DumpReportDto getDumpReportDto(String reportCode) {
DumpReportDto dtos = null;
try {
DataSourceDumpReport report = this.getDatabaseManager().getBackupReport(reportCode);
if (null == report) {
logger.warn("no dump found with code {}", reportCode);
throw new RestRourceNotFoundException(DatabaseValidator.ERRCODE_NO_DUMP_FOUND, "reportCode", reportCode);
}
dtos = new DumpReportDto(report, this.getComponentManager());
} catch (RestRourceNotFoundException r) {
throw r;
} catch (Throwable t) {
logger.error("error extracting database report {}", reportCode, t);
throw new RestServerError("error extracting database report " + reportCode, t);
}
return dtos;
}
use of org.entando.entando.aps.system.init.model.DataSourceDumpReport in project entando-core by entando.
the class DatabaseDumper method createBackup.
protected void createBackup(AbstractInitializerManager.Environment environment, SystemInstallationReport installationReport) throws ApsSystemException {
try {
DataSourceDumpReport report = new DataSourceDumpReport(installationReport);
long start = System.currentTimeMillis();
String backupSubFolder = (AbstractInitializerManager.Environment.develop.equals(environment)) ? environment.toString() : DateConverter.getFormattedDate(new Date(), "yyyyMMddHHmmss");
report.setSubFolderName(backupSubFolder);
List<Component> components = this.getComponents();
for (int i = 0; i < components.size(); i++) {
Component componentConfiguration = components.get(i);
this.createBackup(componentConfiguration.getTableMapping(), report, backupSubFolder);
}
this.createBackup(this.getEntandoTableMapping(), report, backupSubFolder);
long time = System.currentTimeMillis() - start;
report.setRequiredTime(time);
report.setDate(new Date());
StringBuilder reportFolder = new StringBuilder(this.getLocalBackupsFolder());
if (null != backupSubFolder) {
reportFolder.append(backupSubFolder).append(File.separator);
}
this.save(DatabaseManager.DUMP_REPORT_FILE_NAME, reportFolder.toString(), report.toXml());
} catch (Throwable t) {
_logger.error("error in ", t);
throw new ApsSystemException("Error while creating backup", t);
}
}
use of org.entando.entando.aps.system.init.model.DataSourceDumpReport in project entando-core by entando.
the class DatabaseManager method installDatabase.
@Override
public SystemInstallationReport installDatabase(SystemInstallationReport report, boolean checkOnStatup) throws Exception {
String lastLocalBackupFolder = null;
if (null == report) {
report = SystemInstallationReport.getInstance();
if (checkOnStatup && !Environment.test.equals(this.getEnvironment())) {
// non c'è db locale installato, cerca nei backup locali
DataSourceDumpReport lastDumpReport = this.getLastDumpReport();
if (null != lastDumpReport) {
lastLocalBackupFolder = lastDumpReport.getSubFolderName();
report.setStatus(SystemInstallationReport.Status.RESTORE);
} else {
// SE NON c'è cerca il default dump
Map<String, Resource> sqlDump = this.getDefaultSqlDump();
if (null != sqlDump && sqlDump.size() > 0) {
report.setStatus(SystemInstallationReport.Status.RESTORE);
}
}
}
}
try {
this.initMasterDatabases(report, checkOnStatup);
List<Component> components = this.getComponentManager().getCurrentComponents();
for (Component entandoComponentConfiguration : components) {
this.initComponentDatabases(entandoComponentConfiguration, report, checkOnStatup);
}
this.initMasterDefaultResource(report, checkOnStatup);
for (Component entandoComponentConfiguration : components) {
this.initComponentDefaultResources(entandoComponentConfiguration, report, checkOnStatup);
}
if (checkOnStatup && report.getStatus().equals(SystemInstallationReport.Status.RESTORE)) {
// ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH:MI:SS.FF'
if (null != lastLocalBackupFolder) {
this.restoreBackup(lastLocalBackupFolder);
} else {
this.restoreDefaultDump();
}
}
} catch (Throwable t) {
if (null != report && report.isUpdated()) {
report.setUpdated();
report.setStatus(SystemInstallationReport.Status.INCOMPLETE);
}
logger.error("Error while initializating Db Installer", t);
throw new Exception("Error while initializating Db Installer", t);
}
return report;
}
Aggregations