Search in sources :

Example 6 with Component

use of org.entando.entando.aps.system.init.model.Component 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 7 with Component

use of org.entando.entando.aps.system.init.model.Component 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)

Example 8 with Component

use of org.entando.entando.aps.system.init.model.Component in project entando-core by entando.

the class DatabaseRestorer method dropAndRestoreBackup.

protected void dropAndRestoreBackup(String backupSubFolder) throws ApsSystemException {
    try {
        List<Component> components = this.getComponents();
        int size = components.size();
        for (int i = 0; i < components.size(); i++) {
            Component componentConfiguration = components.get(size - i - 1);
            this.dropTables(componentConfiguration.getTableMapping());
        }
        this.dropTables(this.getEntandoTableMapping());
        this.restoreBackup(backupSubFolder);
    } catch (Throwable t) {
        _logger.error("Error while restoring backup: {}", backupSubFolder, t);
        throw new ApsSystemException("Error while restoring backup", t);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Component(org.entando.entando.aps.system.init.model.Component)

Example 9 with Component

use of org.entando.entando.aps.system.init.model.Component in project entando-core by entando.

the class DatabaseRestorer method restoreBackup.

protected void restoreBackup(String backupSubFolder) throws ApsSystemException {
    try {
        this.restoreLocalDump(this.getEntandoTableMapping(), backupSubFolder);
        List<Component> components = this.getComponents();
        for (int i = 0; i < components.size(); i++) {
            Component componentConfiguration = components.get(i);
            this.restoreLocalDump(componentConfiguration.getTableMapping(), backupSubFolder);
        }
    } catch (Throwable t) {
        _logger.error("Error while restoring local backup", t);
        throw new ApsSystemException("Error while restoring local backup", t);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Component(org.entando.entando.aps.system.init.model.Component)

Example 10 with Component

use of org.entando.entando.aps.system.init.model.Component in project entando-core by entando.

the class InitializerManager method executePostInitProcesses.

public void executePostInitProcesses() throws BeansException {
    SystemInstallationReport report = null;
    try {
        report = this.extractReport();
        List<Component> components = this.getComponentManager().getCurrentComponents();
        for (int i = 0; i < components.size(); i++) {
            Component component = components.get(i);
            ComponentInstallationReport componentReport = report.getComponentReport(component.getCode(), false);
            SystemInstallationReport.Status postProcessStatus = componentReport.getPostProcessStatus();
            if (!postProcessStatus.equals(SystemInstallationReport.Status.INIT)) {
                continue;
            }
            String compEnvKey = (AbstractInitializerManager.Environment.test.equals(this.getEnvironment())) ? AbstractInitializerManager.Environment.test.toString() : AbstractInitializerManager.Environment.production.toString();
            ComponentEnvironment componentEnvironment = (null != component.getEnvironments()) ? component.getEnvironments().get(compEnvKey) : null;
            List<IPostProcess> postProcesses = (null != componentEnvironment) ? componentEnvironment.getPostProcesses() : null;
            if (null == postProcesses || postProcesses.isEmpty()) {
                postProcessStatus = SystemInstallationReport.Status.NOT_AVAILABLE;
            } else if (!this.isCheckOnStartup()) {
                postProcessStatus = SystemInstallationReport.Status.SKIPPED;
            } else if (!componentReport.isPostProcessExecutionRequired()) {
                // Porting or restore
                postProcessStatus = SystemInstallationReport.Status.NOT_AVAILABLE;
            } else {
                postProcessStatus = this.executePostProcesses(postProcesses);
            }
            componentReport.setPostProcessStatus(postProcessStatus);
            report.setUpdated();
        }
    } catch (Throwable t) {
        logger.error("Error while executing post processes", t);
        throw new FatalBeanException("Error while executing post processes", t);
    } finally {
        if (null != report && report.isUpdated()) {
            this.saveReport(report);
        }
    }
}
Also used : ComponentEnvironment(org.entando.entando.aps.system.init.model.ComponentEnvironment) IPostProcess(org.entando.entando.aps.system.init.model.IPostProcess) ComponentInstallationReport(org.entando.entando.aps.system.init.model.ComponentInstallationReport) FatalBeanException(org.springframework.beans.FatalBeanException) SystemInstallationReport(org.entando.entando.aps.system.init.model.SystemInstallationReport) Component(org.entando.entando.aps.system.init.model.Component)

Aggregations

Component (org.entando.entando.aps.system.init.model.Component)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)5 ArrayList (java.util.ArrayList)3 ComponentInstallationReport (org.entando.entando.aps.system.init.model.ComponentInstallationReport)2 DataSourceDumpReport (org.entando.entando.aps.system.init.model.DataSourceDumpReport)2 Resource (org.springframework.core.io.Resource)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 ComponentEnvironment (org.entando.entando.aps.system.init.model.ComponentEnvironment)1 IPostProcess (org.entando.entando.aps.system.init.model.IPostProcess)1 SystemInstallationReport (org.entando.entando.aps.system.init.model.SystemInstallationReport)1 ComponentLoader (org.entando.entando.aps.system.init.util.ComponentLoader)1 Element (org.jdom.Element)1 FatalBeanException (org.springframework.beans.FatalBeanException)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1