Skip to content

Commit

Permalink
Removed duplicate cicsplexes
Browse files Browse the repository at this point in the history
Signed-off-by: EKhan <[email protected]>
  • Loading branch information
enamkhan committed Feb 7, 2025
1 parent f930e66 commit dd3ffdc
Show file tree
Hide file tree
Showing 3 changed files with 253 additions and 3 deletions.
200 changes: 200 additions & 0 deletions packages/vsce/__tests__/__unit__/utils/plexUtils.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/**
* 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 * as profileUtils from "../../../src/utils/plexUtils";

describe("Profile Utils tests", () => {
describe("compareCicsplexes", () => {
it("should return 0 as both are the same", () => {
const plex1 = {
status: "ACTIVE",
mpstatus: "YES",
accesstype: "LOCAL"
};

const plex2 = {
status: "ACTIVE",
mpstatus: "YES",
accesstype: "LOCAL"
};

const response = profileUtils.compareCicsplexes(plex1, plex2);
expect(response).toEqual(0);
});

it("should return -1 as plex1 has INACTIVE status", () => {
const plex1 = {
status: "INACTIVE",
mpstatus: "YES",
accesstype: "LOCAL"
};

const plex2 = {
status: "ACTIVE",
mpstatus: "YES",
accesstype: "LOCAL"
};

const response = profileUtils.compareCicsplexes(plex1, plex2);
expect(response).toEqual(-1);
});

it("should return -1 as plex1 has mpstatus NO", () => {
const plex1 = {
status: "ACTIVE",
mpstatus: "NO",
accesstype: "LOCAL"
};

const plex2 = {
status: "ACTIVE",
mpstatus: "YES",
accesstype: "LOCAL"
};

const response = profileUtils.compareCicsplexes(plex1, plex2);
expect(response).toEqual(-1);
});

it("should return -1 as plex1 has accesstype ADJACENT", () => {
const plex1 = {
status: "ACTIVE",
mpstatus: "YES",
accesstype: "ADJACENT"
};

const plex2 = {
status: "ACTIVE",
mpstatus: "YES",
accesstype: "LOCAL"
};

const response = profileUtils.compareCicsplexes(plex1, plex2);
expect(response).toEqual(-1);
});

it("should return 1 as plex2 has INACTIVE status", () => {
const plex1 = {
status: "ACTIVE",
mpstatus: "YES",
accesstype: "LOCAL"
};

const plex2 = {
status: "INACTIVE",
mpstatus: "YES",
accesstype: "LOCAL"
};

const response = profileUtils.compareCicsplexes(plex1, plex2);
expect(response).toEqual(1);
});

it("should return 1 as plex2 has mpstatus NO", () => {
const plex1 = {
status: "ACTIVE",
mpstatus: "YES",
accesstype: "LOCAL"
};

const plex2 = {
status: "ACTIVE",
mpstatus: "NO",
accesstype: "LOCAL"
};

const response = profileUtils.compareCicsplexes(plex1, plex2);
expect(response).toEqual(1);
});

it("should return 1 as plex2 has accesstype ADJACENT", () => {
const plex1 = {
status: "ACTIVE",
mpstatus: "YES",
accesstype: "LOCAL"
};

const plex2 = {
status: "ACTIVE",
mpstatus: "YES",
accesstype: "ADJACENT"
};

const response = profileUtils.compareCicsplexes(plex1, plex2);
expect(response).toEqual(1);
});
});

describe("filterCicsplexByConstraints", () => {
it("should return an array of 2 plexes as both are valid", () => {
const plexes = [
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'ACTIVE'},
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX2', status: 'ACTIVE'}
];
const allplexes = profileUtils.filterCicsplexByConstraints(plexes);
expect(allplexes.size).toEqual(2);
});


it("should return an array of 1 plex as one in inactive both are valid", () => {
const plexes = [
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'INACTIVE'},
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'ACTIVE'}
];
const allplexes = profileUtils.filterCicsplexByConstraints(plexes);
expect(allplexes.size).toEqual(1);
});


it("should return an array of 1 plex even though both are inactive", () => {
const plexes = [
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'INACTIVE'},
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'INACTIVE'}
];
const allplexes = profileUtils.filterCicsplexByConstraints(plexes);
expect(allplexes.size).toEqual(1);
});


it("should return an array of 1 plex as one of the plexes has mpstatus NO", () => {
const plexes = [
{accesstype: 'LOCAL', mpstatus: 'NO', plexname: 'PLEX1', status: 'ACTIVE'},
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'ACTIVE'}
];
const allplexes = profileUtils.filterCicsplexByConstraints(plexes);
expect(allplexes.size).toEqual(1);
});

it("should return an array of 1 plex as one of the plexes has accesstype ADJACENT", () => {
const plexes = [
{accesstype: 'ADJACENT', mpstatus: 'YES', plexname: 'PLEX1', status: 'ACTIVE'},
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'ACTIVE'}
];
const allplexes = profileUtils.filterCicsplexByConstraints(plexes);
expect(allplexes.size).toEqual(1);
});


it("should return an array of 3 plex", () => {
const plexes = [
{accesstype: 'LOCAL', mpstatus: 'YES', plexname: 'PLEX1', status: 'ACTIVE'},
{accesstype: 'LOCAL', mpstatus: 'NO', plexname: 'PLEX2#', status: 'ACTIVE'},
{accesstype: 'ADJACENT', mpstatus: 'YES', plexname: 'PLEX2#', status: 'ACTIVE'},
{accesstype: 'LOCAL', mpstatus: 'NO', plexname: 'PLEX3#', status: 'ACTIVE'},
{accesstype: 'ADJACENT', mpstatus: 'YES', plexname: 'PLEX3#', status: 'ACTIVE'}
];

const allplexes = profileUtils.filterCicsplexByConstraints(plexes);
expect(allplexes.size).toEqual(3);
});

});
});
46 changes: 46 additions & 0 deletions packages/vsce/src/utils/plexUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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.
*
*/

