[477] | 1 | package schedframe.resources.computing; |
---|
| 2 | |
---|
[1247] | 3 | import java.util.ArrayList; |
---|
[477] | 4 | import java.util.List; |
---|
| 5 | import java.util.Properties; |
---|
| 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; |
---|
[1247] | 12 | import schedframe.resources.computing.profiles.energy.power.ui.NodePowerInterface; |
---|
| 13 | import schedframe.resources.computing.properties.NodePropertiesBuilder; |
---|
[477] | 14 | import schedframe.resources.computing.properties.PropertiesDirector; |
---|
| 15 | import schedframe.resources.units.Cost; |
---|
| 16 | import schedframe.resources.units.Memory; |
---|
| 17 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 18 | |
---|
[1247] | 19 | public class Node extends ComputingResource{ |
---|
[477] | 20 | |
---|
| 21 | |
---|
[1247] | 22 | public Node (ComputingResourceDescription resDesc) { |
---|
[477] | 23 | super(resDesc); |
---|
| 24 | |
---|
| 25 | //extensionList.add(new EnergyExtension(this, resDesc.getPowerInterface(), resDesc.getEnergyEstimationPlugin())); |
---|
[756] | 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())); |
---|
[1207] | 30 | } |
---|
[477] | 31 | |
---|
[1247] | 32 | public NodePowerInterface getPowerInterface(){ |
---|
| 33 | NodePowerInterface powerInterface = null; |
---|
[477] | 34 | if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){ |
---|
| 35 | EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION); |
---|
[1247] | 36 | powerInterface = (NodePowerInterface)ee.getPowerInterface(); |
---|
[477] | 37 | } |
---|
[497] | 38 | return powerInterface; |
---|
[477] | 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 | |
---|
[1247] | 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 | |
---|
[477] | 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 { |
---|
[1207] | 92 | return (Memory) ((ComputingResourceCharacteristics)resourceCharacteristic).getResourceUnit(StandardResourceUnitName.MEMORY); |
---|
[477] | 93 | } |
---|
| 94 | |
---|
| 95 | //COST |
---|
| 96 | public int getProcessingCost() throws NoSuchFieldException { |
---|
| 97 | return getCost().getAmount(); |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | private Cost getCost() throws NoSuchFieldException { |
---|
[1207] | 101 | return (Cost) ((ComputingResourceCharacteristics)resourceCharacteristic).getResourceUnit(StandardResourceUnitName.COST); |
---|
[477] | 102 | } |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | public Properties getProperties(){ |
---|
| 106 | PropertiesDirector propDirector = new PropertiesDirector(); |
---|
[1247] | 107 | propDirector.setPropertiesBuilder(new NodePropertiesBuilder()); |
---|
[477] | 108 | propDirector.constructProperties(this); |
---|
| 109 | return propDirector.getProperties(); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | |
---|
[756] | 113 | /*private void accept(EnergyExtension e){ |
---|
[477] | 114 | extensionList.add(e); |
---|
| 115 | e.setResource(this); |
---|
[756] | 116 | }*/ |
---|
[477] | 117 | } |
---|