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