1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.oodt.pcs.pedigree;
19
20
21 import org.apache.oodt.pcs.metadata.PCSMetadata;
22 import org.apache.oodt.pcs.metadata.PCSConfigMetadata;
23 import org.apache.oodt.pcs.query.FilenameQuery;
24 import org.apache.oodt.pcs.query.InputFilesQuery;
25 import org.apache.oodt.pcs.query.JobIdQuery;
26 import org.apache.oodt.pcs.util.FileManagerUtils;
27 import org.apache.oodt.cas.filemgr.structs.Product;
28 import org.apache.oodt.cas.metadata.Metadata;
29
30
31 import java.util.Iterator;
32 import java.util.List;
33 import java.util.Stack;
34 import java.util.Vector;
35
36
37
38
39
40
41
42
43 public class Pedigree implements PCSMetadata, PCSConfigMetadata {
44
45
46 private FileManagerUtils fm;
47
48
49 private boolean listNotCataloged = false;
50
51
52 private List prodTypeExcludeList;
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 public Pedigree(String fmUrlStr, boolean listNotCat, List excludeList) {
70 this(new FileManagerUtils(FileManagerUtils.safeGetUrlFromString(fmUrlStr)),
71 listNotCat, excludeList);
72
73 }
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 public Pedigree(FileManagerUtils fm, boolean listNotCat, List excludeList) {
90 this.fm = fm;
91 this.listNotCataloged = listNotCat;
92 this.prodTypeExcludeList = excludeList;
93 }
94
95
96
97
98
99
100
101
102
103
104
105
106
107 public PedigreeTree doPedigree(Product orig, boolean upstream) {
108 List pedProds = null;
109 PedigreeTreeNode origRoot = PedigreeTreeNode
110 .getPedigreeTreeNodeFromProduct(orig, null);
111
112
113 Stack roots = new Stack();
114 roots.add(origRoot);
115
116 do {
117
118 PedigreeTreeNode currRoot = (PedigreeTreeNode) roots.pop();
119
120
121
122
123
124 if (upstream) {
125 pedProds = getUpstreamPedigreedProducts(currRoot.getNodeProduct());
126 } else {
127 pedProds = getDownstreamPedigreedProducts(currRoot.getNodeProduct());
128 }
129
130 if (pedProds != null && pedProds.size() > 0) {
131 for (Iterator i = pedProds.iterator(); i.hasNext();) {
132 Product p = (Product) i.next();
133 if (p.getProductName().equals(
134 currRoot.getNodeProduct().getProductName())) {
135
136
137 continue;
138 }
139 PedigreeTreeNode prodNode = PedigreeTreeNode
140 .getPedigreeTreeNodeFromProduct(p, currRoot);
141 roots.add(prodNode);
142 }
143 } else {
144
145 }
146
147 } while (!roots.empty());
148
149 return new PedigreeTree(origRoot);
150 }
151
152
153
154
155
156
157
158
159
160
161 public List getUpstreamPedigreedProducts(Product orig) {
162 if (orig == null
163 || (orig != null && orig.getProductType() == null)
164 || (orig != null && orig.getProductType() != null
165 && orig.getProductType().getName() == null)
166 || (orig != null && orig.getProductType() != null
167 && orig.getProductType().getName() != null &&
168 orig.getProductType().getName().equals(UNKNOWN))) {
169 return new Vector();
170 }
171 Metadata pMet = fm.safeGetMetadata(orig);
172 return getProducts(pMet.getAllMetadata(INPUT_FILES));
173
174 }
175
176
177
178
179
180
181
182
183
184
185 public List getDownstreamPedigreedProducts(Product orig) {
186 return fm.queryAllTypes(new InputFilesQuery(orig.getProductName(), fm)
187 .buildQuery(), this.prodTypeExcludeList);
188 }
189
190
191
192
193
194
195
196
197
198
199
200
201 public List getWorkflowInstProds(String wInstId) {
202 return fm.queryAllTypes(new JobIdQuery(wInstId, fm).buildQuery(),
203 this.prodTypeExcludeList);
204 }
205
206 private List getProducts(List prodNames) {
207 if (prodNames == null || (prodNames != null && prodNames.size() == 0)) {
208 return new Vector();
209 }
210
211 List prods = new Vector(prodNames.size());
212
213 for (Iterator i = prodNames.iterator(); i.hasNext();) {
214 String prodName = (String) i.next();
215 List prodList = fm.queryAllTypes(new FilenameQuery(prodName, fm)
216 .buildQuery(), this.prodTypeExcludeList);
217 if (prodList != null && prodList.size() > 0) {
218 prods.add((Product) prodList.get(0));
219 } else {
220 if (this.listNotCataloged) {
221
222 prods.add(Product.getDefaultFlatProduct(prodName, UNKNOWN));
223 }
224 }
225 }
226
227 return prods;
228 }
229
230 }