"src/sdk/git@developer.sourcefind.cn:OpenDAS/nni.git" did not exist on "c3cd9fe7ffdb20d07f7562592774fe071b235de3"
Unverified Commit db91e8e6 authored by SparkSnail's avatar SparkSnail Committed by GitHub
Browse files

Support https in paiHost (#1873)

parent 0c7f22fb
...@@ -9,7 +9,7 @@ import { TrialJobApplicationForm, TrialJobDetail, TrialJobStatus } from '../../ ...@@ -9,7 +9,7 @@ import { TrialJobApplicationForm, TrialJobDetail, TrialJobStatus } from '../../
export class PAIClusterConfig { export class PAIClusterConfig {
public readonly userName: string; public readonly userName: string;
public readonly passWord?: string; public readonly passWord?: string;
public readonly host: string; public host: string;
public readonly token?: string; public readonly token?: string;
/** /**
......
...@@ -52,7 +52,7 @@ export class PAIJobInfoCollector { ...@@ -52,7 +52,7 @@ export class PAIJobInfoCollector {
// Rest call to get PAI job info and update status // 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 // Refer https://github.com/Microsoft/pai/blob/master/docs/rest-server/API.md for more detail about PAI Rest API
const getJobInfoRequest: request.Options = { 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', method: 'GET',
json: true, json: true,
headers: { headers: {
......
...@@ -68,6 +68,7 @@ class PAIK8STrainingService extends PAITrainingService { ...@@ -68,6 +68,7 @@ class PAIK8STrainingService extends PAITrainingService {
} else if(this.paiClusterConfig.token) { } else if(this.paiClusterConfig.token) {
this.paiToken = this.paiClusterConfig.token; this.paiToken = this.paiClusterConfig.token;
} }
this.paiClusterConfig.host = this.formatPAIHost(this.paiClusterConfig.host);
break; break;
case TrialConfigMetadataKey.TRIAL_CONFIG: case TrialConfigMetadataKey.TRIAL_CONFIG:
...@@ -257,7 +258,7 @@ class PAIK8STrainingService extends PAITrainingService { ...@@ -257,7 +258,7 @@ class PAIK8STrainingService extends PAITrainingService {
// Step 3. Submit PAI job via Rest call // 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 // Refer https://github.com/Microsoft/pai/blob/master/docs/rest-server/API.md for more detail about PAI Rest API
const submitJobRequest: request.Options = { 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', method: 'POST',
body: paiJobConfig, body: paiJobConfig,
headers: { headers: {
......
...@@ -165,7 +165,7 @@ abstract class PAITrainingService implements TrainingService { ...@@ -165,7 +165,7 @@ abstract class PAITrainingService implements TrainingService {
} }
const stopJobRequest: request.Options = { 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`, /jobs/${trialJobDetail.paiJobName}/executionType`,
method: 'PUT', method: 'PUT',
json: true, json: true,
...@@ -216,6 +216,16 @@ abstract class PAITrainingService implements TrainingService { ...@@ -216,6 +216,16 @@ abstract class PAITrainingService implements TrainingService {
return this.metricsEmitter; 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> { protected async statusCheckingLoop(): Promise<void> {
while (!this.stopping) { while (!this.stopping) {
if(this.paiClusterConfig && this.paiClusterConfig.passWord) { if(this.paiClusterConfig && this.paiClusterConfig.passWord) {
...@@ -259,7 +269,7 @@ abstract class PAITrainingService implements TrainingService { ...@@ -259,7 +269,7 @@ abstract class PAITrainingService implements TrainingService {
} }
const authenticationReq: request.Options = { 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', method: 'POST',
json: true, json: true,
body: { body: {
......
...@@ -107,7 +107,7 @@ class PAIYarnTrainingService extends PAITrainingService { ...@@ -107,7 +107,7 @@ class PAIYarnTrainingService extends PAITrainingService {
} else { } else {
throw new Error('pai cluster config format error, please set password or token!'); throw new Error('pai cluster config format error, please set password or token!');
} }
this.paiClusterConfig.host = this.formatPAIHost(this.paiClusterConfig.host);
break; break;
case TrialConfigMetadataKey.TRIAL_CONFIG: case TrialConfigMetadataKey.TRIAL_CONFIG:
...@@ -272,7 +272,7 @@ class PAIYarnTrainingService extends PAITrainingService { ...@@ -272,7 +272,7 @@ class PAIYarnTrainingService extends PAITrainingService {
// Step 3. Submit PAI job via Rest call // 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 // Refer https://github.com/Microsoft/pai/blob/master/docs/rest-server/API.md for more detail about PAI Rest API
const submitJobRequest: request.Options = { 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', method: 'POST',
json: true, json: true,
body: paiJobConfig, body: paiJobConfig,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment