Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Support https in paiHost (#1873)
Browse files Browse the repository at this point in the history
  • Loading branch information
SparkSnail authored Dec 25, 2019
1 parent 0c7f22f commit db91e8e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/nni_manager/training_service/pai/paiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TrialJobApplicationForm, TrialJobDetail, TrialJobStatus } from '../../
export class PAIClusterConfig {
public readonly userName: string;
public readonly passWord?: string;
public readonly host: string;
public host: string;
public readonly token?: string;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class PAIJobInfoCollector {
// Rest call to get PAI job info and update status
// Refer https://github.com/Microsoft/pai/blob/master/docs/rest-server/API.md for more detail about PAI Rest API
const getJobInfoRequest: request.Options = {
uri: `http://${paiClusterConfig.host}/rest-server/api/v1/user/${paiClusterConfig.userName}/jobs/${paiTrialJob.paiJobName}`,
uri: `${paiClusterConfig.host}/rest-server/api/v1/user/${paiClusterConfig.userName}/jobs/${paiTrialJob.paiJobName}`,
method: 'GET',
json: true,
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class PAIK8STrainingService extends PAITrainingService {
} else if(this.paiClusterConfig.token) {
this.paiToken = this.paiClusterConfig.token;
}
this.paiClusterConfig.host = this.formatPAIHost(this.paiClusterConfig.host);
break;

case TrialConfigMetadataKey.TRIAL_CONFIG:
Expand Down Expand Up @@ -257,7 +258,7 @@ class PAIK8STrainingService extends PAITrainingService {
// Step 3. Submit PAI job via Rest call
// Refer https://github.com/Microsoft/pai/blob/master/docs/rest-server/API.md for more detail about PAI Rest API
const submitJobRequest: request.Options = {
uri: `http://${this.paiClusterConfig.host}/rest-server/api/v2/jobs`,
uri: `${this.paiClusterConfig.host}/rest-server/api/v2/jobs`,
method: 'POST',
body: paiJobConfig,
headers: {
Expand Down
14 changes: 12 additions & 2 deletions src/nni_manager/training_service/pai/paiTrainingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ abstract class PAITrainingService implements TrainingService {
}

const stopJobRequest: request.Options = {
uri: `http://${this.paiClusterConfig.host}/rest-server/api/v1/user/${this.paiClusterConfig.userName}\
uri: `${this.paiClusterConfig.host}/rest-server/api/v1/user/${this.paiClusterConfig.userName}\
/jobs/${trialJobDetail.paiJobName}/executionType`,
method: 'PUT',
json: true,
Expand Down Expand Up @@ -216,6 +216,16 @@ abstract class PAITrainingService implements TrainingService {
return this.metricsEmitter;
}

protected formatPAIHost(host: string): string {
// If users' host start with 'http://' or 'https://', use the original host,
// or format to 'http//${host}'
if (host.startsWith('http://') || host.startsWith('https://')) {
return host;
} else {
return `http://${host}`;
}
}

protected async statusCheckingLoop(): Promise<void> {
while (!this.stopping) {
if(this.paiClusterConfig && this.paiClusterConfig.passWord) {
Expand Down Expand Up @@ -259,7 +269,7 @@ abstract class PAITrainingService implements TrainingService {
}

const authenticationReq: request.Options = {
uri: `http://${this.paiClusterConfig.host}/rest-server/api/v1/token`,
uri: `${this.paiClusterConfig.host}/rest-server/api/v1/token`,
method: 'POST',
json: true,
body: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class PAIYarnTrainingService extends PAITrainingService {
} else {
throw new Error('pai cluster config format error, please set password or token!');
}

this.paiClusterConfig.host = this.formatPAIHost(this.paiClusterConfig.host);
break;

case TrialConfigMetadataKey.TRIAL_CONFIG:
Expand Down Expand Up @@ -272,7 +272,7 @@ class PAIYarnTrainingService extends PAITrainingService {
// Step 3. Submit PAI job via Rest call
// Refer https://github.com/Microsoft/pai/blob/master/docs/rest-server/API.md for more detail about PAI Rest API
const submitJobRequest: request.Options = {
uri: `http://${this.paiClusterConfig.host}/rest-server/api/v1/user/${this.paiClusterConfig.userName}/jobs`,
uri: `${this.paiClusterConfig.host}/rest-server/api/v1/user/${this.paiClusterConfig.userName}/jobs`,
method: 'POST',
json: true,
body: paiJobConfig,
Expand Down

0 comments on commit db91e8e

Please sign in to comment.