Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(orchestrator): add ability to re-trigger workflow in error state #1624

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/orchestrator-common/src/QueryParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const QUERY_PARAM_BUSINESS_KEY = 'businessKey' as const;
export const QUERY_PARAM_INSTANCE_ID = 'instanceId' as const;
export const QUERY_PARAM_INSTANCE_STATE = 'state';
export const QUERY_PARAM_INCLUDE_ASSESSMENT = 'includeAssessment' as const;
export const QUERY_PARAM_ASSESSMENT_INSTANCE_ID =
'assessmentInstanceId' as const;
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Grid } from '@material-ui/core';
import {
QUERY_PARAM_ASSESSMENT_INSTANCE_ID,
QUERY_PARAM_INSTANCE_ID,
QUERY_PARAM_INSTANCE_STATE,
WorkflowInputSchemaResponse,
} from '@janus-idp/backstage-plugin-orchestrator-common';

Expand All @@ -42,6 +43,9 @@ export const ExecuteWorkflowPage = () => {
const [assessmentInstanceId] = useQueryParamState<string>(
QUERY_PARAM_ASSESSMENT_INSTANCE_ID,
);
const [instanceState] = useQueryParamState<string>(
QUERY_PARAM_INSTANCE_STATE,
);
const navigate = useNavigate();
const instanceLink = useRouteRef(workflowInstanceRouteRef);
const {
Expand Down Expand Up @@ -85,6 +89,39 @@ export const ExecuteWorkflowPage = () => {
[orchestratorApi, workflowId, navigate, instanceLink, assessmentInstanceId],
);

const isErrorState = React.useMemo(
() => instanceState === 'ERROR',
[instanceState],
);

const handleRetrigger = useCallback(
async (getParameters: () => JsonObject) => {
setUpdateError(undefined);
let parameters: JsonObject = {};
try {
parameters = getParameters();
} catch (err) {
setUpdateError(getErrorObject(err));
return;
}
if (instanceId) {
try {
setIsExecuting(true);
const response = await orchestratorApi.retriggerInstanceInError({
instanceId,
inputData: parameters,
});
navigate(instanceLink({ instanceId: response.id }));
} catch (err) {
setUpdateError(getErrorObject(err));
} finally {
setIsExecuting(false);
}
}
},
[orchestratorApi, instanceId, navigate, instanceLink],
);

const onReset = useCallback(() => {
setUpdateError(undefined);
}, [setUpdateError]);
Expand Down Expand Up @@ -128,13 +165,13 @@ export const ExecuteWorkflowPage = () => {
<StepperForm
steps={schemaResponse.schemaSteps}
isComposedSchema={schemaResponse.isComposedSchema}
handleExecute={handleExecute}
handleExecute={isErrorState ? handleRetrigger : handleExecute}
isExecuting={isExecuting}
onReset={onReset}
/>
) : (
<JsonTextAreaForm
handleExecute={handleExecute}
handleExecute={isErrorState ? handleRetrigger : handleExecute}
isExecuting={isExecuting}
/>
)}
Expand Down
38 changes: 26 additions & 12 deletions plugins/orchestrator/src/components/WorkflowInstancePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
AssessedProcessInstance,
QUERY_PARAM_ASSESSMENT_INSTANCE_ID,
QUERY_PARAM_INSTANCE_ID,
QUERY_PARAM_INSTANCE_STATE,
} from '@janus-idp/backstage-plugin-orchestrator-common';

import { orchestratorApiRef } from '../api';
Expand Down Expand Up @@ -154,6 +155,7 @@ export const WorkflowInstancePage = ({
const urlToNavigate = buildUrl(routeUrl, {
[QUERY_PARAM_INSTANCE_ID]: value.instance.id,
[QUERY_PARAM_ASSESSMENT_INSTANCE_ID]: value.assessedBy?.id,
[QUERY_PARAM_INSTANCE_STATE]: value.instance.state,
});
navigate(urlToNavigate);
}, [value, navigate, executeWorkflowLink]);
Expand Down Expand Up @@ -196,18 +198,30 @@ export const WorkflowInstancePage = ({
/>
<Grid container item justifyContent="flex-end" spacing={1}>
{!canRerun && (
<Grid item>
<Button
variant="contained"
color="secondary"
disabled={!canAbort}
onClick={
canAbort ? toggleAbortConfirmationDialog : undefined
}
>
Abort
</Button>
</Grid>
<>
<Grid item>
<Button
variant="contained"
color="primary"
disabled={!canAbort}
onClick={canAbort ? handleRerun : undefined}
>
Retrigger
</Button>
</Grid>
<Grid item>
<Button
variant="contained"
color="secondary"
disabled={!canAbort}
onClick={
canAbort ? toggleAbortConfirmationDialog : undefined
}
>
Abort
</Button>
</Grid>
</>
)}
{!canAbort && (
<Grid item>
Expand Down
Loading