-
Notifications
You must be signed in to change notification settings - Fork 89
/
ZoweExplorerFtpJesApi.ts
282 lines (270 loc) · 11.4 KB
/
ZoweExplorerFtpJesApi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/**
* 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
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
import * as zowe from "@zowe/cli";
import { ZoweExplorerApi } from "@zowe/zowe-explorer-api";
import { JobUtils, DataSetUtils, TRANSFER_TYPE_ASCII } from "@zowe/zos-ftp-for-zowe-cli";
import { DownloadJobs, IJobFile } from "@zowe/cli";
import { IJob, IJobStatus, ISpoolFile } from "@zowe/zos-ftp-for-zowe-cli/lib/api/JobInterface";
import { AbstractFtpApi, ConnectionType } from "./ZoweExplorerAbstractFtpApi";
import { ZoweFtpExtensionError } from "./ZoweFtpExtensionError";
// 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 */
interface IJobRefactor extends IJob {
jobId: string;
jobName: string;
}
interface ISpoolFileRefactor extends ISpoolFile {
stepName: string;
procStep: string;
ddName: string;
}
export class FtpJesApi extends AbstractFtpApi implements ZoweExplorerApi.IJes {
public async getJobsByOwnerAndPrefix(owner: string, prefix: string): Promise<zowe.IJob[]> {
const result = this.getIJobResponse();
const session = this.getSession(this.profile);
try {
if (session.jesListConnection === undefined || session.jesListConnection.connected === false) {
session.jesListConnection = await this.ftpClient(this.checkedProfile());
}
if (session.jesListConnection.connected === true) {
const options = {
owner: owner,
};
const response = await JobUtils.listJobs(session.jesListConnection, prefix, options);
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 IJobRefactor).jobId || job.jobid,
jobname: (job as IJobRefactor).jobName || job.jobname,
owner: job.owner,
class: job.class,
status: job.status,
};
});
return results;
}
}
return [result];
} catch (err) {
throw new ZoweFtpExtensionError(err.message);
}
}
public async getJob(jobid: string): Promise<zowe.IJob> {
const result = this.getIJobResponse();
let connection;
try {
connection = await this.ftpClient(this.checkedProfile());
if (connection) {
const jobStatus: IJobStatus = await JobUtils.findJobByID(connection, jobid);
if (jobStatus) {
return {
...result,
/* it’s prepared for the potential change in zftp api, renaming jobid to jobId, jobname to jobName. */
jobid: (jobStatus as IJobRefactor).jobId || jobStatus.jobid,
jobname: (jobStatus as IJobRefactor).jobName || jobStatus.jobname,
owner: jobStatus.owner,
class: jobStatus.class,
status: jobStatus.status,
};
}
}
return result;
} catch (err) {
throw new ZoweFtpExtensionError(err.message);
} finally {
this.releaseConnection(connection);
}
}
public async getSpoolFiles(jobname: string, jobid: string): Promise<zowe.IJobFile[]> {
const result = this.getIJobFileResponse();
let connection: unknown;
try {
connection = await this.ftpClient(this.checkedProfile());
if (connection) {
const response: IJobStatus = await JobUtils.findJobByID(connection, jobid);
const files = response.spoolFiles;
if (files) {
return files.map((file: ISpoolFile) => {
return {
/**
* 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 ISpoolFileRefactor).stepName || file.stepname,
procstep: (file as ISpoolFileRefactor).procStep || file.procstep,
class: file.class,
ddname: (file as ISpoolFileRefactor).ddName || file.ddname,
} as unknown as zowe.IJobFile;
});
} else {
return [];
}
}
return [result];
} catch (err) {
throw new ZoweFtpExtensionError(err.message);
} finally {
this.releaseConnection(connection as ConnectionType);
}
}
public async downloadSpoolContent(parms: zowe.IDownloadAllSpoolContentParms): Promise<void> {
let connection;
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 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": Number(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: String(spoolFileToDownload.ddname),
id: Number(spoolFileToDownload.id),
"records-url": "",
subsystem: "JES2",
stepname: String(spoolFileToDownload.stepname),
procstep: String(
spoolFileToDownload.procstep === "N/A" || spoolFileToDownload.procstep == null ? undefined : spoolFileToDownload.procstep
),
};
const destinationFile = DownloadJobs.getSpoolDownloadFile(mockJobFile, parms.omitJobidDirectory, parms.outDir);
zowe.imperative.IO.createDirsSyncFromFilePath(destinationFile);
zowe.imperative.IO.writeFile(destinationFile, spoolFileToDownload.contents);
}
}
} catch (err) {
throw new ZoweFtpExtensionError(err.message);
} finally {
this.releaseConnection(connection);
}
}
public async getSpoolContentById(jobname: string, jobid: string, spoolId: number): Promise<string> {
let connection;
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) {
return response.toString();
}
}
return "";
} catch (err) {
throw new ZoweFtpExtensionError(err.message);
} finally {
this.releaseConnection(connection);
}
}
public getJclForJob(_job: zowe.IJob): Promise<string> {
throw new ZoweFtpExtensionError("Get jcl is not supported in the FTP extension.");
}
public submitJcl(_jcl: string, _internalReaderRecfm?: string, _internalReaderLrecl?: string): Promise<zowe.IJob> {
throw new ZoweFtpExtensionError("Submit jcl is not supported in the FTP extension.");
}
public async submitJob(jobDataSet: string): Promise<zowe.IJob> {
const result = this.getIJobResponse();
let connection;
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;
} catch (err) {
throw new ZoweFtpExtensionError(err.message);
} finally {
this.releaseConnection(connection);
}
}
public async deleteJob(jobname: string, jobid: string): Promise<void> {
let connection;
try {
connection = await this.ftpClient(this.checkedProfile());
if (connection) {
await JobUtils.deleteJob(connection, jobid);
}
} catch (err) {
throw new ZoweFtpExtensionError(err.message);
} finally {
this.releaseConnection(connection);
}
}
private getIJobResponse(): zowe.IJob {
return {
jobid: "",
jobname: "",
subsystem: "",
owner: "",
status: "",
type: "",
class: "",
retcode: "",
"step-data": [],
url: "",
"files-url": "",
"job-correlator": "",
phase: 0,
"phase-name": "",
"reason-not-running": "",
};
}
private getIJobFileResponse(): zowe.IJobFile {
return {
jobid: "",
jobname: "",
recfm: "",
"byte-count": 0,
"record-count": 0,
"job-correlator": "",
class: "",
id: 0,
ddname: "",
"records-url": "",
lrecl: 0,
subsystem: "",
stepname: "",
procstep: "",
};
}
}