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