1 | package simulator.workload.reader.archive.gwf; |
---|
2 | |
---|
3 | import java.io.IOException; |
---|
4 | |
---|
5 | import org.apache.commons.logging.Log; |
---|
6 | import org.apache.commons.logging.LogFactory; |
---|
7 | import org.exolab.castor.types.Duration; |
---|
8 | |
---|
9 | import org.qcg.broker.schemas.jobdesc.ComputingResourceBaseTypeChoice; |
---|
10 | import org.qcg.broker.schemas.jobdesc.ComputingResourceBaseTypeChoiceItem; |
---|
11 | import org.qcg.broker.schemas.jobdesc.ComputingResourceParameterType; |
---|
12 | import org.qcg.broker.schemas.jobdesc.ComputingResourceType; |
---|
13 | import org.qcg.broker.schemas.jobdesc.ExecutionTimeType; |
---|
14 | import org.qcg.broker.schemas.jobdesc.ParameterTypeChoice; |
---|
15 | import org.qcg.broker.schemas.jobdesc.ParameterTypeChoiceItem; |
---|
16 | import org.qcg.broker.schemas.jobdesc.RequirementsType; |
---|
17 | import org.qcg.broker.schemas.jobdesc.ResourceRequirementsType; |
---|
18 | import org.qcg.broker.schemas.jobdesc.Task; |
---|
19 | import org.qcg.broker.schemas.jobdesc.Value; |
---|
20 | import org.qcg.broker.schemas.jobdesc.types.ComputingParameterName; |
---|
21 | import simulator.workload.reader.archive.GrmsWAJobReader; |
---|
22 | import simulator.workload.reader.archive.WAParser; |
---|
23 | |
---|
24 | /** |
---|
25 | * |
---|
26 | * @author Marcin Krystek |
---|
27 | * |
---|
28 | */ |
---|
29 | |
---|
30 | public class Grms3GWFJobReader extends GrmsWAJobReader{ |
---|
31 | |
---|
32 | private Log log = LogFactory.getLog(Grms3GWFJobReader.class); |
---|
33 | |
---|
34 | public Grms3GWFJobReader(String fileName) throws NullPointerException, |
---|
35 | IOException { |
---|
36 | super(fileName); |
---|
37 | this.waParser.loadHeader(); |
---|
38 | } |
---|
39 | |
---|
40 | public Grms3GWFJobReader(WAParser parser) { |
---|
41 | super(parser); |
---|
42 | } |
---|
43 | |
---|
44 | protected Task createTask(String[] data) { |
---|
45 | RequirementsType requirements = null; |
---|
46 | ResourceRequirementsType taskReq = null; |
---|
47 | ComputingResourceType compResource = null; |
---|
48 | ComputingResourceBaseTypeChoice choice = null; |
---|
49 | ComputingResourceBaseTypeChoiceItem crItem = null; |
---|
50 | ComputingResourceParameterType param = null; |
---|
51 | |
---|
52 | Task task = null; |
---|
53 | long value = -1; |
---|
54 | |
---|
55 | task = new Task(); |
---|
56 | requirements = new RequirementsType(); |
---|
57 | taskReq = new ResourceRequirementsType(); |
---|
58 | compResource = new ComputingResourceType(); |
---|
59 | choice = new ComputingResourceBaseTypeChoice(); |
---|
60 | |
---|
61 | compResource.setComputingResourceBaseTypeChoice(choice); |
---|
62 | taskReq.addComputingResource(compResource); |
---|
63 | requirements.setResourceRequirements(taskReq); |
---|
64 | task.setRequirements(requirements); |
---|
65 | |
---|
66 | for(int i = 0; i < GWFFields.DATA_FIELDS.length; i++){ |
---|
67 | try { |
---|
68 | |
---|
69 | value = Long.parseLong(data[GWFFields.DATA_FIELDS[i]]); |
---|
70 | |
---|
71 | switch(GWFFields.DATA_FIELDS[i]){ |
---|
72 | case GWFFields.DATA_NPROCS: |
---|
73 | if(value <= 0){ |
---|
74 | if(log.isWarnEnabled()) |
---|
75 | log.warn("Task "+data[0] + " is omited. Number of allocated processors should be grather then 0."); |
---|
76 | return null; |
---|
77 | } |
---|
78 | break; |
---|
79 | case GWFFields.DATA_REQ_NPROCS: |
---|
80 | if(value <= 0){ |
---|
81 | if(log.isWarnEnabled()) |
---|
82 | log.warn("Task "+data[0] + " is omited. Number of requested processors should be grather then 0."); |
---|
83 | return null; |
---|
84 | } |
---|
85 | break; |
---|
86 | case GWFFields.DATA_RUN_TIME: |
---|
87 | if(value <= 0){ |
---|
88 | if(log.isWarnEnabled()) |
---|
89 | log.warn("Task "+data[0] + " is omited. Task runtime should be grather then 0."); |
---|
90 | return null; |
---|
91 | } |
---|
92 | break; |
---|
93 | } |
---|
94 | |
---|
95 | if (value == -1) continue; |
---|
96 | |
---|
97 | } catch (NumberFormatException e) { |
---|
98 | if(GWFFields.DATA_FIELDS[i] != GWFFields.DATA_JOB_ID) |
---|
99 | continue; |
---|
100 | } |
---|
101 | |
---|
102 | switch(GWFFields.DATA_FIELDS[i]){ |
---|
103 | case GWFFields.DATA_JOB_ID: |
---|
104 | currntJobID = data[GWFFields.DATA_FIELDS[i]]; |
---|
105 | String tab[] = this.waParser.getIDMapping(currntJobID); |
---|
106 | task.setTaskId(tab[1]); |
---|
107 | break; |
---|
108 | |
---|
109 | case GWFFields.DATA_SUBMIT_TIME: |
---|
110 | /* |
---|
111 | * This is information for simulator not for task description. |
---|
112 | * See WorkloadLoader for details. |
---|
113 | */ |
---|
114 | break; |
---|
115 | |
---|
116 | case GWFFields.DATA_RUN_TIME: |
---|
117 | /* |
---|
118 | * This is information for simulator not for task description. |
---|
119 | * See WorkloadLoader for details. |
---|
120 | */ |
---|
121 | break; |
---|
122 | |
---|
123 | case GWFFields.DATA_NPROCS: |
---|
124 | /* |
---|
125 | * This is information for simulator not for task description. |
---|
126 | * See WorkloadLoader for details. |
---|
127 | */ |
---|
128 | break; |
---|
129 | |
---|
130 | case GWFFields.DATA_USED_MEMORY: |
---|
131 | /* |
---|
132 | * This is information for simulator not for task description. |
---|
133 | * See WorkloadLoader for details. |
---|
134 | */ |
---|
135 | break; |
---|
136 | |
---|
137 | case GWFFields.DATA_REQ_NPROCS: |
---|
138 | |
---|
139 | crItem = new ComputingResourceBaseTypeChoiceItem(); |
---|
140 | param = new ComputingResourceParameterType(); |
---|
141 | |
---|
142 | param.setName(ComputingParameterName.CPUCOUNT); |
---|
143 | { |
---|
144 | ParameterTypeChoice tpChoice = new ParameterTypeChoice(); |
---|
145 | ParameterTypeChoiceItem item = new ParameterTypeChoiceItem(); |
---|
146 | Value paramValue = new Value(); |
---|
147 | |
---|
148 | paramValue.setContent(Long.valueOf(value).doubleValue()); |
---|
149 | item.setValue(paramValue); |
---|
150 | tpChoice.addParameterTypeChoiceItem(item); |
---|
151 | param.setParameterTypeChoice(tpChoice); |
---|
152 | } |
---|
153 | crItem.setHostParameter(param); |
---|
154 | choice.addComputingResourceBaseTypeChoiceItem(crItem); |
---|
155 | |
---|
156 | break; |
---|
157 | |
---|
158 | case GWFFields.DATA_REQ_TIME: |
---|
159 | ExecutionTimeType executionTime = new ExecutionTimeType(); |
---|
160 | |
---|
161 | // requested time is expressed in swf file in seconds |
---|
162 | // multiply value * 1000 to get milliseconds |
---|
163 | Duration d = new Duration(value * 1000); |
---|
164 | |
---|
165 | executionTime.setExecutionDuration(d); |
---|
166 | task.setExecutionTime(executionTime); |
---|
167 | break; |
---|
168 | |
---|
169 | case GWFFields.DATA_REQ_MEMORY: |
---|
170 | crItem = new ComputingResourceBaseTypeChoiceItem(); |
---|
171 | param = new ComputingResourceParameterType(); |
---|
172 | |
---|
173 | param.setName(ComputingParameterName.MEMORY); |
---|
174 | { |
---|
175 | ParameterTypeChoice tpChoice = new ParameterTypeChoice(); |
---|
176 | ParameterTypeChoiceItem item = new ParameterTypeChoiceItem(); |
---|
177 | Value paramValue = new Value(); |
---|
178 | |
---|
179 | paramValue.setContent(Long.valueOf(value).doubleValue()); |
---|
180 | item.setValue(paramValue); |
---|
181 | tpChoice.addParameterTypeChoiceItem(item); |
---|
182 | param.setParameterTypeChoice(tpChoice); |
---|
183 | } |
---|
184 | |
---|
185 | crItem.setHostParameter(param); |
---|
186 | choice.addComputingResourceBaseTypeChoiceItem(crItem); |
---|
187 | |
---|
188 | break; |
---|
189 | |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
193 | return task; |
---|
194 | } |
---|
195 | } |
---|