Skip to content

Commit

Permalink
Removed duplicate CICSplexes so they don't appear in the tree
Browse files Browse the repository at this point in the history
* Remove duplicate plex names

Signed-off-by: enam-khan <[email protected]>

* Lint error

Signed-off-by: enam-khan <[email protected]>

* Some changes following review

Signed-off-by: enam-khan <[email protected]>

* Fixed lint error

Signed-off-by: enam-khan <[email protected]>

* Added CHANGELOG entry

Signed-off-by: enam-khan <[email protected]>

* Removed unused import

Signed-off-by: enam-khan <[email protected]>

* Added a test with many more plexes

Signed-off-by: enam-khan <[email protected]>

* Adde space

Signed-off-by: enam-khan <[email protected]>

* Added comment

Signed-off-by: enam-khan <[email protected]>

* Updated Changelog

Signed-off-by: enam-khan <[email protected]>

* Update following review

Signed-off-by: enam-khan <[email protected]>

---------

Signed-off-by: enam-khan <[email protected]>
  • Loading branch information
enamkhan authored Feb 12, 2025
1 parent d1fcf79 commit f4cb407
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/vsce/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
All notable changes to the "cics-extension-for-zowe" extension will be documented in this file.

## Recent Changes

- BugFix: Duplicate CICSplex exist when connecting to a multi-CMAS system. [#227](https://github.com/zowe/cics-for-zowe-client/issues/227)
- Enhancement: Show CMCI error response codes when failing to make requests. [#220](https://github.com/zowe/cics-for-zowe-client/issues/220)

## `3.3.2`
Expand Down
215 changes: 215 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,215 @@
/**
* 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 {ICicsPlexInfo, scoreCicsPlexByStatus, getBestCICSplexes} from "../../../src/utils/plexUtils";

function getPlexInfo(plexname: string, status: string, mpstatus: string, accesstype: string) {
const plex: ICicsPlexInfo =
{
_keydata: "",
accesstype: accesstype,
botrsupd: "",
cmasname: "",
mpstatus: mpstatus,
plexname: plexname,
readrs: "",
rspoolid: "",
status: status,
sysid: "",
toprsupd: "",
transitcmas: "",
transitcnt: "",
updaters: ""
};
return plex;
}


describe("Plex Utils tests", () => {
describe("compareCicsplexes", () => {
it("should return 15 for active plex with mpstatus yes and accesstype local", () => {
const plex = getPlexInfo("PLEX", "ACTIVE", "YES", "LOCAL");

const response = scoreCicsPlexByStatus(plex);
expect(response).toEqual(15);
});

it("should return 8 for plex for plex with inactive status", () => {
const plex = getPlexInfo("PLEX", "INACTIVE", "YES", "LOCAL");

const response = scoreCicsPlexByStatus(plex);
expect(response).toEqual(8);
});

it("should return 12 when plex has mpstatus NO", () => {
const plex = getPlexInfo("PLEX", "ACTIVE", "NO", "LOCAL");

const response = scoreCicsPlexByStatus(plex);
expect(response).toEqual(12);
});

it("should return 10 when plex has accesstype ADJACENT", () => {
const plex = getPlexInfo("PLEX", "ACTIVE", "YES", "ADJACENT");

const response = scoreCicsPlexByStatus(plex);
expect(response).toEqual(10);
});

it("should return 7 when plex has mpstatus NO and accesstype os adjacent", () => {
const plex = getPlexInfo("PLEX", "ACTIVE", "NO", "ADJACENT");

const response = scoreCicsPlexByStatus(plex);
expect(response).toEqual(7);
});

it("should return 0 as plex is inactive, mpstatus no and accesstype adjacent", () => {
const plex = getPlexInfo("PLEX", "INACTIVE", "NO", "ADJACENT");

const response = scoreCicsPlexByStatus(plex);
expect(response).toEqual(0);
});
});

describe("getBestCICSplexes", () => {
it("should return a map of 2 plexes as both are valid", () => {
const plexes = [
getPlexInfo("PLEX1", 'ACTIVE', 'YES', 'LOCAL'),
getPlexInfo("PLEX2", 'ACTIVE', 'YES', 'LOCAL')
];
const allplexes = getBestCICSplexes(plexes);
expect(allplexes.size).toEqual(2);
});

it("should return a map of 1 plex as one in inactive both are valid", () => {
const expected = getPlexInfo("PLEX1", 'ACTIVE', 'YES', 'LOCAL');
const plexes = [
getPlexInfo("PLEX1", 'INACTIVE', 'YES', 'LOCAL'),
expected
];
const allplexes = getBestCICSplexes(plexes);
expect(allplexes.size).toEqual(1);
expect(allplexes.get("PLEX1")).toEqual(expected);
});

it("should return a map of 1 plex even though both are inactive", () => {
const expected = getPlexInfo("PLEX1", 'INACTIVE', 'YES', 'LOCAL');
const plexes = [
expected,
getPlexInfo("PLEX1", 'INACTIVE', 'YES', 'LOCAL')
];
const allplexes = getBestCICSplexes(plexes);
expect(allplexes.size).toEqual(1);
expect(allplexes.get("PLEX1")).toEqual(expected);
});

it("should return a map of 1 plex as one of the plexes has mpstatus NO", () => {
const expected = getPlexInfo("PLEX1", 'ACTIVE', 'YES', 'LOCAL');
const plexes = [
getPlexInfo("PLEX1", 'ACTIVE', 'NO', 'LOCAL'),
expected
];
const allplexes = getBestCICSplexes(plexes);
expect(allplexes.size).toEqual(1);
expect(allplexes.get("PLEX1")).toEqual(
getPlexInfo("PLEX1", 'ACTIVE', 'YES', 'LOCAL'));
});

it("should return a map of 1 plex as one of the plexes has accesstype ADJACENT", () => {
const expected = getPlexInfo("PLEX1", 'ACTIVE', 'YES', 'LOCAL')
const plexes = [
getPlexInfo("PLEX1", 'ACTIVE', 'YES', 'ADJACENT'),
expected
];
const allplexes = getBestCICSplexes(plexes);
expect(allplexes.size).toEqual(1);
expect(allplexes.get("PLEX1")).toEqual(
getPlexInfo("PLEX1", 'ACTIVE', 'YES', 'LOCAL'));
});

it("should return an array of 3 plexes", () => {
const plexes = [
getPlexInfo("PLEX1", 'ACTIVE', 'YES', 'LOCAL'),
getPlexInfo("PLEX2#", 'ACTIVE', 'NO', 'LOCAL'),
getPlexInfo("PLEX2#", 'ACTIVE', 'YES', 'ADJACENT'),
getPlexInfo("PLEX3#", 'ACTIVE', 'NO', 'LOCAL'),
getPlexInfo("PLEX3#", 'ACTIVE', 'YES', 'ADJACENT')
];

const allplexes = getBestCICSplexes(plexes);

expect(allplexes.size).toEqual(3);
expect(allplexes.get("PLEX1")).toEqual(
getPlexInfo("PLEX1", 'ACTIVE', 'YES', 'LOCAL'));
expect(allplexes.get("PLEX2#")).toEqual(
getPlexInfo("PLEX2#", 'ACTIVE', 'NO', 'LOCAL'));
expect(allplexes.get("PLEX3#")).toEqual(
getPlexInfo("PLEX3#", 'ACTIVE', 'NO', 'LOCAL'));
});

it("should return an array of 4 plexes", () => {
const plexes = [
getPlexInfo("PLEX1", "ACTIVE", "YES", "LOCAL"),
getPlexInfo("PLEX1", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX1", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX1", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX1", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX1", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX1", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX1", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX1", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX1", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX2", "ACTIVE", "YES", "LOCAL"),
getPlexInfo("PLEX2", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX2", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX2", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX2", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX2", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX2", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX2", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX2", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX2", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX3", "ACTIVE", "YES", "LOCAL"),
getPlexInfo("PLEX3", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX3", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX3", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX3", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX3", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX3", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX3", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX3", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX3", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX4", "ACTIVE", "YES", "LOCAL"),
getPlexInfo("PLEX4", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX4", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX4", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX4", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX4", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX4", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX4", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX4", "ACTIVE", "NO", "ADJACENT"),
getPlexInfo("PLEX4", "ACTIVE", "NO", "ADJACENT")
];

const allplexes = getBestCICSplexes(plexes);

expect(allplexes.size).toEqual(4);
expect(allplexes.get("PLEX1")).toEqual(
getPlexInfo("PLEX1", "ACTIVE", "YES", "LOCAL"));
expect(allplexes.get("PLEX2")).toEqual(
getPlexInfo("PLEX2", "ACTIVE", "YES", "LOCAL"));
expect(allplexes.get("PLEX3")).toEqual(
getPlexInfo("PLEX3", "ACTIVE", "YES", "LOCAL"));
expect(allplexes.get("PLEX4")).toEqual(
getPlexInfo("PLEX4", "ACTIVE", "YES", "LOCAL"));

});
});
});
43 changes: 43 additions & 0 deletions packages/vsce/src/utils/plexUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 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 interface ICicsPlexInfo {
_keydata: string;
accesstype: string,
botrsupd: string,
cmasname: string,
mpstatus: string,
plexname: string,
readrs: string,
rspoolid: string,
status: string,
sysid: string,
toprsupd: string,
transitcmas: string,
transitcnt: string,
updaters: string
}

export function scoreCicsPlexByStatus(plex: ICicsPlexInfo): number {
return (plex.status === "ACTIVE" && 7) + (plex.accesstype === "LOCAL" && 5) + (plex.mpstatus === "YES" && 3);
}

// pick the highest scoring cicsplexes if there are duplicates
export function getBestCICSplexes(cicscicsplex: ICicsPlexInfo[]) {
const allcicsplexes = new Map<string, ICicsPlexInfo>();
cicscicsplex.sort((a, b) => scoreCicsPlexByStatus(a) - scoreCicsPlexByStatus(b));

for (const plex of cicscicsplex) {
allcicsplexes.set(plex.plexname, plex);
}

return allcicsplexes;
}
9 changes: 6 additions & 3 deletions packages/vsce/src/utils/profileManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { CICSPlexTree } from "../trees/CICSPlexTree";
import { toArray } from "./commandUtils";
import constants from "./constants";
import cicsProfileMeta from "./profileDefinition";
import { getBestCICSplexes } from "./plexUtils";

export class ProfileManagement {
private static zoweExplorerAPI = ZoweVsCodeExtension.getZoweExplorerApi();
Expand Down Expand Up @@ -304,13 +305,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)) {
const cicscicsplexs = getBestCICSplexes(toArray(response.records.cicscicsplex));

cicscicsplexs.forEach((value: {}, key: string) => {
infoLoaded.push({
plexname: plex.plexname,
plexname: key,
regions: [],
group: false,
});
}
});
}
} catch (error) {
Gui.showMessage(`Error retrieving cache - ${JSON.stringify(error)}`, {
Expand Down

0 comments on commit f4cb407

Please sign in to comment.