1 | package schedframe.resources.computing; |
---|
2 | |
---|
3 | import java.util.List; |
---|
4 | import java.util.Properties; |
---|
5 | |
---|
6 | import schedframe.resources.ResourceStatus; |
---|
7 | import schedframe.resources.StandardResourceType; |
---|
8 | import schedframe.resources.computing.description.ComputingResourceDescription; |
---|
9 | import schedframe.resources.computing.extensions.ExtensionType; |
---|
10 | import schedframe.resources.computing.profiles.energy.EnergyExtension; |
---|
11 | import schedframe.resources.computing.profiles.energy.power.ui.ComputingNodePowerInterface; |
---|
12 | import schedframe.resources.computing.properties.ComputingNodePropertiesBuilder; |
---|
13 | import schedframe.resources.computing.properties.PropertiesDirector; |
---|
14 | import schedframe.resources.units.Cost; |
---|
15 | import schedframe.resources.units.Memory; |
---|
16 | import schedframe.resources.units.StandardResourceUnitName; |
---|
17 | |
---|
18 | public class ComputingNode extends ComputingResource{ |
---|
19 | |
---|
20 | |
---|
21 | public ComputingNode (ComputingResourceDescription resDesc) { |
---|
22 | super(resDesc); |
---|
23 | |
---|
24 | //extensionList.add(new EnergyExtension(this, resDesc.getPowerInterface(), resDesc.getEnergyEstimationPlugin())); |
---|
25 | //PowerInterface pi = PowerInterfaceFactory.createPowerInterface(this, resDesc.getPowerProfile()); |
---|
26 | //AirThroughputInterface ai = AirThroughputInterfaceFactory.createAirThroughputInterface(this, resDesc.getAirThroughputProfile()); |
---|
27 | //accept(new EnergyExtension(pi, resDesc.getPowerProfile())); |
---|
28 | //accept(new EnergyExtension(pi, resDesc.getPowerProfile(), ai, resDesc.getAirThroughputProfile())); |
---|
29 | } |
---|
30 | |
---|
31 | public ComputingNodePowerInterface getPowerInterface(){ |
---|
32 | ComputingNodePowerInterface powerInterface = null; |
---|
33 | if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){ |
---|
34 | EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION); |
---|
35 | powerInterface = (ComputingNodePowerInterface)ee.getPowerInterface(); |
---|
36 | } |
---|
37 | return powerInterface; |
---|
38 | } |
---|
39 | |
---|
40 | @SuppressWarnings("unchecked") |
---|
41 | public List<Processor> getProcessors(){ |
---|
42 | return (List<Processor>) getDescendantsByType(StandardResourceType.Processor); |
---|
43 | } |
---|
44 | |
---|
45 | @SuppressWarnings("unchecked") |
---|
46 | public List<Processor> getFreeProcessors(){ |
---|
47 | return (List<Processor>) getDescendantsByTypeAndStatus(StandardResourceType.Processor, ResourceStatus.FREE); |
---|
48 | } |
---|
49 | |
---|
50 | public int getProcessorsNumber() { |
---|
51 | return getProcessors().size(); |
---|
52 | } |
---|
53 | |
---|
54 | public int getFreeProcessorsNumber() { |
---|
55 | return getFreeProcessors().size(); |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | //MEMORY |
---|
60 | public int getFreeMemory() throws NoSuchFieldException { |
---|
61 | return getMemory().getFreeAmount(); |
---|
62 | } |
---|
63 | |
---|
64 | public int getTotalMemory() throws NoSuchFieldException { |
---|
65 | return getMemory().getAmount(); |
---|
66 | } |
---|
67 | |
---|
68 | public boolean isMemRequirementSatisfied(int memoryReq) throws NoSuchFieldException { |
---|
69 | if (getFreeMemory() < memoryReq) |
---|
70 | return false; |
---|
71 | return true; |
---|
72 | } |
---|
73 | |
---|
74 | public Memory getMemory() throws NoSuchFieldException { |
---|
75 | return (Memory) ((ComputingResourceCharacteristics)resourceCharacteristic).getResourceUnit(StandardResourceUnitName.MEMORY); |
---|
76 | } |
---|
77 | |
---|
78 | //COST |
---|
79 | public int getProcessingCost() throws NoSuchFieldException { |
---|
80 | return getCost().getAmount(); |
---|
81 | } |
---|
82 | |
---|
83 | private Cost getCost() throws NoSuchFieldException { |
---|
84 | return (Cost) ((ComputingResourceCharacteristics)resourceCharacteristic).getResourceUnit(StandardResourceUnitName.COST); |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | public Properties getProperties(){ |
---|
89 | PropertiesDirector propDirector = new PropertiesDirector(); |
---|
90 | propDirector.setPropertiesBuilder(new ComputingNodePropertiesBuilder()); |
---|
91 | propDirector.constructProperties(this); |
---|
92 | return propDirector.getProperties(); |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | /*private void accept(EnergyExtension e){ |
---|
97 | extensionList.add(e); |
---|
98 | e.setResource(this); |
---|
99 | }*/ |
---|
100 | } |
---|