Remove request promise for request-light (#10346)

* remove request promise for request-light

* make sure data is a string not a json

* add configure call

* remove unused reference

* more fixes

* Move configure calls

* clean up

* fix name

* move test deps as dev

Co-authored-by: chgagnon <chgagnon@microsoft.com>
This commit is contained in:
Anthony Dresser
2020-05-12 10:27:11 -07:00
committed by GitHub
parent eda25f72c1
commit ff848b5903
5 changed files with 49 additions and 88 deletions

View File

@@ -37,15 +37,14 @@ export class SparkJobSubmissionModel {
constructor(
private readonly _sqlClusterConnection: SqlClusterConnection,
private readonly _dialog: azdata.window.Dialog,
private readonly _appContext: AppContext,
requestService?: typeof import('request-promise')) {
private readonly _appContext: AppContext) {
if (!this._sqlClusterConnection || !this._dialog || !this._appContext) {
throw new Error(localize('sparkJobSubmission.SparkJobSubmissionModelInitializeError',
"Parameters for SparkJobSubmissionModel is illegal"));
}
this._dialogService = new SparkJobSubmissionService(requestService);
this._dialogService = new SparkJobSubmissionService();
this._guidForClusterFolder = utils.generateGuid();
}

View File

@@ -10,21 +10,9 @@ import * as constants from '../../../constants';
import { SqlClusterConnection } from '../../../objectExplorerNodeProvider/connection';
import * as utils from '../../../utils';
import * as auth from '../../../util/auth';
import { Options } from 'request-promise';
import * as request from 'request-light';
export class SparkJobSubmissionService {
private _requestPromise: typeof import('request-promise');
constructor(
requestService?: typeof import('request-promise')) {
if (requestService) {
// this is to fake the request service for test.
this._requestPromise = requestService;
} else {
this._requestPromise = require('request-promise');
}
}
public async submitBatchJob(submissionArgs: SparkJobSubmissionInput): Promise<string> {
try {
let livyUrl: string = `https://${submissionArgs.host}:${submissionArgs.port}${submissionArgs.livyPath}/`;
@@ -32,12 +20,11 @@ export class SparkJobSubmissionService {
// Get correct authentication headers
let headers = await this.getAuthenticationHeaders(submissionArgs);
let options: Options = {
uri: livyUrl,
method: 'POST',
json: true,
rejectUnauthorized: !auth.getIgnoreSslVerificationConfigSetting(),
body: {
let options: request.XHROptions = {
url: livyUrl,
type: 'POST',
strictSSL: !auth.getIgnoreSslVerificationConfigSetting(),
data: {
file: submissionArgs.sparkFile,
proxyUser: submissionArgs.user,
className: submissionArgs.mainClass,
@@ -51,7 +38,7 @@ export class SparkJobSubmissionService {
if (submissionArgs.jobArguments && submissionArgs.jobArguments.trim()) {
let argsList = submissionArgs.jobArguments.split(' ');
if (argsList.length > 0) {
options.body['args'] = argsList;
options.data['args'] = argsList;
}
}
@@ -59,7 +46,7 @@ export class SparkJobSubmissionService {
if (submissionArgs.jarFileList && submissionArgs.jarFileList.trim()) {
let jarList = submissionArgs.jarFileList.split(';');
if (jarList.length > 0) {
options.body['jars'] = jarList;
options.data['jars'] = jarList;
}
}
@@ -67,7 +54,7 @@ export class SparkJobSubmissionService {
if (submissionArgs.pyFileList && submissionArgs.pyFileList.trim()) {
let pyList = submissionArgs.pyFileList.split(';');
if (pyList.length > 0) {
options.body['pyFiles'] = pyList;
options.data['pyFiles'] = pyList;
}
}
@@ -75,11 +62,17 @@ export class SparkJobSubmissionService {
if (submissionArgs.otherFileList && submissionArgs.otherFileList.trim()) {
let otherList = submissionArgs.otherFileList.split(';');
if (otherList.length > 0) {
options.body['files'] = otherList;
options.data['files'] = otherList;
}
}
const response = await this._requestPromise(options);
options.data = JSON.stringify(options.data);
// Note this is currently required to be called each time since request-light is overwriting
// the setting passed in through the options. If/when that gets fixed this can be removed
request.configure(null, !auth.getIgnoreSslVerificationConfigSetting());
const response = JSON.parse((await request.xhr(options)).responseText);
if (response && utils.isValidNumber(response.id)) {
return response.id;
}
@@ -108,16 +101,19 @@ export class SparkJobSubmissionService {
let livyUrl = `https://${submissionArgs.host}:${submissionArgs.port}${submissionArgs.livyPath}/${livyBatchId}/log`;
let headers = await this.getAuthenticationHeaders(submissionArgs);
let options = {
uri: livyUrl,
method: 'GET',
json: true,
rejectUnauthorized: !auth.getIgnoreSslVerificationConfigSetting(),
let options: request.XHROptions = {
url: livyUrl,
type: 'GET',
strictSSL: !auth.getIgnoreSslVerificationConfigSetting(),
// authentication headers
headers: headers
};
const response = await this._requestPromise(options);
// Note this is currently required to be called each time since request-light is overwriting
// the setting passed in through the options. If/when that gets fixed this can be removed
request.configure(null, !auth.getIgnoreSslVerificationConfigSetting());
const response = JSON.parse((await request.xhr(options)).responseText);
if (response && response.log) {
return this.extractYarnAppIdFromLog(response.log);
}