- Timestamp:
- 11/26/13 11:56:07 (11 years ago)
- Location:
- DCWoRMS/branches/coolemall/src/schedframe/resources/computing/description
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
DCWoRMS/branches/coolemall/src/schedframe/resources/computing/description/ComputingResourceDescription.java
r1113 r1207 1 1 package schedframe.resources.computing.description; 2 2 3 import java.io.FileInputStream;4 import java.io.FileNotFoundException;5 import java.io.IOException;6 3 import java.util.ArrayList; 4 import java.util.Collection; 5 import java.util.HashMap; 6 import java.util.Iterator; 7 7 import java.util.List; 8 import java.util.PropertyResourceBundle; 9 import java.util.ResourceBundle; 8 import java.util.Map; 10 9 11 import schedframe.Parameter;12 10 import schedframe.Parameters; 13 import schedframe.Property;14 11 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; 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; 12 import schedframe.resources.devices.Device; 13 import schedframe.resources.devices.description.DeviceDescription; 14 import schedframe.resources.devices.description.PhysicalResourceDescription; 29 15 import schedframe.resources.units.ResourceUnit; 30 16 import schedframe.resources.units.ResourceUnitFactory; 17 import schedframe.resources.units.ResourceUnitName; 31 18 import schedframe.resources.utils.ResourceIdGenerator; 32 19 import schemas.ComputingResource; 33 import schemas.PowerUsage;34 import schemas.Profile;35 import simulator.utils.InstanceFactory;36 import example.energy.DefaultEnergyEstimationPlugin;37 20 38 public class ComputingResourceDescription extends ExecutingResourceDescription {39 21 40 //protected Map<ResourceUnitName, List<AbstractResourceUnit>> resUnits; 41 protected PowerProfile powerProfile; 42 protected AirThroughputProfile airThroughputProfile; 43 protected ThermalProfile thermalProfile; 44 protected Location location; 45 protected String category; 46 //protected Parameters parameters; 22 public class ComputingResourceDescription extends PhysicalResourceDescription implements ExecutingResourceDescription { 47 23 24 protected Map<ResourceUnitName, List<ResourceUnit>> resUnits; 25 protected List<Device> devices; 26 48 27 public ComputingResourceDescription(ComputingResource computingResource) { 49 28 … … 55 34 if (computingResource.getComputingResourceTypeChoiceSequence() != null) { 56 35 initResourceUnits(computingResource.getComputingResourceTypeChoiceSequence().getResourceUnit()); 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 } 36 76 37 initProfiles(computingResource.getComputingResourceTypeChoiceSequence().getProfile()); 77 38 initLocation(computingResource.getComputingResourceTypeChoiceSequence().getLocation()); 39 initDevices(computingResource.getComputingResourceTypeChoiceSequence().getDevice()); 78 40 this.parameters = extractParameters(computingResource.getComputingResourceTypeChoiceSequence().getParameter()); 79 41 } … … 97 59 } 98 60 } 99 100 private void initProfiles(Profile profile) {101 if (profile != null) {102 initPowerProfile(profile.getPowerProfile());103 initAirThroughputProfile(profile.getAirThroughputProfile());104 initThermalProfile(profile.getThermalProfile());105 }106 }107 61 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){ 115 String energyEstimationPluginName = powerProfileCharacteristic.getEnergyEstimationPlugin().getName(); 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); 62 private void initDevices(schemas.Device[] dev) { 63 if (dev != null){ 64 this.devices = new ArrayList<Device>(); 65 for(int i = 0; i < dev.length; i++){ 66 Device device = new Device(new DeviceDescription(dev[i])); 67 this.devices.add(device); 124 68 } 125 126 if(powerProfileCharacteristic.getPowerStates() != null) {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()), t136 .getPowerUsage().getContent(), t.getTime().getContent());137 Parameters params = extractParameters(t.getParameter());138 transition.init(params);139 transitions.add(transition);140 }141 //CoolEmAll DEBB description case142 if(ps.getPowerUsage() == null){143 ps.setPowerUsage(new PowerUsage("0"));144 }145 PowerState powerState = new PowerState(PowerStateNameFactory.createPowerStateName(ps.getName()), ps146 .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>();155 int parameterCount = powerProfileCharacteristic.getParameterCount();156 for(int i = 0; i < parameterCount; i++){157 schemas.Parameter parameter = powerProfileCharacteristic.getParameter(i);158 if(parameter.getName().equals("pState")){159 PState.Builder builder = new PState.Builder();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 if(property.getStringValueWithUnit(0).getContent() != null && property.getStringValueWithUnit(0).getContent().length() > 0){171 builder = builder.powerUsage(Double.valueOf(property.getStringValueWithUnit(0).getContent()));172 }173 } else if (property.getName().equals("powerUsageMin")){174 if(property.getStringValueWithUnit(0).getContent() != null && property.getStringValueWithUnit(0).getContent().length() > 0){175 builder = builder.powerUsageMin(Double.valueOf(property.getStringValueWithUnit(0).getContent()));176 }177 } else if (property.getName().equals("powerUsageMax")){178 if(property.getStringValueWithUnit(0).getContent() != null && property.getStringValueWithUnit(0).getContent().length() > 0){179 builder = builder.powerUsageMax(Double.valueOf(property.getStringValueWithUnit(0).getContent()));180 }181 }182 }183 PState pState = builder.build();184 pStates.add(pState);185 }186 }187 }188 this.powerProfile = new PowerProfile(energyEstimationPlugin, powerStates, pStates);189 Parameters params = extractParameters(powerProfileCharacteristic.getParameter());190 this.powerProfile.init(params);191 69 } 192 70 } 193 71 194 private void initAirThroughputProfile(schemas.AirThroughputProfile airThroughputProfile) { 195 if (airThroughputProfile != null) { 196 197 AirThroughputEstimationPlugin airThroughputEstimationPlugin = null; 198 List<AirThroughputState> airThroughputStates = null; 199 if(airThroughputProfile.getAirThroughputEstimationPlugin() != null){ 200 String airThroughputEstimationPluginName = airThroughputProfile.getAirThroughputEstimationPlugin().getName(); 201 if(airThroughputEstimationPluginName != null) { 202 airThroughputEstimationPlugin = (AirThroughputEstimationPlugin) InstanceFactory.createInstance( 203 airThroughputEstimationPluginName, AirThroughputEstimationPlugin.class); 204 } else { 205 airThroughputEstimationPlugin = new DefaultAirThroughputEstimationPlugin(); 206 } 207 Parameters params = extractParameters(airThroughputProfile.getAirThroughputEstimationPlugin().getParameter()); 208 airThroughputEstimationPlugin.init(params); 209 } 210 if(airThroughputProfile.getAirThroughputStates() != null){ 211 airThroughputStates = new ArrayList<AirThroughputState>(); 212 int airThrouhputStateCount = airThroughputProfile.getAirThroughputStates().getAirThroughputStateCount(); 213 for (int i = 0; i < airThrouhputStateCount; i++) { 214 schemas.AirThroughputState ats = airThroughputProfile.getAirThroughputStates().getAirThroughputState(i); 215 AirThroughputState airThroughputState = new AirThroughputState(ats.getName(), ats.getValue() 216 .getContent(), ats.getPowerUsage().getContent()); 217 Parameters params = extractParameters(ats.getParameter()); 218 airThroughputState.init(params); 219 airThroughputStates.add(airThroughputState); 220 } 221 } 222 this.airThroughputProfile = new AirThroughputProfile(airThroughputEstimationPlugin, airThroughputStates); 223 Parameters params = extractParameters(airThroughputProfile.getParameter()); 224 this.airThroughputProfile.init(params); 225 } 72 public String getCompResourceParameterValue(String name){ 73 return getParameters().get(name).get(0).getContent(); 226 74 } 227 228 private void initThermalProfile(schemas.ThermalProfile thermalProfile) {229 230 if (thermalProfile != null) {231 232 TemperatureEstimationPlugin temperatureEstimationPlugin = null;233 234 if(thermalProfile.getTemperatureEstimationPlugin() != null){235 String temperatureEstimationPluginName = thermalProfile.getTemperatureEstimationPlugin().getName();236 if(temperatureEstimationPluginName != null) {237 temperatureEstimationPlugin = (TemperatureEstimationPlugin) InstanceFactory.createInstance(238 temperatureEstimationPluginName, TemperatureEstimationPlugin.class);239 } else {240 temperatureEstimationPlugin = new DefaultTemperatureEstimationPlugin();241 }242 Parameters params = extractParameters(thermalProfile.getTemperatureEstimationPlugin().getParameter());243 temperatureEstimationPlugin.init(params);244 }245 this.thermalProfile = new ThermalProfile();246 Parameters params = extractParameters(thermalProfile.getParameter());247 this.thermalProfile.init(params);248 }249 }250 251 private void initLocation(schemas.Location l) {252 if (location != null) {253 this.location = new Location(l.getHorizontal(), l.getVertical(), l.getDepth());254 Parameters params = extractParameters(l.getParameter());255 this.location.init(params);256 }257 }258 259 75 260 76 /*private Properties initProperties(schemas.Parameter[] parameters){ … … 285 101 return prop; 286 102 }*/ 287 288 private Parameters extractParameters(schemas.Parameter[] parameters){289 290 Parameters params = null;291 292 if(parameters.length != 0)293 params = new Parameters();294 295 for(int i = 0; i < parameters.length; i++){296 schemas.Parameter parameter = parameters[i];297 Parameter param = new Parameter(parameter.getName());298 if(parameter.getParameterTypeSequence() != null && parameter.getParameterTypeSequence().getProperty() != null)299 {300 int propertyCount = parameter.getParameterTypeSequence().getPropertyCount();301 for(int j = 0; j < propertyCount; j++){302 schemas.Property property = parameter.getParameterTypeSequence().getProperty(j);303 Property prop = new Property(property.getName());304 int stringValueWithUnitCount = property.getStringValueWithUnitCount();305 for(int k = 0; k < stringValueWithUnitCount; k++){306 prop.add(property.getStringValueWithUnit(k));307 }308 param.addProperty(prop);309 }310 } else {311 int stringValueWithUnitCount = parameter.getStringValueWithUnitCount();312 for(int j = 0; j < stringValueWithUnitCount; j++){313 param.add(parameter.getStringValueWithUnit(j));314 }315 }316 params.put(parameter.getName(), param);317 }318 return params;319 }320 103 321 public PowerProfile getPowerProfile() {322 return powerProfile;323 }324 104 325 public AirThroughputProfile getAirThroughputProfile() { 326 return airThroughputProfile; 327 } 328 329 public ThermalProfile getThermalProfile() { 330 return thermalProfile; 331 } 332 333 public Location getLocation() { 334 return location; 335 } 336 337 public String getCategory() { 338 return category; 105 public List<Device> getDevices() { 106 return devices; 339 107 } 340 108 341 109 342 /***COOLEMALL CASE RELATED***/ 343 344 private static ResourceBundle recsBundle; 345 346 private ResourceBundle getRecsBundle(String fileName) throws FileNotFoundException, IOException{ 347 if(recsBundle == null){ 348 recsBundle = new PropertyResourceBundle(new FileInputStream(fileName)); 110 public void addResourceUnit(ResourceUnit unit) { 111 if (this.resUnits == null) 112 this.resUnits = new HashMap<ResourceUnitName, List<ResourceUnit>>(1); 113 List<ResourceUnit> list = null; 114 if (this.resUnits.containsKey(unit.getName())) { 115 list = this.resUnits.get(unit.getName()); 116 } else { 117 list = new ArrayList<ResourceUnit>(1); 118 this.resUnits.put(unit.getName(), list); 349 119 } 350 return recsBundle;120 list.add(unit); 351 121 } 352 122 353 protected String getEEP(String query, String fileName) throws FileNotFoundException, IOException{ 354 ResourceBundle recsBundle = getRecsBundle(fileName); 355 return recsBundle.getString(query); 123 public ResourceUnit getResourceUnit(ResourceUnitName unitName) throws NoSuchFieldException { 124 return getResourceUnitList(unitName).get(0); 356 125 } 357 358 protected String createEEPQuery(ComputingResource compRes) { 359 String query = compRes.getClazz() + "EEP"; 360 return query; 126 127 public List<ResourceUnit> getResourceUnitList(ResourceUnitName unitName) throws NoSuchFieldException { 128 if (resUnits.containsKey(unitName)) 129 return resUnits.get(unitName); 130 else 131 throw new NoSuchFieldException("Resource unit " + unitName + " is not available in resource " + this.id); 132 } 133 134 public Collection<ResourceUnit> getResourceUnit() { 135 if (resUnits == null) 136 return null; 137 List<ResourceUnit> values = new ArrayList<ResourceUnit>(); 138 Collection<List<ResourceUnit>> lists = resUnits.values(); 139 Iterator<List<ResourceUnit>> itr = lists.iterator(); 140 141 while (itr.hasNext()) { 142 List<ResourceUnit> list = itr.next(); 143 values.addAll(list); 144 } 145 146 return values; 147 } 148 149 public Map<ResourceUnitName, List<ResourceUnit>> getResourceUnits() { 150 return resUnits; 361 151 } 362 152 } -
DCWoRMS/branches/coolemall/src/schedframe/resources/computing/description/ExecutingResourceDescription.java
r477 r1207 1 1 package schedframe.resources.computing.description; 2 2 3 import java.util.ArrayList;4 3 import java.util.Collection; 5 import java.util.HashMap;6 import java.util.Iterator;7 4 import java.util.List; 8 5 import java.util.Map; 9 6 10 import schedframe.Parameters;11 import schedframe.resources.ResourceType;12 7 import schedframe.resources.units.ResourceUnit; 13 8 import schedframe.resources.units.ResourceUnitName; 14 9 15 public class ExecutingResourceDescription extends AbstractResourceDescription { 10 public interface ExecutingResourceDescription { 11 12 public void addResourceUnit(ResourceUnit unit); 13 14 public ResourceUnit getResourceUnit(ResourceUnitName unitName) throws NoSuchFieldException ; 16 15 17 protected Map<ResourceUnitName, List<ResourceUnit>> resUnits; 18 protected Parameters parameters; 16 public List<ResourceUnit> getResourceUnitList(ResourceUnitName unitName) throws NoSuchFieldException; 17 18 public Collection<ResourceUnit> getResourceUnit(); 19 19 20 public ExecutingResourceDescription(ResourceType type) { 21 super(type); 22 } 23 24 public Parameters getParameters() { 25 return parameters; 26 } 27 28 public String getCompResourceParameterValue(String name){ 29 return getParameters().get(name).get(0).getContent(); 30 } 31 32 public void addResourceUnit(ResourceUnit unit) { 33 if (this.resUnits == null) 34 this.resUnits = new HashMap<ResourceUnitName, List<ResourceUnit>>(1); 35 List<ResourceUnit> list = null; 36 if (this.resUnits.containsKey(unit.getName())) { 37 list = this.resUnits.get(unit.getName()); 38 } else { 39 list = new ArrayList<ResourceUnit>(1); 40 this.resUnits.put(unit.getName(), list); 41 } 42 list.add(unit); 43 } 44 45 public ResourceUnit getResourceUnit(ResourceUnitName unitName) throws NoSuchFieldException { 46 return getResourceUnitList(unitName).get(0); 47 } 48 49 public List<ResourceUnit> getResourceUnitList(ResourceUnitName unitName) throws NoSuchFieldException { 50 if (resUnits.containsKey(unitName)) 51 return resUnits.get(unitName); 52 else 53 throw new NoSuchFieldException("Resource unit " + unitName + " is not available in resource " + this.id); 54 } 55 56 public Collection<ResourceUnit> getResourceUnit() { 57 if (resUnits == null) 58 return null; 59 List<ResourceUnit> values = new ArrayList<ResourceUnit>(); 60 Collection<List<ResourceUnit>> lists = resUnits.values(); 61 Iterator<List<ResourceUnit>> itr = lists.iterator(); 62 63 while (itr.hasNext()) { 64 List<ResourceUnit> list = itr.next(); 65 values.addAll(list); 66 } 67 68 return values; 69 } 70 71 public Map<ResourceUnitName, List<ResourceUnit>> getResourceUnits() { 72 return resUnits; 73 } 20 public Map<ResourceUnitName, List<ResourceUnit>> getResourceUnits(); 74 21 } -
DCWoRMS/branches/coolemall/src/schedframe/resources/computing/description/ResourceDescription.java
r477 r1207 5 5 import java.util.List; 6 6 7 import schedframe.Parameters; 7 8 import schedframe.resources.ResourceType; 8 9 9 10 10 public abstract class AbstractResourceDescription {11 public abstract class ResourceDescription { 11 12 12 13 protected String id; 13 14 protected ResourceType type; 14 protected List<AbstractResourceDescription> children; 15 protected List<ResourceDescription> children; 16 protected Parameters parameters; 15 17 16 public AbstractResourceDescription(ResourceType type){18 public ResourceDescription(ResourceType type){ 17 19 this.type = type; 18 this.children = null;19 20 } 20 21 21 public List< AbstractResourceDescription> getChildren() {22 public List<ResourceDescription> getChildren() { 22 23 return children; 23 24 } 24 25 25 public void setChildren(List< AbstractResourceDescription> children) {26 public void setChildren(List<ResourceDescription> children) { 26 27 this.children = children; 27 28 } 28 29 29 public void addChildren( AbstractResourceDescription child) {30 public void addChildren(ResourceDescription child) { 30 31 //child.setParent(this); 31 32 if(children == null) 32 children = new ArrayList< AbstractResourceDescription> (1);33 children = new ArrayList<ResourceDescription> (1); 33 34 this.children.add(child); 34 35 } … … 40 41 public ResourceType getType() { 41 42 return type; 43 } 44 45 public Parameters getParameters() { 46 return parameters; 42 47 } 43 48
Note: See TracChangeset
for help on using the changeset viewer.