1 | package schedframe.resources.computing.profiles.energy.power.ui; |
---|
2 | |
---|
3 | import schedframe.resources.ResourceStatus; |
---|
4 | import schedframe.resources.computing.ComputingNode; |
---|
5 | import schedframe.resources.computing.ComputingResource; |
---|
6 | import schedframe.resources.computing.profiles.energy.EnergyEvent; |
---|
7 | import schedframe.resources.computing.profiles.energy.EnergyEventType; |
---|
8 | import schedframe.resources.computing.profiles.energy.power.PowerProfile; |
---|
9 | import schedframe.resources.computing.profiles.energy.power.PowerStateName; |
---|
10 | import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName; |
---|
11 | |
---|
12 | public class ComputingNodePowerInterface extends ComputingResourcePowerInterface{ |
---|
13 | |
---|
14 | public static long START_TIME = 600000; |
---|
15 | public static long SHUTDOWN_TIME = 300000; |
---|
16 | public static double START_COST = 4000; |
---|
17 | public static double SHUTDOWN_COST = 2000; |
---|
18 | |
---|
19 | |
---|
20 | public ComputingNodePowerInterface(ComputingResource resource, PowerProfile pp){ |
---|
21 | super(resource, pp); |
---|
22 | currentPowerState = StandardPowerStateName.ON; |
---|
23 | } |
---|
24 | |
---|
25 | public boolean setPowerState(PowerStateName state){ |
---|
26 | if(!supportPowerState(state)) |
---|
27 | return false; |
---|
28 | currentPowerState = state; |
---|
29 | ComputingNode computingNode = (ComputingNode) resource; |
---|
30 | boolean pePowerStateChangeStatus = false; |
---|
31 | if(computingNode.getProcessors() != null) |
---|
32 | { |
---|
33 | for(ComputingResource child:computingNode.getProcessors()){ |
---|
34 | if(child.getPowerInterface() != null){ |
---|
35 | pePowerStateChangeStatus = child.getPowerInterface().setPowerState(state); |
---|
36 | } |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | if(!pePowerStateChangeStatus){ |
---|
41 | computingNode.handleEvent(new EnergyEvent(EnergyEventType.POWER_STATE_CHANGED, computingNode.getName())); |
---|
42 | } |
---|
43 | |
---|
44 | if(state == StandardPowerStateName.OFF){ |
---|
45 | computingNode.setStatus(ResourceStatus.UNAVAILABLE); |
---|
46 | } |
---|
47 | else if(state == StandardPowerStateName.ON){ |
---|
48 | computingNode.setStatus(ResourceStatus.FREE); |
---|
49 | } |
---|
50 | //computingNode.handleEvent(new EnergyEvent(EnergyEventType.POWER_STATE_CHANGED, computingNode.getName())); |
---|
51 | return true; |
---|
52 | } |
---|
53 | |
---|
54 | public void turnOn(){ |
---|
55 | setPowerState(StandardPowerStateName.ON); |
---|
56 | } |
---|
57 | |
---|
58 | public void turnOff(){ |
---|
59 | setPowerState(StandardPowerStateName.OFF); |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | } |
---|