use of org.entando.entando.aps.system.init.model.Component in project entando-core by entando.
the class DatabaseDumper method createBackup.
protected void createBackup(AbstractInitializerManager.Environment environment, SystemInstallationReport installationReport) throws ApsSystemException {
try {
DataSourceDumpReport report = new DataSourceDumpReport(installationReport);
long start = System.currentTimeMillis();
String backupSubFolder = (AbstractInitializerManager.Environment.develop.equals(environment)) ? environment.toString() : DateConverter.getFormattedDate(new Date(), "yyyyMMddHHmmss");
report.setSubFolderName(backupSubFolder);
List<Component> components = this.getComponents();
for (int i = 0; i < components.size(); i++) {
Component componentConfiguration = components.get(i);
this.createBackup(componentConfiguration.getTableMapping(), report, backupSubFolder);
}
this.createBackup(this.getEntandoTableMapping(), report, backupSubFolder);
long time = System.currentTimeMillis() - start;
report.setRequiredTime(time);
report.setDate(new Date());
StringBuilder reportFolder = new StringBuilder(this.getLocalBackupsFolder());
if (null != backupSubFolder) {
reportFolder.append(backupSubFolder).append(File.separator);
}
this.save(DatabaseManager.DUMP_REPORT_FILE_NAME, reportFolder.toString(), report.toXml());
} catch (Throwable t) {
_logger.error("error in ", t);
throw new ApsSystemException("Error while creating backup", t);
}
}
use of org.entando.entando.aps.system.init.model.Component in project entando-core by entando.
the class DatabaseManager method installDatabase.
@Override
public SystemInstallationReport installDatabase(SystemInstallationReport report, boolean checkOnStatup) throws Exception {
String lastLocalBackupFolder = null;
if (null == report) {
report = SystemInstallationReport.getInstance();
if (checkOnStatup && !Environment.test.equals(this.getEnvironment())) {
// non c'è db locale installato, cerca nei backup locali
DataSourceDumpReport lastDumpReport = this.getLastDumpReport();
if (null != lastDumpReport) {
lastLocalBackupFolder = lastDumpReport.getSubFolderName();
report.setStatus(SystemInstallationReport.Status.RESTORE);
} else {
// SE NON c'è cerca il default dump
Map<String, Resource> sqlDump = this.getDefaultSqlDump();
if (null != sqlDump && sqlDump.size() > 0) {
report.setStatus(SystemInstallationReport.Status.RESTORE);
}
}
}
}
try {
this.initMasterDatabases(report, checkOnStatup);
List<Component> components = this.getComponentManager().getCurrentComponents();
for (Component entandoComponentConfiguration : components) {
this.initComponentDatabases(entandoComponentConfiguration, report, checkOnStatup);
}
this.initMasterDefaultResource(report, checkOnStatup);
for (Component entandoComponentConfiguration : components) {
this.initComponentDefaultResources(entandoComponentConfiguration, report, checkOnStatup);
}
if (checkOnStatup && report.getStatus().equals(SystemInstallationReport.Status.RESTORE)) {
// ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH:MI:SS.FF'
if (null != lastLocalBackupFolder) {
this.restoreBackup(lastLocalBackupFolder);
} else {
this.restoreDefaultDump();
}
}
} catch (Throwable t) {
if (null != report && report.isUpdated()) {
report.setUpdated();
report.setStatus(SystemInstallationReport.Status.INCOMPLETE);
}
logger.error("Error while initializating Db Installer", t);
throw new Exception("Error while initializating Db Installer", t);
}
return report;
}
use of org.entando.entando.aps.system.init.model.Component in project entando-core by entando.
the class DatabaseRestorer method dropAndRestoreBackup.
protected void dropAndRestoreBackup(String backupSubFolder) throws ApsSystemException {
try {
List<Component> components = this.getComponents();
int size = components.size();
for (int i = 0; i < components.size(); i++) {
Component componentConfiguration = components.get(size - i - 1);
this.dropTables(componentConfiguration.getTableMapping());
}
this.dropTables(this.getEntandoTableMapping());
this.restoreBackup(backupSubFolder);
} catch (Throwable t) {
_logger.error("Error while restoring backup: {}", backupSubFolder, t);
throw new ApsSystemException("Error while restoring backup", t);
}
}
use of org.entando.entando.aps.system.init.model.Component in project entando-core by entando.
the class DatabaseRestorer method restoreBackup.
protected void restoreBackup(String backupSubFolder) throws ApsSystemException {
try {
this.restoreLocalDump(this.getEntandoTableMapping(), backupSubFolder);
List<Component> components = this.getComponents();
for (int i = 0; i < components.size(); i++) {
Component componentConfiguration = components.get(i);
this.restoreLocalDump(componentConfiguration.getTableMapping(), backupSubFolder);
}
} catch (Throwable t) {
_logger.error("Error while restoring local backup", t);
throw new ApsSystemException("Error while restoring local backup", t);
}
}
use of org.entando.entando.aps.system.init.model.Component in project entando-core by entando.
the class InitializerManager method executePostInitProcesses.
public void executePostInitProcesses() throws BeansException {
SystemInstallationReport report = null;
try {
report = this.extractReport();
List<Component> components = this.getComponentManager().getCurrentComponents();
for (int i = 0; i < components.size(); i++) {
Component component = components.get(i);
ComponentInstallationReport componentReport = report.getComponentReport(component.getCode(), false);
SystemInstallationReport.Status postProcessStatus = componentReport.getPostProcessStatus();
if (!postProcessStatus.equals(SystemInstallationReport.Status.INIT)) {
continue;
}
String compEnvKey = (AbstractInitializerManager.Environment.test.equals(this.getEnvironment())) ? AbstractInitializerManager.Environment.test.toString() : AbstractInitializerManager.Environment.production.toString();
ComponentEnvironment componentEnvironment = (null != component.getEnvironments()) ? component.getEnvironments().get(compEnvKey) : null;
List<IPostProcess> postProcesses = (null != componentEnvironment) ? componentEnvironment.getPostProcesses() : null;
if (null == postProcesses || postProcesses.isEmpty()) {
postProcessStatus = SystemInstallationReport.Status.NOT_AVAILABLE;
} else if (!this.isCheckOnStartup()) {
postProcessStatus = SystemInstallationReport.Status.SKIPPED;
} else if (!componentReport.isPostProcessExecutionRequired()) {
// Porting or restore
postProcessStatus = SystemInstallationReport.Status.NOT_AVAILABLE;
} else {
postProcessStatus = this.executePostProcesses(postProcesses);
}
componentReport.setPostProcessStatus(postProcessStatus);
report.setUpdated();
}
} catch (Throwable t) {
logger.error("Error while executing post processes", t);
throw new FatalBeanException("Error while executing post processes", t);
} finally {
if (null != report && report.isUpdated()) {
this.saveReport(report);
}
}
}
Aggregations