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