Search in sources :

Example 1 with ComponentEnvironment

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

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

ComponentEnvironment (org.entando.entando.aps.system.init.model.ComponentEnvironment)2 ComponentInstallationReport (org.entando.entando.aps.system.init.model.ComponentInstallationReport)2 SystemInstallationReport (org.entando.entando.aps.system.init.model.SystemInstallationReport)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 DataSource (javax.sql.DataSource)1 Component (org.entando.entando.aps.system.init.model.Component)1 DataInstallationReport (org.entando.entando.aps.system.init.model.DataInstallationReport)1 IPostProcess (org.entando.entando.aps.system.init.model.IPostProcess)1 FatalBeanException (org.springframework.beans.FatalBeanException)1 Resource (org.springframework.core.io.Resource)1