TaskBackend.java revision a395dd575518d9e5280fc5d5d5ef47c61b174647
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
*/
/**
* This class provides an implementation of a Directory Server backend that may
* be used to execute various kinds of administrative tasks on a one-time or
* recurring basis.
*/
public class TaskBackend
extends Backend
implements ConfigurationChangeListener<TaskBackendCfg>
{
/**
* The tracer object for the debug logger.
*/
// The current configuration state.
private TaskBackendCfg currentConfig;
// The DN of the configuration entry for this backend.
private DN configEntryDN;
// The DN of the entry that will serve as the parent for all recurring task
// entries.
private DN recurringTaskParentDN;
// The DN of the entry that will serve as the parent for all scheduled task
// entries.
private DN scheduledTaskParentDN;
// The DN of the entry that will serve as the root for all task entries.
private DN taskRootDN;
// The set of base DNs defined for this backend.
// The set of supported controls for this backend.
// The set of supported features for this backend.
// The length of time in seconds after a task is completed that it should be
// removed from the set of scheduled tasks.
private long retentionTime;
// The e-mail address to use for the sender from notification messages.
private String notificationSenderAddress;
// The path to the task backing file.
private String taskBackingFile;
// The task scheduler that will be responsible for actually invoking scheduled
// tasks.
private TaskScheduler taskScheduler;
/**
* Creates a new backend with the provided information. All backend
* implementations must implement a default constructor that use
* <CODE>super()</CODE> to invoke this constructor.
*/
public TaskBackend()
{
super();
// Perform all initialization in initializeBackend.
}
/**
* {@inheritDoc}
*/
@Override()
throws ConfigException
{
// Make sure that the provided set of base DNs contains exactly one value.
// We will only allow one base for task entries.
{
throw new ConfigException(message);
}
{
throw new ConfigException(message);
}
else
{
try
{
}
catch (Exception e)
{
if (debugEnabled())
{
}
// This should never happen.
throw new ConfigException(message, e);
}
try
{
}
catch (Exception e)
{
if (debugEnabled())
{
}
// This should never happen.
throw new ConfigException(message, e);
}
}
// Get the retention time that will be used to determine how long task
// information stays around once the associated task is completed.
// Get the notification sender address.
if (notificationSenderAddress == null)
{
try
{
notificationSenderAddress = "opends-task-notification@" +
}
catch (Exception e)
{
notificationSenderAddress = "opends-task-notification@opends.org";
}
}
// Get the path to the task data backing file.
// Define an empty sets for the supported controls and features.
currentConfig = cfg;
}
/**
* {@inheritDoc}
*/
@Override()
public void initializeBackend()
{
// Create the scheduler and initialize it from the backing file.
taskScheduler = new TaskScheduler(this);
// Register with the Directory Server as a configurable component.
// Register the task base as a private suffix.
try
{
}
catch (Exception e)
{
if (debugEnabled())
{
}
throw new InitializationException(message, e);
}
}
/**
* {@inheritDoc}
*/
@Override()
public void finalizeBackend()
{
try
{
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
try
{
message, true);
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
try
{
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
}
/**
* {@inheritDoc}
*/
@Override()
public DN[] getBaseDNs()
{
return baseDNs;
}
/**
* {@inheritDoc}
*/
@Override()
public long getEntryCount()
{
if (taskScheduler != null)
{
return taskScheduler.getEntryCount();
}
return -1;
}
/**
* {@inheritDoc}
*/
@Override()
public boolean isLocal()
{
// For the purposes of this method, this is a local backend.
return true;
}
/**
* {@inheritDoc}
*/
@Override()
{
// All searches in this backend will always be considered indexed.
return true;
}
/**
* {@inheritDoc}
*/
@Override()
throws DirectoryException
{
if(ret < 0)
{
return ConditionResult.UNDEFINED;
}
else if(ret == 0)
{
return ConditionResult.FALSE;
}
else
{
return ConditionResult.TRUE;
}
}
/**
* {@inheritDoc}
*/
@Override()
throws DirectoryException
{
{
return -1;
}
{
// scheduled and recurring parents.
if(!subtree)
{
return 2;
}
else
{
return taskScheduler.getScheduledTaskCount() +
}
}
{
return taskScheduler.getScheduledTaskCount();
}
{
return taskScheduler.getRecurringTaskCount();
}
{
return -1;
}
{
return 0;
}
{
return 0;
}
else
{
return -1;
}
}
/**
* {@inheritDoc}
*/
@Override()
throws DirectoryException
{
{
return null;
}
{
return taskScheduler.getTaskRootEntry();
}
{
return taskScheduler.getScheduledTaskParentEntry();
}
{
return taskScheduler.getRecurringTaskParentEntry();
}
{
return null;
}
{
}
{
}
else
{
// If we've gotten here then this is not an entry that should exist in the
// task backend.
return null;
}
}
/**
* {@inheritDoc}
*/
@Override()
throws DirectoryException
{
// Get the DN for the entry and then get its parent.
{
}
// If the parent DN is equal to the parent for scheduled tasks, then try to
// treat the provided entry like a scheduled task.
{
return;
}
// If the parent DN is equal to the parent for recurring tasks, then try to
// treat the provided entry like a recurring task.
{
return;
}
// We won't allow the entry to be added.
}
/**
* {@inheritDoc}
*/
@Override()
throws DirectoryException
{
// Get the parent for the provided entry DN. It must be either the
// scheduled or recurring task parent DN.
{
}
{
// It's a scheduled task. Make sure that it exists.
if (t == null)
{
}
// Look at the state of the task. We will allow pending and completed
// tasks to be removed, but not running tasks.
{
}
{
}
else
{
}
}
{
// It's a recurring task. Make sure that it exists.
{
}
// Try to remove the recurring task. This will fail if there are any
// associated iterations pending or running.
}
else
{
}
}
/**
* {@inheritDoc}
*/
@Override()
throws DirectoryException
{
if (! taskScheduler.holdsSchedulerLock())
{
for (int i=0; i < 3; i++)
{
{
break;
}
}
{
}
}
try
{
// Get the parent for the provided entry DN. It must be either the
// scheduled or recurring task parent DN.
{
}
{
// It's a scheduled task. Make sure that it exists.
if (t == null)
{
}
// Look at the state of the task. We will allow anything to be altered
// for a pending task. For a running task, we will only allow the state
// to be altered in order to cancel it. We will not allow any
// modifications for completed tasks.
{
return;
}
{
// If the task is running, we will only allow it to be cancelled.
// This will only be allowed using the replace modification type on
// the ds-task-state attribute if the value starts with "cancel" or
// "stop". In that case, we'll cancel the task.
boolean acceptable = true;
{
if (m.isInternal())
{
continue;
}
{
acceptable = false;
break;
}
Attribute a = m.getAttribute();
{
acceptable = false;
break;
}
{
acceptable = false;
break;
}
{
acceptable = false;
break;
}
{
acceptable = false;
break;
}
}
if (acceptable)
{
return;
}
else
{
message);
}
}
else
{
message);
}
}
{
// We don't currently support altering recurring tasks.
}
else
{
}
}
finally
{
{
}
}
}
/**
* {@inheritDoc}
*/
@Override()
throws DirectoryException
{
}
/**
* {@inheritDoc}
*/
@Override()
{
// Look at the base DN and scope for the search operation to decide which
// entries we need to look at.
boolean searchRoot = false;
boolean searchScheduledParent = false;
boolean searchScheduledTasks = false;
boolean searchRecurringParent = false;
boolean searchRecurringTasks = false;
{
switch (searchScope)
{
case BASE_OBJECT:
searchRoot = true;
break;
case SINGLE_LEVEL:
searchScheduledParent = true;
searchRecurringParent = true;
break;
case WHOLE_SUBTREE:
searchRoot = true;
searchScheduledParent = true;
searchRecurringParent = true;
searchScheduledTasks = true;
searchRecurringTasks = true;
break;
case SUBORDINATE_SUBTREE:
searchScheduledParent = true;
searchRecurringParent = true;
searchScheduledTasks = true;
searchRecurringTasks = true;
break;
}
}
{
switch (searchScope)
{
case BASE_OBJECT:
searchScheduledParent = true;
break;
case SINGLE_LEVEL:
searchScheduledTasks = true;
break;
case WHOLE_SUBTREE:
searchScheduledParent = true;
searchScheduledTasks = true;
break;
case SUBORDINATE_SUBTREE:
searchScheduledTasks = true;
break;
}
}
{
switch (searchScope)
{
case BASE_OBJECT:
searchRecurringParent = true;
break;
case SINGLE_LEVEL:
searchRecurringTasks = true;
break;
case WHOLE_SUBTREE:
searchRecurringParent = true;
searchRecurringTasks = true;
break;
case SUBORDINATE_SUBTREE:
searchRecurringTasks = true;
break;
}
}
else
{
{
}
{
try
{
if (e == null)
{
}
{
}
return;
}
finally
{
}
}
{
try
{
if (e == null)
{
}
{
}
return;
}
finally
{
}
}
else
{
}
}
if (searchRoot)
{
if (searchFilter.matchesEntry(e))
{
{
return;
}
}
}
{
if (searchFilter.matchesEntry(e))
{
{
return;
}
}
}
if (searchScheduledTasks)
{
{
return;
}
}
{
if (searchFilter.matchesEntry(e))
{
{
return;
}
}
}
if (searchRecurringTasks)
{
{
return;
}
}
}
/**
* {@inheritDoc}
*/
@Override()
{
return supportedControls;
}
/**
* {@inheritDoc}
*/
@Override()
{
return supportedFeatures;
}
/**
* {@inheritDoc}
*/
@Override()
public boolean supportsLDIFExport()
{
// LDIF exports are supported.
return true;
}
/**
* {@inheritDoc}
*/
@Override()
throws DirectoryException
{
// FIXME -- Implement support for exporting to LDIF.
}
/**
* {@inheritDoc}
*/
@Override()
public boolean supportsLDIFImport()
{
// This backend does not support LDIF imports.
return false;
}
/**
* {@inheritDoc}
*/
@Override()
throws DirectoryException
{
// This backend does not support LDIF imports.
}
/**
* {@inheritDoc}
*/
@Override()
public boolean supportsBackup()
{
return true;
}
/**
* {@inheritDoc}
*/
@Override()
{
return true;
}
/**
* {@inheritDoc}
*/
@Override()
throws DirectoryException
{
// NYI -- Create the backup.
}
/**
* {@inheritDoc}
*/
@Override()
throws DirectoryException
{
// NYI -- Remove the backup.
}
/**
* {@inheritDoc}
*/
@Override()
public boolean supportsRestore()
{
return true;
}
/**
* {@inheritDoc}
*/
@Override()
throws DirectoryException
{
// NYI -- Restore the backup.
}
/**
* {@inheritDoc}
*/
@Override()
{
}
/**
* {@inheritDoc}
*/
{
}
/**
* Indicates whether the provided configuration is acceptable for this task
* backend.
*
* @param config The configuration for which to make the
* determination.
* @param unacceptableReasons A list into which the unacceptable reasons
* should be placed.
* @param taskBackingFile The currently-configured task backing file, or
* {@code null} if it should not be taken into
* account.
*
* @return {@code true} if the configuration is acceptable, or {@code false}
* if not.
*/
{
boolean configIsAcceptable = true;
try
{
if ((taskBackingFile == null) ||
{
if (f.exists())
{
// This is only a problem if it's different from the active one.
if (taskBackingFile != null)
{
configIsAcceptable = false;
}
}
else
{
File p = f.getParentFile();
if (p == null)
{
configIsAcceptable = false;
}
else if (! p.exists())
{
p.getPath(),
configIsAcceptable = false;
}
else if (! p.isDirectory())
{
p.getPath(),
configIsAcceptable = false;
}
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
getExceptionMessage(e)));
configIsAcceptable = false;
}
return configIsAcceptable;
}
/**
* {@inheritDoc}
*/
{
boolean adminActionRequired = false;
try
{
{
{
if (f.exists())
{
}
else
{
File p = f.getParentFile();
if (p == null)
{
}
else if (! p.exists())
{
}
else if (! p.isDirectory())
{
}
}
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
getExceptionMessage(e)));
}
{
// Everything looks OK, so apply the changes.
if (retentionTime != tmpRetentionTime)
{
}
{
}
}
if (tmpNotificationAddress == null)
{
try
{
tmpNotificationAddress = "opends-task-notification@" +
}
catch (Exception e)
{
tmpNotificationAddress = "opends-task-notification@opends.org";
}
}
}
/**
* Retrieves the DN of the configuration entry for this task backend.
*
* @return The DN of the configuration entry for this task backend.
*/
public DN getConfigEntryDN()
{
return configEntryDN;
}
/**
* Retrieves the path to the backing file that will hold the scheduled and
* recurring task definitions.
*
* @return The path to the backing file that will hold the scheduled and
* recurring task definitions.
*/
public String getTaskBackingFile()
{
return f.getPath();
}
/**
* Retrieves the sender address that should be used for e-mail notifications
* of task completion.
*
* @return The sender address that should be used for e-mail notifications of
* task completion.
*/
public String getNotificationSenderAddress()
{
return notificationSenderAddress;
}
/**
* Retrieves the length of time in seconds that information for a task should
* be retained after processing on it has completed.
*
* @return The length of time in seconds that information for a task should
* be retained after processing on it has completed.
*/
public long getRetentionTime()
{
return retentionTime;
}
/**
* Retrieves the DN of the entry that is the root for all task information in
* the Directory Server.
*
* @return The DN of the entry that is the root for all task information in
* the Directory Server.
*/
public DN getTaskRootDN()
{
return taskRootDN;
}
/**
* Retrieves the DN of the entry that is the immediate parent for all
* recurring task information in the Directory Server.
*
* @return The DN of the entry that is the immediate parent for all recurring
* task information in the Directory Server.
*/
public DN getRecurringTasksParentDN()
{
return recurringTaskParentDN;
}
/**
* Retrieves the DN of the entry that is the immediate parent for all
* scheduled task information in the Directory Server.
*
* @return The DN of the entry that is the immediate parent for all scheduled
* task information in the Directory Server.
*/
public DN getScheduledTasksParentDN()
{
return scheduledTaskParentDN;
}
/**
* Retrieves the scheduled task for the entry with the provided DN.
*
* @param taskEntryDN The DN of the entry for the task to retrieve.
*
* @return The requested task, or {@code null} if there is no task with the
* specified entry DN.
*/
{
}
/**
* Retrieves the recurring task for the entry with the provided DN.
*
* @param taskEntryDN The DN of the entry for the recurring task to
* retrieve.
*
* @return The requested recurring task, or {@code null} if there is no task
* with the specified entry DN.
*/
{
}
/**
* {@inheritDoc}
*/
{
throw new UnsupportedOperationException("Operation not supported.");
}
}