| | |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.util.Reject; |
| | | import org.opends.server.admin.Configuration; |
| | | import org.opends.server.admin.server.ConfigurationChangeListener; |
| | | import org.opends.server.admin.std.server.TaskBackendCfg; |
| | | import org.opends.server.api.Backend; |
| | |
| | | * recurring basis. |
| | | */ |
| | | public class TaskBackend |
| | | extends Backend |
| | | extends Backend<TaskBackendCfg> |
| | | implements ConfigurationChangeListener<TaskBackendCfg> |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | |
| | | |
| | | // The current configuration state. |
| | | /** The current configuration state. */ |
| | | private TaskBackendCfg currentConfig; |
| | | |
| | | // The DN of the configuration entry for this backend. |
| | | /** 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. |
| | | /** |
| | | * 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. |
| | | /** |
| | | * 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. |
| | | /** 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 base DNs defined for this backend. */ |
| | | private DN[] baseDNs; |
| | | |
| | | // The set of supported controls for this backend. |
| | | private HashSet<String> supportedControls; |
| | | |
| | | // The set of supported features for this backend. |
| | | private HashSet<String> supportedFeatures; |
| | | |
| | | // The length of time in seconds after a task is completed that it should be |
| | | // removed from the set of scheduled tasks. |
| | | /** |
| | | * 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. |
| | | /** The e-mail address to use for the sender from notification messages. */ |
| | | private String notificationSenderAddress; |
| | | |
| | | // The path to the task backing file. |
| | | /** The path to the task backing file. */ |
| | | private String taskBackingFile; |
| | | |
| | | // The task scheduler that will be responsible for actually invoking scheduled |
| | | // tasks. |
| | | /** |
| | | * The task scheduler that will be responsible for actually invoking scheduled |
| | | * tasks. |
| | | */ |
| | | private TaskScheduler taskScheduler; |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public void configureBackend(Configuration config) |
| | | throws ConfigException |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void configureBackend(TaskBackendCfg cfg) throws ConfigException |
| | | { |
| | | Reject.ifNull(config); |
| | | Reject.ifFalse(config instanceof TaskBackendCfg); |
| | | Reject.ifNull(cfg); |
| | | |
| | | TaskBackendCfg cfg = (TaskBackendCfg)config; |
| | | |
| | | DN[] baseDNs = new DN[cfg.getBaseDN().size()]; |
| | | final DN[] baseDNs = new DN[cfg.getBaseDN().size()]; |
| | | cfg.getBaseDN().toArray(baseDNs); |
| | | |
| | | ConfigEntry configEntry = DirectoryServer.getConfigEntry(cfg.dn()); |
| | |
| | | |
| | | // Make sure that the provided set of base DNs contains exactly one value. |
| | | // We will only allow one base for task entries. |
| | | if ((baseDNs == null) || (baseDNs.length == 0)) |
| | | if (baseDNs.length == 0) |
| | | { |
| | | LocalizableMessage message = ERR_TASKBE_NO_BASE_DNS.get(); |
| | | throw new ConfigException(message); |
| | | throw new ConfigException(ERR_TASKBE_NO_BASE_DNS.get()); |
| | | } |
| | | else if (baseDNs.length > 1) |
| | | { |
| | |
| | | taskRootDN = baseDNs[0]; |
| | | |
| | | String recurringTaskBaseString = RECURRING_TASK_BASE_RDN + "," + |
| | | taskRootDN.toString(); |
| | | taskRootDN; |
| | | try |
| | | { |
| | | recurringTaskParentDN = DN.valueOf(recurringTaskBaseString); |
| | |
| | | } |
| | | |
| | | String scheduledTaskBaseString = SCHEDULED_TASK_BASE_RDN + "," + |
| | | taskRootDN.toString(); |
| | | taskRootDN; |
| | | try |
| | | { |
| | | scheduledTaskParentDN = DN.valueOf(scheduledTaskBaseString); |
| | |
| | | // Get the path to the task data backing file. |
| | | taskBackingFile = cfg.getTaskBackingFile(); |
| | | |
| | | // Define an empty sets for the supported controls and features. |
| | | supportedControls = new HashSet<String>(0); |
| | | supportedFeatures = new HashSet<String>(0); |
| | | |
| | | currentConfig = cfg; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void initializeBackend() |
| | | throws ConfigException, InitializationException |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void finalizeBackend() |
| | | { |
| | | currentConfig.removeTaskChangeListener(this); |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public DN[] getBaseDNs() |
| | | { |
| | | return baseDNs; |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public long getEntryCount() |
| | | { |
| | | if (taskScheduler != null) |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isLocal() |
| | | { |
| | | // For the purposes of this method, this is a local backend. |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isIndexed(AttributeType attributeType, IndexType indexType) |
| | | { |
| | | // All searches in this backend will always be considered indexed. |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConditionResult hasSubordinates(DN entryDN) |
| | | throws DirectoryException |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public long numSubordinates(DN entryDN, boolean subtree) |
| | | throws DirectoryException |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Entry getEntry(DN entryDN) |
| | | throws DirectoryException |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void addEntry(Entry entry, AddOperation addOperation) |
| | | throws DirectoryException |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void deleteEntry(DN entryDN, DeleteOperation deleteOperation) |
| | | throws DirectoryException |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void replaceEntry(Entry oldEntry, Entry newEntry, |
| | | ModifyOperation modifyOperation) throws DirectoryException |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void renameEntry(DN currentDN, Entry entry, |
| | | ModifyDNOperation modifyDNOperation) |
| | | throws DirectoryException |
| | | { |
| | | LocalizableMessage message = ERR_TASKBE_MODIFY_DN_NOT_SUPPORTED.get(); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, |
| | | ERR_BACKEND_MODIFY_DN_NOT_SUPPORTED.get(currentDN, getBackendID())); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void search(SearchOperation searchOperation) |
| | | throws DirectoryException, CanceledOperationException { |
| | | // Look at the base DN and scope for the search operation to decide which |
| | |
| | | scheduledTaskParentDN, null); |
| | | } |
| | | |
| | | if (((searchScope == SearchScope.BASE_OBJECT) || |
| | | (searchScope == SearchScope.WHOLE_SUBTREE)) && |
| | | searchFilter.matchesEntry(e)) |
| | | if ((searchScope == SearchScope.BASE_OBJECT || searchScope == SearchScope.WHOLE_SUBTREE) |
| | | && searchFilter.matchesEntry(e)) |
| | | { |
| | | searchOperation.returnEntry(e, null); |
| | | } |
| | |
| | | recurringTaskParentDN, null); |
| | | } |
| | | |
| | | if (((searchScope == SearchScope.BASE_OBJECT) || |
| | | (searchScope == SearchScope.WHOLE_SUBTREE)) && |
| | | searchFilter.matchesEntry(e)) |
| | | if ((searchScope == SearchScope.BASE_OBJECT || searchScope == SearchScope.WHOLE_SUBTREE) |
| | | && searchFilter.matchesEntry(e)) |
| | | { |
| | | searchOperation.returnEntry(e, null); |
| | | } |
| | |
| | | if (searchRoot) |
| | | { |
| | | Entry e = taskScheduler.getTaskRootEntry(); |
| | | if (searchFilter.matchesEntry(e)) |
| | | if (searchFilter.matchesEntry(e) && !searchOperation.returnEntry(e, null)) |
| | | { |
| | | if (! searchOperation.returnEntry(e, null)) |
| | | { |
| | | return; |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | |
| | |
| | | if (searchScheduledParent) |
| | | { |
| | | Entry e = taskScheduler.getScheduledTaskParentEntry(); |
| | | if (searchFilter.matchesEntry(e)) |
| | | if (searchFilter.matchesEntry(e) && !searchOperation.returnEntry(e, null)) |
| | | { |
| | | if (! searchOperation.returnEntry(e, null)) |
| | | { |
| | | return; |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | |
| | | |
| | | if (searchScheduledTasks) |
| | | if (searchScheduledTasks |
| | | && !taskScheduler.searchScheduledTasks(searchOperation)) |
| | | { |
| | | if (! taskScheduler.searchScheduledTasks(searchOperation)) |
| | | { |
| | | return; |
| | | } |
| | | return; |
| | | } |
| | | |
| | | |
| | | if (searchRecurringParent) |
| | | { |
| | | Entry e = taskScheduler.getRecurringTaskParentEntry(); |
| | | if (searchFilter.matchesEntry(e)) |
| | | { |
| | | if (! searchOperation.returnEntry(e, null)) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | if (searchRecurringTasks) |
| | | { |
| | | if (! taskScheduler.searchRecurringTasks(searchOperation)) |
| | | if (searchFilter.matchesEntry(e) && !searchOperation.returnEntry(e, null)) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | |
| | | if (searchRecurringTasks |
| | | && !taskScheduler.searchRecurringTasks(searchOperation)) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public HashSet<String> getSupportedControls() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Set<String> getSupportedControls() |
| | | { |
| | | return supportedControls; |
| | | return Collections.emptySet(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public HashSet<String> getSupportedFeatures() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public Set<String> getSupportedFeatures() |
| | | { |
| | | return supportedFeatures; |
| | | return Collections.emptySet(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean supportsLDIFExport() |
| | | { |
| | | // LDIF exports are supported. |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void exportLDIF(LDIFExportConfig exportConfig) |
| | | throws DirectoryException |
| | | { |
| | |
| | | } |
| | | finally |
| | | { |
| | | try |
| | | { |
| | | ldifWriter.close(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | logger.traceException(e); |
| | | } |
| | | try |
| | | { |
| | | ldifReader.close(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | logger.traceException(e); |
| | | } |
| | | close(ldifWriter, ldifReader); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean supportsLDIFImport() |
| | | { |
| | | // This backend does not support LDIF imports. |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public LDIFImportResult importLDIF(LDIFImportConfig importConfig) |
| | | throws DirectoryException |
| | | { |
| | | // This backend does not support LDIF imports. |
| | | LocalizableMessage message = ERR_TASKBE_IMPORT_NOT_SUPPORTED.get(); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); |
| | | throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, |
| | | ERR_BACKEND_IMPORT_NOT_SUPPORTED.get(getBackendID())); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean supportsBackup() |
| | | { |
| | | // This backend does provide a backup/restore mechanism. |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean supportsBackup(BackupConfig backupConfig, |
| | | StringBuilder unsupportedReason) |
| | | { |
| | | // This backend does provide a backup/restore mechanism. |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void createBackup(BackupConfig backupConfig) |
| | | throws DirectoryException |
| | | { |
| | |
| | | inputStream.close(); |
| | | } catch (Exception e) { |
| | | logger.traceException(e); |
| | | |
| | | try { |
| | | inputStream.close(); |
| | | } catch (Exception e2) { |
| | | } |
| | | |
| | | try { |
| | | zipStream.close(); |
| | | } catch (Exception e2) { |
| | | } |
| | | close(inputStream, zipStream); |
| | | |
| | | message = ERR_TASKS_BACKUP_CANNOT_BACKUP_TASKS_FILE.get(baseName, |
| | | stackTraceToSingleLineString(e)); |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void removeBackup(BackupDirectory backupDirectory, |
| | | String backupID) |
| | | throws DirectoryException |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean supportsRestore() |
| | | { |
| | | // This backend does provide a backup/restore mechanism. |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void restoreBackup(RestoreConfig restoreConfig) |
| | | throws DirectoryException |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public boolean isConfigurationAcceptable(Configuration configuration, |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isConfigurationAcceptable(TaskBackendCfg config, |
| | | List<LocalizableMessage> unacceptableReasons) |
| | | { |
| | | TaskBackendCfg config = (TaskBackendCfg) configuration; |
| | | return isConfigAcceptable(config, unacceptableReasons, null); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isConfigurationChangeAcceptable(TaskBackendCfg configEntry, |
| | | List<LocalizableMessage> unacceptableReasons) |
| | |
| | | try |
| | | { |
| | | String tmpBackingFile = config.getTaskBackingFile(); |
| | | if ((taskBackingFile == null) || |
| | | (! taskBackingFile.equals(tmpBackingFile))) |
| | | if (taskBackingFile == null || |
| | | !taskBackingFile.equals(tmpBackingFile)) |
| | | { |
| | | File f = getFileForPath(tmpBackingFile); |
| | | if (f.exists()) |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ConfigChangeResult applyConfigurationChange(TaskBackendCfg configEntry) |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void preloadEntryCache() throws UnsupportedOperationException { |
| | | throw new UnsupportedOperationException("Operation not supported."); |