Search in sources :

Example 6 with SystemInstallationReport

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

the class InitializerManagerTest method should_get_currentReport.

@Test
public void should_get_currentReport() {
    when(cacheWrapper.getReport()).thenReturn(createMockReport());
    SystemInstallationReport report = this.initializerManager.getCurrentReport();
    assertThat(report, is(not(nullValue())));
}
Also used : SystemInstallationReport(org.entando.entando.aps.system.init.model.SystemInstallationReport) Test(org.junit.Test)

Example 7 with SystemInstallationReport

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

the class AbstractInitializerManager method extractReport.

protected SystemInstallationReport extractReport() throws ApsSystemException {
    SystemInstallationReport report = null;
    try {
        InstallationReportDAO dao = new InstallationReportDAO();
        DataSource dataSource = (DataSource) this.getBeanFactory().getBean("portDataSource");
        dao.setDataSource(dataSource);
        report = dao.loadReport(this.getConfigVersion());
    } catch (Throwable t) {
        _logger.error("error Error extracting report", t);
        throw new ApsSystemException("Error extracting report", t);
    }
    return report;
}
Also used : SystemInstallationReport(org.entando.entando.aps.system.init.model.SystemInstallationReport) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DataSource(javax.sql.DataSource)

Example 8 with SystemInstallationReport

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

the class DatabaseManager method initComponentDefaultResources.

private void initComponentDefaultResources(Component componentConfiguration, SystemInstallationReport report, boolean checkOnStatup) throws ApsSystemException {
    String logPrefix = "|   ";
    System.out.println("+ [ Component: " + componentConfiguration.getCode() + " ] :: DATA\n" + logPrefix);
    ComponentInstallationReport componentReport = report.getComponentReport(componentConfiguration.getCode(), false);
    if (componentReport.getStatus().equals(SystemInstallationReport.Status.OK)) {
        logger.debug(logPrefix + "( ok )  Already installed\n" + logPrefix);
        System.out.println(logPrefix + "( ok )  Already installed\n" + logPrefix);
        return;
    } else if (componentReport.getStatus().equals(SystemInstallationReport.Status.UNINSTALLED)) {
        logger.debug(logPrefix + "( ok )  Uninstalled\n" + logPrefix);
        System.out.println(logPrefix + "( ok )  Uninstalled\n" + logPrefix);
        return;
    }
    DataInstallationReport dataReport = componentReport.getDataReport();
    try {
        System.out.println(logPrefix + "Starting installation\n" + logPrefix);
        String[] dataSourceNames = this.extractBeanNames(DataSource.class);
        for (String dataSourceName : dataSourceNames) {
            if ((report.getStatus().equals(SystemInstallationReport.Status.PORTING) || report.getStatus().equals(SystemInstallationReport.Status.RESTORE)) && checkOnStatup) {
                dataReport.getDatabaseStatus().put(dataSourceName, report.getStatus());
                System.out.println("|   ( ok )  " + dataSourceName);
                report.setUpdated();
                continue;
            }
            DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName);
            SystemInstallationReport.Status dataStatus = dataReport.getDatabaseStatus().get(dataSourceName);
            if (SystemInstallationReport.isSafeStatus(dataStatus)) {
                logger.debug(logPrefix + "( ok )  Already installed\n" + logPrefix);
                System.out.println(logPrefix + "( ok )  Already installed\n" + logPrefix);
                continue;
            }
            Map<String, ComponentEnvironment> environments = componentConfiguration.getEnvironments();
            String compEnvKey = (Environment.test.equals(this.getEnvironment())) ? Environment.test.toString() : Environment.production.toString();
            ComponentEnvironment componentEnvironment = (null != environments) ? environments.get(compEnvKey) : null;
            Resource resource = (null != componentEnvironment) ? componentEnvironment.getSqlResources(dataSourceName) : null;
            String script = (null != resource) ? this.readFile(resource) : null;
            if (null != script && script.trim().length() > 0) {
                if (checkOnStatup) {
                    dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.INCOMPLETE);
                    this.getDatabaseRestorer().initOracleSchema(dataSource);
                    TableDataUtils.valueDatabase(script, dataSourceName, dataSource, dataReport);
                    System.out.println("|   ( ok )  " + dataSourceName);
                    dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.OK);
                } else {
                    dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.SKIPPED);
                }
                report.setUpdated();
            } else {
                System.out.println(logPrefix + "( !! )  skipping " + dataSourceName + ": not available");
                dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.NOT_AVAILABLE);
                report.setUpdated();
            }
        }
        System.out.println(logPrefix + "\n" + logPrefix + "Installation complete\n" + logPrefix);
        logger.debug(logPrefix + "\n" + logPrefix + "Installation complete\n" + logPrefix);
    } catch (Throwable t) {
        logger.error("Error restoring default resources of component {}", componentConfiguration.getCode(), t);
        throw new ApsSystemException("Error restoring default resources of component " + componentConfiguration.getCode(), t);
    }
}
Also used : ComponentEnvironment(org.entando.entando.aps.system.init.model.ComponentEnvironment) DataInstallationReport(org.entando.entando.aps.system.init.model.DataInstallationReport) ComponentInstallationReport(org.entando.entando.aps.system.init.model.ComponentInstallationReport) Resource(org.springframework.core.io.Resource) SystemInstallationReport(org.entando.entando.aps.system.init.model.SystemInstallationReport) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DataSource(javax.sql.DataSource)

Example 9 with SystemInstallationReport

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

Example 10 with SystemInstallationReport

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

the class InitializerManager method reloadCurrentReport.

@Override
public void reloadCurrentReport() {
    try {
        SystemInstallationReport report = this.extractReport();
        this.getCacheWrapper().setCurrentReport(report);
    } catch (Throwable t) {
        logger.error("Error reloading report", t);
        throw new RuntimeException("Error reloading report", t);
    }
}
Also used : SystemInstallationReport(org.entando.entando.aps.system.init.model.SystemInstallationReport)

Aggregations

SystemInstallationReport (org.entando.entando.aps.system.init.model.SystemInstallationReport)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)6 DataSource (javax.sql.DataSource)5 ComponentInstallationReport (org.entando.entando.aps.system.init.model.ComponentInstallationReport)5 ComponentEnvironment (org.entando.entando.aps.system.init.model.ComponentEnvironment)2 DataInstallationReport (org.entando.entando.aps.system.init.model.DataInstallationReport)2 DataSourceInstallationReport (org.entando.entando.aps.system.init.model.DataSourceInstallationReport)2 FatalBeanException (org.springframework.beans.FatalBeanException)2 Resource (org.springframework.core.io.Resource)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Component (org.entando.entando.aps.system.init.model.Component)1 IPostProcess (org.entando.entando.aps.system.init.model.IPostProcess)1 InvalidPostProcessResultException (org.entando.entando.aps.system.init.model.InvalidPostProcessResultException)1 Test (org.junit.Test)1 BeansException (org.springframework.beans.BeansException)1