package schedframe.resources.computing.profiles.energy; import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import schedframe.events.Event; import schedframe.resources.computing.Node; import schedframe.resources.computing.Processor; import schedframe.resources.computing.extensions.Extension; import schedframe.resources.computing.extensions.ExtensionException; import schedframe.resources.computing.extensions.ExtensionType; import schedframe.resources.computing.profiles.energy.airthroughput.AirflowInterfaceFactory; import schedframe.resources.computing.profiles.energy.airthroughput.AirflowProfile; import schedframe.resources.computing.profiles.energy.airthroughput.ui.AirflowInterface; import schedframe.resources.computing.profiles.energy.power.PowerInterfaceFactory; import schedframe.resources.computing.profiles.energy.power.PowerProfile; import schedframe.resources.computing.profiles.energy.power.PowerStateName; import schedframe.resources.computing.profiles.energy.power.ui.PowerInterface; import schedframe.resources.computing.profiles.energy.thermal.ThermalInterfaceFactory; import schedframe.resources.computing.profiles.energy.thermal.ThermalProfile; import schedframe.resources.computing.profiles.energy.thermal.ui.ThermalInterface; import schedframe.resources.devices.PhysicalResource; import schedframe.scheduling.manager.tasks.JobRegistryImpl; import simulator.DataCenterWorkloadSimulator; public class EnergyExtension implements Extension{ private Log log = LogFactory.getLog(EnergyExtension.class); protected PowerInterface powerInterface; protected PowerProfile powerProfile; protected AirflowInterface airflowInterface; protected AirflowProfile airflowProfile; protected ThermalInterface thermalInterface; protected ThermalProfile thermalProfile; protected PhysicalResource resource; /*public EnergyExtension(PhysicalResource resource, PowerInterface powerInterface, PowerProfile powerProfile) { super(); this.resource = resource; this.powerProfile = powerProfile; this.powerInterface = PowerInterfaceFactory.createPowerInterface(resource, powerProfile); } public EnergyExtension(PhysicalResource resource, PowerProfile powerProfile, AirThroughputProfile airFlowProfile) { super(); this.resource = resource; this.powerProfile = powerProfile; this.powerInterface = PowerInterfaceFactory.createPowerInterface(resource, powerProfile); this.airFlowProfile = airFlowProfile; this.airFlowInterface = AirThroughputInterfaceFactory.createAirThroughputInterface(resource, airFlowProfile); } public EnergyExtension(PhysicalResource resource, PowerProfile powerProfile, AirThroughputProfile airFlowProfile, ThermalProfile thermalProfile) { super(); this.resource = resource; this.powerProfile = powerProfile; this.powerInterface = PowerInterfaceFactory.createPowerInterface(resource, powerProfile); this.airFlowProfile = airFlowProfile; this.airFlowInterface = AirThroughputInterfaceFactory.createAirThroughputInterface(resource, airFlowProfile); this.thermalProfile = thermalProfile; this.thermalInterface = ThermalInterfaceFactory.createThermalInterface(resource, thermalProfile); }*/ public static class Builder { protected PhysicalResource resource; protected PowerInterface powerInterface; protected PowerProfile powerProfile; protected AirflowInterface airflowInterface; protected AirflowProfile airflowProfile; protected ThermalInterface thermalInterface; protected ThermalProfile thermalProfile; public Builder resource(PhysicalResource res) {this.resource = res; return this;} public Builder powerProfile(PowerProfile pp){this.powerProfile = pp; this.powerInterface = PowerInterfaceFactory.createPowerInterface(resource, powerProfile); return this; } public Builder airflowProfile(AirflowProfile atp){this.airflowProfile = atp; this.airflowInterface = AirflowInterfaceFactory.createAirflowInterface(resource, airflowProfile); return this; } public Builder thermalProfile(ThermalProfile tp){this.thermalProfile = tp; this.thermalInterface = ThermalInterfaceFactory.createThermalInterface(resource, thermalProfile); return this; } public EnergyExtension build() { return new EnergyExtension(this); } } private EnergyExtension(Builder builder) { this.resource = builder.resource; this.powerInterface = builder.powerInterface; this.powerProfile = builder.powerProfile; this.airflowInterface = builder.airflowInterface ; this.airflowProfile = builder.airflowProfile; this.thermalInterface = builder.thermalInterface; this.thermalProfile = builder.thermalProfile; } public boolean supportsEvent(Event event) { if(powerProfile == null || powerProfile.getEnergyEstimationPlugin() == null) return false; if(event.getType().getName().equals(ResourceEventType.UTILIZATION_CHANGED.getName())) return true; else if(event.getType().getName().equals(ResourceEventType.TASK_STARTED.getName())) return true; else if(event.getType().getName().equals(ResourceEventType.TASK_FINISHED.getName())) return true; else if(event.getType().getName().equals(ResourceEventType.POWER_STATE_CHANGED.getName())) return true; else if(event.getType().getName().equals(ResourceEventType.CPU_FREQUENCY_CHANGED.getName())) return true; else if(event.getType().getName().equals(ResourceEventType.UPDATE_POWER_STATE.getName())) return true; if(event.getType().getName().equals(ResourceEventType.AIRFLOW_STATE_CHANGED.getName())) return true; if(event.getType().getName().equals(ResourceEventType.TEMPERATURE_CHANGED.getName())) return true; if(event.getType().getName().equals(ResourceEventType.TIMER.getName())) return true; else return false; } public void handleEvent(Event event) { ResourceEvent resEvent = (ResourceEvent)event; double power = 0; boolean status = false; try{ switch (resEvent.getType()) { case UTILIZATION_CHANGED: power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(resEvent, new JobRegistryImpl(resource.getFullName()), resource); status = powerProfile.addToPowerUsageHistory(power); break; case TASK_STARTED: power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(resEvent, new JobRegistryImpl(resource.getFullName()), resource); status = powerProfile.addToPowerUsageHistory(power); break; case TASK_FINISHED: power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(resEvent, new JobRegistryImpl(resource.getFullName()), resource); status = powerProfile.addToPowerUsageHistory(power); break; case POWER_STATE_CHANGED: power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(resEvent, new JobRegistryImpl(resource.getFullName()), resource); status = powerProfile.addToPowerUsageHistory(power); break; case CPU_FREQUENCY_CHANGED: power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(resEvent, new JobRegistryImpl(resource.getFullName()), resource); status = powerProfile.addToPowerUsageHistory(power); break; case UPDATE_POWER_STATE: if(resource.getFullName().equals(resEvent.getSource())){ PowerStateName newPowerState = (PowerStateName) resEvent.getData(); powerInterface.setPowerState(newPowerState); } break; case AIRFLOW_STATE_CHANGED: double airflow = powerProfile.getEnergyEstimationPlugin().estimateAirflow(resEvent, new JobRegistryImpl(resource.getFullName()), resource); airflowProfile.addToAirFlowHistory(airflow); break; case TEMPERATURE_CHANGED: double temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(resEvent, new JobRegistryImpl(resource.getFullName()), resource); thermalProfile.addToTemperatureHistory(temperature); break; case TIMER: power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(resEvent, new JobRegistryImpl(resource.getFullName()), resource); status = powerProfile.addToPowerUsageHistory(power); if(resource instanceof Processor || resource instanceof Node){ temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(resEvent, new JobRegistryImpl(resource.getFullName()), resource); thermalProfile.addToTemperatureHistory(temperature); } break; } }catch(Exception e){ } if(status){ DataCenterWorkloadSimulator.getEventManager().sendToResources(resource.getType(), 0, new ResourceEvent(ResourceEventType.TEMPERATURE_CHANGED, resource.getFullName())); } } public void init(Properties properties) throws ExtensionException { // TODO Auto-generated method stub } public ExtensionType getType() { return ExtensionType.ENERGY_EXTENSION; } /*public ComputingResource getResource() { return computingResource; } public void setResource(ComputingResource compRes){ this.computingResource = compRes; }*/ public PowerInterface getPowerInterface() { return powerInterface; } public PowerProfile getPowerProfile() { return powerProfile; } public AirflowInterface getAirflowInterface() { return airflowInterface; } public AirflowProfile getAirflowProfile() { return airflowProfile; } public ThermalProfile getThermalProfile() { return thermalProfile; } public ThermalInterface getThermalInterface() { return thermalInterface; } }