/**
* {@inheritDoc}
*/
public ConfigChangeResult applyConfigurationChange(LocalDBBackendCfg cfg)
{
ConfigChangeResult ccr;
boolean adminActionRequired = false;
ArrayList<Message> messages = new ArrayList<Message>();
try
{
if(env != null)
{
// Check if any JE non-mutable properties were changed.
EnvironmentConfig oldEnvConfig = env.getConfig();
EnvironmentConfig newEnvConfig =
ConfigurableEnvironment.parseConfigEntry(cfg);
Map<?,?> paramsMap = EnvironmentParams.SUPPORTED_PARAMS;
// Iterate through native JE properties.
SortedSet<String> jeProperties = cfg.getJEProperty();
for (String jeEntry : jeProperties) {
// There is no need to validate properties yet again.
StringTokenizer st = new StringTokenizer(jeEntry, "=");
if (st.countTokens() == 2) {
String jePropertyName = st.nextToken();
String jePropertyValue = st.nextToken();
ConfigParam param = (ConfigParam) paramsMap.get(jePropertyName);
if (!param.isMutable()) {
String oldValue = oldEnvConfig.getConfigParam(param.getName());
String newValue = jePropertyValue;
if (!oldValue.equalsIgnoreCase(newValue)) {
adminActionRequired = true;
messages.add(INFO_CONFIG_JE_PROPERTY_REQUIRES_RESTART.get(
jePropertyName));
if(debugEnabled()) {
TRACER.debugInfo("The change to the following property " +
"will take effect when the component is restarted: " +
jePropertyName);
}
}
}
}
}
// Iterate through JE configuration attributes.
for (Object o : paramsMap.values())
{
ConfigParam param = (ConfigParam) o;
if (!param.isMutable())
{
String oldValue = oldEnvConfig.getConfigParam(param.getName());
String newValue = newEnvConfig.getConfigParam(param.getName());
if (!oldValue.equalsIgnoreCase(newValue))
{
adminActionRequired = true;
String configAttr = ConfigurableEnvironment.
getAttributeForProperty(param.getName());
if (configAttr != null)
{
messages.add(NOTE_JEB_CONFIG_ATTR_REQUIRES_RESTART
.get(configAttr));
}
else
{
messages.add(NOTE_JEB_CONFIG_ATTR_REQUIRES_RESTART
.get(param.getName()));
}
if(debugEnabled())
{
TRACER.debugInfo("The change to the following property will " +
"take effect when the backend is restarted: " +
param.getName());
}
}
}
}
// This takes care of changes to the JE environment for those
// properties that are mutable at runtime.
env.setMutableConfig(newEnvConfig);
if (debugEnabled())
{
TRACER.debugInfo(env.getConfig().toString());
}
}
// Create the directory if it doesn't exist.
if(!cfg.getDBDirectory().equals(this.config.getDBDirectory()))
{
File parentDirectory = getFileForPath(cfg.getDBDirectory());
File backendDirectory =
new File(parentDirectory, cfg.getBackendId());
if (!backendDirectory.exists())
{
if(!backendDirectory.mkdirs())
{
messages.add(ERR_JEB_CREATE_FAIL.get(
backendDirectory.getPath()));
ccr = new ConfigChangeResult(
DirectoryServer.getServerErrorResultCode(),
adminActionRequired,
messages);
return ccr;
}
}
//Make sure the directory is valid.
else if (!backendDirectory.isDirectory())
{
messages.add(ERR_JEB_DIRECTORY_INVALID.get(
backendDirectory.getPath()));
ccr = new ConfigChangeResult(
DirectoryServer.getServerErrorResultCode(),
adminActionRequired,
messages);
return ccr;
}
adminActionRequired = true;
messages.add(NOTE_JEB_CONFIG_DB_DIR_REQUIRES_RESTART.get(
this.config.getDBDirectory(), cfg.getDBDirectory()));
}
if(!cfg.getDBDirectoryPermissions().equalsIgnoreCase(
config.getDBDirectoryPermissions()) ||
!cfg.getDBDirectory().equals(this.config.getDBDirectory()))
{
FilePermission backendPermission;
try
{
backendPermission =
FilePermission.decodeUNIXMode(cfg.getDBDirectoryPermissions());
}
catch(Exception e)
{
messages.add(ERR_CONFIG_BACKEND_MODE_INVALID.get(
config.dn().toString()));
ccr = new ConfigChangeResult(
DirectoryServer.getServerErrorResultCode(),
adminActionRequired,
messages);
return ccr;
}
//Make sure the mode will allow the server itself access to
//the database
if(!backendPermission.isOwnerWritable() ||
!backendPermission.isOwnerReadable() ||
!backendPermission.isOwnerExecutable())
{
messages.add(ERR_CONFIG_BACKEND_INSANE_MODE.get(
cfg.getDBDirectoryPermissions()));
ccr = new ConfigChangeResult(
DirectoryServer.getServerErrorResultCode(),
adminActionRequired,
messages);
return ccr;
}
// Get the backend database backendDirectory permissions and apply
if(FilePermission.canSetPermissions())
{
File parentDirectory = getFileForPath(config.getDBDirectory());
File backendDirectory = new File(parentDirectory,
config.getBackendId());
try
{
if(!FilePermission.setPermissions(backendDirectory,
backendPermission))
{
Message message = WARN_JEB_UNABLE_SET_PERMISSIONS.get(
backendPermission.toString(), backendDirectory.toString());
logError(message);
}
}
catch(Exception e)
{
// Log an warning that the permissions were not set.
Message message = WARN_JEB_SET_PERMISSIONS_FAILED.get(
backendDirectory.toString(), e.toString());
logError(message);
}
}
}
getMonitorProvider().enableFilterUseStats(
cfg.isIndexFilterAnalyzerEnabled());
getMonitorProvider().setMaxEntries(cfg.getMaxEntries());
this.config = cfg;
}
catch (Exception e)
{
messages.add(Message.raw(stackTraceToSingleLineString(e)));
ccr = new ConfigChangeResult(DirectoryServer.getServerErrorResultCode(),
adminActionRequired,
messages);
return ccr;
}
ccr = new ConfigChangeResult(ResultCode.SUCCESS, adminActionRequired,
messages);
return ccr;
}