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