-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed duplicate CICSplexes so they don't appear in the tree
* 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
Showing
4 changed files
with
265 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
215 changes: 215 additions & 0 deletions
215
packages/vsce/__tests__/__unit__/utils/plexUtils.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
|
||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters