Skip to content

Commit c71020a

Browse files
[Backport 2.x] Reset workflow state to initial state after successful deprovision (#643)
Reset workflow state to initial state after successful deprovision (#635) (cherry picked from commit 33ea800) Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 7e00561 commit c71020a

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
1616
### Features
1717
### Enhancements
1818
### Bug Fixes
19-
### Bug Fixes
19+
- Reset workflow state to initial state after successful deprovision ([#635](https://github.com/opensearch-project/flow-framework/pull/635))
2020
- Silently ignore content on APIs that don't require it ([#639](https://github.com/opensearch-project/flow-framework/pull/639))
2121

2222
### Infrastructure

src/main/java/org/opensearch/flowframework/transport/DeprovisionWorkflowTransportAction.java

+9-13
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@
4444

4545
import static org.opensearch.flowframework.common.CommonValue.DEPROVISION_WORKFLOW_THREAD_POOL;
4646
import static org.opensearch.flowframework.common.CommonValue.PROVISIONING_PROGRESS_FIELD;
47-
import static org.opensearch.flowframework.common.CommonValue.PROVISION_START_TIME_FIELD;
47+
import static org.opensearch.flowframework.common.CommonValue.PROVISION_END_TIME_FIELD;
4848
import static org.opensearch.flowframework.common.CommonValue.RESOURCES_CREATED_FIELD;
4949
import static org.opensearch.flowframework.common.CommonValue.STATE_FIELD;
5050
import static org.opensearch.flowframework.common.WorkflowResources.getDeprovisionStepByWorkflowStep;
5151
import static org.opensearch.flowframework.common.WorkflowResources.getResourceByWorkflowStep;
52+
import static org.opensearch.flowframework.util.ParseUtils.getUserContext;
5253

5354
/**
5455
* Transport Action to deprovision a workflow from a stored use case template
@@ -224,18 +225,13 @@ private void updateWorkflowState(
224225
ActionListener<WorkflowResponse> listener
225226
) {
226227
if (remainingResources.isEmpty()) {
227-
// Successful deprovision
228-
flowFrameworkIndicesHandler.updateFlowFrameworkSystemIndexDoc(
228+
// Successful deprovision, reset state to initial
229+
flowFrameworkIndicesHandler.putInitialStateToWorkflowState(
229230
workflowId,
230-
Map.ofEntries(
231-
Map.entry(STATE_FIELD, State.NOT_STARTED),
232-
Map.entry(PROVISIONING_PROGRESS_FIELD, ProvisioningProgress.NOT_STARTED),
233-
Map.entry(PROVISION_START_TIME_FIELD, Instant.now().toEpochMilli()),
234-
Map.entry(RESOURCES_CREATED_FIELD, Collections.emptyList())
235-
),
236-
ActionListener.wrap(updateResponse -> {
237-
logger.info("updated workflow {} state to NOT_STARTED", workflowId);
238-
}, exception -> { logger.error("Failed to update workflow state", exception); })
231+
getUserContext(client),
232+
ActionListener.wrap(indexResponse -> {
233+
logger.info("Reset workflow {} state to NOT_STARTED", workflowId);
234+
}, exception -> { logger.error("Failed to reset to initial workflow state for {}", workflowId, exception); })
239235
);
240236
// return workflow ID
241237
listener.onResponse(new WorkflowResponse(workflowId));
@@ -246,7 +242,7 @@ private void updateWorkflowState(
246242
Map.ofEntries(
247243
Map.entry(STATE_FIELD, State.COMPLETED),
248244
Map.entry(PROVISIONING_PROGRESS_FIELD, ProvisioningProgress.DONE),
249-
Map.entry(PROVISION_START_TIME_FIELD, Instant.now().toEpochMilli()),
245+
Map.entry(PROVISION_END_TIME_FIELD, Instant.now().toEpochMilli()),
250246
Map.entry(RESOURCES_CREATED_FIELD, remainingResources)
251247
),
252248
ActionListener.wrap(updateResponse -> {

0 commit comments

Comments
 (0)