/**
* {@inheritDoc}
*/
protected TaskState runTask()
{
RebuildConfig rebuildConfig = new RebuildConfig();
try
{
rebuildConfig.setBaseDN(DN.decode(baseDN));
}
catch(DirectoryException de)
{
Message message =
ERR_CANNOT_DECODE_BASE_DN.get(baseDN, de.getMessageObject());
logError(message);
return TaskState.STOPPED_BY_ERROR;
}
for(String index : indexes)
{
rebuildConfig.addRebuildIndex(index);
}
Backend backend =
DirectoryServer.getBackendWithBaseDN(rebuildConfig.getBaseDN());
if(backend == null)
{
Message message = ERR_NO_BACKENDS_FOR_BASE.get(baseDN);
logError(message);
return TaskState.STOPPED_BY_ERROR;
}
if (!(backend instanceof BackendImpl))
{
Message message = ERR_REBUILDINDEX_WRONG_BACKEND_TYPE.get();
logError(message);
return TaskState.STOPPED_BY_ERROR;
}
// Acquire a shared lock for the backend if we are rebuilding attribute
// indexes only. If we are rebuilding one or more system indexes, we have
// to aquire exclusive lock.
String lockFile = LockFileManager.getBackendLockFileName(backend);
StringBuilder failureReason = new StringBuilder();
// Disable the backend.
try
{
TaskUtils.disableBackend(backend.getBackendID());
}
catch (DirectoryException e)
{
if (debugEnabled())
{
TRACER.debugCaught(DebugLogLevel.ERROR, e);
}
logError(e.getMessageObject());
return TaskState.STOPPED_BY_ERROR;
}
try
{
if(! LockFileManager.acquireExclusiveLock(lockFile, failureReason))
{
Message message = ERR_REBUILDINDEX_CANNOT_EXCLUSIVE_LOCK_BACKEND.get(
backend.getBackendID(), String.valueOf(failureReason));
logError(message);
return TaskState.STOPPED_BY_ERROR;
}
}
catch (Exception e)
{
Message message = ERR_REBUILDINDEX_CANNOT_EXCLUSIVE_LOCK_BACKEND.get(
backend.getBackendID(), getExceptionMessage(e));
logError(message);
return TaskState.STOPPED_BY_ERROR;
}
if(tmpDirectory == null)
{
tmpDirectory = "import-tmp";
}
rebuildConfig.setTmpDirectory(tmpDirectory);
rebuildConfig.setRebuildAll(rebuildAll);
TaskState returnCode = TaskState.COMPLETED_SUCCESSFULLY;
// Launch the rebuild process.
try
{
BackendImpl jebBackend = (BackendImpl)backend;