From b64409db2b69cc570c4e2322a38d830e2bd01ad8 Mon Sep 17 00:00:00 2001 From: tian na Date: Mon, 17 May 2021 16:37:00 +0800 Subject: [PATCH 1/5] close-connection Signed-off-by: tian na --- .../src/ZoweExplorerFtpJesApi.ts | 275 ++++++++++-------- .../src/ZoweExplorerFtpMvsApi.ts | 244 +++++++++------- .../src/ZoweExplorerFtpUssApi.ts | 213 ++++++++------ 3 files changed, 424 insertions(+), 308 deletions(-) diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts index 2755f50ec5..454341ad23 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts @@ -27,135 +27,160 @@ import { AbstractFtpApi } from "./ZoweExplorerAbstractFtpApi"; export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { public async getJobsByOwnerAndPrefix(owner: string, prefix: string): Promise { const result = this.getIJobResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (connection) { - const options = { - owner: owner, - }; - const response = (await JobUtils.listJobs(connection, prefix, options)) as IJob[]; - if (response) { - const results = response.map((job: IJob) => { - return { - ...result, - /* it’s prepared for the potential change in zftp api, renaming jobid to jobId, jobname to jobName. */ - jobid: (job as any).jobId || job.jobid, - jobname: (job as any).jobName || job.jobname, - owner: job.owner, - class: job.class, - status: job.status, - }; - }); - return results; + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + const options = { + owner: owner, + }; + const response = (await JobUtils.listJobs(connection, prefix, options)) as IJob[]; + if (response) { + const results = response.map((job: IJob) => { + return { + ...result, + /* it’s prepared for the potential change in zftp api, renaming jobid to jobId, jobname to jobName. */ + jobid: (job as any).jobId || job.jobid, + jobname: (job as any).jobName || job.jobname, + owner: job.owner, + class: job.class, + status: job.status, + }; + }); + return results; + } } + return [result]; + } finally { + connection.close(); } - return [result]; } public async getJob(jobid: string): Promise { const result = this.getIJobResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (connection) { - const jobStatus: IJobStatus = await JobUtils.findJobByID(connection, jobid); - if (jobStatus) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-return - return { - ...result, - /* it’s prepared for the potential change in zftp api, renaming jobid to jobId, jobname to jobName. */ - jobid: (jobStatus as any).jobId || jobStatus.jobid, - jobname: (jobStatus as any).jobName || jobStatus.jobname, - owner: jobStatus.owner, - class: jobStatus.class, - status: jobStatus.status, - }; + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + const jobStatus: IJobStatus = await JobUtils.findJobByID(connection, jobid); + if (jobStatus) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return { + ...result, + /* it’s prepared for the potential change in zftp api, renaming jobid to jobId, jobname to jobName. */ + jobid: (jobStatus as any).jobId || jobStatus.jobid, + jobname: (jobStatus as any).jobName || jobStatus.jobname, + owner: jobStatus.owner, + class: jobStatus.class, + status: jobStatus.status, + }; + } } + return result; + } finally { + connection.close(); } - return result; } public async getSpoolFiles(jobname: string, jobid: string): Promise { const result = this.getIJobFileResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (connection) { - const response: IJobStatus = await JobUtils.findJobByID(connection, jobid); - const files: any = response.spoolFiles; - if (files) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-return - return files.map((file: ISpoolFile) => { - return { - /* it’s prepared for the potential change in zftp api, renaming stepname to stepName, procstep to procStep, ddname to ddName. */ - jobid: jobid, - jobname: jobname, - "byte-count": file.byteCount, - id: file.id, - stepname: (file as any).stepName || file.stepname, - procstep: (file as any).procStep || file.procstep, - class: file.class, - ddname: (file as any).ddName || file.ddname, - }; - }); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + const response: IJobStatus = await JobUtils.findJobByID(connection, jobid); + const files: any = response.spoolFiles; + if (files) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return files.map((file: ISpoolFile) => { + return { + /* it’s prepared for the potential change in zftp api, renaming stepname to stepName, procstep to procStep, ddname to ddName. */ + jobid: jobid, + jobname: jobname, + "byte-count": file.byteCount, + id: file.id, + stepname: (file as any).stepName || file.stepname, + procstep: (file as any).procStep || file.procstep, + class: file.class, + ddname: (file as any).ddName || file.ddname, + }; + }); + } } + return [result]; + } finally { + connection.close(); } - return [result]; } public async downloadSpoolContent(parms: zowe.IDownloadAllSpoolContentParms): Promise { - const connection = await this.ftpClient(this.checkedProfile()); - /* it's duplicate code with zftp. We may add new job API in the next zftp to cover spool file downloading. */ - if (connection) { - const destination = parms.outDir == null ? "./output/" : parms.outDir; - const jobDetails = await JobUtils.findJobByID(connection, parms.jobid); - if (jobDetails.spoolFiles == null || jobDetails.spoolFiles.length === 0) { - throw new Error("No spool files were available."); - } - const fullSpoolFiles = await JobUtils.getSpoolFiles(connection, jobDetails.jobid); - for (const spoolFileToDownload of fullSpoolFiles) { - const mockJobFile: IJobFile = { - // mock a job file to get the same format of download directories - jobid: jobDetails.jobid, - jobname: jobDetails.jobname, - recfm: "FB", - lrecl: 80, - "byte-count": spoolFileToDownload.byteCount, - // todo is recfm or lrecl available? FB 80 could be wrong - "record-count": 0, - "job-correlator": "", // most of these options don't matter for download - class: "A", - ddname: spoolFileToDownload.ddname, - id: spoolFileToDownload.id, - "records-url": "", - subsystem: "JES2", - stepname: spoolFileToDownload.stepname, - procstep: - spoolFileToDownload.procstep === "N/A" || spoolFileToDownload.procstep == null - ? undefined - : spoolFileToDownload.procstep, - }; - const destinationFile = DownloadJobs.getSpoolDownloadFile( - mockJobFile, - parms.omitJobidDirectory, - parms.outDir - ); - imperative.IO.createDirsSyncFromFilePath(destinationFile); - imperative.IO.writeFile(destinationFile, spoolFileToDownload.contents); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + /* it's duplicate code with zftp. We may add new job API in the next zftp to cover spool file downloading. */ + if (connection) { + const destination = parms.outDir == null ? "./output/" : parms.outDir; + const jobDetails = await JobUtils.findJobByID(connection, parms.jobid); + if (jobDetails.spoolFiles == null || jobDetails.spoolFiles.length === 0) { + throw new Error("No spool files were available."); + } + const fullSpoolFiles = await JobUtils.getSpoolFiles(connection, jobDetails.jobid); + for (const spoolFileToDownload of fullSpoolFiles) { + const mockJobFile: IJobFile = { + // mock a job file to get the same format of download directories + jobid: jobDetails.jobid, + jobname: jobDetails.jobname, + recfm: "FB", + lrecl: 80, + "byte-count": spoolFileToDownload.byteCount, + // todo is recfm or lrecl available? FB 80 could be wrong + "record-count": 0, + "job-correlator": "", // most of these options don't matter for download + class: "A", + ddname: spoolFileToDownload.ddname, + id: spoolFileToDownload.id, + "records-url": "", + subsystem: "JES2", + stepname: spoolFileToDownload.stepname, + procstep: + spoolFileToDownload.procstep === "N/A" || spoolFileToDownload.procstep == null + ? undefined + : spoolFileToDownload.procstep, + }; + const destinationFile = DownloadJobs.getSpoolDownloadFile( + mockJobFile, + parms.omitJobidDirectory, + parms.outDir + ); + imperative.IO.createDirsSyncFromFilePath(destinationFile); + imperative.IO.writeFile(destinationFile, spoolFileToDownload.contents); + } } + } finally { + connection.close(); } } public async getSpoolContentById(jobname: string, jobid: string, spoolId: number): Promise { - const connection = await this.ftpClient(this.checkedProfile()); - if (connection) { - const options = { - fileId: spoolId.toString(), - jobName: jobname, - jobId: jobid, - owner: "*", - }; - const response: Buffer = await JobUtils.getSpoolFileContent(connection, options); - if (response) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-return - return response.toString(); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + const options = { + fileId: spoolId.toString(), + jobName: jobname, + jobId: jobid, + owner: "*", + }; + const response: Buffer = await JobUtils.getSpoolFileContent(connection, options); + if (response) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return response.toString(); + } } + return ""; + } finally { + connection.close(); } - return ""; } public getJclForJob(job: zowe.IJob): Promise { @@ -168,24 +193,34 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { public async submitJob(jobDataSet: string): Promise { const result = this.getIJobResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (connection) { - const transferOptions = { - transferType: TRANSFER_TYPE_ASCII, - }; - const content = await DataSetUtils.downloadDataSet(connection, jobDataSet, transferOptions); - const jcl = content.toString(); - const jobId: string = await JobUtils.submitJob(connection, jcl); - if (jobId) { - result.jobid = jobId; + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + const transferOptions = { + transferType: TRANSFER_TYPE_ASCII, + }; + const content = await DataSetUtils.downloadDataSet(connection, jobDataSet, transferOptions); + const jcl = content.toString(); + const jobId: string = await JobUtils.submitJob(connection, jcl); + if (jobId) { + result.jobid = jobId; + } } + return result; + } finally { + connection.close(); } - return result; } public async deleteJob(jobname: string, jobid: string): Promise { - const connection = await this.ftpClient(this.checkedProfile()); - if (connection) { - await JobUtils.deleteJob(connection, jobid); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + await JobUtils.deleteJob(connection, jobid); + } + } finally { + connection.close(); } } diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts index 27fd141786..45fe3cb69c 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unsafe-call */ /* * This program and the accompanying materials are made available under the terms of the * * Eclipse Public License v2.0 which accompanies this distribution, and is available at * @@ -26,61 +27,76 @@ import { AbstractFtpApi } from "./ZoweExplorerAbstractFtpApi"; export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { public async dataSet(filter: string, options?: zowe.IListOptions): Promise { const result = this.getDefaultResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (connection) { - const response: any[] = await DataSetUtils.listDataSets(connection, filter); - if (response) { - result.success = true; - result.apiResponse.items = response.map((element) => ({ - dsname: element.dsname, - dsorg: element.dsorg, - volume: element.volume, - recfm: element.recfm, - blksz: element.blksz, - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - migr: element.volume && element.volume.toUpperCase() === "MIGRATED" ? "YES" : "NO", - })); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + const response: any[] = await DataSetUtils.listDataSets(connection, filter); + if (response) { + result.success = true; + result.apiResponse.items = response.map((element) => ({ + dsname: element.dsname, + dsorg: element.dsorg, + volume: element.volume, + recfm: element.recfm, + blksz: element.blksz, + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + migr: element.volume && element.volume.toUpperCase() === "MIGRATED" ? "YES" : "NO", + })); + } } + return result; + } finally { + connection.close(); } - return result; } public async allMembers(dataSetName: string, options?: zowe.IListOptions): Promise { const result = this.getDefaultResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (connection) { - const response: any[] = await DataSetUtils.listMembers(connection, dataSetName); - if (response) { - result.success = true; - result.apiResponse.items = response.map((element) => ({ - member: element.name, - changed: element.changed, - created: element.created, - id: element.id, - })); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + const response: any[] = await DataSetUtils.listMembers(connection, dataSetName); + if (response) { + result.success = true; + result.apiResponse.items = response.map((element) => ({ + member: element.name, + changed: element.changed, + created: element.created, + id: element.id, + })); + } } + return result; + } finally { + connection.close(); } - return result; } public async getContents(dataSetName: string, options: zowe.IDownloadOptions): Promise { - const connection = await this.ftpClient(this.checkedProfile()); const result = this.getDefaultResponse(); const targetFile = options.file; const transferOptions = { transferType: options.binary ? TRANSFER_TYPE_BINARY : TRANSFER_TYPE_ASCII, localFile: targetFile, }; - if (connection && targetFile) { - imperative.IO.createDirsSyncFromFilePath(targetFile); - await DataSetUtils.downloadDataSet(connection, dataSetName, transferOptions); - result.success = true; - result.commandResponse = ""; - result.apiResponse.etag = await this.hashFile(targetFile); - } else { - throw new Error(result.commandResponse); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection && targetFile) { + imperative.IO.createDirsSyncFromFilePath(targetFile); + await DataSetUtils.downloadDataSet(connection, dataSetName, transferOptions); + result.success = true; + result.commandResponse = ""; + result.apiResponse.etag = await this.hashFile(targetFile); + } else { + throw new Error(result.commandResponse); + } + return result; + } finally { + connection.close(); } - return result; } public async putContents( @@ -104,30 +120,35 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { targetDataset = dataSetName + "(" + member + ")"; } const result = this.getDefaultResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (!connection) { - throw new Error(result.commandResponse); - } - // Save-Save with FTP requires loading the file first - if (options.returnEtag && options.etag) { - const contentsTag = await this.getContentsTag(dataSetName); - if (contentsTag && contentsTag !== options.etag) { - // TODO: extension.ts should not check for zosmf errors. - throw new Error("Save conflict. Please pull the latest content from mainfram first."); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (!connection) { + throw new Error(result.commandResponse); } + // Save-Save with FTP requires loading the file first + if (options.returnEtag && options.etag) { + const contentsTag = await this.getContentsTag(dataSetName); + if (contentsTag && contentsTag !== options.etag) { + // TODO: extension.ts should not check for zosmf errors. + throw new Error("Save conflict. Please pull the latest content from mainfram first."); + } + } + await DataSetUtils.uploadDataSet(connection, targetDataset, transferOptions); + result.success = true; + if (options.returnEtag) { + const contentsTag = await this.getContentsTag(dataSetName); + result.apiResponse = [ + { + etag: contentsTag, + }, + ]; + } + result.commandResponse = "Data set uploaded successfully."; + return result; + } finally { + connection.close(); } - await DataSetUtils.uploadDataSet(connection, targetDataset, transferOptions); - result.success = true; - if (options.returnEtag) { - const contentsTag = await this.getContentsTag(dataSetName); - result.apiResponse = [ - { - etag: contentsTag, - }, - ]; - } - result.commandResponse = "Data set uploaded successfully."; - return result; } public async createDataSet( @@ -136,7 +157,6 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { options?: Partial ): Promise { const result = this.getDefaultResponse(); - const connection = await this.ftpClient(this.checkedProfile()); /* eslint-disable @typescript-eslint/restrict-plus-operands */ const dcbList = []; if (options?.alcunit) { @@ -167,14 +187,20 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { const allocateOptions = { dcb: dcb, }; - if (connection) { - await DataSetUtils.allocateDataSet(connection, dataSetName, allocateOptions); - result.success = true; - result.commandResponse = "Data set created successfully."; - } else { - throw new Error(result.commandResponse); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + await DataSetUtils.allocateDataSet(connection, dataSetName, allocateOptions); + result.success = true; + result.commandResponse = "Data set created successfully."; + } else { + throw new Error(result.commandResponse); + } + return result; + } finally { + connection.close(); } - return result; } public async createDataSetMember( @@ -186,15 +212,20 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { content: "", }; const result = this.getDefaultResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (!connection) { - throw new Error(result.commandResponse); - } + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (!connection) { + throw new Error(result.commandResponse); + } - await DataSetUtils.uploadDataSet(connection, dataSetName, transferOptions); - result.success = true; - result.commandResponse = "Member created successfully."; - return result; + await DataSetUtils.uploadDataSet(connection, dataSetName, transferOptions); + result.success = true; + result.commandResponse = "Member created successfully."; + return result; + } finally { + connection.close(); + } } public allocateLikeDataSet(dataSetName: string, likeDataSetName: string): Promise { @@ -211,15 +242,20 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { public async renameDataSet(currentDataSetName: string, newDataSetName: string): Promise { const result = this.getDefaultResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (connection) { - await DataSetUtils.renameDataSet(connection, currentDataSetName, newDataSetName); - result.success = true; - result.commandResponse = "Rename completed successfully."; - } else { - throw new Error(result.commandResponse); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + await DataSetUtils.renameDataSet(connection, currentDataSetName, newDataSetName); + result.success = true; + result.commandResponse = "Rename completed successfully."; + } else { + throw new Error(result.commandResponse); + } + return result; + } finally { + connection.close(); } - return result; } public async renameDataSetMember( @@ -228,17 +264,22 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { newMemberName: string ): Promise { const result = this.getDefaultResponse(); - const connection = await this.ftpClient(this.checkedProfile()); const currentName = dataSetName + "(" + currentMemberName + ")"; const newName = dataSetName + "(" + newMemberName + ")"; - if (connection) { - await DataSetUtils.renameDataSet(connection, currentName, newName); - result.success = true; - result.commandResponse = "Rename completed successfully."; - } else { - throw new Error(result.commandResponse); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + await DataSetUtils.renameDataSet(connection, currentName, newName); + result.success = true; + result.commandResponse = "Rename completed successfully."; + } else { + throw new Error(result.commandResponse); + } + return result; + } finally { + connection.close(); } - return result; } public hMigrateDataSet(dataSetName: string): Promise { @@ -253,15 +294,20 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { options?: zowe.IDeleteDatasetOptions ): Promise { const result = this.getDefaultResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (connection) { - await DataSetUtils.deleteDataSet(connection, dataSetName); - result.success = true; - result.commandResponse = "Delete completed successfully."; - } else { - throw new Error(result.commandResponse); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + await DataSetUtils.deleteDataSet(connection, dataSetName); + result.success = true; + result.commandResponse = "Delete completed successfully."; + } else { + throw new Error(result.commandResponse); + } + return result; + } finally { + connection.close(); } - return result; } private async getContentsTag(dataSetName: string): Promise { diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts index 31077dbfef..3688d2a19c 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts @@ -30,20 +30,25 @@ import { AbstractFtpApi } from "./ZoweExplorerAbstractFtpApi"; export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { public async fileList(ussFilePath: string): Promise { const result = this.getDefaultResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (connection) { - const response: any[] = await UssUtils.listFiles(connection, ussFilePath); - if (response) { - result.success = true; - result.apiResponse.items = response.map((element) => ({ - name: element.name, - size: element.size, - mtime: element.lastModified, - mode: element.permissions, - })); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + const response: any[] = await UssUtils.listFiles(connection, ussFilePath); + if (response) { + result.success = true; + result.apiResponse.items = response.map((element) => ({ + name: element.name, + size: element.size, + mtime: element.lastModified, + mode: element.permissions, + })); + } } + return result; + } finally { + connection.close(); } - return result; } // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await, require-await @@ -52,7 +57,6 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { } public async getContents(ussFilePath: string, options: zowe.IDownloadOptions): Promise { - const connection = await this.ftpClient(this.checkedProfile()); const result = this.getDefaultResponse(); const targetFile = options.file; const transferOptions = { @@ -60,16 +64,22 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { localFile: targetFile, size: 1, }; - if (connection && targetFile) { - imperative.IO.createDirsSyncFromFilePath(targetFile); - await UssUtils.downloadFile(connection, ussFilePath, transferOptions); - result.success = true; - result.commandResponse = ""; - result.apiResponse.etag = await this.hashFile(targetFile); - } else { - throw new Error(result.commandResponse); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection && targetFile) { + imperative.IO.createDirsSyncFromFilePath(targetFile); + await UssUtils.downloadFile(connection, ussFilePath, transferOptions); + result.success = true; + result.commandResponse = ""; + result.apiResponse.etag = await this.hashFile(targetFile); + } else { + throw new Error(result.commandResponse); + } + return result; + } finally { + connection.close(); } - return result; } public async putContents( @@ -85,37 +95,42 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { localFile: inputFilePath, }; const result = this.getDefaultResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (!connection) { - throw new Error(result.commandResponse); - } - // Save-Save with FTP requires loading the file first - if (returnEtag && etag) { - const tmpFileName = tmp.tmpNameSync(); - const options: zowe.IDownloadOptions = { - binary, - file: tmpFileName, - }; - const loadResult = await this.getContents(ussFilePath, options); - if ( - loadResult && - loadResult.success && - loadResult.apiResponse && - loadResult.apiResponse.etag && - loadResult.apiResponse.etag !== etag - ) { - // TODO: extension.ts should not check for zosmf errors. - throw new Error("Rest API failure with HTTP(S) status 412"); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (!connection) { + throw new Error(result.commandResponse); } - } - await UssUtils.uploadFile(connection, ussFilePath, transferOptions); - result.success = true; - if (returnEtag) { - result.apiResponse.etag = await this.hashFile(inputFilePath); - } - result.commandResponse = "File updated."; + // Save-Save with FTP requires loading the file first + if (returnEtag && etag) { + const tmpFileName = tmp.tmpNameSync(); + const options: zowe.IDownloadOptions = { + binary, + file: tmpFileName, + }; + const loadResult = await this.getContents(ussFilePath, options); + if ( + loadResult && + loadResult.success && + loadResult.apiResponse && + loadResult.apiResponse.etag && + loadResult.apiResponse.etag !== etag + ) { + // TODO: extension.ts should not check for zosmf errors. + throw new Error("Rest API failure with HTTP(S) status 412"); + } + } + await UssUtils.uploadFile(connection, ussFilePath, transferOptions); + result.success = true; + if (returnEtag) { + result.apiResponse.etag = await this.hashFile(inputFilePath); + } + result.commandResponse = "File updated."; - return result; + return result; + } finally { + connection.close(); + } } public async uploadDirectory( @@ -148,62 +163,82 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { mode?: string ): Promise { const result = this.getDefaultResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (connection && connection.client) { - if (type === "directory") { - await UssUtils.makeDirectory(connection, ussPath); - } else if (type === "File" || type === "file") { - const content = Buffer.from(CoreUtils.addCarriageReturns("")); - const transferOptions = { - transferType: TRANSFER_TYPE_ASCII, - content: content, - }; - await UssUtils.uploadFile(connection, ussPath, transferOptions); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection && connection.client) { + if (type === "directory") { + await UssUtils.makeDirectory(connection, ussPath); + } else if (type === "File" || type === "file") { + const content = Buffer.from(CoreUtils.addCarriageReturns("")); + const transferOptions = { + transferType: TRANSFER_TYPE_ASCII, + content: content, + }; + await UssUtils.uploadFile(connection, ussPath, transferOptions); + } + result.success = true; + result.commandResponse = "Directory or file created."; + } else { + throw new Error(result.commandResponse); } - result.success = true; - result.commandResponse = "Directory or file created."; - } else { - throw new Error(result.commandResponse); + return result; + } finally { + connection.close(); } - return result; } public async delete(ussPath: string, recursive?: boolean): Promise { const result = this.getDefaultResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (connection) { - if (recursive) { - await this.deleteDirectory(ussPath, connection); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + if (recursive) { + await this.deleteDirectory(ussPath, connection); + } else { + await UssUtils.deleteFile(connection, ussPath); + } + result.success = true; + result.commandResponse = "Delete completed."; } else { - await UssUtils.deleteFile(connection, ussPath); + throw new Error(result.commandResponse); } - result.success = true; - result.commandResponse = "Delete completed."; - } else { - throw new Error(result.commandResponse); + return result; + } finally { + connection.close(); } - return result; } public async rename(currentUssPath: string, newUssPath: string): Promise { const result = this.getDefaultResponse(); - const connection = await this.ftpClient(this.checkedProfile()); - if (connection) { - await UssUtils.renameFile(connection, currentUssPath, newUssPath); - result.success = true; - result.commandResponse = "Rename completed."; - } else { - throw new Error(result.commandResponse); + let connection: any; + try { + connection = await this.ftpClient(this.checkedProfile()); + if (connection) { + await UssUtils.renameFile(connection, currentUssPath, newUssPath); + result.success = true; + result.commandResponse = "Rename completed."; + } else { + throw new Error(result.commandResponse); + } + return result; + } finally { + connection.close(); } - return result; } private async deleteDirectory(ussPath: string, connection: any): Promise { const result = this.getDefaultResponse(); - const response: any = await UssUtils.deleteDirectory(connection, ussPath); - if (response) { - result.success = true; - result.commandResponse = "Delete Completed"; + try { + connection = await this.ftpClient(this.checkedProfile()); + const response: any = await UssUtils.deleteDirectory(connection, ussPath); + if (response) { + result.success = true; + result.commandResponse = "Delete Completed"; + } + } finally { + connection.close(); } } From 57e213f47ad99a118387a225a8d27d431feded72 Mon Sep 17 00:00:00 2001 From: tian na Date: Tue, 18 May 2021 15:00:54 +0800 Subject: [PATCH 2/5] using releaseConnection and add check connection Signed-off-by: tian na --- .../src/ZoweExplorerAbstractFtpApi.ts | 8 ++++ .../src/ZoweExplorerFtpJesApi.ts | 38 ++++++++++----- .../src/ZoweExplorerFtpMvsApi.ts | 47 +++++++++++++------ .../src/ZoweExplorerFtpUssApi.ts | 28 ++++++++--- 4 files changed, 87 insertions(+), 34 deletions(-) diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerAbstractFtpApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerAbstractFtpApi.ts index 9b168c8079..936d481c57 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerAbstractFtpApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerAbstractFtpApi.ts @@ -9,7 +9,11 @@ * * */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/* eslint-disable @typescript-eslint/no-unsafe-call */ +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ +/* eslint-disable @typescript-eslint/explicit-function-return-type */ import * as imperative from "@zowe/imperative"; import { FTPConfig, IZosFTPProfile } from "@zowe/zos-ftp-for-zowe-cli"; import { ZoweExplorerApi } from "@zowe/zowe-explorer-api"; @@ -66,4 +70,8 @@ export abstract class AbstractFtpApi implements ZoweExplorerApi.ICommon { secureFtp: ftpProfile.secureFtp, }); } + public releaseConnection(connection: any) { + connection.close(); + return; + } } diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts index 454341ad23..6873d76fa3 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts @@ -9,6 +9,11 @@ * * */ +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ +/* eslint-disable @typescript-eslint/no-unsafe-call */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/no-unused-vars*/ import * as zowe from "@zowe/cli"; import * as imperative from "@zowe/imperative"; @@ -18,11 +23,6 @@ import { DownloadJobs, IJobFile } from "@zowe/cli"; import { IJob, IJobStatus, ISpoolFile } from "@zowe/zos-ftp-for-zowe-cli/lib/api/JobInterface"; import { AbstractFtpApi } from "./ZoweExplorerAbstractFtpApi"; // The Zowe FTP CLI plugin is written and uses mostly JavaScript, so relax the rules here. -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unused-vars*/ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { public async getJobsByOwnerAndPrefix(owner: string, prefix: string): Promise { @@ -52,7 +52,9 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { } return [result]; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -78,7 +80,9 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -109,7 +113,9 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { } return [result]; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } public async downloadSpoolContent(parms: zowe.IDownloadAllSpoolContentParms): Promise { @@ -156,7 +162,9 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { } } } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -179,7 +187,9 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { } return ""; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -209,7 +219,9 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } public async deleteJob(jobname: string, jobid: string): Promise { @@ -220,7 +232,9 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { await JobUtils.deleteJob(connection, jobid); } } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts index 45fe3cb69c..d9e2114721 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-call */ /* * This program and the accompanying materials are made available under the terms of the * * Eclipse Public License v2.0 which accompanies this distribution, and is available at * @@ -10,6 +9,11 @@ * * */ +/* eslint-disable @typescript-eslint/no-unsafe-call */ +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/restrict-plus-operands */ import * as fs from "fs"; import * as crypto from "crypto"; import * as tmp from "tmp"; @@ -21,8 +25,6 @@ import { ZoweExplorerApi } from "@zowe/zowe-explorer-api"; import { DataSetUtils, TRANSFER_TYPE_ASCII, TRANSFER_TYPE_BINARY } from "@zowe/zos-ftp-for-zowe-cli"; import { AbstractFtpApi } from "./ZoweExplorerAbstractFtpApi"; // The Zowe FTP CLI plugin is written and uses mostly JavaScript, so relax the rules here. -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { public async dataSet(filter: string, options?: zowe.IListOptions): Promise { @@ -40,14 +42,15 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { volume: element.volume, recfm: element.recfm, blksz: element.blksz, - // eslint-disable-next-line @typescript-eslint/no-unsafe-call migr: element.volume && element.volume.toUpperCase() === "MIGRATED" ? "YES" : "NO", })); } } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -70,7 +73,9 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -95,7 +100,9 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -108,7 +115,6 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { transferType: options.binary ? TRANSFER_TYPE_BINARY : TRANSFER_TYPE_ASCII, localFile: inputFilePath, }; - // eslint-disable-next-line @typescript-eslint/no-unsafe-call const file = path.basename(inputFilePath).replace(/[^a-z0-9]+/gi, ""); const member = file.substr(0, 8); let targetDataset; @@ -147,7 +153,9 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { result.commandResponse = "Data set uploaded successfully."; return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -157,7 +165,6 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { options?: Partial ): Promise { const result = this.getDefaultResponse(); - /* eslint-disable @typescript-eslint/restrict-plus-operands */ const dcbList = []; if (options?.alcunit) { dcbList.push("ALCUNIT=" + options.alcunit); @@ -199,7 +206,9 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -224,7 +233,9 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { result.commandResponse = "Member created successfully."; return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -254,7 +265,9 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -278,7 +291,9 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -306,7 +321,9 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts index 3688d2a19c..ae202c8bff 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts @@ -47,7 +47,9 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -78,7 +80,9 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -129,7 +133,9 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -184,7 +190,9 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -206,7 +214,9 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -224,7 +234,9 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { } return result; } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } @@ -238,7 +250,9 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { result.commandResponse = "Delete Completed"; } } finally { - connection.close(); + if (connection != null) { + this.releaseConnection(connection); + } } } From 51807887fb642d251960e3c2ecf91b27793ea095 Mon Sep 17 00:00:00 2001 From: tian na Date: Tue, 18 May 2021 17:09:16 +0800 Subject: [PATCH 3/5] eslint adjust Signed-off-by: tian na --- .../src/ZoweExplorerAbstractFtpApi.ts | 5 ++--- .../src/ZoweExplorerFtpJesApi.ts | 5 +---- .../src/ZoweExplorerFtpMvsApi.ts | 9 ++++++--- .../src/ZoweExplorerFtpUssApi.ts | 2 -- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerAbstractFtpApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerAbstractFtpApi.ts index 936d481c57..b17af55463 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerAbstractFtpApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerAbstractFtpApi.ts @@ -9,11 +9,8 @@ * * */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/explicit-function-return-type */ import * as imperative from "@zowe/imperative"; import { FTPConfig, IZosFTPProfile } from "@zowe/zos-ftp-for-zowe-cli"; import { ZoweExplorerApi } from "@zowe/zowe-explorer-api"; @@ -70,7 +67,9 @@ export abstract class AbstractFtpApi implements ZoweExplorerApi.ICommon { secureFtp: ftpProfile.secureFtp, }); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-function-return-type public releaseConnection(connection: any) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-call connection.close(); return; } diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts index 6873d76fa3..f1347101ae 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts @@ -11,9 +11,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/no-unused-vars*/ import * as zowe from "@zowe/cli"; import * as imperative from "@zowe/imperative"; @@ -95,7 +92,7 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { const response: IJobStatus = await JobUtils.findJobByID(connection, jobid); const files: any = response.spoolFiles; if (files) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-return + // eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-call return files.map((file: ISpoolFile) => { return { /* it’s prepared for the potential change in zftp api, renaming stepname to stepName, procstep to procStep, ddname to ddName. */ diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts index d9e2114721..7eb4eafd8d 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts @@ -9,11 +9,8 @@ * * */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -/* eslint-disable @typescript-eslint/restrict-plus-operands */ import * as fs from "fs"; import * as crypto from "crypto"; import * as tmp from "tmp"; @@ -42,6 +39,7 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { volume: element.volume, recfm: element.recfm, blksz: element.blksz, + // eslint-disable-next-line @typescript-eslint/no-unsafe-call migr: element.volume && element.volume.toUpperCase() === "MIGRATED" ? "YES" : "NO", })); } @@ -170,24 +168,29 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { dcbList.push("ALCUNIT=" + options.alcunit); } if (options?.blksize) { + // eslint-disable-next-line @typescript-eslint/restrict-plus-operands dcbList.push("BLKSIZE=" + options.blksize); } if (options?.dirblk) { + // eslint-disable-next-line @typescript-eslint/restrict-plus-operands dcbList.push("DIRECTORY=" + options.dirblk); } if (options?.dsorg) { dcbList.push("DSORG=" + options.dsorg); } if (options?.lrecl) { + // eslint-disable-next-line @typescript-eslint/restrict-plus-operands dcbList.push("LRECL=" + options.lrecl); } if (options?.primary) { + // eslint-disable-next-line @typescript-eslint/restrict-plus-operands dcbList.push("PRIMARY=" + options.primary); } if (options?.recfm) { dcbList.push("RECFM=" + options.recfm); } if (options?.secondary) { + // eslint-disable-next-line @typescript-eslint/restrict-plus-operands dcbList.push("SECONDARY=" + options.secondary); } const dcb = dcbList.join(" "); diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts index ae202c8bff..08c97a4385 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts @@ -24,8 +24,6 @@ import { AbstractFtpApi } from "./ZoweExplorerAbstractFtpApi"; // The Zowe FTP CLI plugin is written and uses mostly JavaScript, so relax the rules here. /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-explicit-any */ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { public async fileList(ussFilePath: string): Promise { From ab6c1f66cc9c405287ad90771ea1710ecd94adf7 Mon Sep 17 00:00:00 2001 From: tian na Date: Thu, 20 May 2021 13:45:50 +0800 Subject: [PATCH 4/5] update releaseConection Signed-off-by: tian na --- .../src/ZoweExplorerAbstractFtpApi.ts | 12 +++--- .../src/ZoweExplorerFtpJesApi.ts | 32 +++++---------- .../src/ZoweExplorerFtpMvsApi.ts | 40 +++++-------------- .../src/ZoweExplorerFtpUssApi.ts | 28 ++++--------- 4 files changed, 33 insertions(+), 79 deletions(-) diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerAbstractFtpApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerAbstractFtpApi.ts index b17af55463..f25f04399f 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerAbstractFtpApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerAbstractFtpApi.ts @@ -9,7 +9,6 @@ * * */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ import * as imperative from "@zowe/imperative"; import { FTPConfig, IZosFTPProfile } from "@zowe/zos-ftp-for-zowe-cli"; @@ -67,10 +66,11 @@ export abstract class AbstractFtpApi implements ZoweExplorerApi.ICommon { secureFtp: ftpProfile.secureFtp, }); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-function-return-type - public releaseConnection(connection: any) { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - connection.close(); - return; + public releaseConnection(connection: any): void { + if (connection != null) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access + connection.close(); + return; + } } } diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts index f1347101ae..4fb0379e9f 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts @@ -9,8 +9,6 @@ * * */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ import * as zowe from "@zowe/cli"; import * as imperative from "@zowe/imperative"; @@ -20,6 +18,8 @@ import { DownloadJobs, IJobFile } from "@zowe/cli"; import { IJob, IJobStatus, ISpoolFile } from "@zowe/zos-ftp-for-zowe-cli/lib/api/JobInterface"; import { AbstractFtpApi } from "./ZoweExplorerAbstractFtpApi"; // The Zowe FTP CLI plugin is written and uses mostly JavaScript, so relax the rules here. +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { public async getJobsByOwnerAndPrefix(owner: string, prefix: string): Promise { @@ -49,9 +49,7 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { } return [result]; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -77,9 +75,7 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -110,9 +106,7 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { } return [result]; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } public async downloadSpoolContent(parms: zowe.IDownloadAllSpoolContentParms): Promise { @@ -159,9 +153,7 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { } } } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -184,9 +176,7 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { } return ""; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -216,9 +206,7 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } public async deleteJob(jobname: string, jobid: string): Promise { @@ -229,9 +217,7 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { await JobUtils.deleteJob(connection, jobid); } } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts index 7eb4eafd8d..cbc81aa389 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpMvsApi.ts @@ -9,8 +9,6 @@ * * */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-assignment */ import * as fs from "fs"; import * as crypto from "crypto"; import * as tmp from "tmp"; @@ -22,6 +20,8 @@ import { ZoweExplorerApi } from "@zowe/zowe-explorer-api"; import { DataSetUtils, TRANSFER_TYPE_ASCII, TRANSFER_TYPE_BINARY } from "@zowe/zos-ftp-for-zowe-cli"; import { AbstractFtpApi } from "./ZoweExplorerAbstractFtpApi"; // The Zowe FTP CLI plugin is written and uses mostly JavaScript, so relax the rules here. +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { public async dataSet(filter: string, options?: zowe.IListOptions): Promise { @@ -46,9 +46,7 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -71,9 +69,7 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -98,9 +94,7 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -151,9 +145,7 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { result.commandResponse = "Data set uploaded successfully."; return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -209,9 +201,7 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -236,9 +226,7 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { result.commandResponse = "Member created successfully."; return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -268,9 +256,7 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -294,9 +280,7 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -324,9 +308,7 @@ export class FtpMvsApi extends AbstractFtpApi implements ZoweExplorerApi.IMvs { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts index 08c97a4385..14035a275b 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpUssApi.ts @@ -45,9 +45,7 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -78,9 +76,7 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -131,9 +127,7 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -188,9 +182,7 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -212,9 +204,7 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -232,9 +222,7 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { } return result; } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } @@ -248,9 +236,7 @@ export class FtpUssApi extends AbstractFtpApi implements ZoweExplorerApi.IUss { result.commandResponse = "Delete Completed"; } } finally { - if (connection != null) { - this.releaseConnection(connection); - } + this.releaseConnection(connection); } } From 47e3bcfc11eef050ac83c8575c1dcd349843533d Mon Sep 17 00:00:00 2001 From: Lauren Li <45975633+lauren-li@users.noreply.github.com> Date: Mon, 7 Jun 2021 09:02:00 -0400 Subject: [PATCH 5/5] Remove as IJob Signed-off-by: Lauren Li <45975633+lauren-li@users.noreply.github.com> --- .../zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts index 8a80e6287b..9f0b582b95 100644 --- a/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts +++ b/packages/zowe-explorer-ftp-extension/src/ZoweExplorerFtpJesApi.ts @@ -31,7 +31,7 @@ export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes { const options = { owner: owner, }; - const response = (await JobUtils.listJobs(connection, prefix, options)) as IJob[]; + const response = await JobUtils.listJobs(connection, prefix, options); if (response) { const results = response.map((job: IJob) => { return {