[477] | 1 | package schedframe.resources.computing.description; |
---|
| 2 | |
---|
[815] | 3 | import java.io.FileInputStream; |
---|
| 4 | import java.io.FileNotFoundException; |
---|
| 5 | import java.io.IOException; |
---|
[477] | 6 | import java.util.ArrayList; |
---|
| 7 | import java.util.List; |
---|
[815] | 8 | import java.util.PropertyResourceBundle; |
---|
| 9 | import java.util.ResourceBundle; |
---|
[477] | 10 | |
---|
| 11 | import schedframe.Parameter; |
---|
| 12 | import schedframe.Parameters; |
---|
| 13 | import schedframe.Property; |
---|
| 14 | import schedframe.resources.ResourceTypeFactory; |
---|
| 15 | import schedframe.resources.computing.location.Location; |
---|
| 16 | import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputProfile; |
---|
| 17 | import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputState; |
---|
| 18 | import schedframe.resources.computing.profiles.energy.airthroughput.plugin.AirThroughputEstimationPlugin; |
---|
| 19 | import schedframe.resources.computing.profiles.energy.airthroughput.plugin.DefaultAirThroughputEstimationPlugin; |
---|
| 20 | import schedframe.resources.computing.profiles.energy.power.PState; |
---|
| 21 | import schedframe.resources.computing.profiles.energy.power.PowerProfile; |
---|
| 22 | import schedframe.resources.computing.profiles.energy.power.PowerState; |
---|
| 23 | import schedframe.resources.computing.profiles.energy.power.PowerStateNameFactory; |
---|
| 24 | import schedframe.resources.computing.profiles.energy.power.Transition; |
---|
| 25 | import schedframe.resources.computing.profiles.energy.power.plugin.EnergyEstimationPlugin; |
---|
[815] | 26 | import schedframe.resources.computing.profiles.energy.thermal.ThermalProfile; |
---|
| 27 | import schedframe.resources.computing.profiles.energy.thermal.plugin.DefaultTemperatureEstimationPlugin; |
---|
| 28 | import schedframe.resources.computing.profiles.energy.thermal.plugin.TemperatureEstimationPlugin; |
---|
[477] | 29 | import schedframe.resources.units.ResourceUnit; |
---|
| 30 | import schedframe.resources.units.ResourceUnitFactory; |
---|
| 31 | import schedframe.resources.utils.ResourceIdGenerator; |
---|
| 32 | import schemas.ComputingResource; |
---|
[815] | 33 | import schemas.PowerUsage; |
---|
[477] | 34 | import schemas.Profile; |
---|
| 35 | import simulator.utils.InstanceFactory; |
---|
| 36 | import example.energy.DefaultEnergyEstimationPlugin; |
---|
| 37 | |
---|
| 38 | public class ComputingResourceDescription extends ExecutingResourceDescription { |
---|
| 39 | |
---|
| 40 | //protected Map<ResourceUnitName, List<AbstractResourceUnit>> resUnits; |
---|
| 41 | protected PowerProfile powerProfile; |
---|
| 42 | protected AirThroughputProfile airThroughputProfile; |
---|
[815] | 43 | protected ThermalProfile thermalProfile; |
---|
[477] | 44 | protected Location location; |
---|
[512] | 45 | protected String category; |
---|
[477] | 46 | //protected Parameters parameters; |
---|
| 47 | |
---|
| 48 | public ComputingResourceDescription(ComputingResource computingResource) { |
---|
| 49 | |
---|
| 50 | super(ResourceTypeFactory.createResourceType(computingResource.getClazz())); |
---|
[815] | 51 | this.category = computingResource.getType(); |
---|
| 52 | |
---|
[477] | 53 | initId(computingResource); |
---|
| 54 | |
---|
| 55 | if (computingResource.getComputingResourceTypeChoiceSequence() != null) { |
---|
| 56 | initResourceUnits(computingResource.getComputingResourceTypeChoiceSequence().getResourceUnit()); |
---|
[815] | 57 | try { |
---|
| 58 | if(System.getProperty("coolemall.resdesc") != null){ |
---|
| 59 | schemas.EnergyEstimationPlugin eep = new schemas.EnergyEstimationPlugin(); |
---|
| 60 | eep.setName(getEEP(createEEPQuery(computingResource), System.getProperty("coolemall.resdesc"))); |
---|
| 61 | if(computingResource.getComputingResourceTypeChoiceSequence().getProfile() != null) { |
---|
| 62 | if(computingResource.getComputingResourceTypeChoiceSequence().getProfile().getPowerProfile() != null) { |
---|
| 63 | computingResource.getComputingResourceTypeChoiceSequence().getProfile().getPowerProfile().setEnergyEstimationPlugin(eep); |
---|
| 64 | } |
---|
| 65 | } else { |
---|
| 66 | schemas.Profile p = new schemas.Profile(); |
---|
| 67 | computingResource.getComputingResourceTypeChoiceSequence().setProfile(p); |
---|
| 68 | schemas.PowerProfile pp = new schemas.PowerProfile(); |
---|
| 69 | computingResource.getComputingResourceTypeChoiceSequence().getProfile().setPowerProfile(pp); |
---|
| 70 | computingResource.getComputingResourceTypeChoiceSequence().getProfile().getPowerProfile().setEnergyEstimationPlugin(eep); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | } catch (FileNotFoundException e) { |
---|
| 74 | } catch (IOException e) { |
---|
| 75 | } |
---|
[477] | 76 | initProfiles(computingResource.getComputingResourceTypeChoiceSequence().getProfile()); |
---|
| 77 | initLocation(computingResource.getComputingResourceTypeChoiceSequence().getLocation()); |
---|
| 78 | this.parameters = extractParameters(computingResource.getComputingResourceTypeChoiceSequence().getParameter()); |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | private void initId(ComputingResource computingResource){ |
---|
| 83 | this.id = computingResource.getName() != null ? computingResource.getName() : type.toString(); |
---|
| 84 | if(computingResource.getCount() > 1 || computingResource.getName() == null){ |
---|
[815] | 85 | this.id = id + "_" + String.valueOf(ResourceIdGenerator.getId(type.toString())); |
---|
[477] | 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | private void initResourceUnits(schemas.ResourceUnit[] resourceUnitCharacteristics) { |
---|
| 90 | for (int i = 0; i < resourceUnitCharacteristics.length; i++) { |
---|
| 91 | schemas.ResourceUnit resourceUnitCharacteristic = resourceUnitCharacteristics[i]; |
---|
| 92 | ResourceUnit resourceUnit = ResourceUnitFactory.createUnit(resourceUnitCharacteristic.getClazz(), this.id, |
---|
| 93 | Double.valueOf(resourceUnitCharacteristic.getAmount().getContent()).intValue(), 0); |
---|
| 94 | Parameters params = extractParameters(resourceUnitCharacteristic.getParameter()); |
---|
| 95 | resourceUnit.init(params); |
---|
| 96 | addResourceUnit(resourceUnit); |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | private void initProfiles(Profile profile) { |
---|
| 101 | if (profile != null) { |
---|
| 102 | initPowerProfile(profile.getPowerProfile()); |
---|
| 103 | initAirThroughputProfile(profile.getAirThroughputProfile()); |
---|
[815] | 104 | initThermalProfile(profile.getThermalProfile()); |
---|
[477] | 105 | } |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | private void initPowerProfile(schemas.PowerProfile powerProfileCharacteristic) { |
---|
| 109 | |
---|
| 110 | if (powerProfileCharacteristic != null) { |
---|
| 111 | EnergyEstimationPlugin energyEstimationPlugin = null; |
---|
| 112 | List<PowerState> powerStates = null; |
---|
| 113 | List<PState> pStates = null; |
---|
| 114 | if(powerProfileCharacteristic.getEnergyEstimationPlugin() != null){ |
---|
[815] | 115 | String energyEstimationPluginName = powerProfileCharacteristic.getEnergyEstimationPlugin().getName(); |
---|
[477] | 116 | if(energyEstimationPluginName != null) { |
---|
| 117 | energyEstimationPlugin = (EnergyEstimationPlugin) InstanceFactory.createInstance( |
---|
| 118 | energyEstimationPluginName, EnergyEstimationPlugin.class); |
---|
| 119 | } else { |
---|
| 120 | energyEstimationPlugin = new DefaultEnergyEstimationPlugin(); |
---|
| 121 | } |
---|
| 122 | Parameters params = extractParameters(powerProfileCharacteristic.getEnergyEstimationPlugin().getParameter()); |
---|
| 123 | energyEstimationPlugin.init(params); |
---|
| 124 | } |
---|
| 125 | |
---|
[752] | 126 | if(powerProfileCharacteristic.getPowerStates() != null) { |
---|
[477] | 127 | powerStates = new ArrayList<PowerState>(); |
---|
| 128 | int powerStateCount = powerProfileCharacteristic.getPowerStates().getPowerStateCount(); |
---|
| 129 | for (int i = 0; i < powerStateCount ; i++) { |
---|
| 130 | schemas.PowerState ps = powerProfileCharacteristic.getPowerStates().getPowerState(i); |
---|
| 131 | List<Transition> transitions = new ArrayList<Transition>(); |
---|
| 132 | int transitionCount = ps.getTransitionCount(); |
---|
| 133 | for (int j = 0; j < transitionCount; j++) { |
---|
| 134 | schemas.Transition t = ps.getTransition(j); |
---|
| 135 | Transition transition = new Transition(PowerStateNameFactory.createPowerStateName(t.getTo()), t |
---|
| 136 | .getPowerUsage().getContent(), t.getTime().getContent()); |
---|
| 137 | Parameters params = extractParameters(t.getParameter()); |
---|
| 138 | transition.init(params); |
---|
| 139 | transitions.add(transition); |
---|
| 140 | } |
---|
[815] | 141 | //CoolEmAll DEBB description case |
---|
| 142 | if(ps.getPowerUsage() == null){ |
---|
| 143 | ps.setPowerUsage(new PowerUsage("0")); |
---|
| 144 | } |
---|
[477] | 145 | PowerState powerState = new PowerState(PowerStateNameFactory.createPowerStateName(ps.getName()), ps |
---|
| 146 | .getPowerUsage().getContent(), transitions); |
---|
| 147 | Parameters params = extractParameters(ps.getParameter()); |
---|
| 148 | powerState.init(params); |
---|
| 149 | powerStates.add(powerState); |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | if(powerProfileCharacteristic.getParameter() != null){ |
---|
| 154 | pStates = new ArrayList<PState>(); |
---|
[815] | 155 | int parameterCount = powerProfileCharacteristic.getParameterCount(); |
---|
[477] | 156 | for(int i = 0; i < parameterCount; i++){ |
---|
| 157 | schemas.Parameter parameter = powerProfileCharacteristic.getParameter(i); |
---|
| 158 | if(parameter.getName().equals("pState")){ |
---|
[815] | 159 | PState.Builder builder = new PState.Builder(); |
---|
[477] | 160 | int propertyCount = parameter.getParameterTypeSequence().getPropertyCount(); |
---|
| 161 | for(int j = 0; j < propertyCount; j++){ |
---|
| 162 | schemas.Property property = parameter.getParameterTypeSequence().getProperty(j); |
---|
| 163 | if(property.getName().equals("name")){ |
---|
| 164 | builder = builder.name(property.getStringValueWithUnit(0).getContent()); |
---|
| 165 | } else if (property.getName().equals("frequency")){ |
---|
| 166 | builder = builder.frequency(Double.valueOf(property.getStringValueWithUnit(0).getContent())); |
---|
| 167 | } else if (property.getName().equals("voltage")){ |
---|
| 168 | builder = builder.voltage(Double.valueOf(property.getStringValueWithUnit(0).getContent())); |
---|
| 169 | } else if (property.getName().equals("powerUsage")){ |
---|
| 170 | builder = builder.powerUsage(Double.valueOf(property.getStringValueWithUnit(0).getContent())); |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | PState pState = builder.build(); |
---|
| 174 | pStates.add(pState); |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | this.powerProfile = new PowerProfile(energyEstimationPlugin, powerStates, pStates); |
---|
| 179 | Parameters params = extractParameters(powerProfileCharacteristic.getParameter()); |
---|
| 180 | this.powerProfile.init(params); |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | private void initAirThroughputProfile(schemas.AirThroughputProfile airThroughputProfile) { |
---|
| 185 | if (airThroughputProfile != null) { |
---|
| 186 | |
---|
| 187 | AirThroughputEstimationPlugin airThroughputEstimationPlugin = null; |
---|
| 188 | List<AirThroughputState> airThroughputStates = null; |
---|
| 189 | if(airThroughputProfile.getAirThroughputEstimationPlugin() != null){ |
---|
| 190 | String airThroughputEstimationPluginName = airThroughputProfile.getAirThroughputEstimationPlugin().getName(); |
---|
| 191 | if(airThroughputEstimationPluginName != null) { |
---|
| 192 | airThroughputEstimationPlugin = (AirThroughputEstimationPlugin) InstanceFactory.createInstance( |
---|
| 193 | airThroughputEstimationPluginName, AirThroughputEstimationPlugin.class); |
---|
| 194 | } else { |
---|
| 195 | airThroughputEstimationPlugin = new DefaultAirThroughputEstimationPlugin(); |
---|
| 196 | } |
---|
| 197 | Parameters params = extractParameters(airThroughputProfile.getAirThroughputEstimationPlugin().getParameter()); |
---|
| 198 | airThroughputEstimationPlugin.init(params); |
---|
| 199 | } |
---|
| 200 | if(airThroughputProfile.getAirThroughputStates() != null){ |
---|
| 201 | airThroughputStates = new ArrayList<AirThroughputState>(); |
---|
[815] | 202 | int airThrouhputStateCount = airThroughputProfile.getAirThroughputStates().getAirThroughputStateCount(); |
---|
[477] | 203 | for (int i = 0; i < airThrouhputStateCount; i++) { |
---|
| 204 | schemas.AirThroughputState ats = airThroughputProfile.getAirThroughputStates().getAirThroughputState(i); |
---|
| 205 | AirThroughputState airThroughputState = new AirThroughputState(ats.getName(), ats.getValue() |
---|
| 206 | .getContent(), ats.getPowerUsage().getContent()); |
---|
| 207 | Parameters params = extractParameters(ats.getParameter()); |
---|
| 208 | airThroughputState.init(params); |
---|
| 209 | airThroughputStates.add(airThroughputState); |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | this.airThroughputProfile = new AirThroughputProfile(airThroughputEstimationPlugin, airThroughputStates); |
---|
| 213 | Parameters params = extractParameters(airThroughputProfile.getParameter()); |
---|
| 214 | this.airThroughputProfile.init(params); |
---|
| 215 | } |
---|
| 216 | } |
---|
| 217 | |
---|
[815] | 218 | private void initThermalProfile(schemas.ThermalProfile thermalProfile) { |
---|
| 219 | |
---|
| 220 | if (thermalProfile != null) { |
---|
| 221 | |
---|
| 222 | TemperatureEstimationPlugin temperatureEstimationPlugin = null; |
---|
| 223 | |
---|
| 224 | if(thermalProfile.getTemperatureEstimationPlugin() != null){ |
---|
| 225 | String temperatureEstimationPluginName = thermalProfile.getTemperatureEstimationPlugin().getName(); |
---|
| 226 | if(temperatureEstimationPluginName != null) { |
---|
| 227 | temperatureEstimationPlugin = (TemperatureEstimationPlugin) InstanceFactory.createInstance( |
---|
| 228 | temperatureEstimationPluginName, TemperatureEstimationPlugin.class); |
---|
| 229 | } else { |
---|
| 230 | temperatureEstimationPlugin = new DefaultTemperatureEstimationPlugin(); |
---|
| 231 | } |
---|
| 232 | Parameters params = extractParameters(thermalProfile.getTemperatureEstimationPlugin().getParameter()); |
---|
| 233 | temperatureEstimationPlugin.init(params); |
---|
| 234 | } |
---|
| 235 | this.thermalProfile = new ThermalProfile(); |
---|
| 236 | Parameters params = extractParameters(thermalProfile.getParameter()); |
---|
| 237 | this.thermalProfile.init(params); |
---|
| 238 | } |
---|
| 239 | } |
---|
| 240 | |
---|
[477] | 241 | private void initLocation(schemas.Location l) { |
---|
| 242 | if (location != null) { |
---|
| 243 | this.location = new Location(l.getHorizontal(), l.getVertical(), l.getDepth()); |
---|
| 244 | Parameters params = extractParameters(l.getParameter()); |
---|
| 245 | this.location.init(params); |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | /*private Properties initProperties(schemas.Parameter[] parameters){ |
---|
| 251 | Properties prop = new Properties(); |
---|
| 252 | |
---|
| 253 | for(int i = 0; i < parameters.length; i++){ |
---|
| 254 | schemas.Parameter parameter = parameters[i]; |
---|
| 255 | List values = new ArrayList(); |
---|
| 256 | if(parameter.getParameterTypeSequence().getProperty() != null) |
---|
| 257 | { |
---|
| 258 | Map<String, List<StringValueWithUnit>> properties = new HashMap<String, List<StringValueWithUnit>>(); |
---|
| 259 | List<StringValueWithUnit> propValues = new ArrayList<StringValueWithUnit>(); |
---|
| 260 | for(int j = 0; j < parameter.getParameterTypeSequence().getPropertyCount(); j++){ |
---|
| 261 | schemas.Property property = parameter.getParameterTypeSequence().getProperty(j); |
---|
| 262 | for(int k = 0; k < property.getStringValueWithUnitCount(); k++){ |
---|
| 263 | propValues.add(property.getStringValueWithUnit(k)); |
---|
| 264 | } |
---|
| 265 | properties.put(property.getName(), propValues); |
---|
| 266 | } |
---|
| 267 | values.add(properties); |
---|
| 268 | }else { |
---|
| 269 | for(int j = 0; j < parameter.getStringValueWithUnitCount(); j++){ |
---|
| 270 | values.add(parameter.getStringValueWithUnit(j)); |
---|
| 271 | } |
---|
| 272 | } |
---|
| 273 | prop.put(parameter.getName(), values); |
---|
| 274 | } |
---|
| 275 | return prop; |
---|
| 276 | }*/ |
---|
| 277 | |
---|
| 278 | private Parameters extractParameters(schemas.Parameter[] parameters){ |
---|
| 279 | |
---|
| 280 | Parameters params = null; |
---|
| 281 | |
---|
| 282 | if(parameters.length != 0) |
---|
| 283 | params = new Parameters(); |
---|
| 284 | |
---|
| 285 | for(int i = 0; i < parameters.length; i++){ |
---|
| 286 | schemas.Parameter parameter = parameters[i]; |
---|
| 287 | Parameter param = new Parameter(parameter.getName()); |
---|
| 288 | if(parameter.getParameterTypeSequence() != null && parameter.getParameterTypeSequence().getProperty() != null) |
---|
| 289 | { |
---|
| 290 | int propertyCount = parameter.getParameterTypeSequence().getPropertyCount(); |
---|
| 291 | for(int j = 0; j < propertyCount; j++){ |
---|
| 292 | schemas.Property property = parameter.getParameterTypeSequence().getProperty(j); |
---|
| 293 | Property prop = new Property(property.getName()); |
---|
| 294 | int stringValueWithUnitCount = property.getStringValueWithUnitCount(); |
---|
| 295 | for(int k = 0; k < stringValueWithUnitCount; k++){ |
---|
| 296 | prop.add(property.getStringValueWithUnit(k)); |
---|
| 297 | } |
---|
| 298 | param.addProperty(prop); |
---|
| 299 | } |
---|
| 300 | } else { |
---|
| 301 | int stringValueWithUnitCount = parameter.getStringValueWithUnitCount(); |
---|
| 302 | for(int j = 0; j < stringValueWithUnitCount; j++){ |
---|
| 303 | param.add(parameter.getStringValueWithUnit(j)); |
---|
| 304 | } |
---|
| 305 | } |
---|
| 306 | params.put(parameter.getName(), param); |
---|
| 307 | } |
---|
| 308 | return params; |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | public PowerProfile getPowerProfile() { |
---|
| 312 | return powerProfile; |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | public AirThroughputProfile getAirThroughputProfile() { |
---|
| 316 | return airThroughputProfile; |
---|
| 317 | } |
---|
| 318 | |
---|
[815] | 319 | public ThermalProfile getThermalProfile() { |
---|
| 320 | return thermalProfile; |
---|
| 321 | } |
---|
| 322 | |
---|
[477] | 323 | public Location getLocation() { |
---|
| 324 | return location; |
---|
| 325 | } |
---|
| 326 | |
---|
[512] | 327 | public String getCategory() { |
---|
| 328 | return category; |
---|
| 329 | } |
---|
[477] | 330 | |
---|
[815] | 331 | |
---|
| 332 | /***COOLEMALL CASE RELATED***/ |
---|
| 333 | |
---|
| 334 | private static ResourceBundle recsBundle; |
---|
| 335 | |
---|
| 336 | private ResourceBundle getRecsBundle(String fileName) throws FileNotFoundException, IOException{ |
---|
| 337 | if(recsBundle == null){ |
---|
| 338 | recsBundle = new PropertyResourceBundle(new FileInputStream(fileName)); |
---|
| 339 | } |
---|
| 340 | return recsBundle; |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | protected String getEEP(String query, String fileName) throws FileNotFoundException, IOException{ |
---|
| 344 | ResourceBundle recsBundle = getRecsBundle(fileName); |
---|
| 345 | return recsBundle.getString(query); |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | protected String createEEPQuery(ComputingResource compRes) { |
---|
| 349 | String query = compRes.getClazz() + "EEP"; |
---|
| 350 | return query; |
---|
| 351 | } |
---|
[477] | 352 | } |
---|