Package io.littlehorse.sdk.wfsdk
Class Workflow
- java.lang.Object
-
- io.littlehorse.sdk.wfsdk.Workflow
-
public abstract class Workflow extends java.lang.ObjectThe Workflow class represents a `WfSpec` object in the API.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcompileAndSaveToDisk(java.lang.String directory)Writes out the PutWfSpecRequest in JSON form in a directory.java.lang.StringcompileWfToJson()Returns the associated PutWfSpecRequest in JSON form.abstract io.littlehorse.sdk.common.proto.PutWfSpecRequestcompileWorkflow()Compiles this Workflow into a `WfSpec`.booleandoesWfSpecExist(io.littlehorse.sdk.common.proto.LittleHorseGrpc.LittleHorseBlockingStub client)Checks if the WfSpec existsbooleandoesWfSpecExist(io.littlehorse.sdk.common.proto.LittleHorseGrpc.LittleHorseBlockingStub client, java.lang.Integer majorVersion)Checks if the WfSpec exists for a given versionjava.lang.IntegergetDefaultTaskTimeout()Returns the default task timeout, or null if it is not set.java.lang.StringgetName()Gets the workflow name passed atnewWorkflow(String, ThreadFunc)abstract java.util.Set<java.lang.String>getRequiredExternalEventDefNames()Returns the names of all `ExternalEventDef`s used by this workflow.abstract java.util.Set<java.lang.String>getRequiredTaskDefNames()Returns the names of all `TaskDef`s used by this workflow.static WorkflownewWorkflow(java.lang.String name, ThreadFunc entrypointThreadFunc)Creates a new Workflow with the provided name and entrypoint thread function.voidregisterWfSpec(io.littlehorse.sdk.common.proto.LittleHorseGrpc.LittleHorseBlockingStub client)Deploys the WfSpec object to the LH Server.voidsetDefaultTaskExponentialBackoffPolicy(io.littlehorse.sdk.common.proto.ExponentialBackoffRetryPolicy defaultPolicy)Tells the Workflow to configure (by default) the specified ExponentialBackoffRetryPolicy as the retry policy.voidsetDefaultTaskRetries(int defaultSimpleRetries)Tells the Workflow to configure (by default) a Simple Retry Policy for every Task Node.voidsetDefaultTaskTimeout(int timeoutSeconds)Sets the default timeout for all TaskRun's in this workflow.voidsetParent(java.lang.String parentWfSpecName)Makes this a child workflow.WorkflowwithDefaultThreadRetentionPolicy(io.littlehorse.sdk.common.proto.ThreadRetentionPolicy policy)Sets the retention policy for all ThreadRun's belong to this WfSpec.WorkflowwithRetentionPolicy(io.littlehorse.sdk.common.proto.WorkflowRetentionPolicy policy)Sets the retention policy for all WfRun's created by this WfSpec.WorkflowwithUpdateType(io.littlehorse.sdk.common.proto.AllowedUpdateType allowedUpdateType)Defines the type of update to perform when saving the WfSpec: AllowedUpdateType.ALL (Default): Creates a new WfSpec with a different version (either major or revision).
-
-
-
Method Detail
-
setParent
public void setParent(java.lang.String parentWfSpecName)
Makes this a child workflow.- Parameters:
parentWfSpecName- is the name of the parent wfSpec.
-
setDefaultTaskTimeout
public void setDefaultTaskTimeout(int timeoutSeconds)
Sets the default timeout for all TaskRun's in this workflow.- Parameters:
timeoutSeconds- is the value for the timeout to set.
-
getDefaultTaskTimeout
public java.lang.Integer getDefaultTaskTimeout()
Returns the default task timeout, or null if it is not set.- Returns:
- the default task timeout for this Workflow.
-
setDefaultTaskRetries
public void setDefaultTaskRetries(int defaultSimpleRetries)
Tells the Workflow to configure (by default) a Simple Retry Policy for every Task Node. Passing a value of '1' means that there will be one retry upon failure. Retries are scheduled immediately without delay. Can be overriden by setting the retry policy on the WorkflowThread or TaskNodeOutput level.- Parameters:
defaultSimpleRetries- is the number ofretries to attempt.
-
setDefaultTaskExponentialBackoffPolicy
public void setDefaultTaskExponentialBackoffPolicy(io.littlehorse.sdk.common.proto.ExponentialBackoffRetryPolicy defaultPolicy)
Tells the Workflow to configure (by default) the specified ExponentialBackoffRetryPolicy as the retry policy. Can be overriden by setting the retry policy on the WorkflowThread or TaskNodeOutput level.- Parameters:
defaultPolicy- is the Exponential Backoff Retry Policy to configure by default for all Task Nodes.
-
getName
public java.lang.String getName()
Gets the workflow name passed atnewWorkflow(String, ThreadFunc)- Returns:
- the Workflow name
-
withRetentionPolicy
public Workflow withRetentionPolicy(io.littlehorse.sdk.common.proto.WorkflowRetentionPolicy policy)
Sets the retention policy for all WfRun's created by this WfSpec.- Parameters:
policy- is the Workflow Retention Policy.- Returns:
- this Workflow.
-
withDefaultThreadRetentionPolicy
public Workflow withDefaultThreadRetentionPolicy(io.littlehorse.sdk.common.proto.ThreadRetentionPolicy policy)
Sets the retention policy for all ThreadRun's belong to this WfSpec. Note that each Thread can override the configured Retention Policy by using WorkflowThread#withRetentionPolicy.- Parameters:
policy- is the Workflow Retention Policy.- Returns:
- this Workflow.
-
newWorkflow
public static Workflow newWorkflow(java.lang.String name, ThreadFunc entrypointThreadFunc)
Creates a new Workflow with the provided name and entrypoint thread function.- Parameters:
name- is the name of the `WfSpec`.entrypointThreadFunc- is the ThreadFunc for the entrypoint ThreadSpec.- Returns:
- a Workflow.
-
withUpdateType
public Workflow withUpdateType(io.littlehorse.sdk.common.proto.AllowedUpdateType allowedUpdateType)
Defines the type of update to perform when saving the WfSpec: AllowedUpdateType.ALL (Default): Creates a new WfSpec with a different version (either major or revision). AllowedUpdateType.MINOR_REVISION_ONLY: Creates a new WfSpec with a different revision if the change is a major version it fails. AllowedUpdateType.NONE: Fail with the ALREADY_EXISTS response code.- Parameters:
allowedUpdateType-- Returns:
- this Worflow
-
compileWorkflow
public abstract io.littlehorse.sdk.common.proto.PutWfSpecRequest compileWorkflow()
Compiles this Workflow into a `WfSpec`.- Returns:
- a `PutWfSpecRequest` that can be used for the gRPC putWfSpec() call.
-
getRequiredTaskDefNames
public abstract java.util.Set<java.lang.String> getRequiredTaskDefNames()
Returns the names of all `TaskDef`s used by this workflow.- Returns:
- a Set of Strings containing the names of all `TaskDef`s used by this workflow.
-
getRequiredExternalEventDefNames
public abstract java.util.Set<java.lang.String> getRequiredExternalEventDefNames()
Returns the names of all `ExternalEventDef`s used by this workflow. Includes ExternalEventDefs used for Interrupts or for EXTERNAL_EVENT nodes.- Returns:
- a Set of Strings containing the names of all `ExternalEventDef`s used by this workflow.
-
compileWfToJson
public java.lang.String compileWfToJson()
Returns the associated PutWfSpecRequest in JSON form.- Returns:
- the associated PutWfSpecRequest in JSON form.
-
doesWfSpecExist
public boolean doesWfSpecExist(io.littlehorse.sdk.common.proto.LittleHorseGrpc.LittleHorseBlockingStub client)
Checks if the WfSpec exists- Parameters:
client- is an LHClient.- Returns:
- true if the workflow spec is registered or false otherwise
-
doesWfSpecExist
public boolean doesWfSpecExist(io.littlehorse.sdk.common.proto.LittleHorseGrpc.LittleHorseBlockingStub client, java.lang.Integer majorVersion)Checks if the WfSpec exists for a given version- Parameters:
client- is an LHClient.majorVersion- the workflow Major Version- Returns:
- true if the workflow spec is registered for this Major Version or false otherwise
-
registerWfSpec
public void registerWfSpec(io.littlehorse.sdk.common.proto.LittleHorseGrpc.LittleHorseBlockingStub client)
Deploys the WfSpec object to the LH Server. Registering the WfSpec via Workflow::registerWfSpec() is the same as client.putWfSpec(workflow.compileWorkflow()).- Parameters:
client- is an LHClient.
-
compileAndSaveToDisk
public void compileAndSaveToDisk(java.lang.String directory)
Writes out the PutWfSpecRequest in JSON form in a directory.- Parameters:
directory- is the location to save the resources.
-
-