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

Revision 756, 4.1 KB checked in by wojtekp, 12 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.airthroughput.AirThroughputInterfaceFactory;
13import schedframe.resources.computing.profiles.energy.airthroughput.ui.AirThroughputInterface;
14import schedframe.resources.computing.profiles.energy.power.PowerInterfaceFactory;
15import schedframe.resources.computing.profiles.energy.power.ui.ComputingNodePowerInterface;
16import schedframe.resources.computing.profiles.energy.power.ui.PowerInterface;
17import schedframe.resources.computing.properties.ComputingNodePropertiesBuilder;
18import schedframe.resources.computing.properties.PropertiesDirector;
19import schedframe.resources.units.Cost;
20import schedframe.resources.units.Memory;
21import schedframe.resources.units.StandardResourceUnitName;
22
23public 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}
Note: See TracBrowser for help on using the repository browser.