1 | package test.rewolucja.energy.profile; |
---|
2 | |
---|
3 | import schedframe.resources.PowerState; |
---|
4 | import schedframe.resources.profile.PowerUsage; |
---|
5 | import test.rewolucja.energy.EnergyEvent; |
---|
6 | import test.rewolucja.energy.EnergyEventType; |
---|
7 | import test.rewolucja.energy.extension.EnergyExtension; |
---|
8 | import test.rewolucja.resources.ResourceStatus; |
---|
9 | import test.rewolucja.resources.physical.base.ComputingResource; |
---|
10 | import test.rewolucja.resources.physical.implementation.CPU; |
---|
11 | import test.rewolucja.resources.physical.implementation.ComputingNode; |
---|
12 | import test.rewolucja.resources.physical.implementation.DataCenter; |
---|
13 | |
---|
14 | |
---|
15 | public abstract class AbstractPowerProfile implements PowerInterface{ |
---|
16 | |
---|
17 | protected PowerState powerState; |
---|
18 | protected EnergyExtension energyExtension; |
---|
19 | //protected Resource resource; |
---|
20 | |
---|
21 | public AbstractPowerProfile(){ |
---|
22 | } |
---|
23 | |
---|
24 | public void init(String arg){ |
---|
25 | System.out.println(this.getClass().getName() + " " + arg); |
---|
26 | } |
---|
27 | |
---|
28 | public PowerUsage getRecentPowerUsage(){ |
---|
29 | PowerUsage powerUsage = null; |
---|
30 | int lastIdx = energyExtension.getPowerUsageHistory().size() - 1; |
---|
31 | if(lastIdx >= 0) |
---|
32 | powerUsage = energyExtension.getPowerUsageHistory().get(lastIdx); |
---|
33 | return powerUsage; |
---|
34 | } |
---|
35 | |
---|
36 | public boolean setPowerState(PowerState state) { |
---|
37 | powerState = state; |
---|
38 | ComputingResource resource = energyExtension.getResource(); |
---|
39 | if(resource.getChildren() != null) |
---|
40 | { |
---|
41 | for(ComputingResource child:resource.getChildren()){ |
---|
42 | if(child.getPowerInterface().supportPowerState(state)) |
---|
43 | child.getPowerInterface().setPowerState(state); |
---|
44 | } |
---|
45 | } |
---|
46 | if(state == PowerState.OFF){ |
---|
47 | resource.setStatus(ResourceStatus.NOTAVAILABLE); |
---|
48 | } |
---|
49 | else if(state == PowerState.ON){ |
---|
50 | resource.setStatus(ResourceStatus.FREE); |
---|
51 | } |
---|
52 | //notifications from all levels |
---|
53 | resource.handleEvent(new EnergyEvent(EnergyEventType.POWER_STATE_CHANGED, resource.getName())); |
---|
54 | |
---|
55 | //notification from last level |
---|
56 | //if (resource.getChildren() == null) resource.handleEvent(new EnergyEvent(EnergyEventType.POWER_STATE_CHANGED, resource)); |
---|
57 | return true; |
---|
58 | } |
---|
59 | |
---|
60 | public PowerState getPowerState() { |
---|
61 | return powerState; |
---|
62 | } |
---|
63 | |
---|
64 | /*public double getCurrentPowerConsumption(){ |
---|
65 | return energyExtension.getEnergyEstimationPlugin().estimatePowerConsumption(null, JobRegistry.getInstance(energyExtension.getResource().getName()), energyExtension.getResource()); |
---|
66 | }*/ |
---|
67 | |
---|
68 | |
---|
69 | @Override |
---|
70 | public void visit(CPU processor) { |
---|
71 | throw new RuntimeException("Not implemented."); |
---|
72 | } |
---|
73 | |
---|
74 | @Override |
---|
75 | public void visit(ComputingNode node) { |
---|
76 | throw new RuntimeException("Not implemented."); |
---|
77 | } |
---|
78 | |
---|
79 | @Override |
---|
80 | public void visit(DataCenter dataCenter) { |
---|
81 | throw new RuntimeException("Not implemented."); |
---|
82 | } |
---|
83 | |
---|
84 | } |
---|