source: DCWoRMS/trunk/src/schedframe/resources/computing/profiles/energy/EnergyExtension.java @ 755

Revision 755, 6.1 KB checked in by wojtekp, 12 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.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.airthroughput.AirThroughputInterfaceFactory;
14import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputProfile;
15import schedframe.resources.computing.profiles.energy.airthroughput.ui.AirThroughputInterface;
16import schedframe.resources.computing.profiles.energy.power.PowerInterfaceFactory;
17import schedframe.resources.computing.profiles.energy.power.PowerProfile;
18import schedframe.resources.computing.profiles.energy.power.ui.PowerInterface;
19import schedframe.scheduling.manager.tasks.JobRegistryImpl;
20
21public class EnergyExtension implements Extension{
22
23        private Log log = LogFactory.getLog(EnergyExtension.class);
24
25        protected PowerInterface powerInterface;
26        protected PowerProfile powerProfile;
27       
28        protected AirThroughputInterface airFlowInterface;
29        protected AirThroughputProfile airFlowProfile;
30       
31        protected ComputingResource computingResource;
32
33        public EnergyExtension(PowerInterface powerInterface, PowerProfile pp) {
34                this.powerInterface = powerInterface;
35                this.powerProfile = pp;
36        }
37
38        public EnergyExtension(PowerInterface powerInterface, PowerProfile powerProfile,
39                        AirThroughputInterface airFlowInterface, AirThroughputProfile airFlowProfile) {
40                super();
41                this.powerInterface = powerInterface;
42                this.powerProfile = powerProfile;
43                this.airFlowInterface = airFlowInterface;
44                this.airFlowProfile = airFlowProfile;
45        }
46       
47        public EnergyExtension(ComputingResource computingResource, PowerProfile powerProfile,
48                        AirThroughputProfile airFlowProfile) {
49                super();
50                this.computingResource = computingResource;
51                this.powerProfile = powerProfile;
52                this.powerInterface = PowerInterfaceFactory.createPowerInterface(computingResource, powerProfile);
53                this.airFlowProfile = airFlowProfile;
54                this.airFlowInterface = AirThroughputInterfaceFactory.createAirThroughputInterface(computingResource, airFlowProfile);
55        }
56
57        public boolean supportsEvent(Event event) {
58
59                if(powerProfile == null || powerProfile.getEnergyEstimationPlugin() == null)
60                        return false;
61                if(event.getType().getName().equals(EnergyEventType.POWER_STATE_CHANGED.getName()))
62                        return true;
63                else if(event.getType().getName().equals(EnergyEventType.FREQUENCY_CHANGED.getName()))
64                        return true;
65                else if(event.getType().getName().equals(EnergyEventType.TASK_STARTED.getName()))
66                        return true;
67                else if(event.getType().getName().equals(EnergyEventType.TASK_FINISHED.getName()))
68                        return true;
69               
70                if(airFlowProfile == null)
71                        return false;   
72                if(event.getType().getName().equals(EnergyEventType.AIRFLOW_STATE_CHANGED.getName()))
73                        return true;
74               
75                else return false;
76        }
77
78        public void handleEvent(Event event) {
79                EnergyEvent enEvent = (EnergyEvent)event;
80                double power = 0;
81                switch (enEvent.getType()) {
82               
83                case POWER_STATE_CHANGED:
84                        power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource);
85                        /*if(resource instanceof ComputingNode){
86                                ComputingNode node = (ComputingNode)resource;
87                                if(event.getData() instanceof PowerState){
88                                        PowerState newState = (PowerState)event.getData();
89                                        if(newState == PowerState.ON) {
90                                                addToPowerUsageHistory(power+node.getPowerInterface().START_COST);
91                                                addToPowerUsageHistory(DateTimeUtils.currentTimeMillis()+node.getPowerInterface().START_TIME, power);
92                                        }else if(newState == PowerState.OFF){
93                                                addToPowerUsageHistory(power+node.getPowerInterface().SHUTDOWN_COST);
94                                                addToPowerUsageHistory(DateTimeUtils.currentTimeMillis()+node.getPowerInterface().SHUTDOWN_TIME, power);
95                                        }
96                                }
97                        }
98                        else */powerProfile.addToPowerUsageHistory(power);
99                        break;
100                       
101                case FREQUENCY_CHANGED:
102                        power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource);
103                        powerProfile.addToPowerUsageHistory(power);
104                        break;
105                       
106                case TASK_STARTED:
107                        power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource);
108                        powerProfile.addToPowerUsageHistory(power);
109                        break;
110
111                case TASK_FINISHED:
112                        //System.out.println(this.resource.getName() + " - ENERGY EXTENSION: TASK FINISHED");
113                        power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource);
114                        //System.out.println(this.resource.getName() + " - ESTIMATED ENERGY:" + power);
115                        powerProfile.addToPowerUsageHistory(power);
116                        break;
117                case AIRFLOW_STATE_CHANGED:
118                        System.out.println("=====" + computingResource.getName());
119                        double airFlow = powerProfile.getEnergyEstimationPlugin().estimateAirThroughput(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource);
120                        airFlowProfile.addToPowerUsageHistory(airFlow);
121                        power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource);
122                        powerProfile.addToPowerUsageHistory(power);
123                        break;
124                }
125        }
126
127        public void init(Properties properties) throws ExtensionException {
128                // TODO Auto-generated method stub
129        }
130
131        public ExtensionType getType() {
132                return ExtensionType.ENERGY_EXTENSION;
133        }
134
135        /*public ComputingResource getResource() {
136                return computingResource;
137        }
138
139        public void setResource(ComputingResource compRes){
140                this.computingResource = compRes;
141        }*/
142
143        public PowerInterface getPowerInterface() {
144                return powerInterface;
145        }
146
147        public PowerProfile getPowerProfile() {
148                return powerProfile;
149        }
150
151        public AirThroughputInterface getAirThroughputInterface() {
152                return airFlowInterface;
153        }
154
155        public AirThroughputProfile getAirFlowProfile() {
156                return airFlowProfile;
157        }
158
159}
Note: See TracBrowser for help on using the repository browser.