Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zos download attributes #2335

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0983d3e
attributes passed to ussFile(), need to implement
jace-roell Oct 29, 2024
bf60219
poc work
jace-roell Oct 30, 2024
4b5c6fc
progress checkpoint
jace-roell Oct 30, 2024
c87ee64
progress
jace-roell Oct 30, 2024
b2781ce
handle binary in .zos attributes files
jace-roell Oct 31, 2024
3a1a16e
binary fix
jace-roell Oct 31, 2024
2483f41
unused import
jace-roell Oct 31, 2024
1f57ce6
system test work
jace-roell Nov 1, 2024
dff1a43
remove temp files
jace-roell Nov 1, 2024
60d81b4
system test start
jace-roell Nov 1, 2024
59f18a8
system test fix with file extensions for remoteEncoding
jace-roell Nov 1, 2024
8406831
changelog, system tests, unit tests
jace-roell Nov 4, 2024
29d9e5c
changelog
jace-roell Nov 4, 2024
fe613e3
change encoding on test
jace-roell Nov 4, 2024
d0c9178
integration test snapshot
jace-roell Nov 4, 2024
fe263c5
fixed changed test encoding
jace-roell Nov 4, 2024
4056a4f
left over package.json data from canceled integration tests
jace-roell Nov 4, 2024
54a0ff0
Merge branch 'master' into zos-download-attributes
jace-roell Nov 4, 2024
f4177de
changelog
jace-roell Nov 4, 2024
b5d768b
changelog fix
jace-roell Nov 4, 2024
73ae952
condensed attributes assignment to downloadOptions and removed unnece…
jace-roell Nov 5, 2024
e9e1953
Merge branch 'master' into zos-download-attributes
jace-roell Nov 5, 2024
59df2f0
linting
jace-roell Nov 5, 2024
8dd118f
changelog
jace-roell Nov 5, 2024
055baa1
changelog
jace-roell Nov 5, 2024
35dc5d1
changelog
jace-roell Nov 5, 2024
4f23a0f
Merge branch 'master' into zos-download-attributes
jace-roell Nov 5, 2024
6edee45
changelog
jace-roell Nov 5, 2024
299557c
changelog
jace-roell Nov 5, 2024
685fa54
Update packages/zosfiles/CHANGELOG.md
jace-roell Nov 6, 2024
35a2351
Merge branch 'master' into zos-download-attributes
jace-roell Nov 6, 2024
c0002e7
condenses attributes being passed to download options object
jace-roell Nov 6, 2024
d0be449
remove unneccesary property
jace-roell Nov 6, 2024
75aaab8
import
jace-roell Nov 6, 2024
b05be48
shell script for system test fix
jace-roell Nov 6, 2024
a2494c8
added local encoding support and updated system tests
jace-roell Nov 6, 2024
7872472
changelog and linting
jace-roell Nov 6, 2024
49325e9
changelog
jace-roell Nov 6, 2024
47b3ed0
changelog
jace-roell Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the Zowe CLI package will be documented in this file.

## Recent Changes

