use of org.entando.entando.ent.exception.EntException in project entando-engine by entando.
the class DatabaseManager method createTables.
private void createTables(String databaseName, List<String> tableClassNames, DataSource dataSource, DataSourceInstallationReport schemaReport) throws EntException {
try {
DatabaseType type = this.getDatabaseRestorer().getType(dataSource);
TableFactory tableFactory = new TableFactory(databaseName, dataSource, type);
tableFactory.createTables(tableClassNames, schemaReport);
} catch (Throwable t) {
logger.error("Error creating tables to db {}", databaseName, t);
throw new EntException("Error creating tables to db " + databaseName, t);
}
}
use of org.entando.entando.ent.exception.EntException in project entando-engine by entando.
the class DatabaseManager method initComponentDatabases.
public void initComponentDatabases(Component componentConfiguration, SystemInstallationReport report, boolean checkOnStatup) throws EntException {
logger.info(INIT_MSG_P, componentConfiguration.getCode(), LOG_PREFIX);
ComponentInstallationReport componentReport = report.getComponentReport(componentConfiguration.getCode(), true);
if (componentReport.getStatus().equals(SystemInstallationReport.Status.OK)) {
logger.debug(LOG_PREFIX + "( ok ) Already installed\n" + LOG_PREFIX);
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok ) Already installed\n" + LOG_PREFIX);
return;
} else if (componentReport.getStatus().equals(SystemInstallationReport.Status.UNINSTALLED)) {
logger.debug(LOG_PREFIX + "( ok ) Uninstalled\n" + LOG_PREFIX);
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok ) Uninstalled\n" + LOG_PREFIX);
return;
}
try {
String[] dataSourceNames = this.extractBeanNames(DataSource.class);
Map<String, List<String>> tableMapping = componentConfiguration.getTableMapping();
DataSourceInstallationReport dataSourceReport = componentReport.getDataSourceReport();
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "Starting installation\n" + LOG_PREFIX);
for (String dataSourceName : dataSourceNames) {
List<String> tableClassNames = (null != tableMapping) ? tableMapping.get(dataSourceName) : null;
if (null == tableClassNames || tableClassNames.isEmpty()) {
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( !! ) 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(LOG_PREFIX + "( ok ) {} already installed {}", dataSourceName, SystemInstallationReport.Status.PORTING);
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok ) " + dataSourceName + " already installed" + SystemInstallationReport.Status.PORTING);
continue;
}
SystemInstallationReport.Status schemaStatus = dataSourceReport.getDatabaseStatus().get(dataSourceName);
if (SystemInstallationReport.isSafeStatus(schemaStatus)) {
// Already Done!
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( 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);
ApsSystemUtils.directStdoutTrace(LOG_PREFIX);
dataSourceReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.OK);
} else {
dataSourceReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.SKIPPED);
}
report.setUpdated();
}
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "\n" + LOG_PREFIX + "Installation complete\n" + LOG_PREFIX);
logger.debug(LOG_PREFIX + "\n" + LOG_PREFIX + "Installation complete\n" + LOG_PREFIX);
} catch (Throwable t) {
logger.error("Error initializating component {}", componentConfiguration.getCode(), t);
throw new EntException("Error initializating component " + componentConfiguration.getCode(), t);
}
}
use of org.entando.entando.ent.exception.EntException in project entando-engine by entando.
the class DatabaseManager method initComponentDefaultResources.
public void initComponentDefaultResources(Component componentConfiguration, SystemInstallationReport report, boolean checkOnStatup) throws EntException {
logger.info(INIT_MSG_P, componentConfiguration.getCode(), LOG_PREFIX);
ComponentInstallationReport componentReport = report.getComponentReport(componentConfiguration.getCode(), false);
if (componentReport.getStatus().equals(SystemInstallationReport.Status.OK)) {
logger.debug(LOG_PREFIX + "( ok ) Already installed\n" + LOG_PREFIX);
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok ) Already installed\n" + LOG_PREFIX);
return;
} else if (componentReport.getStatus().equals(SystemInstallationReport.Status.UNINSTALLED)) {
logger.debug(LOG_PREFIX + "( ok ) Uninstalled\n" + LOG_PREFIX);
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok ) Uninstalled\n" + LOG_PREFIX);
return;
}
DataInstallationReport dataReport = componentReport.getDataReport();
try {
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "Starting installation\n" + LOG_PREFIX);
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());
ApsSystemUtils.directStdoutTrace("| ( 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(LOG_PREFIX + "( ok ) Already installed\n" + LOG_PREFIX);
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok ) Already installed\n" + LOG_PREFIX);
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);
ApsSystemUtils.directStdoutTrace("| ( ok ) " + dataSourceName);
dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.OK);
} else {
dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.SKIPPED);
}
report.setUpdated();
} else {
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( !! ) skipping " + dataSourceName + ": not available");
dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.NOT_AVAILABLE);
report.setUpdated();
}
}
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "\n" + LOG_PREFIX + "Installation complete\n" + LOG_PREFIX);
logger.debug(LOG_PREFIX + "\n" + LOG_PREFIX + "Installation complete\n" + LOG_PREFIX);
} catch (Throwable t) {
logger.error("Error restoring default resources of component {}", componentConfiguration.getCode(), t);
throw new EntException("Error restoring default resources of component " + componentConfiguration.getCode(), t);
}
}
use of org.entando.entando.ent.exception.EntException in project entando-engine by entando.
the class DatabaseManager method deleteBackup.
@Override
public void deleteBackup(String subFolderName) throws EntException {
try {
String baseDir = this.getLocalBackupsFolder();
String directoryName = baseDir + subFolderName;
this.getStorageManager().deleteDirectory(directoryName, true);
} catch (Throwable t) {
logger.error("Error while deleting backup", t);
throw new EntException("Error while deleting backup", t);
}
}
use of org.entando.entando.ent.exception.EntException in project entando-engine by entando.
the class DatabaseManager method initMasterDatabases.
private void initMasterDatabases(SystemInstallationReport report, boolean checkOnStatup) throws EntException {
logger.info(INIT_MSG_P, "Core", LOG_PREFIX);
ComponentInstallationReport componentReport = report.getComponentReport("entandoCore", true);
DataSourceInstallationReport dataSourceReport = componentReport.getDataSourceReport();
if (componentReport.getStatus().equals(SystemInstallationReport.Status.OK)) {
logger.debug("{}( ok ) Already installed\n{}", LOG_PREFIX, LOG_PREFIX);
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok ) Already installed\n" + LOG_PREFIX);
return;
}
try {
String[] dataSourceNames = this.extractBeanNames(DataSource.class);
Map<String, SystemInstallationReport.Status> databasesStatus = dataSourceReport.getDatabaseStatus();
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "Starting installation");
for (String dataSourceName : dataSourceNames) {
if (report.getStatus().equals(SystemInstallationReport.Status.PORTING)) {
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + " - 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))) {
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "\n" + LOG_PREFIX + "( ok ) " + dataSourceName + " already installed");
} else if (dbStatus == null || !dbStatus.equals(SystemInstallationReport.Status.OK)) {
DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName);
if (checkOnStatup) {
databasesStatus.put(dataSourceName, SystemInstallationReport.Status.INCOMPLETE);
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "");
this.initMasterDatabase(dataSourceName, dataSource, dataSourceReport);
databasesStatus.put(dataSourceName, SystemInstallationReport.Status.OK);
} else {
databasesStatus.put(dataSourceName, SystemInstallationReport.Status.SKIPPED);
}
report.setUpdated();
}
}
ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "\n" + LOG_PREFIX + "Installation complete\n" + LOG_PREFIX);
logger.debug(LOG_PREFIX + "\n" + LOG_PREFIX + "Installation complete\n" + LOG_PREFIX);
} catch (Throwable t) {
logger.error("Error initializating master databases", t);
throw new EntException("Error initializating master databases", t);
}
}
Aggregations