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