source: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/Node.java @ 1247

Revision 1247, 3.8 KB checked in by wojtekp, 11 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.resources.computing;
2
3import java.util.ArrayList;
4import java.util.List;
5import java.util.Properties;
6
7import schedframe.resources.ResourceStatus;
8import schedframe.resources.StandardResourceType;
9import schedframe.resources.computing.description.ComputingResourceDescription;
10import schedframe.resources.computing.extensions.ExtensionType;
11import schedframe.resources.computing.profiles.energy.EnergyExtension;
12import schedframe.resources.computing.profiles.energy.power.ui.NodePowerInterface;
13import schedframe.resources.computing.properties.NodePropertiesBuilder;
14import schedframe.resources.computing.properties.PropertiesDirector;
15import schedframe.resources.units.Cost;
16import schedframe.resources.units.Memory;
17import schedframe.resources.units.StandardResourceUnitName;
18
19public 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}
Note: See TracBrowser for help on using the repository browser.