Skip to content

Commit

Permalink
Reset workflow state to initial state after successful deprovision (#635
Browse files Browse the repository at this point in the history
)

Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis authored Apr 2, 2024
1 parent b246341 commit 33ea800
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
### Features
### Enhancements
### Bug Fixes
### Bug Fixes
- Reset workflow state to initial state after successful deprovision ([#635](https://github.com/opensearch-project/flow-framework/pull/635))
- Silently ignore content on APIs that don't require it ([#639](https://github.com/opensearch-project/flow-framework/pull/639))

### Infrastructure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@

import static org.opensearch.flowframework.common.CommonValue.DEPROVISION_WORKFLOW_THREAD_POOL;
import static org.opensearch.flowframework.common.CommonValue.PROVISIONING_PROGRESS_FIELD;
import static org.opensearch.flowframework.common.CommonValue.PROVISION_START_TIME_FIELD;
import static org.opensearch.flowframework.common.CommonValue.PROVISION_END_TIME_FIELD;
import static org.opensearch.flowframework.common.CommonValue.RESOURCES_CREATED_FIELD;
import static org.opensearch.flowframework.common.CommonValue.STATE_FIELD;
import static org.opensearch.flowframework.common.WorkflowResources.getDeprovisionStepByWorkflowStep;
import static org.opensearch.flowframework.common.WorkflowResources.getResourceByWorkflowStep;
import static org.opensearch.flowframework.util.ParseUtils.getUserContext;

/**
* Transport Action to deprovision a workflow from a stored use case template
Expand Down Expand Up @@ -224,18 +225,13 @@ private void updateWorkflowState(
ActionListener<WorkflowResponse> listener
) {
if (remainingResources.isEmpty()) {
// Successful deprovision
flowFrameworkIndicesHandler.updateFlowFrameworkSystemIndexDoc(
// Successful deprovision, reset state to initial
flowFrameworkIndicesHandler.putInitialStateToWorkflowState(
workflowId,
Map.ofEntries(
Map.entry(STATE_FIELD, State.NOT_STARTED),
Map.entry(PROVISIONING_PROGRESS_FIELD, ProvisioningProgress.NOT_STARTED),
Map.entry(PROVISION_START_TIME_FIELD, Instant.now().toEpochMilli()),
Map.entry(RESOURCES_CREATED_FIELD, Collections.emptyList())
),
ActionListener.wrap(updateResponse -> {
logger.info("updated workflow {} state to NOT_STARTED", workflowId);
}, exception -> { logger.error("Failed to update workflow state", exception); })
getUserContext(client),
ActionListener.wrap(indexResponse -> {
logger.info("Reset workflow {} state to NOT_STARTED", workflowId);
}, exception -> { logger.error("Failed to reset to initial workflow state for {}", workflowId, exception); })
);
// return workflow ID
listener.onResponse(new WorkflowResponse(workflowId));
Expand All @@ -246,7 +242,7 @@ private void updateWorkflowState(
Map.ofEntries(
Map.entry(STATE_FIELD, State.COMPLETED),
Map.entry(PROVISIONING_PROGRESS_FIELD, ProvisioningProgress.DONE),
Map.entry(PROVISION_START_TIME_FIELD, Instant.now().toEpochMilli()),
Map.entry(PROVISION_END_TIME_FIELD, Instant.now().toEpochMilli()),
Map.entry(RESOURCES_CREATED_FIELD, remainingResources)
),
ActionListener.wrap(updateResponse -> {
Expand Down

0 comments on commit 33ea800

Please sign in to comment.