in log4j-flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java [384:466]
public FlumePersistentManager createManager(final String name, final FactoryData data) {
SecretKey secretKey = null;
Database database = null;
Environment environment = null;
final Map<String, String> properties = new HashMap<>();
if (data.properties != null) {
for (final Property property : data.properties) {
properties.put(property.getName(), property.getValue());
}
}
try {
final File dir = new File(data.dataDir);
FileUtils.mkdir(dir, true);
final EnvironmentConfig dbEnvConfig = new EnvironmentConfig();
dbEnvConfig.setTransactional(true);
dbEnvConfig.setAllowCreate(true);
dbEnvConfig.setLockTimeout(5, TimeUnit.SECONDS);
environment = new Environment(dir, dbEnvConfig);
final DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(true);
database = environment.openDatabase(null, name, dbConfig);
} catch (final Exception ex) {
LOGGER.error("Could not create FlumePersistentManager", ex);
// For consistency, close database as well as environment even though it should never happen since the
// database is that last thing in the block above, but this does guard against a future line being
// inserted at the end that would bomb (like some debug logging).
if (database != null) {
database.close();
database = null;
}
if (environment != null) {
environment.close();
environment = null;
}
return null;
}
try {
String key = null;
for (final Map.Entry<String, String> entry : properties.entrySet()) {
if (entry.getKey().equalsIgnoreCase(KEY_PROVIDER)) {
key = entry.getValue();
break;
}
}
if (key != null) {
final PluginManager manager = new PluginManager("KeyProvider");
manager.collectPlugins();
final Map<String, PluginType<?>> plugins = manager.getPlugins();
if (plugins != null) {
boolean found = false;
for (final Map.Entry<String, PluginType<?>> entry : plugins.entrySet()) {
if (entry.getKey().equalsIgnoreCase(key)) {
found = true;
final Class<?> cl = entry.getValue().getPluginClass();
try {
final SecretKeyProvider provider = (SecretKeyProvider) cl.newInstance();
secretKey = provider.getSecretKey();
LOGGER.debug("Persisting events using SecretKeyProvider {}", cl.getName());
} catch (final Exception ex) {
LOGGER.error("Unable to create SecretKeyProvider {}, encryption will be disabled",
cl.getName());
}
break;
}
}
if (!found) {
LOGGER.error("Unable to locate SecretKey provider {}, encryption will be disabled", key);
}
} else {
LOGGER.error("Unable to locate SecretKey provider {}, encryption will be disabled", key);
}
}
} catch (final Exception ex) {
LOGGER.warn("Error setting up encryption - encryption will be disabled", ex);
}
return new FlumePersistentManager(name, data.name, data.agents, data.batchSize, data.retries,
data.connectionTimeout, data.requestTimeout, data.delayMillis, database, environment, secretKey,
data.lockTimeoutRetryCount);
}