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