use of com.agiletec.aps.system.exception.ApsSystemException 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);
}
}
use of com.agiletec.aps.system.exception.ApsSystemException 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);
}
}
use of com.agiletec.aps.system.exception.ApsSystemException 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);
}
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class DatabaseRestorer method initOracleSchema.
protected void initOracleSchema(DataSource dataSource) throws Throwable {
IDatabaseManager.DatabaseType type = this.getType(dataSource);
try {
if (!type.equals(IDatabaseManager.DatabaseType.ORACLE)) {
return;
}
String[] queryTimestampFormat = new String[] { "ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'" };
TableDataUtils.executeQueries(dataSource, queryTimestampFormat, false);
} catch (Throwable t) {
_logger.error("Error initializing oracle schema ", t);
throw new ApsSystemException("Error initializing oracle schema", t);
}
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class DatabaseRestorer method initDerbySchema.
protected void initDerbySchema(DataSource dataSource) throws Throwable {
String username = this.invokeGetMethod("getUsername", dataSource);
try {
String[] queryCreateSchema = new String[] { "CREATE SCHEMA " + username.toUpperCase() };
TableDataUtils.executeQueries(dataSource, queryCreateSchema, false);
} catch (Throwable t) {
_logger.info("Error creating derby schema" + t);
throw new ApsSystemException("Error creating derby schema", t);
}
try {
String[] initSchemaQuery = new String[] { "SET SCHEMA \"" + username.toUpperCase() + "\"" };
TableDataUtils.executeQueries(dataSource, initSchemaQuery, true);
} catch (Throwable t) {
_logger.error("Error initializating Derby Schema", t);
throw new ApsSystemException("Error initializating Derby Schema", t);
}
}
Aggregations