-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cf): "Run Job" stage support for CloudFoundry (#7119)
- Loading branch information
Pierre Delagrave
authored and
Jammy Louie
committed
Jun 21, 2019
1 parent
bbc1d06
commit 454c536
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...scripts/modules/cloudfoundry/src/pipeline/stages/runJob/CloudfoundryRunJobStageConfig.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/scripts/modules/cloudfoundry/src/pipeline/stages/runJob/cloudfoundryRunJob.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }, | ||
], | ||
}); |