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