Skip to content

Commit

Permalink
Merge branch 'master' into enhance-ijob
Browse files Browse the repository at this point in the history
  • Loading branch information
zFernand0 authored Oct 28, 2024
2 parents 11cd8ae + 58fd40f commit 5d7f071
Show file tree
Hide file tree
Showing 20 changed files with 313 additions and 61 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "8.3.1",
"version": "8.4.0",
"command": {
"publish": {
"ignoreChanges": [
Expand Down
18 changes: 9 additions & 9 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.

## `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)

## `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
8 changes: 4 additions & 4 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zowe/cli",
"version": "8.3.1",
"version": "8.4.0",
"zoweVersion": "v3.0.0",
"description": "Zowe CLI is a command line interface (CLI) that provides a simple and streamlined way to interact with IBM z/OS.",
"author": "Zowe",
Expand Down Expand Up @@ -62,12 +62,12 @@
"@zowe/imperative": "8.3.1",
"@zowe/provisioning-for-zowe-sdk": "8.3.1",
"@zowe/zos-console-for-zowe-sdk": "8.3.1",
"@zowe/zos-files-for-zowe-sdk": "8.3.1",
"@zowe/zos-jobs-for-zowe-sdk": "8.3.1",
"@zowe/zos-files-for-zowe-sdk": "8.4.0",
"@zowe/zos-jobs-for-zowe-sdk": "8.4.0",
"@zowe/zos-logs-for-zowe-sdk": "8.3.1",
"@zowe/zos-tso-for-zowe-sdk": "8.3.1",
"@zowe/zos-uss-for-zowe-sdk": "8.3.1",
"@zowe/zos-workflows-for-zowe-sdk": "8.3.1",
"@zowe/zos-workflows-for-zowe-sdk": "8.4.0",
"@zowe/zosmf-for-zowe-sdk": "8.3.1",
"find-process": "1.4.7",
"lodash": "4.17.21",
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: 2 additions & 2 deletions packages/workflows/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zowe/zos-workflows-for-zowe-sdk",
"version": "8.3.1",
"version": "8.4.0",
"description": "Zowe SDK to interact with the z/OS workflows APIs",
"author": "Zowe",
"license": "EPL-2.0",
Expand Down Expand Up @@ -45,7 +45,7 @@
"prepack": "node ../../scripts/prepareLicenses.js"
},
"dependencies": {
"@zowe/zos-files-for-zowe-sdk": "8.3.1"
"@zowe/zos-files-for-zowe-sdk": "8.4.0"
},
"devDependencies": {
"@zowe/cli-test-utils": "8.3.1",
Expand Down
Loading

0 comments on commit 5d7f071

Please sign in to comment.