Ignore:
Timestamp:
11/26/13 11:56:07 (11 years ago)
Author:
wojtekp
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • DCWoRMS/branches/coolemall/src/schedframe/resources/computing/profiles/energy/EnergyExtension.java

    r1165 r1207  
    77 
    88import schedframe.events.Event; 
    9 import schedframe.resources.computing.ComputingResource; 
    109import schedframe.resources.computing.extensions.Extension; 
    1110import schedframe.resources.computing.extensions.ExtensionException; 
     
    2019import schedframe.resources.computing.profiles.energy.thermal.ThermalProfile; 
    2120import schedframe.resources.computing.profiles.energy.thermal.ui.ThermalInterface; 
     21import schedframe.resources.devices.PhysicalResource; 
    2222import schedframe.scheduling.manager.tasks.JobRegistryImpl; 
     23import simulator.DataCenterWorkloadSimulator; 
    2324 
    2425public class EnergyExtension implements Extension{ 
     
    3536        protected ThermalProfile thermalProfile; 
    3637         
    37         protected ComputingResource computingResource; 
    38  
    39  
    40         public EnergyExtension(ComputingResource computingResource, PowerInterface powerInterface, PowerProfile powerProfile) { 
     38        protected PhysicalResource resource; 
     39 
     40 
     41        /*public EnergyExtension(PhysicalResource resource, PowerInterface powerInterface, PowerProfile powerProfile) { 
     42                super(); 
     43                this.resource = resource; 
    4144                this.powerProfile = powerProfile; 
    42                 this.powerInterface = PowerInterfaceFactory.createPowerInterface(computingResource, powerProfile); 
    43         } 
    44          
    45         public EnergyExtension(ComputingResource computingResource, PowerProfile powerProfile, 
     45                this.powerInterface = PowerInterfaceFactory.createPowerInterface(resource, powerProfile); 
     46        } 
     47         
     48        public EnergyExtension(PhysicalResource resource, PowerProfile powerProfile, 
    4649                        AirThroughputProfile airFlowProfile) { 
    4750                super(); 
    48                 this.computingResource = computingResource; 
     51                this.resource = resource; 
    4952                this.powerProfile = powerProfile; 
    50                 this.powerInterface = PowerInterfaceFactory.createPowerInterface(computingResource, powerProfile); 
     53                this.powerInterface = PowerInterfaceFactory.createPowerInterface(resource, powerProfile); 
    5154                this.airFlowProfile = airFlowProfile; 
    52                 this.airFlowInterface = AirThroughputInterfaceFactory.createAirThroughputInterface(computingResource, airFlowProfile); 
    53         } 
    54          
    55         public EnergyExtension(ComputingResource computingResource, PowerProfile powerProfile, 
     55                this.airFlowInterface = AirThroughputInterfaceFactory.createAirThroughputInterface(resource, airFlowProfile); 
     56        } 
     57         
     58        public EnergyExtension(PhysicalResource resource, PowerProfile powerProfile, 
    5659                        AirThroughputProfile airFlowProfile, ThermalProfile thermalProfile) { 
    5760                super(); 
    58                 this.computingResource = computingResource; 
     61                this.resource = resource; 
    5962                this.powerProfile = powerProfile; 
    60                 this.powerInterface = PowerInterfaceFactory.createPowerInterface(computingResource, powerProfile); 
     63                this.powerInterface = PowerInterfaceFactory.createPowerInterface(resource, powerProfile); 
    6164                this.airFlowProfile = airFlowProfile; 
    62                 this.airFlowInterface = AirThroughputInterfaceFactory.createAirThroughputInterface(computingResource, airFlowProfile); 
     65                this.airFlowInterface = AirThroughputInterfaceFactory.createAirThroughputInterface(resource, airFlowProfile); 
    6366                this.thermalProfile = thermalProfile; 
    64                 this.thermalInterface = ThermalInterfaceFactory.createThermalInterface(computingResource, thermalProfile); 
    65         } 
    66  
     67                this.thermalInterface = ThermalInterfaceFactory.createThermalInterface(resource, thermalProfile); 
     68        }*/ 
     69 
     70        public static class Builder { 
     71                   
     72                protected PhysicalResource resource; 
     73                protected PowerInterface powerInterface; 
     74                protected PowerProfile powerProfile; 
     75                 
     76                protected AirThroughputInterface airFlowInterface; 
     77                protected AirThroughputProfile airFlowProfile; 
     78                 
     79                protected ThermalInterface thermalInterface; 
     80                protected ThermalProfile thermalProfile; 
     81                 
     82                public Builder resource(PhysicalResource res) {this.resource = res; return this;} 
     83                 
     84                public Builder powerProfile(PowerProfile pp){this.powerProfile = pp; this.powerInterface = PowerInterfaceFactory.createPowerInterface(resource, powerProfile); return this; } 
     85 
     86        public Builder airFlowProfile(AirThroughputProfile atp){this.airFlowProfile = atp; this.airFlowInterface = AirThroughputInterfaceFactory.createAirThroughputInterface(resource, airFlowProfile); return this; } 
     87 
     88        public Builder thermalProfile(ThermalProfile tp){this.thermalProfile = tp; this.thermalInterface = ThermalInterfaceFactory.createThermalInterface(resource, thermalProfile); return this; } 
     89 
     90        public EnergyExtension build() { 
     91            return new EnergyExtension(this); 
     92        } 
     93        } 
     94         
     95        private EnergyExtension(Builder builder) { 
     96                this.resource = builder.resource; 
     97                this.powerInterface = builder.powerInterface; 
     98                this.powerProfile = builder.powerProfile; 
     99                 
     100                this.airFlowInterface = builder.airFlowInterface ; 
     101                this.airFlowProfile = builder.airFlowProfile; 
     102                 
     103                this.thermalInterface = builder.thermalInterface; 
     104                this.thermalProfile = builder.thermalProfile; 
     105        } 
     106 
     107         
    67108        public boolean supportsEvent(Event event) { 
    68109 
     
    82123                if(event.getType().getName().equals(EnergyEventType.AIRFLOW_STATE_CHANGED.getName())) 
    83124                        return true; 
     125                if(event.getType().getName().equals(EnergyEventType.TEMPERATURE_CHANGED.getName())) 
     126                        return true; 
    84127                 
    85128                else return false; 
     
    90133                EnergyEvent enEvent = (EnergyEvent)event; 
    91134                double power = 0; 
    92                 double temperature = 0; 
     135                boolean status = false; 
    93136                try{ 
    94137                        switch (enEvent.getType()) { 
    95138                         
    96139                        case POWER_STATE_CHANGED: 
    97                                 power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource); 
     140                                power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(resource.getFullName()), resource); 
    98141                                /*if(computingResource instanceof ComputingNode){ 
    99142                                        ComputingNode node = (ComputingNode)computingResource; 
     
    109152                                        } 
    110153                                } 
    111                                 else*/ powerProfile.addToPowerUsageHistory(power); 
    112                                 temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource); 
    113                                 thermalProfile.addToTemperatureHistory(temperature); 
     154                                else*/  
     155                                 
     156                                status = powerProfile.addToPowerUsageHistory(power); 
    114157                                break; 
    115158                                 
    116159                        case FREQUENCY_CHANGED: 
    117                                 power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource); 
    118                                 powerProfile.addToPowerUsageHistory(power); 
    119                                 temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource); 
    120                                 thermalProfile.addToTemperatureHistory(temperature); 
     160                                power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(resource.getFullName()), resource); 
     161                                status = powerProfile.addToPowerUsageHistory(power); 
    121162                                break; 
    122163                                 
    123164                        case TASK_STARTED: 
    124                                 power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource); 
    125                                 powerProfile.addToPowerUsageHistory(power); 
    126                                 temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource); 
    127                                 thermalProfile.addToTemperatureHistory(temperature); 
     165                                power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(resource.getFullName()), resource); 
     166                                status = powerProfile.addToPowerUsageHistory(power); 
    128167                                break; 
    129168         
    130169                        case TASK_FINISHED: 
    131                                 //System.out.println(this.resource.getName() + " - ENERGY EXTENSION: TASK FINISHED"); 
    132                                 power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource); 
    133                                 //System.out.println(this.resource.getName() + " - ESTIMATED ENERGY:" + power); 
    134                                 powerProfile.addToPowerUsageHistory(power); 
    135                                 temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource); 
    136                                 thermalProfile.addToTemperatureHistory(temperature); 
     170                                power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(resource.getFullName()), resource); 
     171                                status = powerProfile.addToPowerUsageHistory(power); 
    137172                                break; 
    138173                                 
    139174                        case RESOURCE_UTILIZATION_CHANGED: 
    140                                 power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource); 
    141                                 powerProfile.addToPowerUsageHistory(power); 
    142                                 temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource); 
    143                                 thermalProfile.addToTemperatureHistory(temperature); 
     175                                power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(resource.getFullName()), resource); 
     176                                status = powerProfile.addToPowerUsageHistory(power); 
    144177                                break; 
    145178                                 
    146179                        case AIRFLOW_STATE_CHANGED: 
    147                                 double airFlow = powerProfile.getEnergyEstimationPlugin().estimateAirThroughput(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource); 
    148                                 airFlowProfile.addToPowerUsageHistory(airFlow); 
    149                                 power = powerProfile.getEnergyEstimationPlugin().estimatePowerConsumption(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource); 
    150                                 powerProfile.addToPowerUsageHistory(power); 
    151                                 temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(computingResource.getName()), computingResource); 
     180                                double airFlow = powerProfile.getEnergyEstimationPlugin().estimateAirThroughput(enEvent, new JobRegistryImpl(resource.getFullName()), resource); 
     181                                airFlowProfile.addToAirFlowHistory(airFlow); 
     182                                break; 
     183                                 
     184                        case TEMPERATURE_CHANGED: 
     185                                double temperature = powerProfile.getEnergyEstimationPlugin().estimateTemperature(enEvent, new JobRegistryImpl(resource.getFullName()), resource); 
    152186                                thermalProfile.addToTemperatureHistory(temperature); 
    153187                                break; 
     
    156190                         
    157191                } 
     192                if(status){ 
     193                        DataCenterWorkloadSimulator.getEventManager().sendToResources(resource.getType(), 0, new EnergyEvent(EnergyEventType.TEMPERATURE_CHANGED, resource.getFullName())); 
     194                } 
    158195        } 
    159196 
Note: See TracChangeset for help on using the changeset viewer.