Skip to content

Commit

Permalink
Merge pull request #2319 from zowe/zos-files-attributes
Browse files Browse the repository at this point in the history
[v3] Zos files attributes
  • Loading branch information
zFernand0 authored Oct 28, 2024
2 parents acd5f6e + 761d960 commit 2a2ba4b
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 42 deletions.
4 changes: 4 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 upload file-to-uss` to allow passing a .zosattributes file path for upload encoding format. [#2319] (https://github.com/zowe/zowe-cli/pull/2319)

## `8.3.0`

- Enhancement: Issue the `zowe files search data-sets` command with the new `encoding` option to use a different code page when searching data set contents. [#2161](https://github.com/zowe/zowe-cli/issues/2161)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
*/

import { Upload } from "@zowe/zos-files-for-zowe-sdk";
import { Upload, ZosFilesAttributes } from "@zowe/zos-files-for-zowe-sdk";
import { UNIT_TEST_ZOSMF_PROF_OPTS } from "../../../../../../../__tests__/__src__/TestConstants";

describe("Upload file-to-uss handler", () => {
Expand All @@ -29,7 +29,7 @@ describe("Upload file-to-uss handler", () => {
let fakeSession = null;

// Mock the submit JCL function
Upload.fileToUssFile = jest.fn(async (session, file, name, options = {}) => {
Upload.uploadFile = jest.fn(async (session, file, name, options = {}) => {
fakeSession = session;
return {
success: true,
Expand Down Expand Up @@ -79,20 +79,111 @@ describe("Upload file-to-uss handler", () => {
}

expect(error).toBeUndefined();
expect(Upload.fileToUssFile).toHaveBeenCalledTimes(1);
expect(Upload.fileToUssFile).toHaveBeenCalledWith(fakeSession, inputfile, USSFileName, {
expect(Upload.uploadFile).toHaveBeenCalledTimes(1);
expect(Upload.uploadFile).toHaveBeenCalledWith(fakeSession, inputfile, USSFileName, {
binary: undefined,
encoding: undefined,
task: {
percentComplete: 0,
stageName: 0,
statusMessage: "Uploading USS file"
}
},
includeHidden: undefined,
maxConcurrentRequests: undefined,
responseTimeout: undefined
});
expect(jsonObj).toMatchSnapshot();
expect(apiMessage).toMatchSnapshot();
expect(logMessage).toMatchSnapshot();
});
it("should upload a file to a USS if requested - zosattributes file", async () => {
// Require the handler and create a new instance
const handlerReq = require("../../../../../src/zosfiles/upload/ftu/FileToUSS.handler");
const handler = new handlerReq.default();
const inputfile = "test-file";
const USSFileName = "testing";
let zosAttributes: any;

let error;
let apiMessage = "";
let jsonObj;
let logMessage = "";
let fakeSession = null;

jest.spyOn(ZosFilesAttributes, "loadFromFile").mockImplementation(() => {
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' }]
]);
zosAttributes.basePath = undefined;
return zosAttributes;
});
Upload.uploadFile = jest.fn(async (session, file, name, options = {}) => {
fakeSession = session;
return {
success: true,
commandResponse: "uploaded",
apiResponse: [
{ success: true, from: inputfile, to: USSFileName }
]
};
});
try {
await handler.process({
arguments: {
$0: "fake",
_: ["fake"],
inputfile,
USSFileName,
...UNIT_TEST_ZOSMF_PROF_OPTS
},
response: {
data: {
setMessage: jest.fn((setMsgArgs) => {
apiMessage = setMsgArgs;
}),
setObj: jest.fn((setObjArgs) => {
jsonObj = setObjArgs;
})
},
console: {
log: jest.fn((logArgs) => {
logMessage += "\n" + logArgs;
})
},
progress: {
startBar: jest.fn(() => {
// do nothing
}),
endBar: jest.fn(() => {
// do nothing
})
}
}
} as any);
} catch (e) {
error = e;
}
expect(error).toBeUndefined();
expect(Upload.uploadFile).toHaveBeenCalledTimes(1);
expect(Upload.uploadFile).toHaveBeenCalledWith(fakeSession, inputfile, USSFileName, {
attributes: zosAttributes,
binary: undefined,
includeHidden: undefined,
maxConcurrentRequests: undefined,
responseTimeout: undefined,
task: {
percentComplete: 0,
stageName: 0,
statusMessage: "Uploading USS file"
}
});
expect(jsonObj).toMatchSnapshot();
expect(apiMessage).toMatchSnapshot();
expect(logMessage).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ Array [
"name": "encoding",
"type": "string",
},
Object {
"aliases": Array [
"attrs",
],
"conflictsWith": Array [
"ascii-files, binary-files",
],
"description": "Path of an attributes file to control how files are uploaded.",
"name": "attributes",
"type": "string",
},
]
`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Upload file-to-uss handler process method should upload a file to a USS if requested - zosattributes file 1`] = `
Object {
"apiResponse": Array [
Object {
"from": "test-file",
"success": true,
"to": "testing",
},
],
"commandResponse": "uploaded",
"success": true,
}
`;

exports[`Upload file-to-uss handler process method should upload a file to a USS if requested - zosattributes file 2`] = `""`;

exports[`Upload file-to-uss handler process method should upload a file to a USS if requested - zosattributes file 3`] = `
"
- 
success: true
from:  test-file
to:  testing
uploaded"
`;

exports[`Upload file-to-uss handler process method should upload a file to a uss if requested 1`] = `
Object {
"apiResponse": Array [
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/zosfiles/upload/ftu/FileToUSS.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export const FileToUSSDefinition: ICommandDefinition = {
],
options: [
UploadOptions.binary,
UploadOptions.encoding
UploadOptions.encoding,
UploadOptions.attributes
],
examples: [
{
Expand Down
66 changes: 45 additions & 21 deletions packages/cli/src/zosfiles/upload/ftu/FileToUSS.handler.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,63 @@
/*
* 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.
*
*/
* 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 { AbstractSession, IHandlerParameters, ITaskWithStatus, TaskStage, TextUtils } from "@zowe/imperative";
import { Upload, IZosFilesResponse } from "@zowe/zos-files-for-zowe-sdk";
import {
AbstractSession,
IHandlerParameters,
ITaskWithStatus,
TaskStage,
TextUtils,
} from "@zowe/imperative";
import { Upload, IZosFilesResponse, IUploadOptions, ZosFilesAttributes } from "@zowe/zos-files-for-zowe-sdk";
import { ZosFilesBaseHandler } from "../../ZosFilesBase.handler";

/**
* Handler to upload content from a local file to a USS file
* @export
*/
export default class FileToUSSHandler extends ZosFilesBaseHandler {
public async processWithSession(commandParameters: IHandlerParameters,
session: AbstractSession): Promise<IZosFilesResponse> {
public async processWithSession(
commandParameters: IHandlerParameters,
session: AbstractSession
): Promise<IZosFilesResponse> {
const task: ITaskWithStatus = {
percentComplete: 0,
statusMessage: "Uploading USS file",
stageName: TaskStage.IN_PROGRESS
stageName: TaskStage.IN_PROGRESS,
};
commandParameters.response.progress.startBar({ task });

const response = await Upload.fileToUssFile(session, commandParameters.arguments.inputfile,
commandParameters.arguments.USSFileName, {
binary: commandParameters.arguments.binary,
encoding: commandParameters.arguments.encoding,
task,
responseTimeout: commandParameters.arguments.responseTimeout
});
const uploadOptions: IUploadOptions = {
binary: commandParameters.arguments.binary,
maxConcurrentRequests:
commandParameters.arguments.maxConcurrentRequests,
task: task,
responseTimeout: commandParameters.arguments.responseTimeout,
includeHidden: commandParameters.arguments.includeHidden,
};

const attributes = ZosFilesAttributes.loadFromFile(
commandParameters.arguments.attributes,
commandParameters.arguments.inputDir
);
if (attributes != null) {
uploadOptions.attributes = attributes;
}

const response = await Upload.uploadFile(
session,
commandParameters.arguments.inputfile,
commandParameters.arguments.USSFileName,
uploadOptions
);

const formatMessage = TextUtils.prettyJson(response.apiResponse);
commandParameters.response.console.log(formatMessage);
Expand Down
4 changes: 4 additions & 0 deletions packages/zosfiles/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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 upload file-to-uss` to allow passing a .zosattributes file path for upload encoding format. [#2319] (https://github.com/zowe/zowe-cli/pull/2319)

## `8.2.0`

- Enhancement: Added an optional `continueSearch` function to the `ISearchOptions` interface. After a data set listing is completed, the new function is called with the list of data sets about to be searched. This allows the extender or end users to continue with the search or cancel it. [#2300](https://github.com/zowe/zowe-cli/pull/2300)
Expand Down
Loading

0 comments on commit 2a2ba4b

Please sign in to comment.