01: /**
02: * This file or a portion of this file is licensed under the terms of
03: * the Globus Toolkit Public License, found in file GTPL, or at
04: * http://www.globus.org/toolkit/download/license.html. This notice must
05: * appear in redistributions of this file, with or without modification.
06: *
07: * Redistributions of this Software, with or without modification, must
08: * reproduce the GTPL in: (1) the Software, or (2) the Documentation or
09: * some other similar material which is provided with the Software (if
10: * any).
11: *
12: * Copyright 1999-2004 University of Chicago and The University of
13: * Southern California. All rights reserved.
14: */package org.griphyn.cPlanner.engine;
15:
16: import org.griphyn.cPlanner.classes.ADag;
17: import org.griphyn.cPlanner.classes.SubInfo;
18: import org.griphyn.cPlanner.classes.PlannerOptions;
19:
20: import org.griphyn.cPlanner.common.LogManager;
21: import org.griphyn.cPlanner.common.PegasusProperties;
22:
23: import org.griphyn.cPlanner.engine.cleanup.Strategy;
24: import org.griphyn.cPlanner.engine.cleanup.InPlace;
25:
26: import org.griphyn.cPlanner.partitioner.graph.Graph;
27: import org.griphyn.cPlanner.partitioner.graph.GraphNode;
28: import org.griphyn.cPlanner.partitioner.graph.Adapter;
29:
30: import java.util.Iterator;
31:
32: /**
33: * The refiner that results in the creation of cleanup jobs within the workflow.
34: *
35: * @author Karan Vahi
36: * @version $Revision: 50 $
37: *
38: */
39: public class CleanupEngine extends Engine {
40:
41: /**
42: * The overloaded constructor.
43: *
44: * @param properties the handle to the properties object.
45: * @param options the options specified by the user to run the planner.
46: *
47: */
48: public CleanupEngine(PegasusProperties properties,
49: PlannerOptions options) {
50: super (properties);
51: mLogger = LogManager.getInstance();
52: mPOptions = options;
53: }
54:
55: /**
56: * Adds the cleanup jobs in the workflow that removes the files staged to the
57: * remote site.
58: *
59: * @param dag the scheduled dag that has to be clustered.
60: *
61: * @return ADag containing the cleanup jobs for the workflow.
62: */
63: public ADag addCleanupJobs(ADag dag) {
64: ADag result;
65:
66: //load the appropriate strategy that is to be used
67: Strategy strategy = new InPlace(mProps, mPOptions);
68:
69: //we first need to convert internally into graph format
70: Graph resultGraph = strategy.addCleanupJobs(Adapter
71: .convert(dag));
72:
73: //convert back to ADag and return
74: result = dag;
75: //we need to reset the jobs and the relations in it
76: result.clearJobs();
77:
78: //traverse through the graph and jobs and edges
79: for (Iterator it = resultGraph.nodeIterator(); it.hasNext();) {
80: GraphNode node = (GraphNode) it.next();
81:
82: //get the job associated with node
83: result.add((SubInfo) node.getContent());
84:
85: //all the children of the node are the edges of the DAG
86: for (Iterator childrenIt = node.getChildren().iterator(); childrenIt
87: .hasNext();) {
88: GraphNode child = (GraphNode) childrenIt.next();
89: result.addNewRelation(node.getID(), child.getID());
90: }
91: }
92:
93: return result;
94: }
95: }
|