InitialLdapContext ctx,
PurgeHistoricalUserData uData)
throws ReplicationCliException
{
printPurgeProgressMessage(uData);
ReplicationCliReturnCode returnCode = ReplicationCliReturnCode.SUCCESSFUL;
boolean taskCreated = false;
int i = 0;
boolean isOver = false;
String dn = null;
String taskID = null;
while (!taskCreated)
{
BasicAttributes attrs = PurgeHistoricalUserData.getTaskAttributes(uData);
dn = PurgeHistoricalUserData.getTaskDN(attrs);
taskID = PurgeHistoricalUserData.getTaskID(attrs);
try
{
DirContext dirCtx = ctx.createSubcontext(dn, attrs);
taskCreated = true;
LOG.log(Level.INFO, "created task entry: "+attrs);
dirCtx.close();
}
catch (NameAlreadyBoundException x)
{
}
catch (NamingException ne)
{
LOG.log(Level.SEVERE, "Error creating task "+attrs, ne);
Message msg = ERR_LAUNCHING_PURGE_HISTORICAL.get();
ReplicationCliReturnCode code = ERROR_LAUNCHING_PURGE_HISTORICAL;
throw new ReplicationCliException(
getThrowableMsg(msg, ne), code, ne);
}
i++;
}
// Wait until it is over
SearchControls searchControls = new SearchControls();
searchControls.setCountLimit(1);
searchControls.setSearchScope(
SearchControls. OBJECT_SCOPE);
String filter = "objectclass=*";
searchControls.setReturningAttributes(
new String[] {
"ds-task-log-message",
"ds-task-state",
"ds-task-purge-conflicts-historical-purged-values-count",
"ds-task-purge-conflicts-historical-purge-completed-in-time",
"ds-task-purge-conflicts-historical-purge-completed-in-time",
"ds-task-purge-conflicts-historical-last-purged-changenumber"
});
String lastLogMsg = null;
// Polling only makes sense when we are recurrently scheduling a task
// or the task is being executed now.
while (!isOver && (uData.getTaskSchedule().getStartDate() == null))
{
try
{
Thread.sleep(500);
}
catch (Throwable t)
{
}
try
{
NamingEnumeration<SearchResult> res =
ctx.search(dn, filter, searchControls);
SearchResult sr = null;
try
{
sr = res.next();
}
finally
{
res.close();
}
String logMsg = getFirstValue(sr, "ds-task-log-message");
if (logMsg != null)
{
if (!logMsg.equals(lastLogMsg))
{
LOG.log(Level.INFO, logMsg);
lastLogMsg = logMsg;
}
}
InstallerHelper helper = new InstallerHelper();
String state = getFirstValue(sr, "ds-task-state");
if (helper.isDone(state) || helper.isStoppedByError(state))
{
isOver = true;
Message errorMsg;
String server = ConnectionUtils.getHostPort(ctx);
if (lastLogMsg == null)
{
errorMsg = INFO_ERROR_DURING_PURGE_HISTORICAL_NO_LOG.get(
state, server);
}
else
{
errorMsg = INFO_ERROR_DURING_PURGE_HISTORICAL_LOG.get(
lastLogMsg, state, server);
}
if (helper.isCompletedWithErrors(state))
{
LOG.log(Level.WARNING, "Completed with error: "+errorMsg);
println(errorMsg);
}
else if (!helper.isSuccessful(state) ||
helper.isStoppedByError(state))
{
LOG.log(Level.WARNING, "Error: "+errorMsg);
ReplicationCliReturnCode code = ERROR_LAUNCHING_PURGE_HISTORICAL;
throw new ReplicationCliException(errorMsg, code, null);
}
}
}
catch (NameNotFoundException x)