source: DCWoRMS/trunk/src/schedframe/resources/computing/ComputingNode.java @ 495

Revision 495, 3.7 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.resources.computing;
2
3import java.util.List;
4import java.util.Properties;
5
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.PowerInterfaceFactory;
13import schedframe.resources.computing.profiles.energy.power.ui.ComputingNodePowerInterface;
14import schedframe.resources.computing.profiles.energy.power.ui.PowerInterface;
15import schedframe.resources.computing.properties.ComputingNodePropertiesBuilder;
16import schedframe.resources.computing.properties.PropertiesDirector;
17import schedframe.resources.units.Cost;
18import schedframe.resources.units.Memory;
19import schedframe.resources.units.StandardResourceUnitName;
20
21public class ComputingNode extends ComputingResource{
22       
23
24        public ComputingNode (ComputingResourceDescription resDesc) {
25                super(resDesc);
26               
27                //extensionList.add(new EnergyExtension(this, resDesc.getPowerInterface(), resDesc.getEnergyEstimationPlugin()));
28                PowerInterface pi = PowerInterfaceFactory.createPowerInterface(this, resDesc.getPowerProfile());
29                accept(new EnergyExtension(pi, 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 ComputingNodePowerInterface getPowerInterface(){
41                ComputingNodePowerInterface powerProfile = null;
42                if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){
43                        EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION);
44                        powerProfile = (ComputingNodePowerInterface)ee.getPowerInterface();
45                }
46                return powerProfile;
47        }
48
49        @SuppressWarnings("unchecked")
50        public List<Processor> getProcessors(){
51                return (List<Processor>) getDescendantsByType(StandardResourceType.Processor);
52        }
53       
54        @SuppressWarnings("unchecked")
55        public List<Processor> getFreeProcessors(){
56                return (List<Processor>) getDescendantsByTypeAndStatus(StandardResourceType.Processor, ResourceStatus.FREE);
57        }
58
59        public int getProcessorsNumber() {
60                return getProcessors().size();
61        }
62
63        public int getFreeProcessorsNumber() {
64                return getFreeProcessors().size();
65        }
66       
67       
68        //MEMORY
69        public int getFreeMemory() throws NoSuchFieldException {
70                return getMemory().getFreeAmount();
71        }
72       
73        public int getTotalMemory() throws NoSuchFieldException {
74                return getMemory().getAmount();
75        }
76
77        public boolean isMemRequirementSatisfied(int memoryReq) throws NoSuchFieldException {
78                if (getFreeMemory() < memoryReq)
79                        return false;
80                return true;
81        }
82       
83        public Memory getMemory() throws NoSuchFieldException {
84                return (Memory)resourceCharacteristic.getResourceUnit(StandardResourceUnitName.MEMORY);
85        }
86       
87        //COST
88        public int getProcessingCost() throws NoSuchFieldException {
89                return getCost().getAmount();
90        }
91       
92        private Cost getCost() throws NoSuchFieldException {
93                return (Cost) resourceCharacteristic.getResourceUnit(StandardResourceUnitName.COST);
94        }
95
96       
97        public Properties getProperties(){
98                PropertiesDirector propDirector = new PropertiesDirector();
99                propDirector.setPropertiesBuilder(new ComputingNodePropertiesBuilder());
100                propDirector.constructProperties(this);
101                return propDirector.getProperties();
102        }
103       
104       
105        public void accept(EnergyExtension e){
106                extensionList.add(e);
107                e.setResource(this);
108        }
109}
Note: See TracBrowser for help on using the repository browser.