Skip to content

Commit

Permalink
feat: add resubmit and retry buttons for archived workflows. Fixes #7908
Browse files Browse the repository at this point in the history
 and #7911 (#8272)

Signed-off-by: Dillen Padhiar <[email protected]>
  • Loading branch information
dpadhiar committed Mar 29, 2022
1 parent 6975607 commit 5598b8c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import {NotificationType, Page, SlidingPanel} from 'argo-ui';
import * as classNames from 'classnames';
import * as React from 'react';
import {RouteComponentProps} from 'react-router';
import {execSpec, Link, Workflow} from '../../../../models';
import {execSpec, Link, NodePhase, Workflow} from '../../../../models';
import {uiUrl} from '../../../shared/base';
import {BasePage} from '../../../shared/components/base-page';
import {ErrorNotice} from '../../../shared/components/error-notice';
import {ProcessURL} from '../../../shared/components/links';
import {Loading} from '../../../shared/components/loading';
import {ResourceEditor} from '../../../shared/components/resource-editor/resource-editor';
import {services} from '../../../shared/services';
import {WorkflowArtifacts} from '../../../workflows/components/workflow-artifacts';

Expand Down Expand Up @@ -89,15 +88,24 @@ export class ArchivedWorkflowDetails extends BasePage<RouteComponentProps<any>,
}

public render() {
const workflowPhase: NodePhase = this.state.workflow && this.state.workflow.status ? this.state.workflow.status.phase : undefined;
const items = [
{
title: 'Retry',
iconClassName: 'fa fa-undo',
disabled: workflowPhase === undefined || !(workflowPhase === 'Failed' || workflowPhase === 'Error'),
action: () => this.retryArchivedWorkflow()
},
{
title: 'Resubmit',
iconClassName: 'fa fa-redo',
action: () => (this.sidePanel = 'resubmit')
iconClassName: 'fa fa-plus-circle',
disabled: false,
action: () => this.resubmitArchivedWorkflow()
},
{
title: 'Delete',
iconClassName: 'fa fa-trash',
disabled: false,
action: () => this.deleteArchivedWorkflow()
}
];
Expand All @@ -108,6 +116,7 @@ export class ArchivedWorkflowDetails extends BasePage<RouteComponentProps<any>,
items.push({
title: link.name,
iconClassName: 'fa fa-external-link-alt',
disabled: false,
action: () => this.openLink(link)
})
);
Expand Down Expand Up @@ -222,25 +231,6 @@ export class ArchivedWorkflowDetails extends BasePage<RouteComponentProps<any>,
{this.sidePanel === 'logs' && (
<WorkflowLogsViewer workflow={this.state.workflow} initialPodName={this.podName} nodeId={this.nodeId} container={this.container} archived={true} />
)}
{this.sidePanel === 'resubmit' && (
<ResourceEditor<Workflow>
editing={true}
title='Resubmit Archived Workflow'
kind='Workflow'
value={{
metadata: {
namespace: this.state.workflow.metadata.namespace,
name: this.state.workflow.metadata.name
},
spec: this.state.workflow.spec
}}
onSubmit={(value: Workflow) =>
services.workflows
.create(value, value.metadata.namespace)
.then(workflow => (document.location.href = uiUrl(`workflows/${workflow.metadata.namespace}/${workflow.metadata.name}`)))
}
/>
)}
</SlidingPanel>
</>
);
Expand Down Expand Up @@ -280,6 +270,36 @@ export class ArchivedWorkflowDetails extends BasePage<RouteComponentProps<any>,
});
}

private resubmitArchivedWorkflow() {
if (!confirm('Are you sure you want to resubmit this archived workflow?')) {
return;
}
services.archivedWorkflows
.resubmit(this.state.workflow.metadata.uid, this.state.workflow.metadata.namespace)
.then(workflow => (document.location.href = uiUrl(`workflows/${workflow.metadata.namespace}/${workflow.metadata.name}`)))
.catch(e => {
this.appContext.apis.notifications.show({
content: 'Failed to resubmit archived workflow ' + e,
type: NotificationType.Error
});
});
}

private retryArchivedWorkflow() {
if (!confirm('Are you sure you want to retry this archived workflow?')) {
return;
}
services.archivedWorkflows
.retry(this.state.workflow.metadata.uid, this.state.workflow.metadata.namespace)
.then(workflow => (document.location.href = uiUrl(`workflows/${workflow.metadata.namespace}/${workflow.metadata.name}`)))
.catch(e => {
this.appContext.apis.notifications.show({
content: 'Failed to retry archived workflow ' + e,
type: NotificationType.Error
});
});
}

private openLink(link: Link) {
const object = {
metadata: {
Expand Down
14 changes: 14 additions & 0 deletions ui/src/app/shared/services/archived-workflows-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,18 @@ export class ArchivedWorkflowsService {
public listLabelValues(key: string) {
return requests.get(`api/v1/archived-workflows-label-values?listOptions.labelSelector=${key}`).then(res => res.body as models.Labels);
}

public resubmit(uid: string, namespace: string) {
return requests
.put(`api/v1/archived-workflows/${uid}/resubmit`)
.send({namespace})
.then(res => res.body as models.Workflow);
}

public retry(uid: string, namespace: string) {
return requests
.put(`api/v1/archived-workflows/${uid}/retry`)
.send({namespace})
.then(res => res.body as models.Workflow);
}
}

0 comments on commit 5598b8c

Please sign in to comment.