|
| 1 | +/* |
| 2 | + * Copyright 2023 The Dapr Authors |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * Unless required by applicable law or agreed to in writing, software |
| 8 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | + * See the License for the specific language governing permissions and |
| 11 | +limitations under the License. |
| 12 | +*/ |
| 13 | + |
| 14 | +package io.dapr.workflows.client; |
| 15 | + |
| 16 | +import javax.annotation.Nullable; |
| 17 | + |
| 18 | +import java.time.Instant; |
| 19 | + |
| 20 | +/** |
| 21 | + * Represents a snapshot of a workflow instance's current state, including |
| 22 | + * metadata. |
| 23 | + */ |
| 24 | +public interface WorkflowState { |
| 25 | + |
| 26 | + /** |
| 27 | + * Gets the name of the workflow. |
| 28 | + * |
| 29 | + * @return the name of the workflow |
| 30 | + */ |
| 31 | + String getName(); |
| 32 | + |
| 33 | + /** |
| 34 | + * Gets the unique ID of the workflow instance. |
| 35 | + * |
| 36 | + * @return the unique ID of the workflow instance |
| 37 | + */ |
| 38 | + String getWorkflowId(); |
| 39 | + |
| 40 | + /** |
| 41 | + * Gets the current runtime status of the workflow instance at the time this |
| 42 | + * object was fetched. |
| 43 | + * |
| 44 | + * @return the current runtime status of the workflow instance at the time this object was fetched |
| 45 | + */ |
| 46 | + WorkflowRuntimeStatus getRuntimeStatus(); |
| 47 | + |
| 48 | + /** |
| 49 | + * Gets the workflow instance's creation time in UTC. |
| 50 | + * |
| 51 | + * @return the workflow instance's creation time in UTC |
| 52 | + */ |
| 53 | + Instant getCreatedAt(); |
| 54 | + |
| 55 | + /** |
| 56 | + * Gets the workflow instance's last updated time in UTC. |
| 57 | + * |
| 58 | + * @return the workflow instance's last updated time in UTC |
| 59 | + */ |
| 60 | + Instant getLastUpdatedAt(); |
| 61 | + |
| 62 | + /** |
| 63 | + * Gets the workflow instance's serialized input, if any, as a string value. |
| 64 | + * |
| 65 | + * @return the workflow instance's serialized input or {@code null} |
| 66 | + */ |
| 67 | + String getSerializedInput(); |
| 68 | + |
| 69 | + /** |
| 70 | + * Gets the workflow instance's serialized output, if any, as a string value. |
| 71 | + * |
| 72 | + * @return the workflow instance's serialized output or {@code null} |
| 73 | + */ |
| 74 | + String getSerializedOutput(); |
| 75 | + |
| 76 | + /** |
| 77 | + * Gets the failure details, if any, for the failed workflow instance. |
| 78 | + * |
| 79 | + * <p>This method returns data only if the workflow is in the |
| 80 | + * {@link WorkflowFailureDetails} failureDetails, |
| 81 | + * and only if this instance metadata was fetched with the option to include |
| 82 | + * output data. |
| 83 | + * |
| 84 | + * @return the failure details of the failed workflow instance or {@code null} |
| 85 | + */ |
| 86 | + @Nullable |
| 87 | + WorkflowFailureDetails getFailureDetails(); |
| 88 | + |
| 89 | + /** |
| 90 | + * Gets a value indicating whether the workflow instance was running at the time |
| 91 | + * this object was fetched. |
| 92 | + * |
| 93 | + * @return {@code true} if the workflow existed and was in a running state otherwise {@code false} |
| 94 | + */ |
| 95 | + boolean isRunning(); |
| 96 | + |
| 97 | + /** |
| 98 | + * Gets a value indicating whether the workflow instance was completed at the |
| 99 | + * time this object was fetched. |
| 100 | + * |
| 101 | + * <p>A workflow instance is considered completed when its runtime status value is |
| 102 | + * {@link WorkflowRuntimeStatus#COMPLETED}, |
| 103 | + * {@link WorkflowRuntimeStatus#FAILED}, or |
| 104 | + * {@link WorkflowRuntimeStatus#TERMINATED}. |
| 105 | + * |
| 106 | + * @return {@code true} if the workflow was in a terminal state; otherwise {@code false} |
| 107 | + */ |
| 108 | + boolean isCompleted(); |
| 109 | + |
| 110 | + /** |
| 111 | + * Deserializes the workflow's input into an object of the specified type. |
| 112 | + * |
| 113 | + * <p>Deserialization is performed using the DataConverter that was |
| 114 | + * configured on the DurableTaskClient object that created this workflow |
| 115 | + * metadata object. |
| 116 | + * |
| 117 | + * @param type the class associated with the type to deserialize the input data |
| 118 | + * into |
| 119 | + * @param <T> the type to deserialize the input data into |
| 120 | + * @return the deserialized input value |
| 121 | + * @throws IllegalStateException if the metadata was fetched without the option |
| 122 | + * to read inputs and outputs |
| 123 | + */ |
| 124 | + <T> T readInputAs(Class<T> type); |
| 125 | + |
| 126 | + /** |
| 127 | + * Deserializes the workflow's output into an object of the specified type. |
| 128 | + * |
| 129 | + * <p>Deserialization is performed using the DataConverter that was |
| 130 | + * configured on the DurableTaskClient |
| 131 | + * object that created this workflow metadata object. |
| 132 | + * |
| 133 | + * @param type the class associated with the type to deserialize the output data |
| 134 | + * into |
| 135 | + * @param <T> the type to deserialize the output data into |
| 136 | + * @return the deserialized input value |
| 137 | + * @throws IllegalStateException if the metadata was fetched without the option |
| 138 | + * to read inputs and outputs |
| 139 | + */ |
| 140 | + <T> T readOutputAs(Class<T> type); |
| 141 | + |
| 142 | +} |
0 commit comments