Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into yiyi/update_SKU_API
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyione committed Oct 19, 2020
2 parents f61ef9d + 6e1b33c commit 0e18971
Show file tree
Hide file tree
Showing 9 changed files with 1,137 additions and 17 deletions.
24 changes: 24 additions & 0 deletions docs/rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ const openPAIClient = new PAIV2.OpenPAIClient(cluster);
job = await openPAIClient.job.getJob(username, jobname);
```

- [x] Get job status with specific attempt(GET /api/v2/jobs/{username}~{jobname}/attempts/{jobAttemptId})

```ts
job = await openPAIClient.job.getJob(username, jobname, jobAttemptId);
```

- [x] Get job config (GET /api/v2/jobs/{username}~{jobname}/config)

```ts
Expand All @@ -207,6 +213,24 @@ const openPAIClient = new PAIV2.OpenPAIClient(cluster);
await openPAIClient.job.updateJobExecutionType(username, jobname, 'STOP');
```

- [x] Add a tag to a job (PUT /api/v2/jobs/{username}~{jobname}/tag)

```ts
await openPAIClient.job.addTag(username, jobname, tag);
```

- [x] Delete a tag from a job (DELETE /api/v2/jobs/{username}~{jobname}/tag)

```ts
await openPAIClient.job.deleteTag(username, jobname, tag);
```

- [x] Get task status (GET /api/v2/jobs/{username}~{jobname}/attempts/{jobAttemptId}/taskRoles/{taskRoleName}/taskIndex/{taskIndex}/attempts)

```ts
await openPAIClient.job.getTask(username, jobname, jobAttemptId, taskRoleName, taskIndex);
```

## job history

- [x] Check if job attempts is healthy (GET /api/v2/jobs/{username}~{jobname}/job-attempts/healthz)
Expand Down
81 changes: 74 additions & 7 deletions src/api/v2/clients/jobClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Licensed under the MIT License.

import {
IJobConfig, IJobInfo, IJobSshInfo, IJobStatus, IPAICluster, IPAIResponse
IJobConfig, IJobInfo, IJobStatus, IPAICluster, IPAIResponse
} from '@api/v2';
import { Util } from '@pai/commom/util';
import * as yaml from 'js-yaml';

import { IJobListQeury } from '../models/job';
import { IEventListQuery, IJobListQeury } from '../models/job';

import { OpenPAIBaseClient } from './baseClient';

Expand Down Expand Up @@ -55,12 +55,21 @@ export class JobClient extends OpenPAIBaseClient {
* Get job status.
* @param userName The user name.
* @param jobName The job name.
* @param jobAttemptId The job attempt id
*/
public async getJob(userName: string, jobName: string): Promise<IJobStatus> {
const url: string = Util.fixUrl(
`${this.cluster.rest_server_uri}/api/v2/jobs/${userName}~${jobName}`,
this.cluster.https
);
public async getJob(userName: string, jobName: string, jobAttemptId?: number): Promise<IJobStatus> {
let url: string;
if (jobAttemptId !== undefined) {
url = Util.fixUrl(
`${this.cluster.rest_server_uri}/api/v2/jobs/${userName}~${jobName}/attempts/${jobAttemptId}`,
this.cluster.https
);
} else {
url = Util.fixUrl(
`${this.cluster.rest_server_uri}/api/v2/jobs/${userName}~${jobName}`,
this.cluster.https
);
}
return await this.httpClient.get(url);
}

Expand Down Expand Up @@ -94,4 +103,62 @@ export class JobClient extends OpenPAIBaseClient {
);
return await this.httpClient.put(url, { value: type });
}

/**
* Add a tag.
* @param userName The user name.
* @param jobName The job name.
* @param tag The tag.
*/
public async addTag(userName: string, jobName: string, tag: string): Promise<any> {
const url: string = Util.fixUrl(
`${this.cluster.rest_server_uri}/api/v2/jobs/${userName}~${jobName}/tag`,
this.cluster.https
);
return await this.httpClient.put(url, { value: tag });
}

/**
* Delelte a tag.
* @param userName The user name.
* @param jobName The job name.
* @param tag The tag.
*/
public async deleteTag(userName: string, jobName: string, tag: string): Promise<any> {
const url: string = Util.fixUrl(
`${this.cluster.rest_server_uri}/api/v2/jobs/${userName}~${jobName}/tag`,
this.cluster.https
);
return await this.httpClient.delete(url, undefined, { data: { value: tag } });
}

/**
* Get task status.
* @param userName The user name.
* @param jobName The job name.
* @param jobAttemptId The job attempt id.
* @param taskRoleName The task role name.
* @param taskIndex The task index.
*/
public async getTask(userName: string, jobName: string, jobAttemptId: number, taskRoleName: string, taskIndex: number)
: Promise<IJobStatus> {
const url: string = Util.fixUrl(
`${this.cluster.rest_server_uri}/api/v2/jobs/${userName}~${jobName}/attempts/${jobAttemptId}/taskRoles/${taskRoleName}/taskIndex/${taskIndex}/attempts`,
this.cluster.https
);
return await this.httpClient.get(url);
}
/**
* Get the events of a job.
* @param userName The user name.
* @param jobName The job name.
* @param query filter jobs by event type
*/
public async listEvents(userName: string, jobName: string, query?: IEventListQuery): Promise<any> {
const url: string = Util.fixUrl(
`${this.cluster.rest_server_uri}/api/v2/jobs/${userName}~${jobName}/events`,
this.cluster.https
);
return await this.httpClient.get(url, undefined, undefined, query);
}
}
3 changes: 2 additions & 1 deletion src/api/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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, IJobListQeury, IJobSshInfo, IJobStatus } from './models/job';
import { IJobAttempt, IJobFrameworkInfo, IJobInfo, IJobListQeury, IJobSshInfo, IJobStatus, ITaskDetail } from './models/job';
import { IPAIResponse } from './models/paiResponse';
import { IMountInfo, IStorageConfig, IStorageDetail, IStorageServer, IStorageSummary } from './models/storage';
import { IToken, ITokenList } from './models/token';
Expand Down Expand Up @@ -61,6 +61,7 @@ export {
IStorageDetail,
IMountInfo,
IJobStatus,
ITaskDetail,
IJobListQeury,
StorageNode,
IGroup,
Expand Down
55 changes: 55 additions & 0 deletions src/api/v2/models/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export interface IJobListQeury {
withTotalCount?: boolean;
}

export interface IEventListQuery {
type?: 'Warning' | 'Normal';
}

export interface IAppExitSpec {
code: number;
phrase: string;
Expand Down Expand Up @@ -131,6 +135,57 @@ export interface IJobStatus {
};
}

interface ITaskAttempt {
attemptId: number;
attemptState: string;
currentAttemptLaunchedTime: number | null;
currentAttemptCompletedTime: number | null;
containerId: string | null;
containerIp: string | null;
containerNodeName: string | null;
containerPorts: object;
containerGpus?: any;
containerLog: string;
containerExitCode: number | null;
containerExitSpec: {
code: number;
phrase: string;
issuer: string;
causer: string;
type: string;
stage: string;
behavior: string;
reaction: string;
reason: string;
repro: string[];
solution?: string[];
} ;
containerExitDiagnostics: string | null;
hived?: {
affinityGroupName?: any;
lazyPreempted?: any;
lazyPreemptionStatus?: any;
};
}

/**
* OpenPAI Task Detail.
*/
export interface ITaskDetail {
taskIndex: number;
taskUid: string;
taskState: string;
retries: number;
accountableRetries: number;
createdTime: number | null;
completedTime: number | null;
username: string;
jobName: string;
jobAttemptId: number;
taskRoleName: string;
attempts: ITaskAttempt[];
}

/**
* OpenPAI Job Framework Infomation.
*/
Expand Down
Loading

0 comments on commit 0e18971

Please sign in to comment.