source: DCWoRMS/branches/coolemall/src/schedframe/resources/devices/DeviceEnergyExtension.java @ 1207

Revision 1207, 9.4 KB checked in by wojtekp, 11 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.resources.devices;
2
3import java.util.Properties;
4
5import org.apache.commons.logging.Log;
6import org.apache.commons.logging.LogFactory;
7
8import schedframe.events.Event;
9import schedframe.resources.computing.ComputingResource;
10import schedframe.resources.computing.extensions.Extension;
11import schedframe.resources.computing.extensions.ExtensionException;
12import schedframe.resources.computing.extensions.ExtensionType;
13import schedframe.resources.computing.profiles.energy.EnergyEvent;
14import schedframe.resources.computing.profiles.energy.EnergyEventType;
15import schedframe.resources.computing.profiles.energy.EnergyExtension;
16import schedframe.resources.computing.profiles.energy.EnergyExtension.Builder;
17import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputInterfaceFactory;
18import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputProfile;
19import schedframe.resources.computing.profiles.energy.airthroughput.ui.AirThroughputInterface;
20import schedframe.resources.computing.profiles.energy.power.PowerInterfaceFactory;
21import schedframe.resources.computing.profiles.energy.power.PowerProfile;
22import schedframe.resources.computing.profiles.energy.power.ui.PowerInterface;
23import schedframe.resources.computing.profiles.energy.thermal.ThermalInterfaceFactory;
24import schedframe.resources.computing.profiles.energy.thermal.ThermalProfile;
25import schedframe.resources.computing.profiles.energy.thermal.ui.ThermalInterface;
26import schedframe.scheduling.manager.tasks.JobRegistryImpl;
27import simulator.DataCenterWorkloadSimulator;
28
29public class DeviceEnergyExtension implements Extension{
30
31        private Log log = LogFactory.getLog(EnergyExtension.class);
32
33        protected PowerInterface powerInterface;
34        protected PowerProfile powerProfile;
35       
36        protected AirThroughputInterface airFlowInterface;
37        protected AirThroughputProfile airFlowProfile;
38       
39        protected ThermalInterface thermalInterface;
40        protected ThermalProfile thermalProfile;
41       
42        protected PhysicalResource resource;
43
44
45        public static class Builder {
46                 
47                protected PhysicalResource resource;
48                protected PowerInterface powerInterface;
49                protected PowerProfile powerProfile;
50               
51                protected AirThroughputInterface airFlowInterface;
52                protected AirThroughputProfile airFlowProfile;
53               
54                protected ThermalInterface thermalInterface;
55                protected ThermalProfile thermalProfile;
56               
57                public Builder resource(PhysicalResource res) {this.resource = res; return this;}
58               
59                public Builder powerProfile(PowerProfile pp){this.powerProfile = pp; this.powerInterface = PowerInterfaceFactory.createPowerInterface(resource, powerProfile); return this; }
60
61        public Builder airFlowProfile(AirThroughputProfile atp){this.airFlowProfile = atp; this.airFlowInterface = AirThroughputInterfaceFactory.createAirThroughputInterface(resource, airFlowProfile); return this; }
62
63        public Builder thermalProfile(ThermalProfile tp){this.thermalProfile = tp; this.thermalInterface = ThermalInterfaceFactory.createThermalInterface(resource, thermalProfile); return this; }
64
65        public DeviceEnergyExtension build() {
66            return new DeviceEnergyExtension(this);
67        }
68        }
69       
70        private DeviceEnergyExtension(Builder builder) {
71                this.resource = builder.resource;
72                this.powerInterface = builder.powerInterface;
73                this.powerProfile = builder.powerProfile;
74               
75                this.airFlowInterface = builder.airFlowInterface ;
76                this.airFlowProfile = builder.airFlowProfile;
77               
78                this.thermalInterface = builder.thermalInterface;
79                this.thermalProfile = builder.thermalProfile;
80        }
81
82       
83        public boolean supportsEvent(Event event) {
84
85                if(powerProfile == null || powerProfile.getEnergyEstimationPlugin() == null)
86                        return false;
87                if(event.getType().getName().equals(EnergyEventType.POWER_STATE_CHANGED.getName()))
88                        return true;
89                else if(event.getType().getName().equals(EnergyEventType.FREQUENCY_CHANGED.getName()))
90                        return true;
91                else if(event.getType().getName().equals(EnergyEventType.TASK_STARTED.getName()))
92                        return true;
93                else if(event.getType().getName().equals(EnergyEventType.TASK_FINISHED.getName()))
94                        return true;
95                else if(event.getType().getName().equals(EnergyEventType.RESOURCE_UTILIZATION_CHANGED.getName()))
96                        return true;
97       
98                if(event.getType().getName().equals(EnergyEventType.AIRFLOW_STATE_CHANGED.getName()))
99                        return true;
100                if(event.getType().getName().equals(EnergyEventType.TEMPERATURE_CHANGED.getName()))
101                        return true;
102               
103                else return false;
104        }
105
106        public void handleEvent(Event event) {
107               
108                EnergyEvent enEvent = (EnergyEvent)event;
109                double power = 0;
110                boolean status = false;
111                try{
112                        switch (enEvent.getType()) {
113                       
114                        case POWER_STATE_CHANGED:
115                                power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(resource.getFullName()), resource);
116                                /*if(computingResource instanceof ComputingNode){
117                                        ComputingNode node = (ComputingNode)computingResource;
118                                        if(event.getData() instanceof PowerState){
119                                                PowerState newState = (PowerState)event.getData();
120                                                if(newState == PowerState.ON) {
121                                                        addToPowerUsageHistory(power+node.getPowerInterface().START_COST);
122                                                        addToPowerUsageHistory(DateTimeUtils.currentTimeMillis() + node.getPowerInterface().START_TIME, power);
123                                                }else if(newState == PowerState.OFF){
124                                                        addToPowerUsageHistory(power+node.getPowerInterface().SHUTDOWN_COST);
125                                                        addToPowerUsageHistory(DateTimeUtils.currentTimeMillis() + node.getPowerInterface().SHUTDOWN_TIME, power);
126                                                }
127                                        }
128                                }
129                                else*/
130                               
131                                status = powerProfile.addToPowerUsageHistory(power);
132                                //temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource);
133                                //thermalProfile.addToTemperatureHistory(temperature);
134                                break;
135                               
136                        case FREQUENCY_CHANGED:
137                                power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(resource.getFullName()), resource);
138                                status = powerProfile.addToPowerUsageHistory(power);
139                                //temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource);
140                                //thermalProfile.addToTemperatureHistory(temperature);
141                                break;
142                               
143                        case TASK_STARTED:
144                                power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(resource.getFullName()), resource);
145                                status = powerProfile.addToPowerUsageHistory(power);
146                                //temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource);
147                                //thermalProfile.addToTemperatureHistory(temperature);
148                                break;
149       
150                        case TASK_FINISHED:
151                                power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(resource.getFullName()), resource);
152                                status = powerProfile.addToPowerUsageHistory(power);
153                                //temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource);
154                                //thermalProfile.addToTemperatureHistory(temperature);
155                                break;
156                               
157                        case RESOURCE_UTILIZATION_CHANGED:
158                                power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(resource.getFullName()), resource);
159                                status = powerProfile.addToPowerUsageHistory(power);
160                                //temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource);
161                                //thermalProfile.addToTemperatureHistory(temperature);
162                                break;
163                               
164                        case AIRFLOW_STATE_CHANGED:
165                                double airFlow = powerProfile.getEnergyEstimationPlugin().estimateAirThroughput(enEvent, new JobRegistryImpl(resource.getFullName()), resource);
166                                airFlowProfile.addToAirFlowHistory(airFlow);
167                                power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(resource.getFullName()), resource);
168                                powerProfile.addToPowerUsageHistory(power);
169                                //temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource);
170                                //thermalProfile.addToTemperatureHistory(temperature);
171                                break;
172                               
173                        case TEMPERATURE_CHANGED:
174                                double temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(resource.getFullName()), resource);
175                                thermalProfile.addToTemperatureHistory(temperature);
176                                break;
177                        }
178                }catch(Exception e){
179                       
180                }
181                if(status){
182                        DataCenterWorkloadSimulator.getEventManager().sendToResources(resource.getType(), 0, new EnergyEvent(EnergyEventType.TEMPERATURE_CHANGED, resource.getFullName()));
183
184                }
185        }
186
187        public void init(Properties properties) throws ExtensionException {
188                // TODO Auto-generated method stub
189        }
190
191        public ExtensionType getType() {
192                return ExtensionType.ENERGY_EXTENSION;
193        }
194
195        /*public ComputingResource getResource() {
196                return computingResource;
197        }
198
199        public void setResource(ComputingResource compRes){
200                this.computingResource = compRes;
201        }*/
202
203        public PowerInterface getPowerInterface() {
204                return powerInterface;
205        }
206
207        public PowerProfile getPowerProfile() {
208                return powerProfile;
209        }
210
211        public AirThroughputInterface getAirThroughputInterface() {
212                return airFlowInterface;
213        }
214
215        public AirThroughputProfile getAirFlowProfile() {
216                return airFlowProfile;
217        }
218       
219        public ThermalProfile getThermalProfile() {
220                return thermalProfile;
221        }
222
223        public ThermalInterface getThermalInterface() {
224                return thermalInterface;
225        }
226
227}
Note: See TracBrowser for help on using the repository browser.