Skip to content

Commit

Permalink
updated PDS check to dsorg.startWith(PO)
Browse files Browse the repository at this point in the history
Signed-off-by: Pujal <pujal.gandhi@broadcom.com>
  • Loading branch information
pujal0909 committed Feb 26, 2025
1 parent b91b989 commit 1c328ef
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe("Copy", () => {
let error;
let response;

const uploadFileToDatasetSpy = jest.spyOn(Upload, 'fileToDataset').mockImplementation(async (session, filePath, dsn) => {
const uploadFileToDatasetSpy = jest.spyOn(Upload, 'fileToDataset').mockImplementation(async (session, filePath) => {
if (filePath === fileLocation) {
throw new Error("Truncation of a record occurred during an I/O operation");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,23 +600,27 @@ describe("Copy", () => {
expectedPayload
);
});

it("should call Create.dataSetLike and create a new data set if the target data set inputted does not exist", async() => {
dataSetExistsSpy.mockResolvedValue(false);
dataSetExistsSpy.mockResolvedValueOnce(true);
dataSetExistsSpy.mockResolvedValueOnce(false);
const response = await Copy.dataSet(
dummySession,
{dsn: toDataSetName},
{"from-dataset": {
dsn:fromDataSetName
}}
);
expect(createSpy).toHaveBeenCalled();

expect(createSpy).toHaveBeenCalledWith(dummySession, toDataSetName, fromDataSetName);
expect(response).toEqual({
success: true,
commandResponse: util.format(ZosFilesMessages.dataSetCopiedIntoNew.message, toDataSetName)
});
});
it("should not create a new data set if the target data set inputted exists", async() => {
dataSetExistsSpy.mockResolvedValue(true);
dataSetExistsSpy.mockResolvedValueOnce(true);
dataSetExistsSpy.mockResolvedValueOnce(true);
const response = await Copy.dataSet(
dummySession,
{dsn: toDataSetName},
Expand Down Expand Up @@ -689,6 +693,21 @@ describe("Copy", () => {
commandResponse: `The source and target data sets are identical.`
});
});
it("should return early if the source data set does not exist", async() => {
dataSetExistsSpy.mockResolvedValueOnce(false);
dataSetExistsSpy.mockResolvedValueOnce(true);
const response = await Copy.dataSet(
dummySession,
{dsn: toDataSetName},
{"from-dataset": {
dsn: fromDataSetName
}}
);
expect(response).toEqual({
success: false,
commandResponse: `Data set copied aborted. The source data set was not found.`
});
});
});
describe("Failure Scenarios", () => {
it("should fail if the zOSMF REST client fails", async () => {
Expand Down
1 change: 0 additions & 1 deletion packages/zosfiles/src/constants/ZosFiles.messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export const ZosFilesMessages: { [key: string]: IMessageDefinition } = {
dataSetCopiedIntoNew: {
message: `Source contents were successfully copied into a new data set - %s`
},

/**
* Message indicating that the data set was created successfully
* @type {IMessageDefinition}
Expand Down
8 changes: 8 additions & 0 deletions packages/zosfiles/src/methods/copy/Copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ export class Copy {
const safeReplace: boolean = options.safeReplace;
const overwriteMembers: boolean = options.replace;

const sourceDataSetExists = await this.dataSetExists(session, options["from-dataset"].dsn);
if(!sourceDataSetExists) {
return {
success: false,
commandResponse: ZosFilesMessages.datasetCopiedAbortedNoTargetDS.message
};
}

if(options["from-dataset"].dsn === toDataSetName && toMemberName === options["from-dataset"].member) {
return {
success: false,
Expand Down
6 changes: 3 additions & 3 deletions packages/zosfiles/src/methods/download/Download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export class Download {
}

if (options.directory == null) {
if (dataSetObj.dsorg === "PO" || dataSetObj.dsorg === "PO-E") {
if (dataSetObj.dsorg && dataSetObj.dsorg.startsWith("PO")) {
mutableOptions.directory = ZosFilesUtils.getDirsFromDataSet(dataSetObj.dsname);
} else {
mutableOptions.file = `${dataSetObj.dsname}.` +
Expand All @@ -371,7 +371,7 @@ export class Download {
mutableOptions.directory = undefined;
mutableOptions.extension = undefined;
}
} else if (dataSetObj.dsorg === "PO" || dataSetObj.dsorg === "PO-E") {
} else if (dataSetObj.dsorg && dataSetObj.dsorg.startsWith("PO")) {
mutableOptions.directory = `${mutableOptions.directory}/${ZosFilesUtils.getDirsFromDataSet(dataSetObj.dsname)}`;
} else {
mutableOptions.file = `${dataSetObj.dsname}.${mutableOptions.extension ?? ZosFilesUtils.DEFAULT_FILE_EXTENSION}`;
Expand All @@ -397,7 +397,7 @@ export class Download {
dataSetObj.status = downloadResponse.commandResponse;
}
});
} else if (dataSetObj.dsorg === "PO" || dataSetObj.dsorg === "PO-E") {
} else if (dataSetObj.dsorg.startsWith("PO")) {
poDownloadTasks.push({
handler: Download.allMembers.bind(this),
dsname: dataSetObj.dsname,
Expand Down
2 changes: 1 addition & 1 deletion packages/zosfiles/src/methods/search/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Search {
if (resp.dsorg && !(resp.migr && resp.migr.toLowerCase() === "yes")) {
if (resp.dsorg === "PS") { // Sequential
searchItemsQueue.push({dsn: resp.dsname});
} else if (resp.dsorg === "PO" || resp.dsorg === "PO-E") { // Partitioned
} else if (resp.dsorg.startsWith("PO")) { // Partitioned
partitionedDataSets.push(resp.dsname);
}
}
Expand Down
21 changes: 9 additions & 12 deletions packages/zosfiles/src/methods/upload/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,19 +348,16 @@ export class Upload {
// If dsnameIndex === -1, it means we could not find the given data set.
// We will attempt the upload anyways so that we can forward/throw the proper error from z/OS MF
const dsInfo = listResponse.apiResponse.items[dsnameIndex];
switch (dsInfo.dsorg) {
case "PO":
case "PO-E":
isUploadToPds = true;
break;
default:
if(dsInfo.dsorg.startsWith("PO")) {
isUploadToPds = true;
}
else {
// if loading to a physical sequential data set and multiple files found then error
if (uploadFileList.length > 1) {
throw new ImperativeError({
msg: ZosFilesMessages.uploadDirectoryToPhysicalSequentialDataSet.message
});
}
break;
if (uploadFileList.length > 1) {
throw new ImperativeError({
msg: ZosFilesMessages.uploadDirectoryToPhysicalSequentialDataSet.message
});
}
}
}
}
Expand Down

0 comments on commit 1c328ef

Please sign in to comment.