Search in sources :

Example 1 with SystemInstallationReport

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

the class DatabaseManager method initMasterDatabases.

private void initMasterDatabases(SystemInstallationReport report, boolean checkOnStatup) throws ApsSystemException {
    String logPrefix = "|   ";
    System.out.println("+ [ Component: Core ] :: SCHEMA\n" + logPrefix);
    ComponentInstallationReport componentReport = report.getComponentReport("entandoCore", true);
    DataSourceInstallationReport dataSourceReport = componentReport.getDataSourceReport();
    if (componentReport.getStatus().equals(SystemInstallationReport.Status.OK)) {
        logger.debug("{}( ok )  Already installed\n{}", logPrefix, logPrefix);
        System.out.println(logPrefix + "( ok )  Already installed\n" + logPrefix);
        return;
    }
    try {
        String[] dataSourceNames = this.extractBeanNames(DataSource.class);
        Map<String, SystemInstallationReport.Status> databasesStatus = dataSourceReport.getDatabaseStatus();
        System.out.println(logPrefix + "Starting installation");
        for (String dataSourceName : dataSourceNames) {
            if (report.getStatus().equals(SystemInstallationReport.Status.PORTING)) {
                System.out.println(logPrefix + " - Already present! db " + dataSourceName);
                SystemInstallationReport.Status status = (checkOnStatup) ? report.getStatus() : SystemInstallationReport.Status.SKIPPED;
                databasesStatus.put(dataSourceName, status);
                report.setUpdated();
                continue;
            }
            SystemInstallationReport.Status dbStatus = databasesStatus.get(dataSourceName);
            if (dbStatus != null && (SystemInstallationReport.isSafeStatus(dbStatus))) {
                System.out.println(logPrefix + "\n" + logPrefix + "( ok )  " + dataSourceName + " already installed");
            } else if (dbStatus == null || !dbStatus.equals(SystemInstallationReport.Status.OK)) {
                DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName);
                // System.out.println(logPrefix + " - '" + dataSourceName + "' Installation Started... ");
                if (checkOnStatup) {
                    databasesStatus.put(dataSourceName, SystemInstallationReport.Status.INCOMPLETE);
                    System.out.println(logPrefix);
                    this.initMasterDatabase(dataSourceName, dataSource, dataSourceReport);
                    databasesStatus.put(dataSourceName, SystemInstallationReport.Status.OK);
                } else {
                    databasesStatus.put(dataSourceName, SystemInstallationReport.Status.SKIPPED);
                }
                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 initializating master databases", t);
        throw new ApsSystemException("Error initializating master databases", t);
    }
}
Also used : ComponentInstallationReport(org.entando.entando.aps.system.init.model.ComponentInstallationReport) SystemInstallationReport(org.entando.entando.aps.system.init.model.SystemInstallationReport) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DataSourceInstallationReport(org.entando.entando.aps.system.init.model.DataSourceInstallationReport) DataSource(javax.sql.DataSource)

Example 2 with SystemInstallationReport

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

the class DatabaseManager method initMasterDefaultResource.

// ---------------- DATA ------------------- START
private void initMasterDefaultResource(SystemInstallationReport report, boolean checkOnStatup) throws ApsSystemException {
    String logPrefix = "|   ";
    System.out.println("+ [ Component: Core ] :: DATA\n" + logPrefix);
    ComponentInstallationReport coreComponentReport = report.getComponentReport("entandoCore", false);
    if (coreComponentReport.getStatus().equals(SystemInstallationReport.Status.OK)) {
        String message = logPrefix + "( ok )  Already installed. " + coreComponentReport.getStatus() + "\n" + logPrefix;
        logger.debug(message);
        System.out.println(message);
        return;
    }
    DataInstallationReport dataReport = coreComponentReport.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());
                report.setUpdated();
                String message = logPrefix + "( ok )  " + dataSourceName + " already installed. " + report.getStatus() + "\n" + logPrefix;
                logger.debug(message);
                System.out.println(message);
                continue;
            }
            SystemInstallationReport.Status schemaStatus = dataReport.getDatabaseStatus().get(dataSourceName);
            if (SystemInstallationReport.isSafeStatus(schemaStatus)) {
                String message = logPrefix + "( ok )  " + dataSourceName + " already installed. " + report.getStatus() + "\n" + logPrefix;
                System.out.println(message);
                continue;
            }
            Resource resource = (Environment.test.equals(this.getEnvironment())) ? this.getTestSqlResources().get(dataSourceName) : this.getEntandoDefaultSqlResources().get(dataSourceName);
            String script = this.readFile(resource);
            if (null != script && script.trim().length() != 0) {
                if (checkOnStatup) {
                    dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.INCOMPLETE);
                    DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName);
                    this.getDatabaseRestorer().initOracleSchema(dataSource);
                    TableDataUtils.valueDatabase(script, dataSourceName, dataSource, null);
                    dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.OK);
                    System.out.println("|   ( ok )  " + dataSourceName);
                } 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 initializating master DefaultResource", t);
        throw new ApsSystemException("Error initializating master DefaultResource", t);
    }
}
Also used : 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 3 with SystemInstallationReport

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

the class DatabaseManager method initComponentDatabases.

