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 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
*.bin binary binary
*.jcl IBM-1047 IBM-1047
*.md UTF-8 UTF-8
*.txt UTF-8 IBM-1047
*.txt binary binary
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 @@ -39,6 +39,7 @@ export const UssFileDefinition: ICommandDefinition = {
}
],
options: [
DownloadOptions.attributes,
DownloadOptions.file,
DownloadOptions.binary,
DownloadOptions.encoding
Expand Down
16 changes: 12 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,21 @@ export default class UssFileHandler extends ZosFilesBaseHandler {
stageName: TaskStage.IN_PROGRESS
};
commandParameters.response.progress.startBar({task});
return Download.ussFile(session, commandParameters.arguments.ussFileName, {

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,
};
const attributes = ZosFilesAttributes.loadFromFile(
commandParameters.arguments.attributes,
);
if (attributes != null) {
downloadOptions.attributes = attributes;
}
return Download.ussFile(session, commandParameters.arguments.ussFileName, downloadOptions);
jace-roell marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
IMountFsOptions,
Mount,
Unmount,
IUSSListOptions
IUSSListOptions,
ZosFilesAttributes
} from "../../../../src";
import { Imperative, IO, Session } from "@zowe/imperative";
import { inspect } from "util";
Expand All @@ -37,10 +38,12 @@
import { Shell } from "@zowe/zos-uss-for-zowe-sdk";
import { PassThrough } from "stream";
import { text } from "stream/consumers";
import { runCliScript } from "../../../../../../__tests__/__packages__/cli-test-utils/lib";
Fixed Show fixed Hide fixed

const rimraf = require("rimraf").sync;
const delayTime = 2000;
const testData = "abcdefghijklmnopqrstuvwxyz";
const testDataBinary = "[][][]";

let REAL_SESSION: Session;
let testEnvironment: ITestEnvironment<ITestPropertiesSchema>;
Expand Down Expand Up @@ -1018,7 +1021,7 @@
let error;
let response: IZosFilesResponse;

await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testData));
await Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testDataBinary));
await wait(delayTime);

try {
Expand Down Expand Up @@ -1081,6 +1084,61 @@

});

it("should download uss file with --attributes flag", async () => {
let error;
let response: any;
let downloadResponse: any;
let 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 Upload.bufferToUssFile(REAL_SESSION, ussname, Buffer.from(testDataBinary));
downloadResponse = await Download.ussFile(REAL_SESSION, ussname, { attributes: zosAttributes});
} catch (err) {
error = err;
}
expect(error).toBeFalsy();
expect(response).toBeTruthy();
expect(downloadResponse).toBeTruthy();

// Compare the downloaded contents to those uploaded
const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString());
expect(fileContents).toEqual(testDataBinary);
});

it("should download uss file with --attributes flag - binary", async () => {
let error;
let response: any;
let downloadResponse: any;
let 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 Upload.uploadFile(REAL_SESSION, __dirname+"/__resources__/testfiles/downloadEncodingCheck.txt" ,ussname, { attributes: zosAttributes});
downloadResponse = await Download.ussFile(REAL_SESSION, ussname, { attributes: zosAttributes});
} catch (err) {
error = err;
}
expect(error).toBeFalsy();
expect(response).toBeTruthy();
expect(downloadResponse).toBeTruthy();

// Compare the downloaded contents to those uploaded
const fileContents = stripNewLines(fs.readFileSync(`./${posix.basename(ussname)}`).toString());

expect(fileContents).toEqual(fs.readFileSync(__dirname+"/__resources__/testfiles/downloadEncodingCheck.txt").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
jace-roell marked this conversation as resolved.
Show resolved Hide resolved
exit $?
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
jace-roell marked this conversation as resolved.
Show resolved Hide resolved
exit $?
5 changes: 5 additions & 0 deletions packages/zosfiles/src/doc/IOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import { ITaskWithStatus } from "@zowe/imperative";
import { IZosFilesOptions } from "./IZosFilesOptions";
import { ZosFilesAttributes } from "../utils/ZosFilesAttributes";
Fixed Show fixed Hide fixed

/**
* This interface defines the options that can be sent to get a data set or USS file function
Expand Down Expand Up @@ -57,4 +58,8 @@ export interface IOptions extends IZosFilesOptions {
* @type {ITaskWithStatus}
*/
task?: ITaskWithStatus;
/**
* The path to a .zosattributes file used to control file conversion and tagging.
*/
attributes?: ZosFilesAttributes;
jace-roell marked this conversation as resolved.
Show resolved Hide resolved
}
13 changes: 11 additions & 2 deletions packages/zosfiles/src/methods/download/Download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { ZosFilesUtils } from "../../utils/ZosFilesUtils";
import { List } from "../list/List";
import { IDownloadOptions, IDownloadSingleOptions } from "./doc/IDownloadOptions";
import { CLIENT_PROPERTY } from "../../doc/types/ZosmfRestClientProperties";
import { Utilities } from "../utilities";
import { Tag, Utilities } from "../utilities";
Fixed Show fixed Hide fixed
import { IZosmfListResponse } from "../list/doc/IZosmfListResponse";
import { IDownloadDsmResult } from "./doc/IDownloadDsmResult";
import { IDownloadUssDirResult } from "./doc/IDownloadUssDirResult";
Expand Down Expand Up @@ -521,7 +521,16 @@ export class Download {

const writeStream = options.stream ?? IO.createWriteStream(destination);

// If data type is not defined by user, check for USS tags
//const remoteEncoding = options.attributes.getRemoteEncoding(ussFileName);
jace-roell marked this conversation as resolved.
Show resolved Hide resolved
if(options.attributes)
{
options.binary = options.attributes.getFileTransferMode(ussFileName, options.binary) === TransferMode.BINARY;
const remoteEncoding = options.attributes.getRemoteEncoding(ussFileName);
if(remoteEncoding === Tag.BINARY) options.encoding = undefined;
awharn marked this conversation as resolved.
Show resolved Hide resolved
else if(remoteEncoding !== null) options.encoding = remoteEncoding;
}

// If data type is not defined by user via encoding flag or attributes file, check for USS tags
if (options.binary == null && options.encoding == null) {
await Utilities.applyTaggedEncoding(session, ussFileName, options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ export interface IDownloadSingleOptions extends IGetOptions {
overwrite?: boolean;

/**
* Optional stream to read the file contents
* Optional stream to write the file contents
*/
stream?: Writable;
/**
* The ZosFilesAttributes instance describe upload attributes for the files and directories
*/
attributes?: ZosFilesAttributes;
}

/**
Expand Down
Loading