export function compareCicsplexes(plex1: any, plex2: any): number {
const compare = function(val1: boolean, val2: boolean): Number {
return Number(val1) - Number(val2);
};

let result = (compare(plex1["status"] === "ACTIVE", plex2["status"] === "ACTIVE"));
if (result != 0) {
return result.valueOf();
}
result = (compare(plex1["mpstatus"] === "YES", plex2["mpstatus"] == "YES"));
if (result != 0) {
return result.valueOf();
}
result = (compare(plex1["accesstype"] === "LOCAL", plex2["accesstype"] === "LOCAL"));
return result.valueOf();
}

export function filterCicsplexByConstraints(cicscicsplex: any[]) {

let allcicsplexes = new Map<string, {}>();

Check failure on line 31 in packages/vsce/src/utils/plexUtils.ts

View workflow job for this annotation

GitHub Actions / lint

'allcicsplexes' is never reassigned. Use 'const' instead

for (const plex of cicscicsplex) {
let plexname: string = plex["plexname"];

Check failure on line 34 in packages/vsce/src/utils/plexUtils.ts

View workflow job for this annotation

GitHub Actions / lint

'plexname' is never reassigned. Use 'const' instead

let old = allcicsplexes.get(plexname);

Check failure on line 36 in packages/vsce/src/utils/plexUtils.ts

View workflow job for this annotation

GitHub Actions / lint

'old' is never reassigned. Use 'const' instead
if (old) {
if (compareCicsplexes(plex, old) > 0) {
allcicsplexes.set(plexname, plex);
}
} else {
allcicsplexes.set(plexname, plex);
}
}
return allcicsplexes;
}
10 changes: 7 additions & 3 deletions packages/vsce/src/utils/profileManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { CICSPlexTree } from "../trees/CICSPlexTree";
import { toArray } from "./commandUtils";
import constants from "./constants";
import cicsProfileMeta from "./profileDefinition";
import { filterCicsplexByConstraints } from "./plexUtils";

export class ProfileManagement {
private static zoweExplorerAPI = ZoweVsCodeExtension.getZoweExplorerApi();
Expand Down Expand Up @@ -98,6 +99,7 @@ export class ProfileManagement {
nodiscard: true,
}
});

return response.resultsummary.api_response1_alt === "OK" ?
response.resultsummary.cachetoken : null;
} catch (error) {
Expand Down Expand Up @@ -216,13 +218,15 @@ export class ProfileManagement {
try {
const { response } = await getCache(session, { cacheToken: isPlex, nodiscard: false });
if (response.records.cicscicsplex) {
for (const plex of toArray(response.records.cicscicsplex)) {
let cicscicsplexs = filterCicsplexByConstraints(toArray(response.records.cicscicsplex));

Check failure on line 221 in packages/vsce/src/utils/profileManagement.ts

View workflow job for this annotation

GitHub Actions / lint

'cicscicsplexs' is never reassigned. Use 'const' instead

cicscicsplexs.forEach((value: {}, key: string) => {
infoLoaded.push({
plexname: plex.plexname,
plexname: key,
regions: [],
group: false,
});
}
});
}
} catch (error) {
window.showErrorMessage(
Expand Down

0 comments on commit dd3ffdc

Please sign in to comment.