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

Introduce enhancements supporting the ZE FTP Copy feature #131

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
13 changes: 13 additions & 0 deletions src/api/DataSetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ export class DataSetUtils {
await connection.allocateDataset(dsn, option.dcb);
}

public static async allocateLikeDataSet(connection: any, dsn: string, like: string): Promise<void> {
this.log.debug("Allocate data set '%s' with similar attributes to '%s", dsn, like);
const files = await connection.listDataset(like);

this.log.debug("Found %d matching data sets", files.length);
if (files.length === 0) {
throw "No datasets found: " + like;
}
const option = files[0];
this.log.debug(JSON.stringify(option));
await connection.allocateDataset(dsn, option);
}

private static get log(): Logger {
return Logger.getAppLogger();
}
Expand Down
6 changes: 5 additions & 1 deletion src/cli/allocate/Allocate.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@

import { ICommandDefinition } from "@zowe/imperative";
import { AllocateDataSetDefinition } from "./data-set/DataSet.definition";
import { LikeDataSetDefinition } from "./like-data-set/LikeDataSet.definition";
import { FTPConfig } from "../../api/FTPConfig";

const AllocateDefinition: ICommandDefinition = {
name: "allocate", aliases: ["alloc"],
summary: "Allocate a sequential dataset or partitioned dataset with '--dcb \"PDSTYPE=PDS\"'",
description: "Allocate a sequential or partitioned dataset",
type: "group",
children: [AllocateDataSetDefinition],
children: [
AllocateDataSetDefinition,
LikeDataSetDefinition,
],
passOn: [
{
property: "options",
Expand Down
28 changes: 28 additions & 0 deletions src/cli/allocate/like-data-set/LikeDataSet.Handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 { FTPBaseHandler } from "../../../FTPBase.Handler";
import { IFTPHandlerParams } from "../../../IFTPHandlerParams";
import { DataSetUtils } from "../../../api";

export default class LikeDataSetHandler extends FTPBaseHandler {

public async processFTP(params: IFTPHandlerParams): Promise<void> {
const options = {
Fixed Show fixed Hide fixed
dcb: params.arguments.dcb
};
await DataSetUtils.allocateLikeDataSet(params.connection, params.arguments.datasetName, params.arguments.like);

const successMsg = params.response.console.log("Allocated dataset %s like %s successfully!", params.arguments.datasetName, params.arguments.like);
params.response.data.setMessage(successMsg);
this.log.info(successMsg);
}
}
45 changes: 45 additions & 0 deletions src/cli/allocate/like-data-set/LikeDataSet.definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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 { ICommandDefinition } from "@zowe/imperative";


export const LikeDataSetDefinition: ICommandDefinition = {
handler: __dirname + "/LikeDataSet.Handler",
description: "Allocate a dataset with the same attributes as another dataset",
type: "command",
name: "like-data-set", aliases: ["like", "lds"],
summary: "Allocate a dataset with similar attributes to another",
examples: [
{
description: "Allocate a dataset \"IBMUSER.NEW.DATASET\" " +
"with the same attributes as \"IBMUSER.ORIGINAL.DATASET\"",
options: "\"IBMUSER.NEW.DATASET\" --like \"IBMUSER.ORIGINAL.DATASET\""
}

],
positionals: [{
name: "datasetName",
description: "The dataset name you'd like to allocate.",
type: "string",
required: true
}],
options: [
{
name: "like", aliases: [],
description: "Dataset name to copy the attributes from.",
required: true,
type: "string"
}
],
profile:
{optional: ["zftp"]}
};