[477] | 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.power.PowerProfileFactory; |
---|
| 13 | import schedframe.resources.computing.profiles.energy.power.ui.ComputingNodePowerInterface; |
---|
| 14 | import schedframe.resources.computing.profiles.energy.power.ui.PowerInterface; |
---|
| 15 | import schedframe.resources.computing.properties.ComputingNodePropertiesBuilder; |
---|
| 16 | import schedframe.resources.computing.properties.PropertiesDirector; |
---|
| 17 | import schedframe.resources.units.Cost; |
---|
| 18 | import schedframe.resources.units.Memory; |
---|
| 19 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 20 | |
---|
| 21 | public 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 = PowerProfileFactory.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 | } |
---|