1 | package schedframe.resources.devices.description; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.List; |
---|
5 | |
---|
6 | import schedframe.Parameter; |
---|
7 | import schedframe.Parameters; |
---|
8 | import schedframe.Property; |
---|
9 | import schedframe.resources.ResourceType; |
---|
10 | import schedframe.resources.computing.description.ResourceDescription; |
---|
11 | import schedframe.resources.computing.location.Location; |
---|
12 | import schedframe.resources.computing.profiles.energy.airthroughput.AirflowStateNameFactory; |
---|
13 | import schedframe.resources.computing.profiles.energy.airthroughput.AirflowProfile; |
---|
14 | import schedframe.resources.computing.profiles.energy.airthroughput.AirflowState; |
---|
15 | import schedframe.resources.computing.profiles.energy.airthroughput.plugin.AirflowEstimationPlugin; |
---|
16 | import schedframe.resources.computing.profiles.energy.airthroughput.plugin.DefaultAirflowEstimationPlugin; |
---|
17 | import schedframe.resources.computing.profiles.energy.power.PState; |
---|
18 | import schedframe.resources.computing.profiles.energy.power.PowerProfile; |
---|
19 | import schedframe.resources.computing.profiles.energy.power.PowerState; |
---|
20 | import schedframe.resources.computing.profiles.energy.power.PowerStateNameFactory; |
---|
21 | import schedframe.resources.computing.profiles.energy.power.Transition; |
---|
22 | import schedframe.resources.computing.profiles.energy.power.plugin.EnergyEstimationPlugin; |
---|
23 | import schedframe.resources.computing.profiles.energy.thermal.ThermalProfile; |
---|
24 | import schedframe.resources.computing.profiles.energy.thermal.plugin.DefaultTemperatureEstimationPlugin; |
---|
25 | import schedframe.resources.computing.profiles.energy.thermal.plugin.TemperatureEstimationPlugin; |
---|
26 | import schedframe.resources.computing.profiles.load.LoadEstimationPluginFactory; |
---|
27 | import schedframe.resources.computing.profiles.load.LoadProfile; |
---|
28 | import schedframe.resources.computing.profiles.load.ResourceLoadCalendar; |
---|
29 | import schedframe.resources.computing.profiles.load.plugin.LoadEstimationPlugin; |
---|
30 | import schemas.PowerUsage; |
---|
31 | import schemas.Profile; |
---|
32 | import simulator.utils.InstanceFactory; |
---|
33 | import example.energy.DefaultEnergyEstimationPlugin; |
---|
34 | import example.load.DefaultLoadEstimationPlugin; |
---|
35 | |
---|
36 | public class PhysicalResourceDescription extends ResourceDescription{ |
---|
37 | |
---|
38 | protected PowerProfile powerProfile; |
---|
39 | protected AirflowProfile airflowProfile; |
---|
40 | protected ThermalProfile thermalProfile; |
---|
41 | protected LoadProfile loadProfile; |
---|
42 | |
---|
43 | protected String category; |
---|
44 | protected Location location; |
---|
45 | |
---|
46 | public PhysicalResourceDescription(ResourceType type) { |
---|
47 | super(type); |
---|
48 | // TODO Auto-generated constructor stub |
---|
49 | } |
---|
50 | |
---|
51 | public void addChildren(PhysicalResourceDescription child) { |
---|
52 | super.addChildren(child); |
---|
53 | if(child.getLoadProfile().getLoadCalendar().getLoadDistribution().size() == 0){ |
---|
54 | child.getLoadProfile().getLoadCalendar().getLoadDistribution().addAll(this.getLoadProfile().getLoadCalendar().getLoadDistribution()); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | protected void initProfiles(Profile profile) { |
---|
59 | if (profile != null) { |
---|
60 | initPowerProfile(profile.getPowerProfile()); |
---|
61 | initAirflowProfile(profile.getAirThroughputProfile()); |
---|
62 | initThermalProfile(profile.getThermalProfile()); |
---|
63 | initLoadProfile(profile.getLoadProfile()); |
---|
64 | } else { |
---|
65 | initLoadProfile(null); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | protected void initPowerProfile(schemas.PowerProfile powerProfileCharacteristic) { |
---|
70 | |
---|
71 | if (powerProfileCharacteristic != null) { |
---|
72 | EnergyEstimationPlugin energyEstimationPlugin = null; |
---|
73 | List<PowerState> powerStates = null; |
---|
74 | List<PState> pStates = null; |
---|
75 | if(powerProfileCharacteristic.getEnergyEstimationPlugin() != null){ |
---|
76 | String energyEstimationPluginName = powerProfileCharacteristic.getEnergyEstimationPlugin().getName(); |
---|
77 | if(energyEstimationPluginName != null) { |
---|
78 | energyEstimationPlugin = (EnergyEstimationPlugin) InstanceFactory.createInstance( |
---|
79 | energyEstimationPluginName, EnergyEstimationPlugin.class); |
---|
80 | } else { |
---|
81 | energyEstimationPlugin = new DefaultEnergyEstimationPlugin(); |
---|
82 | } |
---|
83 | Parameters params = extractParameters(powerProfileCharacteristic.getEnergyEstimationPlugin().getParameter()); |
---|
84 | energyEstimationPlugin.init(params); |
---|
85 | } |
---|
86 | |
---|
87 | if(powerProfileCharacteristic.getPowerStates() != null) { |
---|
88 | powerStates = new ArrayList<PowerState>(); |
---|
89 | int powerStateCount = powerProfileCharacteristic.getPowerStates().getPowerStateCount(); |
---|
90 | for (int i = 0; i < powerStateCount ; i++) { |
---|
91 | schemas.PowerState ps = powerProfileCharacteristic.getPowerStates().getPowerState(i); |
---|
92 | List<Transition> transitions = new ArrayList<Transition>(); |
---|
93 | int transitionCount = ps.getTransitionCount(); |
---|
94 | for (int j = 0; j < transitionCount; j++) { |
---|
95 | schemas.Transition t = ps.getTransition(j); |
---|
96 | Transition transition = new Transition(PowerStateNameFactory.createPowerStateName(t.getTo()), t |
---|
97 | .getPowerUsage().getContent(), t.getTime().getContent()); |
---|
98 | Parameters params = extractParameters(t.getParameter()); |
---|
99 | transition.init(params); |
---|
100 | transitions.add(transition); |
---|
101 | } |
---|
102 | //CoolEmAll DEBB description case |
---|
103 | if(ps.getPowerUsage() == null){ |
---|
104 | ps.setPowerUsage(new PowerUsage("0")); |
---|
105 | } |
---|
106 | PowerState powerState = new PowerState(PowerStateNameFactory.createPowerStateName(ps.getName()), ps |
---|
107 | .getPowerUsage().getContent(), transitions); |
---|
108 | Parameters params = extractParameters(ps.getParameter()); |
---|
109 | powerState.init(params); |
---|
110 | powerStates.add(powerState); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | if(powerProfileCharacteristic.getParameter() != null){ |
---|
115 | pStates = new ArrayList<PState>(); |
---|
116 | int parameterCount = powerProfileCharacteristic.getParameterCount(); |
---|
117 | for(int i = 0; i < parameterCount; i++){ |
---|
118 | schemas.Parameter parameter = powerProfileCharacteristic.getParameter(i); |
---|
119 | if(parameter.getName().equals("pState")){ |
---|
120 | PState.Builder builder = new PState.Builder(); |
---|
121 | int propertyCount = parameter.getParameterTypeSequence().getPropertyCount(); |
---|
122 | for(int j = 0; j < propertyCount; j++){ |
---|
123 | schemas.Property property = parameter.getParameterTypeSequence().getProperty(j); |
---|
124 | if(property.getName().equals("name")){ |
---|
125 | builder = builder.name(property.getStringValueWithUnit(0).getContent()); |
---|
126 | } else if (property.getName().equals("frequency")){ |
---|
127 | builder = builder.frequency(Double.valueOf(property.getStringValueWithUnit(0).getContent())); |
---|
128 | } else if (property.getName().equals("voltage")){ |
---|
129 | builder = builder.voltage(Double.valueOf(property.getStringValueWithUnit(0).getContent())); |
---|
130 | } else if (property.getName().equals("powerUsage")){ |
---|
131 | if(property.getStringValueWithUnit(0).getContent() != null && property.getStringValueWithUnit(0).getContent().length() > 0){ |
---|
132 | builder = builder.powerUsage(Double.valueOf(property.getStringValueWithUnit(0).getContent())); |
---|
133 | } |
---|
134 | } else if (property.getName().equals("loadPowerUsage")){ |
---|
135 | if(property.getStringValueWithUnit(0).getContent() != null && property.getStringValueWithUnit(0).getContent().length() > 0 && |
---|
136 | property.getStringValueWithUnit(1).getContent() != null && property.getStringValueWithUnit(1).getContent().length() > 0){ |
---|
137 | //LoadPowerUsage lpu = new LoadPowerUsage(Double.valueOf(property.getStringValueWithUnit(0).getContent()), Double.valueOf(property.getStringValueWithUnit(1).getContent())); |
---|
138 | //builder = builder.loadPowerUsage(lpu); |
---|
139 | builder.loadPowerUsage(Double.valueOf(property.getStringValueWithUnit(0).getContent()), Double.valueOf(property.getStringValueWithUnit(1).getContent())); |
---|
140 | } |
---|
141 | } |
---|
142 | } |
---|
143 | PState pState = builder.build(); |
---|
144 | pStates.add(pState); |
---|
145 | } |
---|
146 | } |
---|
147 | } |
---|
148 | this.powerProfile = new PowerProfile(energyEstimationPlugin, powerStates, pStates); |
---|
149 | Parameters params = extractParameters(powerProfileCharacteristic.getParameter()); |
---|
150 | this.powerProfile.init(params); |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | protected void initAirflowProfile(schemas.AirThroughputProfile airflowProfile) { |
---|
155 | if (airflowProfile != null) { |
---|
156 | |
---|
157 | AirflowEstimationPlugin airflowEstimationPlugin = null; |
---|
158 | List<AirflowState> airflowStates = null; |
---|
159 | if(airflowProfile.getAirThroughputEstimationPlugin() != null){ |
---|
160 | String airflowEstimationPluginName = airflowProfile.getAirThroughputEstimationPlugin().getName(); |
---|
161 | if(airflowEstimationPluginName != null) { |
---|
162 | airflowEstimationPlugin = (AirflowEstimationPlugin) InstanceFactory.createInstance( |
---|
163 | airflowEstimationPluginName, AirflowEstimationPlugin.class); |
---|
164 | } else { |
---|
165 | airflowEstimationPlugin = new DefaultAirflowEstimationPlugin(); |
---|
166 | } |
---|
167 | Parameters params = extractParameters(airflowProfile.getAirThroughputEstimationPlugin().getParameter()); |
---|
168 | airflowEstimationPlugin.init(params); |
---|
169 | } |
---|
170 | if(airflowProfile.getAirThroughputStates() != null){ |
---|
171 | airflowStates = new ArrayList<AirflowState>(); |
---|
172 | int airflowStateCount = airflowProfile.getAirThroughputStates().getAirThroughputStateCount(); |
---|
173 | for (int i = 0; i < airflowStateCount; i++) { |
---|
174 | schemas.AirThroughputState ats = airflowProfile.getAirThroughputStates().getAirThroughputState(i); |
---|
175 | AirflowState airflowState = new AirflowState(AirflowStateNameFactory.createAirflowStateName(ats.getName()), ats.getValue() |
---|
176 | .getContent(), ats.getPowerUsage().getContent()); |
---|
177 | Parameters params = extractParameters(ats.getParameter()); |
---|
178 | airflowState.init(params); |
---|
179 | airflowStates.add(airflowState); |
---|
180 | } |
---|
181 | } |
---|
182 | this.airflowProfile = new AirflowProfile(airflowEstimationPlugin, airflowStates); |
---|
183 | Parameters params = extractParameters(airflowProfile.getParameter()); |
---|
184 | this.airflowProfile.init(params); |
---|
185 | } |
---|
186 | } |
---|
187 | |
---|
188 | protected void initThermalProfile(schemas.ThermalProfile thermalProfile) { |
---|
189 | |
---|
190 | if (thermalProfile != null) { |
---|
191 | |
---|
192 | TemperatureEstimationPlugin temperatureEstimationPlugin = null; |
---|
193 | |
---|
194 | if(thermalProfile.getTemperatureEstimationPlugin() != null){ |
---|
195 | String temperatureEstimationPluginName = thermalProfile.getTemperatureEstimationPlugin().getName(); |
---|
196 | if(temperatureEstimationPluginName != null) { |
---|
197 | temperatureEstimationPlugin = (TemperatureEstimationPlugin) InstanceFactory.createInstance( |
---|
198 | temperatureEstimationPluginName, TemperatureEstimationPlugin.class); |
---|
199 | } else { |
---|
200 | temperatureEstimationPlugin = new DefaultTemperatureEstimationPlugin(); |
---|
201 | } |
---|
202 | Parameters params = extractParameters(thermalProfile.getTemperatureEstimationPlugin().getParameter()); |
---|
203 | temperatureEstimationPlugin.init(params); |
---|
204 | } |
---|
205 | this.thermalProfile = new ThermalProfile(); |
---|
206 | Parameters params = extractParameters(thermalProfile.getParameter()); |
---|
207 | this.thermalProfile.init(params); |
---|
208 | } |
---|
209 | } |
---|
210 | |
---|
211 | protected void initLoadProfile(schemas.LoadProfile loadProfile) { |
---|
212 | |
---|
213 | if (loadProfile != null) { |
---|
214 | |
---|
215 | LoadEstimationPlugin loadEstimationPlugin = null; |
---|
216 | |
---|
217 | if(loadProfile.getLoadEstimationPlugin() != null){ |
---|
218 | String loadEstimationPluginName = loadProfile.getLoadEstimationPlugin().getName(); |
---|
219 | if(loadEstimationPluginName != null) { |
---|
220 | loadEstimationPlugin = (LoadEstimationPlugin) InstanceFactory.createInstance( |
---|
221 | loadEstimationPluginName, LoadEstimationPlugin.class); |
---|
222 | } else { |
---|
223 | loadEstimationPlugin = new DefaultLoadEstimationPlugin(); |
---|
224 | } |
---|
225 | Parameters params = extractParameters(loadProfile.getLoadEstimationPlugin().getParameter()); |
---|
226 | loadEstimationPlugin.init(params); |
---|
227 | } |
---|
228 | ResourceLoadCalendar resLoadCalander = new ResourceLoadCalendar(loadProfile.getLoadCalendar()); |
---|
229 | this.loadProfile = new LoadProfile(loadEstimationPlugin, resLoadCalander); |
---|
230 | Parameters params = extractParameters(loadProfile.getParameter()); |
---|
231 | this.loadProfile.init(params); |
---|
232 | } else { |
---|
233 | ResourceLoadCalendar resLoadCalander = new ResourceLoadCalendar(); |
---|
234 | LoadEstimationPlugin loadEstimationPlugin = LoadEstimationPluginFactory.createLoadEstimationPlugi(getType()); |
---|
235 | this.loadProfile = new LoadProfile(loadEstimationPlugin, resLoadCalander); |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | protected void initLocation(schemas.Location l) { |
---|
240 | if (location != null) { |
---|
241 | this.location = new Location(l.getHorizontal(), l.getVertical(), l.getDepth()); |
---|
242 | Parameters params = extractParameters(l.getParameter()); |
---|
243 | this.location.init(params); |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | protected Parameters extractParameters(schemas.Parameter[] parameters){ |
---|
248 | |
---|
249 | Parameters params = null; |
---|
250 | |
---|
251 | if(parameters.length != 0) |
---|
252 | params = new Parameters(); |
---|
253 | |
---|
254 | for(int i = 0; i < parameters.length; i++){ |
---|
255 | schemas.Parameter parameter = parameters[i]; |
---|
256 | Parameter param = new Parameter(parameter.getName()); |
---|
257 | if(parameter.getParameterTypeSequence() != null && parameter.getParameterTypeSequence().getProperty() != null) |
---|
258 | { |
---|
259 | int propertyCount = parameter.getParameterTypeSequence().getPropertyCount(); |
---|
260 | for(int j = 0; j < propertyCount; j++){ |
---|
261 | schemas.Property property = parameter.getParameterTypeSequence().getProperty(j); |
---|
262 | Property prop = new Property(property.getName()); |
---|
263 | int stringValueWithUnitCount = property.getStringValueWithUnitCount(); |
---|
264 | for(int k = 0; k < stringValueWithUnitCount; k++){ |
---|
265 | prop.add(property.getStringValueWithUnit(k)); |
---|
266 | } |
---|
267 | param.addProperty(prop); |
---|
268 | } |
---|
269 | } else { |
---|
270 | int stringValueWithUnitCount = parameter.getStringValueWithUnitCount(); |
---|
271 | for(int j = 0; j < stringValueWithUnitCount; j++){ |
---|
272 | param.add(parameter.getStringValueWithUnit(j)); |
---|
273 | } |
---|
274 | } |
---|
275 | params.put(parameter.getName(), param); |
---|
276 | } |
---|
277 | return params; |
---|
278 | } |
---|
279 | |
---|
280 | public PowerProfile getPowerProfile() { |
---|
281 | return powerProfile; |
---|
282 | } |
---|
283 | |
---|
284 | public AirflowProfile getAirflowProfile() { |
---|
285 | return airflowProfile; |
---|
286 | } |
---|
287 | |
---|
288 | public ThermalProfile getThermalProfile() { |
---|
289 | return thermalProfile; |
---|
290 | } |
---|
291 | |
---|
292 | public LoadProfile getLoadProfile() { |
---|
293 | return loadProfile; |
---|
294 | } |
---|
295 | |
---|
296 | public Location getLocation() { |
---|
297 | return location; |
---|
298 | } |
---|
299 | |
---|
300 | public String getCategory() { |
---|
301 | return category; |
---|
302 | } |
---|
303 | } |
---|