Skip to content

Commit

Permalink
feat(cf): "Run Job" stage support for CloudFoundry (#7119)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Delagrave authored and Jammy Louie committed Jun 21, 2019
1 parent bbc1d06 commit 454c536
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/scripts/modules/cloudfoundry/src/cf.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import './pipeline/stages/rollbackCluster/cloudfoundryRollbackClusterStage.modul
import './pipeline/stages/shareService/cloudfoundryShareServiceStage.module';
import './pipeline/stages/unmapLoadBalancers/cloudfoundryUnmapLoadBalancersStage.module';
import './pipeline/stages/unshareService/cloudfoundryUnshareServiceStage.module';
import './pipeline/stages/runJob/cloudfoundryRunJob.module';

CloudProviderRegistry.registerProvider('cloudfoundry', {
name: 'Cloud Foundry',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import * as React from 'react';
import { Observable, Subject } from 'rxjs';

import {
AccountService,
IAccount,
IStageConfigProps,
NgReact,
StageConfigField,
StageConstants,
TextInput,
} from '@spinnaker/core';

import { AccountRegionClusterSelector } from 'cloudfoundry/presentation';

export interface ICloudfoundryRunTaskStageConfigState {
accounts: IAccount[];
region: string;
}

export class CloudfoundryRunJobStageConfig extends React.Component<
IStageConfigProps,
ICloudfoundryRunTaskStageConfigState
> {
private destroy$ = new Subject();

constructor(props: IStageConfigProps) {
super(props);
props.stage.cloudProvider = 'cloudfoundry';
this.state = {
accounts: [],
region: '',
};
}

public componentDidMount(): void {
Observable.fromPromise(AccountService.listAccounts('cloudfoundry'))
.takeUntil(this.destroy$)
.subscribe(accounts => this.setState({ accounts }));
this.props.stageFieldUpdated();
}

public componentWillUnmount(): void {
this.destroy$.next();
}

private componentUpdated = (stage: any): void => {
this.props.updateStageField({
credentials: stage.credentials,
region: stage.region,
cluster: stage.cluster,
});
};

private commandUpdated = (event: React.ChangeEvent<HTMLInputElement>) => {
this.props.updateStageField({ command: event.target.value });
};

private JobNameUpdated = (event: React.ChangeEvent<HTMLInputElement>) => {
this.props.updateStageField({ jobName: event.target.value });
};

private targetUpdated = (target: string) => {
this.props.updateStageField({ target });
};

public render() {
const { application, stage } = this.props;
const { command, jobName, target } = stage;
const { accounts } = this.state;
const { TargetSelect } = NgReact;

return (
<div className="cloudfoundry-resize-asg-stage form-horizontal">
<AccountRegionClusterSelector
accounts={accounts}
application={application}
cloudProvider={'cloudfoundry'}
onComponentUpdate={this.componentUpdated}
component={stage}
isSingleRegion={true}
/>
<StageConfigField label="Target">
<TargetSelect model={{ target }} options={StageConstants.TARGET_LIST} onChange={this.targetUpdated} />
</StageConfigField>
<StageConfigField label="Command">
<TextInput type="text" className="form-control" onChange={this.commandUpdated} value={command} />
</StageConfigField>
<StageConfigField label="Job Name">
<TextInput type="text" className="form-control" onChange={this.JobNameUpdated} value={jobName} />
</StageConfigField>
</div>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { CloudfoundryRunJobStageConfig } from './CloudfoundryRunJobStageConfig';
import { IStage, Registry } from '@spinnaker/core';

Registry.pipeline.registerStage({
accountExtractor: (stage: IStage) => stage.context.credentials,
component: CloudfoundryRunJobStageConfig,
configAccountExtractor: (stage: IStage) => [stage.credentials],
cloudProvider: 'cloudfoundry',
key: 'runJob',
provides: 'runJob',
restartable: true,
defaultTimeoutMs: 2 * 60 * 60 * 1000, // 2 hours
validators: [
{ type: 'requiredField', fieldName: 'credentials' },
{ type: 'requiredField', fieldName: 'region' },
{ type: 'requiredField', fieldName: 'cluster' },
{ type: 'requiredField', fieldName: 'target' },
{ type: 'requiredField', fieldName: 'command' },
{ type: 'requiredField', fieldName: 'jobName' },
],
});

0 comments on commit 454c536

Please sign in to comment.