Skip to content

Commit ab41c88

Browse files
authored
Sample DeletePDS script (#94)
* Added support for DeletePDS groovy script
1 parent 8c3346e commit ab41c88

File tree

2 files changed

+145
-0
lines changed

2 files changed

+145
-0
lines changed

Utilities/DeletePDS/DeletePDS.groovy

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
@groovy.transform.BaseScript com.ibm.dbb.groovy.ScriptLoader baseScript
2+
import groovy.transform.*
3+
import com.ibm.jzos.CatalogSearch;
4+
import com.ibm.jzos.CatalogSearchField;
5+
import com.ibm.jzos.ZFile;
6+
7+
8+
@Field String hlq
9+
@Field String filter
10+
@Field Boolean preview = false
11+
12+
// run setup tasks
13+
setup(args)
14+
15+
16+
// process datasets with provided HLQ
17+
filter = hlq
18+
if (!filter.endsWith(".**"))
19+
filter = filter + ".**"
20+
if (preview)
21+
println("** Searching for all the datasets filtered with HLQ '${hlq}'")
22+
else
23+
println("** Deleting all datasets filtered with HLQ '${hlq}'")
24+
25+
26+
CatalogSearch catalogSearch = new CatalogSearch(filter, 64000);
27+
catalogSearch.addFieldName("ENTNAME");
28+
catalogSearch.search();
29+
def datasetCount = 0
30+
31+
catalogSearch.each { searchEntry ->
32+
CatalogSearch.Entry catalogEntry = (CatalogSearch.Entry) searchEntry;
33+
if (catalogEntry.isDatasetEntry()) {
34+
datasetCount++;
35+
CatalogSearchField field = catalogEntry.getField("ENTNAME");
36+
String dsn = field.getFString().trim();
37+
String qdsn = "'" + dsn + "'"; //Specify that the dsn is fully qualified.
38+
if (ZFile.dsExists(qdsn)) {
39+
if (preview) {
40+
println "*** Found $qdsn"
41+
} else {
42+
println "*** Deleting $qdsn"
43+
ZFile.remove("//$qdsn")
44+
}
45+
}
46+
}
47+
}
48+
if (preview)
49+
println("** Found $datasetCount entries.")
50+
else
51+
println("** Deleted $datasetCount entries.")
52+
53+
54+
/*
55+
setup :
56+
handle cli arguments
57+
*/
58+
def setup(String[] args) {
59+
// parse input arguments
60+
String usage = 'DeletePDS.groovy [options]'
61+
String header = 'options:'
62+
def cli = new CliBuilder(usage:usage,header:header)
63+
cli.h(longOpt:'hlq', args:1, 'High-Level Qualifier of datasets to delete')
64+
cli.p(longOpt:'preview', 'Only lists the datasets without actually deleting them')
65+
def opts = cli.parse(args)
66+
if (!args || !opts) {
67+
cli.usage()
68+
System.exit(1)
69+
}
70+
71+
// update authentication properties with cli options
72+
if (opts.h) hlq = opts.h
73+
if (opts.p) preview = opts.p
74+
75+
assert hlq : "Missing 'hlq' argument"
76+
}

Utilities/DeletePDS/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# DeletePDS Utility
2+
3+
The DeletePDS utility is used to delete PDSes on z/OS that are no longer needed.
4+
Typically, after a build in a feature branch where datasets were created for the build, clean-up should occur to limit and optimize the required storage space on z/OS.
5+
6+
To delete datasets with the DeletePDS utility, you would need to specify the parameter `-h`/`--hlq` to indicate the High-Level Qualifier for your datasets to be deleted. This value is used as a filter expression for identifying the datasets to be deleted.
7+
8+
An other parameter `-p`/`--preview` is helpful to verify which datasets are to be deleted. Using this parameter will just display the datasets that matches the filter expression passed in the HLQ parameter of the script.
9+
10+
11+
Preview:
12+
```
13+
$DBB_HOME/bin/groovyz DeletePDS.groovy -p -h BUILD.CATMAN.DEV
14+
```
15+
Output:
16+
```
17+
** Searching for all the datasets filtered with HLQ 'BUILD.CATMAN.DEV'
18+
*** Found 'BUILD.CATMAN.DEV.ASM'
19+
*** Found 'BUILD.CATMAN.DEV.BMS'
20+
*** Found 'BUILD.CATMAN.DEV.BMS.COPY'
21+
*** Found 'BUILD.CATMAN.DEV.BZU.BZUCFG'
22+
*** Found 'BUILD.CATMAN.DEV.BZU.BZUPLAY'
23+
*** Found 'BUILD.CATMAN.DEV.BZU.BZURPT'
24+
*** Found 'BUILD.CATMAN.DEV.COBOL'
25+
*** Found 'BUILD.CATMAN.DEV.COPY'
26+
*** Found 'BUILD.CATMAN.DEV.DBRM'
27+
*** Found 'BUILD.CATMAN.DEV.LOAD'
28+
*** Found 'BUILD.CATMAN.DEV.MACRO'
29+
*** Found 'BUILD.CATMAN.DEV.OBJ'
30+
*** Found 'BUILD.CATMAN.DEV.TEST.COBOL'
31+
*** Found 'BUILD.CATMAN.DEV.TEST.LOAD'
32+
** Found 14 entries.
33+
** Build finished
34+
```
35+
36+
Deletion:
37+
```
38+
$DBB_HOME/bin/groovyz DeletePDS.groovy -h BUILD.CATMAN.DEV
39+
```
40+
Output:
41+
```
42+
** Deleting all datasets filtered with HLQ 'BUILD.CATMAN.DEV'
43+
*** Deleting 'BUILD.CATMAN.DEV.ASM'
44+
*** Deleting 'BUILD.CATMAN.DEV.BMS'
45+
*** Deleting 'BUILD.CATMAN.DEV.BMS.COPY'
46+
*** Deleting 'BUILD.CATMAN.DEV.BZU.BZUCFG'
47+
*** Deleting 'BUILD.CATMAN.DEV.BZU.BZUPLAY'
48+
*** Deleting 'BUILD.CATMAN.DEV.BZU.BZURPT'
49+
*** Deleting 'BUILD.CATMAN.DEV.COBOL'
50+
*** Deleting 'BUILD.CATMAN.DEV.COPY'
51+
*** Deleting 'BUILD.CATMAN.DEV.DBRM'
52+
*** Deleting 'BUILD.CATMAN.DEV.LOAD'
53+
*** Deleting 'BUILD.CATMAN.DEV.MACRO'
54+
*** Deleting 'BUILD.CATMAN.DEV.OBJ'
55+
*** Deleting 'BUILD.CATMAN.DEV.TEST.COBOL'
56+
*** Deleting 'BUILD.CATMAN.DEV.TEST.LOAD'
57+
** Deleted 14 entries.
58+
** Build finished
59+
```
60+
61+
62+
63+
### DeletePDS.groovy Command Line Options
64+
```
65+
usage: DeletePDS.groovy [options]
66+
options:
67+
-h,--hlq <arg> High-Level Qualifier of datasets to delete
68+
-p,--preview Only lists the datasets without actually deleting them
69+
```

0 commit comments

Comments
 (0)