Class ProcessManagerTools

java.lang.Object
de.aristaflow.adept2.core.processmanager.ProcessManagerTools

public class ProcessManagerTools extends Object
This class provides some useful methods for process manager logic, e. g. retrieving the latest template of a process type and aggregating states of subprocess instances.
  • Method Details

    • getLatestTemplateVersion

      public static TemplateReference getLatestTemplateVersion(SessionToken session, String processType, TemplateManager templMgr, FilterFactory filtFactory)
      Tries to retrieve the template of the designated process type having the highest version number in the template manager. Only released, instantiable, non-outdated and top-level usable templates will be recognised. If no such template is found (the process type is unknown or the filter yields an empty result), null will be returned.

      Important! This method has some serious restrictions:
      Due to the non-linear versioning of templates, the result of this method is ambiguous. It just retrieves the template with the highest version number which need not be the latest version at all. Additionally, the template manager need not know all templates of a process type and therefore only a subset of all templates of the process type may be considered.
      Last but not least, the "interface" of a process type may change between two versions, that is, templates of the same process type may have different input and output parameters. Therefore the "latest" template may be incompatible with the calling context.

      Parameters:
      session - The session with which to retrieve the templates.
      processType - The name of the process type of which to get the "latest" template.
      templMgr - The template manager from which to retrieve the template.
      filtFactory - The filter factory for creating the filters that apply to the templates.
      Returns:
      The "latest" template of the designated process type from the designated template manager. This is the instantiable top-level template having the highest version number. If no template is found for the designated process type, null will be returned.
    • isStartable

      public static boolean isStartable(TemplateReference template)
      Gets whether the designated template is in the state in which getLatestTemplateVersion(SessionToken, String, TemplateManager, FilterFactory) recognises a template: released, instantiable and not outdated on top-level scope and top-level usable. Instances of such a template can be started on top level.
      Parameters:
      template - The template to check. This must not be null.
      Returns:
      Whether the designated template is released, instantiable and not outdated on top-level scope and top-level usable.
    • createStartableStatusFilter

      public static Filter createStartableStatusFilter(FilterFactory filtFactory)
      Creates the filter on template statuses which matches the status of a template in the state in which isStartable(TemplateReference) accepts a template: released, instantiable and not outdated on top-level scope and top-level usable.
      Parameters:
      filtFactory - The filter factory creating the filter. This must not be null.
      Returns:
      The filter matching the statuses of the templates whose instances can be started on top level. This will never be null.
    • createLiveStartFilter

      public static Filter createLiveStartFilter(FilterFactory filtFactory)
      Creates the filter on template statuses which matches the status of a template with a live scheduled start: an enabled one while the template is released, instantiable and not outdated on top-level scope and top-level usable, as createStartableStatusFilter(FilterFactory) requires. A status without scheduled starts does not match.
      Parameters:
      filtFactory - The filter factory creating the filter. This must not be null.
      Returns:
      The filter matching the statuses of the templates with a live scheduled start. This will never be null.
    • isScheduledStartChange

      public static boolean isScheduledStartChange(TemplateStatus status, TemplateStatus stored)
      Gets whether the designated template status changes the scheduled starts of the designated stored status: it carries scheduled starts which differ from the stored ones by content, a stored status without scheduled starts counting as one with none. A status whose scheduled starts are null keeps the stored ones and changes nothing.
      Parameters:
      status - The template status to be stored. This must not be null.
      stored - The stored status of the same template or null if the template is new.
      Returns:
      Whether the designated status changes the scheduled starts of the stored one.
    • isEnabledStartChange

      public static boolean isEnabledStartChange(TemplateStatus status, TemplateStatus stored)
      Gets whether the designated template status changes the enabled scheduled starts of the designated stored status: the enabled ones among its scheduled starts differ from the enabled stored ones by content, so that it enables a start or changes, disables or removes an enabled one. A stored status without scheduled starts counts as one with none. A status whose scheduled starts are null keeps the stored ones and changes nothing.
      Parameters:
      status - The template status to be stored. This must not be null.
      stored - The stored status of the same template or null if the template is new.
      Returns:
      Whether the designated status changes the enabled scheduled starts of the stored one.
    • checkScheduledStarts

      public static void checkScheduledStarts(TemplateStatus status, String name, Collection<? extends Parameter> parameters) throws InvalidScheduledStartException
      Checks the scheduled starts of the designated template status, which enter a storage of templates: each needs an ID, a period and a retry count which are not negative and input values which the designated input parameters of its template accept and which provide every mandatory one, as AdeptDataConversion.rejectParams(Map, Collection) and AdeptDataConversion.getMissingValues(Map, Collection) check them.
      Parameters:
      status - The template status whose scheduled starts to check. This must not be null.
      name - The name of the template of the designated status.
      parameters - The input parameters of the template of the designated status. This must not be null.
      Throws:
      InvalidScheduledStartException - If a scheduled start of the designated status is invalid, an InvalidScheduledStartException naming the first one will be thrown.
    • checkScheduledStartIDs

      public static void checkScheduledStartIDs(TemplateStatus status, Supplier<Collection<TemplateStatus>> others, Function<UUID,String> names) throws InvalidScheduledStartException
      Checks the IDs of the enabled scheduled starts of the designated template status as it is to be stored if its template is released, instantiable, top-level usable and not outdated with it: no other template in this state may have an enabled start of the same ID, so that the ID of an enabled start is live in one template at most. Since releasing a template and enabling a start are both writes of a status, this covers every way a start goes live. The caller checks and stores each status under a lock shared by all of them, so that two statuses of different templates cannot both pass.
      Parameters:
      status - The template status as it is to be stored. This must not be null.
      others - Supplies the statuses of the templates to check against, of which a status of the template of the designated status is skipped. It is called only if that template is in the state named above and the designated status has an enabled start.
      names - Gives the name of a template by its ID, of the designated status or of a supplied one. It is called only for a refusal, which names both templates.
      Throws:
      InvalidScheduledStartException - If an enabled start of the designated status shares its ID with an enabled start of another template in the state named above, an InvalidScheduledStartException naming both templates will be thrown.
    • stopsScheduledStart

      public static boolean stopsScheduledStart(TemplateStatus status, TemplateStatus stored)
      Gets whether the designated template status stops a scheduled start of the designated stored status: the stored status has an enabled start while its template is released, instantiable, top-level usable and not outdated, and the designated status disables or removes this start or takes the template out of this state. A status whose scheduled starts are null keeps the stored ones. Setting the statuses which stop a start before the others lets a start move from one template to another without two templates sharing its ID meanwhile.
      Parameters:
      status - The template status to be stored. This must not be null.
      stored - The stored status of the same template or null if the template is new.
      Returns:
      Whether the designated status stops a scheduled start of the designated stored one.
    • aggregateSubprocessStatuses

      public static ProcessConstants.NodeState aggregateSubprocessStatuses(SessionToken session, Collection<UUID> parallels, InstanceManager im)
      Aggregates several instance execution statuses to the corresponding node state of the parent node.
      Parameters:
      session - The session token for accessing the instance manager for retrieving the instance execution statuses.
      parallels - The IDs of the instances of which to aggregate the instance execution statuses.
      im - The subprocess manager to retrieve the subprocess instances from.
      Returns:
      The node state aggregated from the execution statuses of the designated instances running in parallel.
      See Also:
    • aggregateStatus

      public static ProcessConstants.InstanceExecutionStatus aggregateStatus(SessionToken session, Collection<UUID> parallels, InstanceManager im)
      Aggregates several instance execution statuses to one, that is the designated subprocess instances (running in parallel) are retrieved from the designated subprocess manager instance and their execution statuses are aggregated. Instance execution statuses have the following priority:
      • IE_RUNNING
      • IE_SOFTLY_SUSPENDED
      • IE_SUSPENDED
      • IE_SOFTLY_ABORTED
      • IE_ABORTED
      • IE_FINISHED
      If there is an instance with an execution status of higher priority, this will be used.
      Parameters:
      session - The session token for accessing the instance manager for retrieving the instance execution statuses.
      parallels - The IDs of the instances of which to aggregate the instance execution statuses.
      im - The subprocess manager to retrieve the subprocess instances from.
      Returns:
      The aggregated execution status for all of the designated instances running in parallel.
    • mapToNodeState

      public static ProcessConstants.NodeState mapToNodeState(ProcessConstants.InstanceExecutionStatus instanceExecutionStatus)
      Maps an instance execution status to a node state. This is needed for setting the state of an LWP.
      Parameters:
      instanceExecutionStatus - The instance execution status which to map to a corresponding node state.
      Returns:
      The node state corresponding to the designated instance execution status.
    • templatesStored

      public static boolean templatesStored(CheckReport checkReport, ADEPT2Service processManager)
      Gets whether the designated check report indicates no problems and a successful storing (in the designated process manager). This depends on the check result and, for a process manager of release 15.0.0 or later or of an unknown release, also on the last report entry. Some checks may lead to a warning but this alone does not indicate whether storing has or has not been successful.
      Parameters:
      checkReport - The check report of the template upload (attempt).
      processManager - The process manager to which the templates have been uploaded (or not).
      Returns:
      Whether the templates have been successfully uploaded as indicated by the designated check report.