use of org.entando.entando.aps.system.init.model.DataInstallationReport 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 org.entando.entando.aps.system.init.model.DataInstallationReport 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);
}
}
Aggregations