- Enhancement: Added optional `--attributes` flag to `zowe zos-files download uss-file` to allow passing a .zosattributes file path for download encoding format. [#2322](https://github.com/zowe/zowe-cli/issues/2322)
jace-roell marked this conversation as resolved.
Show resolved Hide resolved

## `8.7.0`

- Enhancement: Added --wait-for-active and --wait-for-output to download options on zosjobs. [#2328](https://github.com/zowe/zowe-cli/pull/2328)
Expand All @@ -18,6 +22,7 @@ All notable changes to the Zowe CLI package will be documented in this file.

- Enhancement: Added support for running applications on TSO/E address spaces. Start applications and receive/transmit messages using the new `tso start`, `tso receive` and `tso send` commands. [#2280](https://github.com/zowe/zowe-cli/pull/2280)


## `8.4.0`

- Enhancement: Added optional `--attributes` flag to `zowe zos-files upload file-to-uss` to allow passing a .zosattributes file path for upload encoding format. [#2319](https://github.com/zowe/zowe-cli/pull/2319)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

exports[`zos-files download uss-file command definition should not have changed 1`] = `
Array [
Object {
"aliases": Array [
"attrs",
],
"conflictsWith": Array [
"binary",
"record",
],
"description": "Path of an attributes file to control how files are downloaded.",
"name": "attributes",
"type": "existingLocalFile",
},
Object {
"aliases": Array [
"b",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { ITestEnvironment } from "../../../../../../__tests__/__src__/environmen
import { runCliScript } from "@zowe/cli-test-utils";
import { ITestPropertiesSchema } from "../../../../../../__tests__/__src__/properties/ITestPropertiesSchema";
import * as fs from "fs";
import { Session } from "@zowe/imperative";
import { GetJobs } from "@zowe/zos-jobs-for-zowe-sdk";

// Test Environment populated in the beforeAll();
let TEST_ENVIRONMENT: ITestEnvironment<ITestPropertiesSchema>;
Expand Down Expand Up @@ -49,14 +47,14 @@ describe("zos-jobs download output command", () => {
it("should download a job and wait for it to reach output status", async () => {
const response = runCliScript(__dirname + "/__scripts__/download-output/download_job_wait_for_output.sh",
TEST_ENVIRONMENT, [IEFBR14_JCL]);
expect(response.stderr.toString()).toBe("");
expect(response.status).toBe(0);
expect(response.stderr.toString()).toBe("");
expect(response.status).toBe(0);
});
it("should download a job and wait for it to reach active status", async () => {
const response = runCliScript(__dirname + "/__scripts__/download-output/download_job_wait_for_active.sh",
TEST_ENVIRONMENT, [IEFBR14_JCL]);
expect(response.stderr.toString()).toBe("");
expect(response.status).toBe(0);
expect(response.stderr.toString()).toBe("");
expect(response.status).toBe(0);
});
});
describe("output", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const UssFileDefinition: ICommandDefinition = {
}
],
options: [
DownloadOptions.attributes,
DownloadOptions.file,
DownloadOptions.binary,
DownloadOptions.encoding
Expand Down
15 changes: 11 additions & 4 deletions packages/cli/src/zosfiles/download/uss/UssFile.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import { ZosFilesBaseHandler } from "../../ZosFilesBase.handler";
import { AbstractSession, IHandlerParameters, ITaskWithStatus, TaskStage } from "@zowe/imperative";
import { Download, IZosFilesResponse } from "@zowe/zos-files-for-zowe-sdk";
import { Download, IDownloadOptions, IZosFilesResponse, ZosFilesAttributes } from "@zowe/zos-files-for-zowe-sdk";

/**
* Handler to download an uss file
Expand All @@ -25,13 +25,20 @@ export default class UssFileHandler extends ZosFilesBaseHandler {
stageName: TaskStage.IN_PROGRESS
};
commandParameters.response.progress.startBar({task});
return Download.ussFile(session, commandParameters.arguments.ussFileName, {

const attributes = ZosFilesAttributes.loadFromFile(
commandParameters.arguments.attributes,
);
const downloadOptions: IDownloadOptions = {
binary: commandParameters.arguments.binary,
encoding: commandParameters.arguments.encoding,
file: commandParameters.arguments.file,
task,
responseTimeout: commandParameters.arguments.responseTimeout,
overwrite: commandParameters.arguments.overwrite
});
overwrite: commandParameters.arguments.overwrite,
attributes
};

return Download.ussFile(session, commandParameters.arguments.ussFileName, downloadOptions);
}
}
6 changes: 5 additions & 1 deletion packages/zosfiles/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

All notable changes to the Zowe z/OS files SDK package will be documented in this file.

## Recent Changes

- Enhancement: Added optional `--attributes` flag to `zowe zos-files download uss-file` to allow passing a .zosattributes file path for download encoding format. [#2322](https://github.com/zowe/zowe-cli/issues/2322)

## `8.6.2`

- BugFix: Resolved issue where encoding argument was missing from `FileToUss.handler.ts` options object. [#2234](https://github.com/zowe/zowe-cli/pull/2334)
- BugFix: Resolved issue where `FileToUss.handler.ts` options object was not properly passed through subsequent command calls. [#2234](https://github.com/zowe/zowe-cli/pull/2334)

## `8.4.0`

- Enhancement: Added optional `--attributes` flag to `zowe zos-files upload file-to-uss` to allow passing a .zosattributes file path for upload encoding format. [#2319] (https://github.com/zowe/zowe-cli/pull/2319)
- Enhancement: Added optional `--attributes` flag to `zowe zos-files upload file-to-uss` to allow passing a .zosattributes file path for upload encoding format. [#2319](https://github.com/zowe/zowe-cli/pull/2319)
jace-roell marked this conversation as resolved.
Show resolved Hide resolved

## `8.2.0`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
IMountFsOptions,
Mount,
Unmount,
IUSSListOptions
IUSSListOptions,
} from "../../../../src";
import { Imperative, IO, Session } from "@zowe/imperative";
import { inspect } from "util";
Expand All @@ -37,6 +37,7 @@ import { posix } from "path";
import { Shell } from "@zowe/zos-uss-for-zowe-sdk";
import { PassThrough } from "stream";
import { text } from "stream/consumers";
import { runCliScript } from "@zowe/cli-test-utils";

const rimraf = require("rimraf").sync;
const delayTime = 2000;
Expand Down Expand Up @@ -1080,7 +1081,91 @@ describe.each([false, true])("Download Data Set - Encoded: %s", (encoded: boolea
expect(fileContents).toEqual(testData);

});

describe.each([false, true])(
"Download Data Set - Binary: %s",
(binary: boolean) => {
it("should upload and download file with correct encoding", async () => {
let response: any;

// Upload binary or encoded file
const uploadFile: string = binary
? "downloadEncodingCheck.txt"
: "downloadEncodingCheckBinary.txt";
let downloadResponse: any;
let error: any;

// Use text file as to get proper response from getRemoteEncoding()
const ussnameAsTxt = ussname + ".txt";
try {
response = runCliScript(
__dirname +
`/__resources__/${
binary
? "upload_file_to_uss.sh"
: "upload_file_to_uss_binary.sh"
}`,
testEnvironment,
[
defaultSystem.tso.account,
defaultSystem.zosmf.host,
defaultSystem.zosmf.port,
defaultSystem.zosmf.user,
defaultSystem.zosmf.password,
defaultSystem.zosmf.rejectUnauthorized,
__dirname +
"/__resources__/testfiles/" +
uploadFile,
ussnameAsTxt,
binary ? "1047" : true,
]
);
downloadResponse = runCliScript(
__dirname + "/__resources__/download_file.sh",
testEnvironment,
[
defaultSystem.tso.account,
defaultSystem.zosmf.host,
defaultSystem.zosmf.port,
defaultSystem.zosmf.user,
defaultSystem.zosmf.password,
defaultSystem.zosmf.rejectUnauthorized,
ussnameAsTxt,
__dirname +
`/__resources__/${
binary
? ".zosattributes"
: ".zosattributes-binary"
}`,
]
);
} catch (err) {
error = err;
}

expect(error).toBeFalsy();
expect(response).toBeTruthy();
expect(downloadResponse).toBeTruthy();

// Compare the downloaded contents to those uploaded
const fileContents = fs
.readFileSync(
`${testEnvironment.workingDir}/${posix.basename(
ussnameAsTxt
)}`
)
.toString();
expect(fileContents).toEqual(
fs
.readFileSync(
__dirname +
"/__resources__/testfiles/" +
uploadFile
)
.toString()
);
});
}
);
// When requesting etag, z/OSMF has a limit on file size when it stops to return etag by default (>8mb)
// We are passing X-IBM-Return-Etag to force z/OSMF to always return etag, but testing here for case where it would be optional
it("should download a 10mb uss file and return Etag", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.json -
*.bin binary binary
*.jcl IBM-1047 IBM-1047
*.md UTF-8 UTF-8
*.txt UTF-8 IBM-1047
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.json -
*.bin binary binary
*.jcl IBM-1047 IBM-1047
*.md UTF-8 UTF-8
*.txt binary binary
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
account=$1
host=$2
port=$3
user=$4
password=$5
ru=$6
fileToDownload=$7
attributes=$8

zowe zos-files download uss "$fileToDownload" --attributes "$attributes" --host $host --port $port --user $user --password $password --ru $ru
exit $?
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abcdefghijklmnopqrstuvwxyz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[][][]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
account=$1
host=$2
port=$3
user=$4
password=$5
ru=$6
inputFile=$7
ussName=$8
encoding=$9

zowe zos-files upload file-to-uss "$inputFile" "$ussName" --encoding $encoding --host $host --port $port --user $user --password $password --ru $ru
exit $?
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
account=$1
host=$2
port=$3
user=$4
password=$5
ru=$6
inputFile=$7
ussName=$8
binary=$9

zowe zos-files upload file-to-uss "$inputFile" "$ussName" --binary $binary --host $host --port $port --user $user --password $password --ru $ru
exit $?
Original file line number Diff line number Diff line change
Expand Up @@ -2184,6 +2184,90 @@ describe("z/OS Files - Download", () => {
expect(ioCreateDirSpy).not.toHaveBeenCalled();
expect(ioWriteStreamSpy).not.toHaveBeenCalled();
});
it("should download uss file using .zosattributes file", async () => {
let response;
let caughtError;
const destination = localFileName;
const zosAttributes = Object.create(ZosFilesAttributes.prototype);
zosAttributes.attributes = new Map([
['*.json', { ignore: true }],
['*.bin', { ignore: false, localEncoding: 'binary', remoteEncoding: 'binary' }],
['*.jcl', { ignore: false, localEncoding: 'IBM-1047', remoteEncoding: 'IBM-1047' }],
['*.md', { ignore: false, localEncoding: 'UTF-8', remoteEncoding: 'UTF-8' }],
['*.txt', { ignore: false, localEncoding: 'UTF-8', remoteEncoding: 'IBM-1047' }]
]);
try {
response = await Download.ussFile(dummySession, ussname, { attributes: zosAttributes });
} catch (e) {
caughtError = e;
}

const endpoint = path.posix.join(ZosFilesConstants.RESOURCE, ZosFilesConstants.RES_USS_FILES, encodeURIComponent(ussname.substring(1)));

expect(caughtError).toBeUndefined();
expect(response).toEqual({
success: true,
commandResponse: util.format(ZosFilesMessages.ussFileDownloadedWithDestination.message, destination),
apiResponse: {}
});

expect(zosmfGetFullSpy).toHaveBeenCalledTimes(1);
expect(zosmfGetFullSpy).toHaveBeenCalledWith(dummySession, {
resource: endpoint,
reqHeaders: [{ "X-IBM-Data-Type": "text;fileEncoding=IBM-1047" }, ZosmfHeaders.ACCEPT_ENCODING, {"Content-Type": "UTF-8"}],
responseStream: fakeStream,
normalizeResponseNewLines: true,
task: undefined /* no progress task */
});

expect(ioCreateDirSpy).toHaveBeenCalledTimes(1);
expect(ioCreateDirSpy).toHaveBeenCalledWith(destination);

expect(ioWriteStreamSpy).toHaveBeenCalledTimes(1);
expect(ioWriteStreamSpy).toHaveBeenCalledWith(destination);
});
it("should download uss file using .zosattributes file - binary", async () => {
let response;
let caughtError;
const destination = localFileName;
const zosAttributes = Object.create(ZosFilesAttributes.prototype);
zosAttributes.attributes = new Map([
['*.json', { ignore: true }],
['*.bin', { ignore: false, localEncoding: 'binary', remoteEncoding: 'binary' }],
['*.jcl', { ignore: false, localEncoding: 'IBM-1047', remoteEncoding: 'IBM-1047' }],
['*.md', { ignore: false, localEncoding: 'UTF-8', remoteEncoding: 'UTF-8' }],
['*.txt', { ignore: false, localEncoding: 'binary', remoteEncoding: 'binary' }]
]);
try {
response = await Download.ussFile(dummySession, ussname, { attributes: zosAttributes });
} catch (e) {
caughtError = e;
}

const endpoint = path.posix.join(ZosFilesConstants.RESOURCE, ZosFilesConstants.RES_USS_FILES, encodeURIComponent(ussname.substring(1)));

expect(caughtError).toBeUndefined();
expect(response).toEqual({
success: true,
commandResponse: util.format(ZosFilesMessages.ussFileDownloadedWithDestination.message, destination),
apiResponse: {}
});

expect(zosmfGetFullSpy).toHaveBeenCalledTimes(1);
expect(zosmfGetFullSpy).toHaveBeenCalledWith(dummySession, {
resource: endpoint,
reqHeaders: [{ "X-IBM-Data-Type": "binary" }],
responseStream: fakeStream,
normalizeResponseNewLines: false,
task: undefined /* no progress task */
});

expect(ioCreateDirSpy).toHaveBeenCalledTimes(1);
expect(ioCreateDirSpy).toHaveBeenCalledWith(destination);

expect(ioWriteStreamSpy).toHaveBeenCalledTimes(1);
expect(ioWriteStreamSpy).toHaveBeenCalledWith(destination);
});
});

describe("USS Directory", () => {
Expand Down
Loading
Loading