Search in sources :

Example 1 with ComponentInstallationReport

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

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

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

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

the class DatabaseAction method checkRestore.

public boolean checkRestore(List<Component> currentComponents, DataSourceDumpReport report) {
    List<String> codes = new ArrayList<String>();
    codes.add("entandoCore");
    for (int i = 0; i < currentComponents.size(); i++) {
        Component component = currentComponents.get(i);
        codes.add(component.getCode());
    }
    List<ComponentInstallationReport> reports = report.getComponentsHistory();
    if (reports.size() != codes.size()) {
        return false;
    }
    for (int i = 0; i < reports.size(); i++) {
        ComponentInstallationReport componentReport = reports.get(i);
        if (!codes.contains(componentReport.getComponentCode())) {
            return false;
        }
    }
    return true;
}
Also used : ComponentInstallationReport(org.entando.entando.aps.system.init.model.ComponentInstallationReport) ArrayList(java.util.ArrayList) Component(org.entando.entando.aps.system.init.model.Component)

Example 5 with ComponentInstallationReport

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

Aggregations

ComponentInstallationReport (org.entando.entando.aps.system.init.model.ComponentInstallationReport)6 SystemInstallationReport (org.entando.entando.aps.system.init.model.SystemInstallationReport)5 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 DataSource (javax.sql.DataSource)4 ArrayList (java.util.ArrayList)2 Component (org.entando.entando.aps.system.init.model.Component)2 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 Resource (org.springframework.core.io.Resource)2 List (java.util.List)1 IPostProcess (org.entando.entando.aps.system.init.model.IPostProcess)1 FatalBeanException (org.springframework.beans.FatalBeanException)1