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