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