use of com.helger.settings.exchange.configfile.ConfigFile in project phoss-smp by phax.
the class SMPManagerProviderSQL method beforeInitManagers.
@Override
public void beforeInitManagers() {
final ConfigFile aCF = SMPServerConfiguration.getConfigFile();
// Set the special PhotonSecurityManager factory
// Must be before Flyway, so that auditing of Flyway actions (may) work
PhotonSecurityManagerFactoryJDBC.install(SMPDBExecutor::new, SMPDBExecutor.TABLE_NAME_CUSTOMIZER);
// Flyway migration is enabled by default
if (aCF.getAsBoolean(SMPJDBCConfiguration.CONFIG_SMP_FLYWAY_ENABLED, true))
FlywayMigrator.Singleton.INSTANCE.runFlyway(m_eDBType);
else
LOGGER.warn("Flyway Migration is disabled according to the configuration item " + SMPJDBCConfiguration.CONFIG_SMP_FLYWAY_ENABLED);
// Register this here, so that the SMPMetaManager is available
DBExecutor.setConnectionStatusChangeCallback((eOld, eNew) -> {
// false: don't trigger callback, because the source is DBExecutor
SMPMetaManager.getInstance().setBackendConnectionState(eNew, false);
});
// Allow communicating in the other direction as well
SMPMetaManager.getInstance().setBackendConnectionStateChangeCallback(eNew -> DBExecutor.resetConnectionEstablished());
}
use of com.helger.settings.exchange.configfile.ConfigFile in project phoss-smp by phax.
the class SMPInternalErrorHandler method doSetup.
public static void doSetup() {
final ConfigFile aCF = SMPServerConfiguration.getConfigFile();
final String sSenderAddress = aCF.getAsString("smp.errorhandler.sender.email");
final String sSenderName = aCF.getAsString("smp.errorhandler.sender.name", "SMP Internal Error Sender");
final String sReceiverAddress = aCF.getAsString("smp.errorhandler.receiver.email");
final String sReceiverName = aCF.getAsString("smp.errorhandler.receiver.name");
final String sSMTPHostName = aCF.getAsString("smp.smtp.hostname");
final int nSMTPPort = aCF.getAsInt("smp.smtp.port", -1);
final String sSMTPUserName = aCF.getAsString("smp.smtp.username");
final String sSMTPPassword = aCF.getAsString("smp.smtp.password");
final boolean bSMTPSSLEnabled = aCF.getAsBoolean("smp.smtp.ssl", false);
final boolean bSMTPSTARTTLSEnabled = aCF.getAsBoolean("smp.smtp.starttls", false);
final long nSMTPConnectionTimeoutMS = aCF.getAsLong("smp.smtp.connectiontimeoutms", 10_000);
final long nSMTPSocketTimeoutMS = aCF.getAsLong("smp.smtp.sockettimeoutms", 10_000);
final boolean bSMTPDebug = aCF.getAsBoolean("smp.smtp.debug", false);
final SMTPSettings aSMTPSettings = StringHelper.hasText(sSMTPHostName) ? new SMTPSettings(sSMTPHostName, nSMTPPort, sSMTPUserName, sSMTPPassword, StandardCharsets.UTF_8, bSMTPSSLEnabled, bSMTPSTARTTLSEnabled, nSMTPConnectionTimeoutMS, nSMTPSocketTimeoutMS, bSMTPDebug) : null;
if (StringHelper.hasText(sSenderAddress) && StringHelper.hasText(sReceiverAddress) && aSMTPSettings != null && aSMTPSettings.areRequiredFieldsSet()) {
// Set global internal error handlers
new SMPInternalErrorHandler().install();
InternalErrorSettings.setSMTPSenderAddress(new EmailAddress(sSenderAddress, sSenderName));
InternalErrorSettings.setSMTPReceiverAddresses(new EmailAddress(sReceiverAddress, sReceiverName));
InternalErrorSettings.setSMTPSettings(aSMTPSettings);
InternalErrorSettings.setFallbackLocale(CSMPServer.DEFAULT_LOCALE);
if (LOGGER.isInfoEnabled())
LOGGER.info("Setup internal error handler to send emails on internal errors to " + sReceiverAddress);
} else {
LOGGER.info("No internal error handler configuration was found. So not sending emails in case of error.");
}
}
use of com.helger.settings.exchange.configfile.ConfigFile in project phoss-smp by phax.
the class FlywayMigrator method runFlyway.
void runFlyway(@Nonnull final EDatabaseType eDBType) {
ValueEnforcer.notNull(eDBType, "DBType");
LOGGER.info("Starting to run Flyway for DB type " + eDBType);
final ConfigFile aCF = SMPServerConfiguration.getConfigFile();
final Callback aCallbackLogging = new BaseCallback() {
public void handle(@Nonnull final Event aEvent, @Nonnull final Context aContext) {
if (LOGGER.isInfoEnabled())
LOGGER.info("Flyway: Event " + aEvent.getId());
if (aEvent == Event.AFTER_EACH_MIGRATE && aContext != null) {
final MigrationInfo aMI = aContext.getMigrationInfo();
if (aMI instanceof MigrationInfoImpl) {
final ResolvedMigration aRM = ((MigrationInfoImpl) aMI).getResolvedMigration();
if (aRM != null)
if (LOGGER.isInfoEnabled())
LOGGER.info(" Performed migration: " + aRM);
}
}
}
};
final Callback aCallbackAudit = new BaseCallback() {
public void handle(@Nonnull final Event aEvent, @Nonnull final Context aContext) {
if (aEvent == Event.AFTER_EACH_MIGRATE && aContext != null) {
final MigrationInfo aMI = aContext.getMigrationInfo();
if (aMI instanceof MigrationInfoImpl) {
final ResolvedMigration aRM = ((MigrationInfoImpl) aMI).getResolvedMigration();
// before that version
if (aRM != null && aRM.getVersion().isAtLeast("7"))
AuditHelper.onAuditExecuteSuccess("sql-migration-success", aRM.getVersion().toString(), aRM.getDescription(), aRM.getScript(), aRM.getType().name(), aRM.getPhysicalLocation());
}
}
}
};
final FluentConfiguration aConfig = Flyway.configure().dataSource(new DriverDataSource(FlywayMigrator.class.getClassLoader(), aCF.getAsString(SMPJDBCConfiguration.CONFIG_JDBC_DRIVER), aCF.getAsString(SMPJDBCConfiguration.CONFIG_JDBC_URL), aCF.getAsString(SMPJDBCConfiguration.CONFIG_JDBC_USER), aCF.getAsString(SMPJDBCConfiguration.CONFIG_JDBC_PASSWORD))).baselineOnMigrate(true).validateOnMigrate(false).baselineVersion("1").baselineDescription("SMP 5.2.x database layout, MySQL only").locations("db/migrate-" + eDBType.getID()).javaMigrations(new V2__MigrateDBUsersToPhotonUsers(), new V5__MigrateTransportProfilesToDB(), new V10__MigrateRolesToDB(), new V11__MigrateUsersToDB(), new V12__MigrateUserGroupsToDB(), new V14__MigrateSettingsToDB(), new V15__MigrateDBUsersToPhotonUsers()).callbacks(aCallbackLogging, aCallbackAudit);
// Flyway to handle the DB schema?
final String sSchema = aCF.getAsString(SMPJDBCConfiguration.CONFIG_JDBC_SCHEMA);
if (StringHelper.hasText(sSchema)) {
// Use the schema only, if it is explicitly configured
// The default schema name is ["$user", public] and as such unusable
aConfig.schemas(sSchema);
}
// If no schema is specified, schema create should also be disabled
final boolean bCreateSchema = aCF.getAsBoolean(SMPJDBCConfiguration.CONFIG_JDBC_SCHEMA_CREATE, false);
aConfig.createSchemas(bCreateSchema);
final Flyway aFlyway = aConfig.load();
if (false)
aFlyway.validate();
aFlyway.migrate();
LOGGER.info("Finished running Flyway");
}
use of com.helger.settings.exchange.configfile.ConfigFile in project phoss-smp by phax.
the class MongoClientSingleton method onAfterInstantiation.
@Override
protected void onAfterInstantiation(@Nonnull final IScope aScope) {
// Standard configuration file
final ConfigFile aConfigFile = SMPServerConfiguration.getConfigFile();
final String sConnectionString = aConfigFile.getAsString(CONFIG_MONGODB_CONNECTION_STRING);
if (StringHelper.hasNoText(sConnectionString))
throw new IllegalStateException("The MongoDB connection string is missing in the configuration. See property '" + CONFIG_MONGODB_CONNECTION_STRING + "'");
final String sDBName = aConfigFile.getAsString(CONFIG_MONGODB_DB_NAME);
if (StringHelper.hasNoText(sDBName))
throw new IllegalStateException("The MongoDB database name is missing in the configuration. See property '" + CONFIG_MONGODB_DB_NAME + "'");
LOGGER.info("Using Mongo DB database name '" + sDBName + "'");
m_aProvider = new MongoClientProvider(sConnectionString, sDBName);
}
Aggregations