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

Commit

Permalink
Merge edf91f9 into 6903b18
Browse files Browse the repository at this point in the history
  • Loading branch information
suiguoxin committed Oct 15, 2020
2 parents 6903b18 + edf91f9 commit 87457cf
Show file tree
Hide file tree
Showing 8 changed files with 781 additions and 98 deletions.
11 changes: 11 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 @@ -218,6 +224,11 @@ const openPAIClient = new PAIV2.OpenPAIClient(cluster);
```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

Expand Down
37 changes: 31 additions & 6 deletions src/api/v2/clients/jobClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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';
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 @@ -123,6 +132,22 @@ export class JobClient extends OpenPAIBaseClient {
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.
Expand Down
3 changes: 2 additions & 1 deletion src/api/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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 @@ -59,6 +59,7 @@ export {
IStorageDetail,
IMountInfo,
IJobStatus,
ITaskDetail,
IJobListQeury,
StorageNode,
IGroup,
Expand Down
50 changes: 50 additions & 0 deletions src/api/v2/models/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,56 @@ 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;
frameworkName: string;
jobAttemptId: number;
taskRoleName: string;
attempts: ITaskAttempt[];
}

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

0 comments on commit 87457cf

Please sign in to comment.