source: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/energy/EnergyExtension.java @ 1596

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