1 | package schedframe.scheduling.tasks; |
---|
2 | |
---|
3 | import java.util.List; |
---|
4 | |
---|
5 | import org.qcg.broker.schemas.resreqs.ComputingResourceBaseTypeItem; |
---|
6 | import org.qcg.broker.schemas.resreqs.ComputingResourceExtType; |
---|
7 | import org.qcg.broker.schemas.resreqs.ComputingResourceParameterType; |
---|
8 | import org.qcg.broker.schemas.resreqs.CountType; |
---|
9 | import org.qcg.broker.schemas.resreqs.ProcessesChoice; |
---|
10 | import org.qcg.broker.schemas.resreqs.ProcessesMapType; |
---|
11 | import org.qcg.broker.schemas.resreqs.ProcessesResourceRequirements; |
---|
12 | import org.qcg.broker.schemas.resreqs.types.ComputingResourceParameterTypeNameType; |
---|
13 | |
---|
14 | import schedframe.scheduling.WorkloadUnitHandler; |
---|
15 | import schedframe.scheduling.manager.tasks.JobRegistryImpl; |
---|
16 | import schedframe.scheduling.tasks.requirements.ResourceParameterName; |
---|
17 | |
---|
18 | /** |
---|
19 | * |
---|
20 | * @author Marcin Krystek |
---|
21 | * |
---|
22 | */ |
---|
23 | public class Processes extends AbstractProcesses{ |
---|
24 | |
---|
25 | protected org.qcg.broker.schemas.resreqs.Processes pr; |
---|
26 | protected int status; |
---|
27 | |
---|
28 | protected Processes(){ |
---|
29 | this.pr = null; |
---|
30 | } |
---|
31 | |
---|
32 | public Processes(org.qcg.broker.schemas.resreqs.Processes qcgProcesses){ |
---|
33 | this.pr = qcgProcesses; |
---|
34 | } |
---|
35 | |
---|
36 | public String getId() { |
---|
37 | return this.pr.getProcessesId(); |
---|
38 | } |
---|
39 | |
---|
40 | public int getProcessesCount() { |
---|
41 | ProcessesChoice choice = this.pr.getProcessesChoice(); |
---|
42 | |
---|
43 | CountType countType = choice.getProcessesCount(); |
---|
44 | if(countType != null) { |
---|
45 | return countType.getValue().getContent().intValue(); |
---|
46 | } |
---|
47 | |
---|
48 | ProcessesMapType mapType = choice.getProcessesMap(); |
---|
49 | if(mapType != null) { |
---|
50 | int slots = mapType.getSlotsPerNode(); |
---|
51 | int processesPerNode = mapType.getProcessesPerNodeCount(); |
---|
52 | return slots * processesPerNode; |
---|
53 | } |
---|
54 | |
---|
55 | return 0; |
---|
56 | } |
---|
57 | |
---|
58 | public int[] getProcessesMap(){ |
---|
59 | if(this.pr.getProcessesChoice().getProcessesMap() == null) |
---|
60 | return null; |
---|
61 | |
---|
62 | return this.pr.getProcessesChoice().getProcessesMap().getProcessesPerNode(); |
---|
63 | } |
---|
64 | |
---|
65 | public int getSlotsPerNode(){ |
---|
66 | if(this.pr.getProcessesChoice().getProcessesMap() == null) |
---|
67 | return 0; |
---|
68 | |
---|
69 | return this.pr.getProcessesChoice().getProcessesMap().getSlotsPerNode(); |
---|
70 | |
---|
71 | } |
---|
72 | |
---|
73 | public double getParameterDoubleValue(ResourceParameterName parameterName) |
---|
74 | throws NoSuchFieldException, IllegalArgumentException { |
---|
75 | ComputingResourceParameterTypeNameType name = ComputingResourceParameterTypeNameType.valueOf(parameterName.value().toUpperCase()); |
---|
76 | |
---|
77 | switch (name) { |
---|
78 | case APPLICATION: |
---|
79 | case CPUARCH: |
---|
80 | case HOSTNAME: |
---|
81 | case LOCALRESOURCEMANAGER: |
---|
82 | case OSNAME: |
---|
83 | case OSRELEASE: |
---|
84 | case OSTYPE: |
---|
85 | case OSVERSION: |
---|
86 | case REMOTESUBMISSIONINTERFACE: |
---|
87 | throw new IllegalArgumentException("For " + parameterName + " use getParameterStringValue() method."); |
---|
88 | } |
---|
89 | |
---|
90 | ComputingResourceBaseTypeItem item[] = getComputingResourceRequirements(); |
---|
91 | |
---|
92 | double returnValue = 0; |
---|
93 | boolean notFound = true; |
---|
94 | |
---|
95 | for(int i = 0; i < item.length && notFound; i++){ |
---|
96 | ComputingResourceParameterType hostParameter = item[i].getHostParameter(); |
---|
97 | if(hostParameter == null) |
---|
98 | continue; |
---|
99 | |
---|
100 | if(name == hostParameter.getName()) { |
---|
101 | returnValue = hostParameter.getParameterTypeChoice().getParameterTypeChoiceItem(0).getParameterValue().getContent(); |
---|
102 | notFound = false; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | if(notFound) |
---|
107 | throw new NoSuchFieldException(parameterName + " for processes " + getId() |
---|
108 | + " is not defined."); |
---|
109 | |
---|
110 | return returnValue; |
---|
111 | } |
---|
112 | |
---|
113 | public String getParameterStringValue(ResourceParameterName parameterName) |
---|
114 | throws NoSuchFieldException, IllegalArgumentException { |
---|
115 | ComputingResourceParameterTypeNameType name = ComputingResourceParameterTypeNameType.valueOf(parameterName.value().toUpperCase()); |
---|
116 | |
---|
117 | switch (name) { |
---|
118 | case CPUCOUNT: |
---|
119 | case GPUCOUNT: |
---|
120 | case CPUSPEED: |
---|
121 | case DISKSPACE: |
---|
122 | case FREECPUS: |
---|
123 | case FREEDISKSPACE: |
---|
124 | case FREEMEMORY: |
---|
125 | case MEMORY: |
---|
126 | throw new IllegalArgumentException("For " + parameterName + " use getParameterDoubleValue() method."); |
---|
127 | } |
---|
128 | |
---|
129 | ComputingResourceBaseTypeItem item[] = getComputingResourceRequirements(); |
---|
130 | |
---|
131 | String returnValue = null; |
---|
132 | boolean notFound = true; |
---|
133 | |
---|
134 | for(int i = 0; i < item.length && notFound; i++){ |
---|
135 | ComputingResourceParameterType hostParameter = item[i].getHostParameter(); |
---|
136 | if(hostParameter == null) |
---|
137 | continue; |
---|
138 | |
---|
139 | if(name == hostParameter.getName()) { |
---|
140 | returnValue = hostParameter.getStringValue(0).getValue(); |
---|
141 | notFound = false; |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | if(notFound) |
---|
146 | throw new NoSuchFieldException(parameterName + " for processes " + getId() + " is not defined."); |
---|
147 | |
---|
148 | |
---|
149 | return returnValue; |
---|
150 | } |
---|
151 | |
---|
152 | public boolean belongsTo(AbstractProcessesGroup group) { |
---|
153 | for(int i = 0; i < this.pr.getGroupIdReferenceCount(); i++){ |
---|
154 | String idRef = this.pr.getGroupIdReference(i); |
---|
155 | if(idRef.equals(group.getId())){ |
---|
156 | return true; |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | return false; |
---|
161 | } |
---|
162 | |
---|
163 | protected ComputingResourceBaseTypeItem[] getComputingResourceRequirements() throws NoSuchFieldException{ |
---|
164 | |
---|
165 | ProcessesResourceRequirements req = this.pr.getProcessesResourceRequirements(); |
---|
166 | if(req == null) |
---|
167 | throw new NoSuchFieldException("Requierements section for processes " + getId() |
---|
168 | + " is not defined."); |
---|
169 | |
---|
170 | ComputingResourceExtType computingResource = req.getComputingResource(0); |
---|
171 | if(computingResource == null) |
---|
172 | throw new NoSuchFieldException("Computing resource requirement for processes " + getId() |
---|
173 | + " is not defined."); |
---|
174 | |
---|
175 | ComputingResourceBaseTypeItem item[] = computingResource.getComputingResourceBaseTypeItem(); |
---|
176 | if(item == null || item.length == 0) |
---|
177 | throw new NoSuchFieldException("Computing resource requirement is empty for processes " + getId()); |
---|
178 | |
---|
179 | return item; |
---|
180 | } |
---|
181 | |
---|
182 | public void setStatus(int status){ |
---|
183 | this.status = status; |
---|
184 | } |
---|
185 | |
---|
186 | public boolean isFinished(){ |
---|
187 | return (this.status > 3 && this.status <= 6); |
---|
188 | } |
---|
189 | |
---|
190 | public boolean isDivisible(){ |
---|
191 | return this.pr.getDivisible(); |
---|
192 | } |
---|
193 | |
---|
194 | public void setDivisible(boolean value){ |
---|
195 | this.pr.setDivisible(value); |
---|
196 | } |
---|
197 | |
---|
198 | public org.qcg.broker.schemas.resreqs.Processes getDescription(){ |
---|
199 | return this.pr; |
---|
200 | } |
---|
201 | |
---|
202 | @Override |
---|
203 | public int getStatus() { |
---|
204 | // TODO Auto-generated method stub |
---|
205 | return 0; |
---|
206 | } |
---|
207 | |
---|
208 | @Override |
---|
209 | public int getUserID() { |
---|
210 | // TODO Auto-generated method stub |
---|
211 | return 0; |
---|
212 | } |
---|
213 | |
---|
214 | @Override |
---|
215 | public String getDocument() throws Exception { |
---|
216 | // TODO Auto-generated method stub |
---|
217 | return null; |
---|
218 | } |
---|
219 | |
---|
220 | @Override |
---|
221 | public boolean isRegistered() { |
---|
222 | // TODO Auto-generated method stub |
---|
223 | return false; |
---|
224 | } |
---|
225 | |
---|
226 | @Override |
---|
227 | public void register(JobRegistryImpl jobRegistry) { |
---|
228 | // TODO Auto-generated method stub |
---|
229 | |
---|
230 | } |
---|
231 | |
---|
232 | @Override |
---|
233 | public void accept(WorkloadUnitHandler wuh) { |
---|
234 | // TODO Auto-generated method stub |
---|
235 | |
---|
236 | } |
---|
237 | } |
---|