package schedframe.resources.devices.description; import java.util.ArrayList; import java.util.List; import schedframe.Parameter; import schedframe.Parameters; import schedframe.Property; import schedframe.resources.ResourceType; import schedframe.resources.computing.description.ResourceDescription; import schedframe.resources.computing.location.Location; import schedframe.resources.computing.profiles.energy.airthroughput.AirflowStateNameFactory; import schedframe.resources.computing.profiles.energy.airthroughput.AirflowProfile; import schedframe.resources.computing.profiles.energy.airthroughput.AirflowState; import schedframe.resources.computing.profiles.energy.airthroughput.plugin.AirflowEstimationPlugin; import schedframe.resources.computing.profiles.energy.airthroughput.plugin.DefaultAirflowEstimationPlugin; import schedframe.resources.computing.profiles.energy.power.PState; import schedframe.resources.computing.profiles.energy.power.PowerProfile; import schedframe.resources.computing.profiles.energy.power.PowerState; import schedframe.resources.computing.profiles.energy.power.PowerStateName; import schedframe.resources.computing.profiles.energy.power.PowerStateNameFactory; import schedframe.resources.computing.profiles.energy.power.Transition; import schedframe.resources.computing.profiles.energy.power.plugin.EnergyEstimationPlugin; import schedframe.resources.computing.profiles.energy.thermal.ThermalProfile; import schedframe.resources.computing.profiles.energy.thermal.plugin.DefaultTemperatureEstimationPlugin; import schedframe.resources.computing.profiles.energy.thermal.plugin.TemperatureEstimationPlugin; import schedframe.resources.computing.profiles.load.LoadEstimationPluginFactory; import schedframe.resources.computing.profiles.load.LoadProfile; import schedframe.resources.computing.profiles.load.ResourceLoadCalendar; import schedframe.resources.computing.profiles.load.plugin.LoadEstimationPlugin; import schemas.PowerUsage; import schemas.Profile; import schemas.StringValueWithUnit; import simulator.utils.InstanceFactory; import example.energy.DefaultEnergyEstimationPlugin; import example.load.DefaultLoadEstimationPlugin; public class PhysicalResourceDescription extends ResourceDescription{ protected PowerProfile powerProfile; protected AirflowProfile airflowProfile; protected ThermalProfile thermalProfile; protected LoadProfile loadProfile; protected String category; protected Location location; public PhysicalResourceDescription(ResourceType type) { super(type); // TODO Auto-generated constructor stub } public void addChildren(PhysicalResourceDescription child) { super.addChildren(child); if(child.getLoadProfile().getLoadCalendar().getLoadDistribution().size() == 0){ child.getLoadProfile().getLoadCalendar().getLoadDistribution().addAll(this.getLoadProfile().getLoadCalendar().getLoadDistribution()); } } protected void initProfiles(Profile profile) { if (profile != null) { initPowerProfile(profile.getPowerProfile()); initAirflowProfile(profile.getAirThroughputProfile()); initThermalProfile(profile.getThermalProfile()); initLoadProfile(profile.getLoadProfile()); } else { initLoadProfile(null); } } protected void initPowerProfile(schemas.PowerProfile powerProfileCharacteristic) { if (powerProfileCharacteristic != null) { EnergyEstimationPlugin energyEstimationPlugin = null; List powerStates = null; List pStates = null; if(powerProfileCharacteristic.getEnergyEstimationPlugin() != null){ String energyEstimationPluginName = powerProfileCharacteristic.getEnergyEstimationPlugin().getName(); if(energyEstimationPluginName != null) { energyEstimationPlugin = (EnergyEstimationPlugin) InstanceFactory.createInstance( energyEstimationPluginName, EnergyEstimationPlugin.class); } else { energyEstimationPlugin = new DefaultEnergyEstimationPlugin(); } Parameters params = extractParameters(powerProfileCharacteristic.getEnergyEstimationPlugin().getParameter()); if(powerProfileCharacteristic.getEnergyEstimationPlugin().getPowerCapLevel() != null) { Parameter param = new Parameter("powerCapLevel"); StringValueWithUnit sv = new StringValueWithUnit(); sv.setContent(String.valueOf(powerProfileCharacteristic.getEnergyEstimationPlugin().getPowerCapLevel().getContent())); sv.setUnit(powerProfileCharacteristic.getEnergyEstimationPlugin().getPowerCapLevel().getUnit()); param.add(sv); if(params == null) params = new Parameters(2); params.put("powerCapLevel", param); } if(powerProfileCharacteristic.getEnergyEstimationPlugin().getPowerFloorLevel() != null) { Parameter param = new Parameter("powerFloorLevel"); StringValueWithUnit sv = new StringValueWithUnit(); sv.setContent(String.valueOf(powerProfileCharacteristic.getEnergyEstimationPlugin().getPowerFloorLevel().getContent())); sv.setUnit(powerProfileCharacteristic.getEnergyEstimationPlugin().getPowerFloorLevel().getUnit()); param.add(sv); if(params == null) params = new Parameters(2); params.put("powerFloorLevel", param); } energyEstimationPlugin.init(params); } if(powerProfileCharacteristic.getPowerStates() != null) { powerStates = new ArrayList(); int powerStateCount = powerProfileCharacteristic.getPowerStates().getPowerStateCount(); for (int i = 0; i < powerStateCount ; i++) { schemas.PowerState ps = powerProfileCharacteristic.getPowerStates().getPowerState(i); List transitions = new ArrayList(0); int transitionCount = ps.getTransitionCount(); for (int j = 0; j < transitionCount; j++) { schemas.Transition t = ps.getTransition(j); PowerStateName transName = t.getName() != null ? PowerStateNameFactory.createPowerStateName(t.getName()) : PowerStateNameFactory.createPowerStateName(ps.getName() + "_" + t.getTo()); Transition transition = new Transition(transName, PowerStateNameFactory.createPowerStateName(t.getTo()), t .getPowerUsage().getContent(), t.getTime().getContent()); Parameters params = extractParameters(t.getParameter()); transition.init(params); transitions.add(transition); } //CoolEmAll DEBB description case if(ps.getPowerUsage() == null){ ps.setPowerUsage(new PowerUsage("0")); } PowerState powerState = new PowerState(PowerStateNameFactory.createPowerStateName(ps.getName()), ps .getPowerUsage().getContent(), transitions); Parameters params = extractParameters(ps.getParameter()); powerState.init(params); powerStates.add(powerState); } } if(powerProfileCharacteristic.getParameter() != null){ pStates = new ArrayList(); int parameterCount = powerProfileCharacteristic.getParameterCount(); for(int i = 0; i < parameterCount; i++){ schemas.Parameter parameter = powerProfileCharacteristic.getParameter(i); if(parameter.getName().equals("pState")){ PState.Builder builder = new PState.Builder(); int propertyCount = parameter.getParameterTypeSequence().getPropertyCount(); for(int j = 0; j < propertyCount; j++){ schemas.Property property = parameter.getParameterTypeSequence().getProperty(j); if(property.getName().equals("name")){ builder = builder.name(property.getStringValueWithUnit(0).getContent()); } else if (property.getName().equals("frequency")){ builder = builder.frequency(Double.valueOf(property.getStringValueWithUnit(0).getContent())); } else if (property.getName().equals("voltage")){ builder = builder.voltage(Double.valueOf(property.getStringValueWithUnit(0).getContent())); } else if (property.getName().equals("powerUsage")){ if(property.getStringValueWithUnit(0).getContent() != null && property.getStringValueWithUnit(0).getContent().length() > 0){ builder = builder.powerUsage(Double.valueOf(property.getStringValueWithUnit(0).getContent())); } } else if (property.getName().equals("loadPowerUsage")){ if(property.getStringValueWithUnit(0).getContent() != null && property.getStringValueWithUnit(0).getContent().length() > 0 && property.getStringValueWithUnit(1).getContent() != null && property.getStringValueWithUnit(1).getContent().length() > 0){ //LoadPowerUsage lpu = new LoadPowerUsage(Double.valueOf(property.getStringValueWithUnit(0).getContent()), Double.valueOf(property.getStringValueWithUnit(1).getContent())); //builder = builder.loadPowerUsage(lpu); builder.loadPowerUsage(Double.valueOf(property.getStringValueWithUnit(0).getContent()), Double.valueOf(property.getStringValueWithUnit(1).getContent())); } } } PState pState = builder.build(); pStates.add(pState); } } } this.powerProfile = new PowerProfile(energyEstimationPlugin, powerStates, pStates); Parameters params = extractParameters(powerProfileCharacteristic.getParameter()); this.powerProfile.init(params); } } protected void initAirflowProfile(schemas.AirThroughputProfile airflowProfile) { if (airflowProfile != null) { AirflowEstimationPlugin airflowEstimationPlugin = null; List airflowStates = null; if(airflowProfile.getAirThroughputEstimationPlugin() != null){ String airflowEstimationPluginName = airflowProfile.getAirThroughputEstimationPlugin().getName(); if(airflowEstimationPluginName != null) { airflowEstimationPlugin = (AirflowEstimationPlugin) InstanceFactory.createInstance( airflowEstimationPluginName, AirflowEstimationPlugin.class); } else { airflowEstimationPlugin = new DefaultAirflowEstimationPlugin(); } Parameters params = extractParameters(airflowProfile.getAirThroughputEstimationPlugin().getParameter()); airflowEstimationPlugin.init(params); } if(airflowProfile.getAirThroughputStates() != null){ airflowStates = new ArrayList(); int airflowStateCount = airflowProfile.getAirThroughputStates().getAirThroughputStateCount(); for (int i = 0; i < airflowStateCount; i++) { schemas.AirThroughputState ats = airflowProfile.getAirThroughputStates().getAirThroughputState(i); AirflowState airflowState = new AirflowState(AirflowStateNameFactory.createAirflowStateName(ats.getName()), ats.getValue() .getContent(), ats.getPowerUsage().getContent()); Parameters params = extractParameters(ats.getParameter()); airflowState.init(params); airflowStates.add(airflowState); } } this.airflowProfile = new AirflowProfile(airflowEstimationPlugin, airflowStates); Parameters params = extractParameters(airflowProfile.getParameter()); this.airflowProfile.init(params); } } protected void initThermalProfile(schemas.ThermalProfile thermalProfile) { if (thermalProfile != null) { TemperatureEstimationPlugin temperatureEstimationPlugin = null; if(thermalProfile.getTemperatureEstimationPlugin() != null){ String temperatureEstimationPluginName = thermalProfile.getTemperatureEstimationPlugin().getName(); if(temperatureEstimationPluginName != null) { temperatureEstimationPlugin = (TemperatureEstimationPlugin) InstanceFactory.createInstance( temperatureEstimationPluginName, TemperatureEstimationPlugin.class); } else { temperatureEstimationPlugin = new DefaultTemperatureEstimationPlugin(); } Parameters params = extractParameters(thermalProfile.getTemperatureEstimationPlugin().getParameter()); temperatureEstimationPlugin.init(params); } this.thermalProfile = new ThermalProfile(); Parameters params = extractParameters(thermalProfile.getParameter()); this.thermalProfile.init(params); } } protected void initLoadProfile(schemas.LoadProfile loadProfile) { if (loadProfile != null) { LoadEstimationPlugin loadEstimationPlugin = null; if(loadProfile.getLoadEstimationPlugin() != null){ String loadEstimationPluginName = loadProfile.getLoadEstimationPlugin().getName(); if(loadEstimationPluginName != null) { loadEstimationPlugin = (LoadEstimationPlugin) InstanceFactory.createInstance( loadEstimationPluginName, LoadEstimationPlugin.class); } else { loadEstimationPlugin = new DefaultLoadEstimationPlugin(); } Parameters params = extractParameters(loadProfile.getLoadEstimationPlugin().getParameter()); loadEstimationPlugin.init(params); } ResourceLoadCalendar resLoadCalander = new ResourceLoadCalendar(loadProfile.getLoadCalendar()); this.loadProfile = new LoadProfile(loadEstimationPlugin, resLoadCalander); Parameters params = extractParameters(loadProfile.getParameter()); this.loadProfile.init(params); } else { ResourceLoadCalendar resLoadCalander = new ResourceLoadCalendar(); LoadEstimationPlugin loadEstimationPlugin = LoadEstimationPluginFactory.createLoadEstimationPlugi(getType()); this.loadProfile = new LoadProfile(loadEstimationPlugin, resLoadCalander); } } protected void initLocation(schemas.Location l) { if (location != null) { this.location = new Location(l.getHorizontal(), l.getVertical(), l.getDepth()); Parameters params = extractParameters(l.getParameter()); this.location.init(params); } } protected Parameters extractParameters(schemas.Parameter[] parameters){ Parameters params = null; if(parameters.length != 0) params = new Parameters(2); for(int i = 0; i < parameters.length; i++){ schemas.Parameter parameter = parameters[i]; Parameter param = new Parameter(parameter.getName()); if(parameter.getParameterTypeSequence() != null && parameter.getParameterTypeSequence().getProperty() != null) { int propertyCount = parameter.getParameterTypeSequence().getPropertyCount(); for(int j = 0; j < propertyCount; j++){ schemas.Property property = parameter.getParameterTypeSequence().getProperty(j); Property prop = new Property(property.getName()); int stringValueWithUnitCount = property.getStringValueWithUnitCount(); for(int k = 0; k < stringValueWithUnitCount; k++){ prop.add(property.getStringValueWithUnit(k)); } param.addProperty(prop); } } else { int stringValueWithUnitCount = parameter.getStringValueWithUnitCount(); for(int j = 0; j < stringValueWithUnitCount; j++){ param.add(parameter.getStringValueWithUnit(j)); } } params.put(parameter.getName(), param); } return params; } public PowerProfile getPowerProfile() { return powerProfile; } public AirflowProfile getAirflowProfile() { return airflowProfile; } public ThermalProfile getThermalProfile() { return thermalProfile; } public LoadProfile getLoadProfile() { return loadProfile; } public Location getLocation() { return location; } public String getCategory() { return category; } }