private void initComponentDatabases(Component componentConfiguration, SystemInstallationReport report, boolean checkOnStatup) throws ApsSystemException {
    String logPrefix = "|   ";
    System.out.println("+ [ Component: " + componentConfiguration.getCode() + " ] :: SCHEMA\n" + logPrefix);
    ComponentInstallationReport componentReport = report.getComponentReport(componentConfiguration.getCode(), true);
    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;
    }
    try {
        String[] dataSourceNames = this.extractBeanNames(DataSource.class);
        Map<String, List<String>> tableMapping = componentConfiguration.getTableMapping();
        DataSourceInstallationReport dataSourceReport = componentReport.getDataSourceReport();
        System.out.println(logPrefix + "Starting installation\n" + logPrefix);
        for (String dataSourceName : dataSourceNames) {
            List<String> tableClassNames = (null != tableMapping) ? tableMapping.get(dataSourceName) : null;
            if (null == tableClassNames || tableClassNames.isEmpty()) {
                System.out.println(logPrefix + "( !! )  skipping " + dataSourceName + ": not available");
                dataSourceReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.NOT_AVAILABLE);
                report.setUpdated();
                continue;
            }
            if (report.getStatus().equals(SystemInstallationReport.Status.PORTING)) {
                SystemInstallationReport.Status status = (checkOnStatup) ? report.getStatus() : SystemInstallationReport.Status.SKIPPED;
                dataSourceReport.getDatabaseStatus().put(dataSourceName, status);
                logger.debug(logPrefix + "( ok )  " + dataSourceName + " already installed" + SystemInstallationReport.Status.PORTING);
                System.out.println(logPrefix + "( ok )  " + dataSourceName + " already installed" + SystemInstallationReport.Status.PORTING);
                continue;
            }
            SystemInstallationReport.Status schemaStatus = dataSourceReport.getDatabaseStatus().get(dataSourceName);
            if (SystemInstallationReport.isSafeStatus(schemaStatus)) {
                // Already Done!
                System.out.println(logPrefix + "( ok )  " + dataSourceName + " already installed" + SystemInstallationReport.Status.PORTING);
                continue;
            }
            if (null == dataSourceReport.getDataSourceTables().get(dataSourceName)) {
                dataSourceReport.getDataSourceTables().put(dataSourceName, new ArrayList<String>());
            }
            if (checkOnStatup) {
                dataSourceReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.INCOMPLETE);
                DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName);
                this.createTables(dataSourceName, tableClassNames, dataSource, dataSourceReport);
                System.out.println(logPrefix);
                dataSourceReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.OK);
            } else {
                dataSourceReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.SKIPPED);
            }
            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 initializating component {}", componentConfiguration.getCode(), t);
        throw new ApsSystemException("Error initializating component " + componentConfiguration.getCode(), t);
    }
}
Also used : ComponentInstallationReport(org.entando.entando.aps.system.init.model.ComponentInstallationReport) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DataSourceInstallationReport(org.entando.entando.aps.system.init.model.DataSourceInstallationReport) DataSource(javax.sql.DataSource) ArrayList(java.util.ArrayList) List(java.util.List) SystemInstallationReport(org.entando.entando.aps.system.init.model.SystemInstallationReport)

Example 4 with SystemInstallationReport

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

the class InitializerManager method init.

public void init() throws Exception {
    SystemInstallationReport report = null;
    try {
        report = this.extractReport();
        report = ((IDatabaseInstallerManager) this.getDatabaseManager()).installDatabase(report, this.isCheckOnStartup());
        this.getCacheWrapper().initCache(report);
    } catch (Throwable t) {
        logger.error("Error while initializating Db Installer", t);
        throw new Exception("Error while initializating Db Installer", t);
    } finally {
        if (null != report && report.isUpdated()) {
            this.saveReport(report);
        }
    }
    logger.debug("{}: initializated - Check on startup {}", this.getClass().getName(), this.isCheckOnStartup());
}
Also used : SystemInstallationReport(org.entando.entando.aps.system.init.model.SystemInstallationReport) FatalBeanException(org.springframework.beans.FatalBeanException) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BeansException(org.springframework.beans.BeansException) InvalidPostProcessResultException(org.entando.entando.aps.system.init.model.InvalidPostProcessResultException)

Example 5 with SystemInstallationReport

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

the class InstallationReportDAO method loadReport.

public SystemInstallationReport loadReport(String version) {
    Connection conn = null;
    PreparedStatement stat = null;
    ResultSet res = null;
    SystemInstallationReport report = null;
    try {
        conn = this.getConnection();
        stat = conn.prepareStatement(VERSION_ITEM);
        stat.setString(1, version);
        stat.setString(2, InitializerManager.REPORT_CONFIG_ITEM);
        res = stat.executeQuery();
        if (res.next()) {
            String xml = res.getString(1);
            report = new SystemInstallationReport(xml);
        } else {
            // PORTING
            report = SystemInstallationReport.getPortingInstance();
        }
    } catch (SQLException sqle) {
        // NOT_AVAILABLE
        _logger.info("Report not available" + sqle);
        return null;
    } catch (Throwable t) {
        _logger.error("Error while loading component installation report - version: {}", version, t);
        throw new RuntimeException("Error while loading component installation report - version: " + version, t);
    } finally {
        closeDaoResources(res, stat, conn);
    }
    return report;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) 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