1 | package test.rewolucja.resources.physical.implementation; |
---|
2 | |
---|
3 | import java.util.List; |
---|
4 | import java.util.Properties; |
---|
5 | |
---|
6 | import schedframe.resources.units.Cost; |
---|
7 | import schedframe.resources.units.Memory; |
---|
8 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
9 | import test.rewolucja.energy.extension.EnergyExtension; |
---|
10 | import test.rewolucja.energy.profile.ComputingNodePowerProfile; |
---|
11 | import test.rewolucja.energy.profile.PowerInterface; |
---|
12 | import test.rewolucja.extensions.ExtensionType; |
---|
13 | import test.rewolucja.resources.Category; |
---|
14 | import test.rewolucja.resources.ResourceCharacteristics; |
---|
15 | import test.rewolucja.resources.ResourceStatus; |
---|
16 | import test.rewolucja.resources.ResourceType; |
---|
17 | import test.rewolucja.resources.description.ExecResourceDescription; |
---|
18 | import test.rewolucja.resources.physical.base.ComputingResource; |
---|
19 | import test.rewolucja.resources.properties.ComputingNodePropertiesBuilder; |
---|
20 | import test.rewolucja.resources.properties.PropertiesDirector; |
---|
21 | |
---|
22 | public class ComputingNode extends ComputingResource{ |
---|
23 | |
---|
24 | Category category; |
---|
25 | |
---|
26 | public ComputingNode (ExecResourceDescription resDesc) { |
---|
27 | super(resDesc); |
---|
28 | category = resDesc.getCategory(); |
---|
29 | accept(resDesc.getPowerProfile()); |
---|
30 | } |
---|
31 | |
---|
32 | /*public ComputingNode (String resourceName, ResourceCharacteristics resourceCharacteristic, Category cat, PowerInterface powerInterface) { |
---|
33 | super(resourceName, ResourceType.COMPUTING_NODE, resourceCharacteristic); |
---|
34 | category = cat; |
---|
35 | accept(powerInterface); |
---|
36 | // extensionList.add(new EnergyExtension(this, "example.energy.ComputingNodeEnergyEstimationPlugin")); |
---|
37 | }*/ |
---|
38 | |
---|
39 | |
---|
40 | public ComputingNodePowerProfile getPowerInterface(){ |
---|
41 | ComputingNodePowerProfile powerProfile = null; |
---|
42 | if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){ |
---|
43 | EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION); |
---|
44 | powerProfile = (ComputingNodePowerProfile)ee.getPowerInterface(); |
---|
45 | } |
---|
46 | return powerProfile; |
---|
47 | } |
---|
48 | |
---|
49 | @SuppressWarnings("unchecked") |
---|
50 | public List<CPU> getProcessors(){ |
---|
51 | try { |
---|
52 | return (List<CPU>) getDescendantsByType(ResourceType.CPU); |
---|
53 | } catch (Exception e) { |
---|
54 | // TODO Auto-generated catch block |
---|
55 | e.printStackTrace(); |
---|
56 | } |
---|
57 | return null; |
---|
58 | } |
---|
59 | |
---|
60 | @SuppressWarnings("unchecked") |
---|
61 | public List<CPU> getFreeProcessors(){ |
---|
62 | try { |
---|
63 | return (List<CPU>) getDescendantsByTypeAndStatus(ResourceType.CPU, ResourceStatus.FREE); |
---|
64 | } catch (Exception e) { |
---|
65 | // TODO Auto-generated catch block |
---|
66 | e.printStackTrace(); |
---|
67 | } |
---|
68 | return null; |
---|
69 | } |
---|
70 | |
---|
71 | public int getProcessorsNumber() { |
---|
72 | return getProcessors().size(); |
---|
73 | } |
---|
74 | |
---|
75 | public int getFreeProcessorsNumber() { |
---|
76 | return getFreeProcessors().size(); |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | //MEMORY |
---|
81 | public int getFreeMemory() { |
---|
82 | return getMemory().getFreeAmount(); |
---|
83 | } |
---|
84 | |
---|
85 | public int getTotalMemory() { |
---|
86 | return getMemory().getAmount(); |
---|
87 | } |
---|
88 | |
---|
89 | public boolean isMemRequirementSatisfied(int memoryReq) { |
---|
90 | if (getFreeMemory() < memoryReq) |
---|
91 | return false; |
---|
92 | return true; |
---|
93 | } |
---|
94 | |
---|
95 | public Memory getMemory () { |
---|
96 | return (Memory)resourceCharacteristic.getResourceUnit(ResourceParameterName.MEMORY); |
---|
97 | } |
---|
98 | |
---|
99 | //COST |
---|
100 | public int getProcessingCost() { |
---|
101 | return getCost().getAmount(); |
---|
102 | } |
---|
103 | |
---|
104 | protected Cost getCost() { |
---|
105 | return (Cost) getResourceCharacteristic().getResourceUnit(ResourceParameterName.COST); |
---|
106 | } |
---|
107 | |
---|
108 | public Category getCategory() { |
---|
109 | return category; |
---|
110 | } |
---|
111 | |
---|
112 | /*public void initCharacteristics(ExecResourceDescription resDesc){ |
---|
113 | |
---|
114 | }*/ |
---|
115 | |
---|
116 | public Properties getProperties(){ |
---|
117 | PropertiesDirector propDirector = new PropertiesDirector(); |
---|
118 | propDirector.setPropertiesBuilder(new ComputingNodePropertiesBuilder()); |
---|
119 | propDirector.constructProperties(this); |
---|
120 | return propDirector.getProperties(); |
---|
121 | } |
---|
122 | |
---|
123 | public void accept(PowerInterface powIntVis){ |
---|
124 | extensionList.add(new EnergyExtension(this, powIntVis, "example.energy.ComputingNodeEnergyEstimationPlugin")); |
---|
125 | powIntVis.visit(this); |
---|
126 | } |
---|
127 | } |
---|