Class PasteurCleanUpPolicy

java.lang.Object
org.odpi.openmetadata.adapters.connectors.pasteur.PasteurCleanUpPolicy

public class PasteurCleanUpPolicy extends Object
PasteurCleanUpPolicy decides which finished actions are old enough to be cleaned up. It is built from the daysToCleanUp and completionStatuses configuration properties and holds no connection to the open metadata ecosystem, so the rules can be tested on their own.

An action is eligible for clean-up when all of these are true:

  • its type, or the nearest of its supertypes, has an entry in daysToCleanUp;
  • its activity status is one of the completion statuses;
  • at least that many days have passed since it completed. The completion time is the action's completionTime property, or the time it was last updated (or created) if that is not set.
  • Field Details

    • DEFAULT_DELETE_METHOD

      public static final DeleteMethod DEFAULT_DELETE_METHOD
      The delete method used unless the deleteMethod configuration property names another. An action with lineage relationships is archived, so lineage queries can still find it, and the others are soft-deleted.
  • Constructor Details

    • PasteurCleanUpPolicy

      public PasteurCleanUpPolicy(Map<String,Long> daysToCleanUp, Collection<String> completionStatuses)
      Constructor.
      Parameters:
      daysToCleanUp - type name to the minimum days after completion - entries with a null key or value, or a negative value, are skipped
      completionStatuses - symbolic names of the activity statuses that show an action has finished
  • Method Details

    • getDaysToCleanUp

      public Map<String,Long> getDaysToCleanUp()
      Return the configured days to clean up.
      Returns:
      sorted map of type name to days
    • getCleanUpTypeNames

      public List<String> getCleanUpTypeNames()
      Return the type names that have an entry in daysToCleanUp, in the order they are cleaned up.
      Returns:
      list of type names
    • getCompletionStatuses

      public Set<String> getCompletionStatuses()
      Return the completion statuses.
      Returns:
      set of symbolic names
    • isActive

      public boolean isActive()
      Return whether there is anything to clean up.
      Returns:
      false if there are no days to clean up or no completion statuses
    • getDaysToCleanUp

      public Long getDaysToCleanUp(String typeName, List<String> superTypeNames)
      Return the minimum days after completion for an action's type. The entry for the type itself is used if there is one, otherwise the entry for the nearest supertype.
      Parameters:
      typeName - name of the action's type
      superTypeNames - names of its supertypes, nearest first - may be null
      Returns:
      days, or null if neither the type nor any of its supertypes has an entry
    • isCompletionStatus

      public boolean isCompletionStatus(String activityStatus)
      Return whether the activity status shows the action has finished.
      Parameters:
      activityStatus - symbolic name of the action's activity status - may be null
      Returns:
      boolean
    • getCompletionDate

      public static Date getCompletionDate(Date completionTime, Date updateTime, Date createTime)
      Return when the action completed. This is its completionTime property if it is set. Otherwise, it is the time the action was last updated, since setting the final status is normally the last update. An action that has never been updated uses its creation time.
      Parameters:
      completionTime - the action's completionTime property - may be null
      updateTime - when the action was last updated - may be null
      createTime - when the action was created - may be null
      Returns:
      date, or null if none of them is known
    • isOldEnough

      public static boolean isOldEnough(Date completionDate, long days, Date now)
      Return whether enough time has passed since an action completed.
      Parameters:
      completionDate - when the action completed - null means it is not known, so the action is kept
      days - minimum days after completion
      now - the time to measure from
      Returns:
      boolean
    • isEligible

      public boolean isEligible(String typeName, List<String> superTypeNames, String activityStatus, Date completionTime, Date updateTime, Date createTime, Date now)
      Return whether an action is eligible for clean-up.
      Parameters:
      typeName - name of the action's type
      superTypeNames - names of its supertypes, nearest first - may be null
      activityStatus - symbolic name of the action's activity status - may be null
      completionTime - the action's completionTime property - may be null
      updateTime - when the action was last updated - may be null
      createTime - when the action was created - may be null
      now - the time to measure from
      Returns:
      boolean
    • parseDaysToCleanUp

      public static Map<String,Long> parseDaysToCleanUp(Object configurationValue, List<String> invalidEntries)
      Turn the value of the daysToCleanUp configuration property into a map of type name to days. The values arrive as numbers (Integer or Long, depending on their size, when the connection is read from JSON) or as strings. The entries that can not be turned into a number of days that is zero or more are skipped and described in invalidEntries.
      Parameters:
      configurationValue - value of the configuration property - may be null
      invalidEntries - list to add descriptions of the skipped entries to
      Returns:
      map of type name to days - empty if the value is null or not a map
    • parseCompletionStatuses

      public static List<String> parseCompletionStatuses(List<String> configuredStatuses, List<String> defaultStatuses, List<String> invalidStatuses)
      Check the configured completion statuses against the ActivityStatus enum. The comparison ignores case and surrounding spaces. The statuses that are not recognized are skipped and added to invalidStatuses.
      Parameters:
      configuredStatuses - value of the completionStatuses configuration property - null means use the default
      defaultStatuses - statuses to use if none are configured
      invalidStatuses - list to add the unrecognized statuses to
      Returns:
      list of the symbolic names of the recognized statuses
    • parseDeleteMethod

      public static DeleteMethod parseDeleteMethod(String configuredDeleteMethod)
      Return the delete method named in the deleteMethod configuration property.
      Parameters:
      configuredDeleteMethod - symbolic name of a DeleteMethod value (case is ignored), or null
      Returns:
      the named delete method, the default if none is named, or null if the name is not a delete method