-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[teraslice-cli] add earl jobs export command (#3717)
This PR makes the following changes: - Add `jobs export` command to teraslice-cli - Creates a `Jobs` class using the provided jobIds, extracts the jobConfig for each job, and saves each config to the local file system. - Each job is saved to `./<job.name>.json` by default. If a file name already exists `-N` will be appended to the file name. - `--outdir` flag will set a custom directory where job files are saved. - A job-id of `all` will export all jobs. This can be combined with `--status` to export all jobs with executions of a specific status. Ref: #3695
- Loading branch information
Showing
13 changed files
with
435 additions
and
14 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
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
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,37 @@ | ||
import { CMD } from '../../interfaces.js'; | ||
import Config from '../../helpers/config.js'; | ||
import YargsOptions from '../../helpers/yargs-options.js'; | ||
import Jobs from '../../helpers/jobs.js'; | ||
import reply from '../../helpers/reply.js'; | ||
|
||
const yargsOptions = new YargsOptions(); | ||
|
||
export default { | ||
command: 'export <cluster-alias> <job-id...>', | ||
describe: 'Export job on a cluster to a json file. By default the file is saved to the current working directory as <job.name>.json\n', | ||
builder(yargs: any) { | ||
yargs.positional('job-id', yargsOptions.buildPositional('job-id')); | ||
yargs.options('config-dir', yargsOptions.buildOption('config-dir')); | ||
yargs.options('outdir', yargsOptions.buildOption('outdir')); | ||
yargs.options('status', yargsOptions.buildOption('jobs-status')); | ||
yargs.options('yes', yargsOptions.buildOption('yes')); | ||
yargs.strict() | ||
.example('$0 jobs export CLUSTER_ALIAS JOB1', 'exports job config as a tjm compatible JSON file') | ||
.example('$0 jobs export CLUSTER_ALIAS JOB1 JOB2', 'exports job configs for two jobs') | ||
.example('$0 jobs export CLUSTER_ALIAS JOB1 --outdir ~/my_jobs', 'exports a job to ~/my_jobs/<job.name>.json') | ||
.example('$0 jobs export CLUSTER_ALIAS all --status failing', 'exports all failing jobs on a cluster (maximum 100)') | ||
.example('$0 jobs export CLUSTER_ALIAS all -y', 'exports all jobs on a cluster (maximum 100) and bypasses any prompts'); | ||
return yargs; | ||
}, | ||
async handler(argv: any) { | ||
const cliConfig = new Config(argv); | ||
const jobs = new Jobs(cliConfig); | ||
|
||
try { | ||
await jobs.initialize(); | ||
await jobs.export(); | ||
} catch (e) { | ||
reply.fatal(e); | ||
} | ||
} | ||
} as CMD; |
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
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
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
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
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
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,35 @@ | ||
import yargs from 'yargs'; | ||
import exportJob from '../../../src/cmds/jobs/export.js'; | ||
|
||
describe('jobs export', () => { | ||
describe('-> parse', () => { | ||
it('should parse properly', () => { | ||
const yargsCmd = yargs().command( | ||
// @ts-expect-error | ||
exportJob.command, | ||
exportJob.describe, | ||
exportJob.builder, | ||
() => true | ||
); | ||
const yargsResult = yargsCmd.parseSync( | ||
'export ts-test1 all', {} | ||
); | ||
expect(yargsResult.clusterAlias).toEqual('ts-test1'); | ||
}); | ||
|
||
it('should parse properly with an id specifed', () => { | ||
const yargsCmd = yargs().command( | ||
// @ts-expect-error | ||
exportJob.command, | ||
exportJob.describe, | ||
exportJob.builder, | ||
() => true | ||
); | ||
const yargsResult = yargsCmd.parseSync( | ||
'export ts-test1 99999999-9999-9999-9999-999999999999', {} | ||
); | ||
expect(yargsResult.clusterAlias).toEqual('ts-test1'); | ||
expect(yargsResult.jobId).toEqual(['99999999-9999-9999-9999-999999999999']); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -5,3 +5,5 @@ clusters: | |
host: http://test-host | ||
save_jobs2: | ||
host: http://test-host | ||
export_jobs1: | ||
host: http://test-host |
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
Oops, something went wrong.