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