Search in sources :

Example 6 with DataSourceDumpReport

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();
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) DataSourceDumpReport(org.entando.entando.aps.system.init.model.DataSourceDumpReport) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 7 with DataSourceDumpReport

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");
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) DataSourceDumpReport(org.entando.entando.aps.system.init.model.DataSourceDumpReport) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 8 with DataSourceDumpReport

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;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) DataSourceDumpReport(org.entando.entando.aps.system.init.model.DataSourceDumpReport) ShortDumpReportDto(org.entando.entando.aps.system.services.database.model.ShortDumpReportDto) DumpReportDto(org.entando.entando.aps.system.services.database.model.DumpReportDto) RestServerError(org.entando.entando.aps.system.exception.RestServerError)

Example 9 with DataSourceDumpReport

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);
    }
}
Also used : DataSourceDumpReport(org.entando.entando.aps.system.init.model.DataSourceDumpReport) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Component(org.entando.entando.aps.system.init.model.Component) Date(java.util.Date)

Example 10 with DataSourceDumpReport

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;
}
Also used : DataSourceDumpReport(org.entando.entando.aps.system.init.model.DataSourceDumpReport) Resource(org.springframework.core.io.Resource) Component(org.entando.entando.aps.system.init.model.Component) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IOException(java.io.IOException)

Aggregations

DataSourceDumpReport (org.entando.entando.aps.system.init.model.DataSourceDumpReport)10 Test (org.junit.Test)4 UserDetails (com.agiletec.aps.system.services.user.UserDetails)3 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)3 ResultActions (org.springframework.test.web.servlet.ResultActions)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 RestServerError (org.entando.entando.aps.system.exception.RestServerError)2 Component (org.entando.entando.aps.system.init.model.Component)2 DumpReportDto (org.entando.entando.aps.system.services.database.model.DumpReportDto)2 ShortDumpReportDto (org.entando.entando.aps.system.services.database.model.ShortDumpReportDto)2 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)1 Resource (org.springframework.core.io.Resource)1