Class FileRetentionTask

  • All Implemented Interfaces:
    java.io.Serializable

    @NotMutable
    @ThreadSafety(level=COMPLETELY_THREADSAFE)
    public final class FileRetentionTask
    extends Task
    This class defines a Directory Server task that can be used to identify files in a specified directory that match a given pattern, and delete any of those files that are outside of a provided set of retention criteria.
    NOTE: This class, and other classes within the com.unboundid.ldap.sdk.unboundidds package structure, are only supported for use against Ping Identity, UnboundID, and Nokia/Alcatel-Lucent 8661 server products. These classes provide support for proprietary functionality or for external specifications that are not considered stable or mature enough to be guaranteed to work in an interoperable way with other types of LDAP servers.

    The files to examine are identified by a combination of three items:
    • A target directory. This is simply the path to the directory that contains the files to examine.
    • A filename pattern. This is a string that will be used to identify the files of interest in the target directory. The pattern may contain zero or more (non-consecutive) asterisks to use as wildcards that match zero or more characters, and it may contain at most one occurrence of the token "${timestamp}" (without the quotation marks) that is a placeholder for a timestamp that indicates when the file was written or the age of the data in that file. For example, the filename pattern "*-${timestamp}.log" will match any file in the target directory that ends with a dash, a timestamp, and an extension of ".log".
    • A timestamp format. This specifies the format that will be used for the value that matches the "${timestamp}" token in the filename pattern. See the FileRetentionTaskTimestampFormat enum for the set of defined timestamp formats.

    The types of retention criteria include:
    • A retain count, which specifies the minimum number of files to retain. For example, if there is a retain count of five, and the target directory contains ten files that match the filename pattern, the task will always keep at least the five most recent files, while the five oldest files will be candidates for removal.
    • A retain age, which specifies the minimum age of the files to retain. If the filename pattern includes a timestamp, then the age of the file will be determined using that timestamp. If the filename pattern does not contain a timestamp, then the age of the file will be determined from the file's create time attribute (if available) or last modified time. The task will always keep all files whose age is less than or equal to the retain age, while files older than the retain age will be candidates for removal.
    • An aggregate retain size, which specifies combined minimum amount of disk space that should be consumed by the files that should be retained. For example, if the task is configured with an aggregate retain size of 500 megabytes and the files to examine are all 75 megabytes each, then the task will keep at least the seven most recent files (because 500/75 = 6.7, and the task will always round up to the next whole number), and any older files in the same directory that match the pattern will be candidates for removal.

    The task must be configured with at least one of the three types of retention criteria, but it may combine any two or all three of them. If a task is configured with multiple types of retention criteria, then a file will only be a candidate for removal if it is outside of all of the retention criteria. For example, if the task is configured with a retain count of 5 and a retain age of 1 week, then the task may retain more than five files if there are more than five files that are less than a week old, and it may retain files that are more than a week old if there are fewer than five files within that age.
    See Also:
    Serialized Form
    • Constructor Detail

      • FileRetentionTask

        public FileRetentionTask()
        Creates a new, uninitialized file retention task instance that should only be used for obtaining general information about this task, including the task name, description, and supported properties. Attempts to use a task created with this constructor for any other reason will likely fail.
      • FileRetentionTask

        public FileRetentionTask​(java.lang.String targetDirectory,
                                 java.lang.String filenamePattern,
                                 FileRetentionTaskTimestampFormat timestampFormat,
                                 java.lang.Integer retainFileCount,
                                 java.lang.Long retainFileAgeMillis,
                                 java.lang.Long retainAggregateFileSizeBytes)
        Creates a new file retention task with the provided information.
        Parameters:
        targetDirectory - The path to the directory containing the files to examine. This must be provided, and the target directory must exist on the server filesystem.
        filenamePattern - A pattern that identifies the files to examine. The pattern may include zero or more (non-consecutive) asterisks that act as wildcards and match zero or more characters. The pattern may also contain at most one occurrence of the "${timestamp}" token, which indicates that the filename includes a timestamp with the format specified in the timestampFormat argument. This must not be null or empty.
        timestampFormat - The expected format for the timestamp that may appear in the filename pattern. This must not be null, even if the filename pattern does not contain a "${timestamp}" token.
        retainFileCount - The minimum number of the most recent files that should be retained. This may be null if only age-based or size-based retention criteria should be used. At least one of the retainFileCount, retainFileAgeMillis, and retainAggregateFileSizeBytes values must be non-null. If this value is non-null, then it must be greater than or equal to zero.
        retainFileAgeMillis - The minimum age, in milliseconds, for files that should be retained. This may be null if only count-based or size-based retention criteria should be used. At least one of the retainFileCount, retainFileAgeMillis, and retainAggregateFileSizeBytes values must be non-null. If this value is non-null, then it must be greater than zero.
        retainAggregateFileSizeBytes - The minimum amount of disk space, in bytes, that should be consumed by the files to be retained. This may be null if only count-based or age-based retention criteria should be used. At least one of the retainFileCount, retainFileAgeMillis, and retainAggregateFileSizeBytes values must be non-null. If this value is non-null, then it must be greater than zero.
      • FileRetentionTask

        public FileRetentionTask​(java.lang.String taskID,
                                 java.lang.String targetDirectory,
                                 java.lang.String filenamePattern,
                                 FileRetentionTaskTimestampFormat timestampFormat,
                                 java.lang.Integer retainFileCount,
                                 java.lang.Long retainFileAgeMillis,
                                 java.lang.Long retainAggregateFileSizeBytes,
                                 java.util.Date scheduledStartTime,
                                 java.util.List<java.lang.String> dependencyIDs,
                                 FailedDependencyAction failedDependencyAction,
                                 java.util.List<java.lang.String> notifyOnStart,
                                 java.util.List<java.lang.String> notifyOnCompletion,
                                 java.util.List<java.lang.String> notifyOnSuccess,
                                 java.util.List<java.lang.String> notifyOnError,
                                 java.lang.Boolean alertOnStart,
                                 java.lang.Boolean alertOnSuccess,
                                 java.lang.Boolean alertOnError)
        Creates a new file retention task with the provided information.
        Parameters:
        taskID - The task ID to use for this task. If it is null then a UUID will be generated for use as the task ID.
        targetDirectory - The path to the directory containing the files to examine. This must be provided, and the target directory must exist on the server filesystem.
        filenamePattern - A pattern that identifies the files to examine. The pattern may include zero or more (non-consecutive) asterisks that act as wildcards and match zero or more characters. The pattern may also contain at most one occurrence of the "${timestamp}" token, which indicates that the filename includes a timestamp with the format specified in the timestampFormat argument. This must not be null or empty.
        timestampFormat - The expected format for the timestamp that may appear in the filename pattern. This must not be null, even if the filename pattern does not contain a "${timestamp}" token.
        retainFileCount - The minimum number of the most recent files that should be retained. This may be null if only age-based or size-based retention criteria should be used. At least one of the retainFileCount, retainFileAgeMillis, and retainAggregateFileSizeBytes values must be non-null. If this value is non-null, then it must be greater than or equal to zero.
        retainFileAgeMillis - The minimum age, in milliseconds, for files that should be retained. This may be null if only count-based or size-based retention criteria should be used. At least one of the retainFileCount, retainFileAgeMillis, and retainAggregateFileSizeBytes values must be non-null. If this value is non-null, then it must be greater than zero.
        retainAggregateFileSizeBytes - The minimum amount of disk space, in bytes, that should be consumed by the files to be retained. This may be null if only count-based or age-based retention criteria should be used. At least one of the retainFileCount, retainFileAgeMillis, and retainAggregateFileSizeBytes values must be non-null. If this value is non-null, then it must be greater than zero.
        scheduledStartTime - The time that this task should start running.
        dependencyIDs - The list of task IDs that will be required to complete before this task will be eligible to start.
        failedDependencyAction - Indicates what action should be taken if any of the dependencies for this task do not complete successfully.
        notifyOnStart - The list of e-mail addresses of individuals that should be notified when this task starts.
        notifyOnCompletion - The list of e-mail addresses of individuals that should be notified when this task completes.
        notifyOnSuccess - The list of e-mail addresses of individuals that should be notified if this task completes successfully.
        notifyOnError - The list of e-mail addresses of individuals that should be notified if this task does not complete successfully.
        alertOnStart - Indicates whether the server should send an alert notification when this task starts.
        alertOnSuccess - Indicates whether the server should send an alert notification if this task completes successfully.
        alertOnError - Indicates whether the server should send an alert notification if this task fails to complete successfully.
      • FileRetentionTask

        public FileRetentionTask​(Entry entry)
                          throws TaskException
        Creates a new file retention task from the provided entry.
        Parameters:
        entry - The entry to use to create this file retention task.
        Throws:
        TaskException - If the provided entry cannot be parsed as a file retention task entry.
      • FileRetentionTask

        public FileRetentionTask​(java.util.Map<TaskProperty,​java.util.List<java.lang.Object>> properties)
                          throws TaskException
        Creates a new file retention task from the provided set of task properties.
        Parameters:
        properties - The set of task properties and their corresponding values to use for the task. It must not be null.
        Throws:
        TaskException - If the provided set of properties cannot be used to create a valid file retention task.
    • Method Detail

      • getTaskName

        public java.lang.String getTaskName()
        Retrieves a human-readable name for this task.
        Overrides:
        getTaskName in class Task
        Returns:
        A human-readable name for this task.
      • getTaskDescription

        public java.lang.String getTaskDescription()
        Retrieves a human-readable description for this task.
        Overrides:
        getTaskDescription in class Task
        Returns:
        A human-readable description for this task.
      • getTargetDirectory

        public java.lang.String getTargetDirectory()
        Retrieves the path to the directory (on the server filesystem) containing the files to examine.
        Returns:
        The path to the directory (on the server filesystem) containing the files to examine.
      • getFilenamePattern

        public java.lang.String getFilenamePattern()
        Retrieves the filename pattern that the task should use to identify which files to examine.
        Returns:
        The filename pattern that the task should use to identify which files to examine.
      • getTimestampFormat

        public FileRetentionTaskTimestampFormat getTimestampFormat()
        Retrieves the format to use to interpret the timestamp element in the filename pattern.
        Returns:
        The format to use to interpret the timestamp element in the filename pattern.
      • getRetainFileCount

        public java.lang.Integer getRetainFileCount()
        Retrieves the minimum number of files to retain, if defined.
        Returns:
        The minimum number of files to retain, or null if there is no count-based retention criteria.
      • getRetainFileAgeMillis

        public java.lang.Long getRetainFileAgeMillis()
        Retrieves the minimum age (in milliseconds) of files to retain, if defined.
        Returns:
        The minimum age (in milliseconds) of files to retain, or null if there is no age-based retention criteria.
      • getRetainAggregateFileSizeBytes

        public java.lang.Long getRetainAggregateFileSizeBytes()
        Retrieves the minimum aggregate size (in bytes) of files to retain, if defined.
        Returns:
        The minimum aggregate size (in bytes) of files to retain, or null if there is no size-based retention criteria.
      • getAdditionalObjectClasses

        protected java.util.List<java.lang.String> getAdditionalObjectClasses()
        Retrieves a list of the additional object classes (other than the base "top" and "ds-task" classes) that should be included when creating new task entries of this type.
        Overrides:
        getAdditionalObjectClasses in class Task
        Returns:
        A list of the additional object classes that should be included in new task entries of this type, or an empty list if there do not need to be any additional classes.
      • getAdditionalAttributes

        protected java.util.List<AttributegetAdditionalAttributes()
        Retrieves a list of the additional attributes (other than attributes common to all task types) that should be included when creating new task entries of this type.
        Overrides:
        getAdditionalAttributes in class Task
        Returns:
        A list of the additional attributes that should be included in new task entries of this type, or an empty list if there do not need to be any additional attributes.
      • getTaskSpecificProperties

        public java.util.List<TaskPropertygetTaskSpecificProperties()
        Retrieves a list of task-specific properties that may be provided when scheduling a task of this type. This method should be overridden by subclasses in order to provide an appropriate set of properties.
        Overrides:
        getTaskSpecificProperties in class Task
        Returns:
        A list of task-specific properties that may be provided when scheduling a task of this type.
      • getTaskPropertyValues

        public java.util.Map<TaskProperty,​java.util.List<java.lang.Object>> getTaskPropertyValues()
        Retrieves the values of the task properties for this task. The data type of the values will vary based on the data type of the corresponding task property and may be one of the following types: Boolean, Date, Long, or String. Task properties which do not have any values will be included in the map with an empty value list.

        Note that subclasses which have additional task properties should override this method and return a map which contains both the property values from this class (obtained from super.getTaskPropertyValues() and the values of their own task-specific properties.
        Overrides:
        getTaskPropertyValues in class Task
        Returns:
        A map of the task property values for this task.