Add parameter to list jobs (#57)
* update swagger * add job list query to listJobs * fix tests * update * update * update * update
This commit is contained in:
Родитель
c491de0aa6
Коммит
fa954c7124
|
@ -0,0 +1 @@
|
|||
* text=auto eol=lf
|
|
@ -7,6 +7,8 @@ import {
|
|||
import { Util } from '@pai/commom/util';
|
||||
import * as yaml from 'js-yaml';
|
||||
|
||||
import { IJobListQeury } from '../models/job';
|
||||
|
||||
import { OpenPAIBaseClient } from './baseClient';
|
||||
|
||||
/**
|
||||
|
@ -37,15 +39,15 @@ export class JobClient extends OpenPAIBaseClient {
|
|||
|
||||
/**
|
||||
* Get the list of jobs.
|
||||
* @param username filter jobs with username.
|
||||
* @param query filter jobs by username, vc, state and keyword. Set offset, limit, order and withTotalCount.
|
||||
*/
|
||||
public async listJobs(username?: string): Promise<IJobInfo[]> {
|
||||
public async listJobs(query?: IJobListQeury): Promise<IJobInfo[] | { totalCount: number, data: IJobInfo[] }> {
|
||||
const url: string = Util.fixUrl(
|
||||
`${this.cluster.rest_server_uri}/api/v2/jobs`,
|
||||
this.cluster.https
|
||||
);
|
||||
return await this.httpClient.get(
|
||||
url, undefined, undefined, { username }
|
||||
url, undefined, undefined, query
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import { StorageNodeV2 as StorageNode } from './clients/storageClient';
|
|||
import { IAuthnInfo, ILoginInfo } from './models/authn';
|
||||
import { IPAICluster, IPAIClusterInfo } from './models/cluster';
|
||||
import { IGroup } from './models/group';
|
||||
import { IJobAttempt, IJobFrameworkInfo, IJobInfo, IJobSshInfo, IJobStatus } from './models/job';
|
||||
import { IJobAttempt, IJobFrameworkInfo, IJobInfo, IJobListQeury, IJobSshInfo, IJobStatus } from './models/job';
|
||||
import { IPAIResponse } from './models/paiResponse';
|
||||
import { IMountInfo, IStorageConfig, IStorageDetail, IStorageServer, IStorageSummary } from './models/storage';
|
||||
import { IToken, ITokenList } from './models/token';
|
||||
|
@ -59,6 +59,7 @@ export {
|
|||
IStorageDetail,
|
||||
IMountInfo,
|
||||
IJobStatus,
|
||||
IJobListQeury,
|
||||
StorageNode,
|
||||
IGroup,
|
||||
GroupClient,
|
||||
|
|
|
@ -29,6 +29,30 @@ export interface IJobInfo {
|
|||
totalTaskRoleNumber: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query object for list job, filter jobs by username, vc, state and keyword. Set offset, limit, order and withTotalCount.
|
||||
* e.g.
|
||||
* {
|
||||
* username: 'user1,user2',
|
||||
* vc: 'vc1,vc2',
|
||||
* state: 'RUNNING,WAITING,STOPPED',
|
||||
* keyword: 'mnist',
|
||||
* offset: 0,
|
||||
* order: 'submissionTime,DESC',
|
||||
* withTotalCount: false
|
||||
* }
|
||||
*/
|
||||
export interface IJobListQeury {
|
||||
username?: string;
|
||||
vc?: string;
|
||||
state?: string;
|
||||
keyword?: string;
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
order?: string; // format <field>,<ASC|DESC>, default value is "submissionTime,DESC"
|
||||
withTotalCount?: boolean;
|
||||
}
|
||||
|
||||
export interface IAppExitSpec {
|
||||
code: number;
|
||||
phrase: string;
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -25,7 +25,7 @@ export function registerJobCommands(cli: CliEngine): void {
|
|||
if (a.all) {
|
||||
return client.job.listJobs();
|
||||
}
|
||||
return client.job.listJobs(a.user || client.config.username());
|
||||
return client.job.listJobs({ username: a.user || client.config.username() });
|
||||
},
|
||||
[
|
||||
{
|
||||
|
|
|
@ -37,7 +37,7 @@ describe('List jobs', () => {
|
|||
// tslint:disable-next-line:mocha-no-side-effect-code
|
||||
it('should return a list of jobs', async () => {
|
||||
const jobClient: JobClient = new JobClient(cluster);
|
||||
const result: IJobInfo[] = await jobClient.listJobs();
|
||||
const result: any = await jobClient.listJobs();
|
||||
expect(result).is.not.empty();
|
||||
}).timeout(10000);
|
||||
});
|
||||
|
@ -50,11 +50,25 @@ describe('List jobs with query', () => {
|
|||
// tslint:disable-next-line:mocha-no-side-effect-code
|
||||
it('should return a list of jobs', async () => {
|
||||
const jobClient: JobClient = new JobClient(cluster);
|
||||
const result: IJobInfo[] = await jobClient.listJobs('core');
|
||||
const result: any = await jobClient.listJobs({ username: 'core' });
|
||||
expect(result).is.not.empty();
|
||||
}).timeout(10000);
|
||||
});
|
||||
|
||||
describe('List jobs with total count', () => {
|
||||
const response: any = { totalCount: 1, data: testJobList };
|
||||
const queryString: string = 'username=core&withTotalCount=true';
|
||||
before(() => nock(`http://${testUri}`).get(`/api/v2/jobs?${queryString}`).reply(200, response));
|
||||
|
||||
// tslint:disable-next-line:mocha-no-side-effect-code
|
||||
it('should return a list of jobs', async () => {
|
||||
const jobClient: JobClient = new JobClient(cluster);
|
||||
const result: any = await jobClient.listJobs({ username: 'core', withTotalCount: true });
|
||||
expect(result.totalCount).equal(1);
|
||||
expect(result.data).is.not.empty();
|
||||
}).timeout(10000);
|
||||
});
|
||||
|
||||
describe('Get job status', () => {
|
||||
const response: IJobStatus = testJobStatus;
|
||||
const userName: string = 'core';
|
||||
|
|
Загрузка…
Ссылка в новой задаче