[104] | 1 | package test.rewolucja.resources.physical.implementation; |
---|
| 2 | |
---|
| 3 | import java.util.List; |
---|
| 4 | import java.util.Properties; |
---|
| 5 | |
---|
| 6 | import schedframe.resources.units.Cost; |
---|
| 7 | import schedframe.resources.units.Memory; |
---|
| 8 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
| 9 | import test.rewolucja.energy.extension.EnergyExtension; |
---|
| 10 | import test.rewolucja.energy.profile.PowerInterface; |
---|
[132] | 11 | import test.rewolucja.energy.profile.implementation.ComputingNodePowerProfile; |
---|
[104] | 12 | import test.rewolucja.extensions.ExtensionType; |
---|
| 13 | import test.rewolucja.resources.Category; |
---|
| 14 | import test.rewolucja.resources.ResourceStatus; |
---|
| 15 | import test.rewolucja.resources.ResourceType; |
---|
| 16 | import test.rewolucja.resources.description.ExecResourceDescription; |
---|
| 17 | import test.rewolucja.resources.physical.base.ComputingResource; |
---|
| 18 | import test.rewolucja.resources.properties.ComputingNodePropertiesBuilder; |
---|
| 19 | import test.rewolucja.resources.properties.PropertiesDirector; |
---|
| 20 | |
---|
| 21 | public class ComputingNode extends ComputingResource{ |
---|
| 22 | |
---|
| 23 | Category category; |
---|
| 24 | |
---|
| 25 | public ComputingNode (ExecResourceDescription resDesc) { |
---|
| 26 | super(resDesc); |
---|
| 27 | category = resDesc.getCategory(); |
---|
| 28 | accept(resDesc.getPowerProfile()); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | /*public ComputingNode (String resourceName, ResourceCharacteristics resourceCharacteristic, Category cat, PowerInterface powerInterface) { |
---|
| 32 | super(resourceName, ResourceType.COMPUTING_NODE, resourceCharacteristic); |
---|
| 33 | category = cat; |
---|
| 34 | accept(powerInterface); |
---|
| 35 | // extensionList.add(new EnergyExtension(this, "example.energy.ComputingNodeEnergyEstimationPlugin")); |
---|
| 36 | }*/ |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | public ComputingNodePowerProfile getPowerInterface(){ |
---|
| 40 | ComputingNodePowerProfile powerProfile = null; |
---|
| 41 | if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){ |
---|
| 42 | EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION); |
---|
| 43 | powerProfile = (ComputingNodePowerProfile)ee.getPowerInterface(); |
---|
| 44 | } |
---|
| 45 | return powerProfile; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | @SuppressWarnings("unchecked") |
---|
[197] | 49 | public List<Processor> getProcessors(){ |
---|
[104] | 50 | try { |
---|
[197] | 51 | return (List<Processor>) getDescendantsByType(ResourceType.CPU); |
---|
[104] | 52 | } catch (Exception e) { |
---|
| 53 | // TODO Auto-generated catch block |
---|
| 54 | e.printStackTrace(); |
---|
| 55 | } |
---|
| 56 | return null; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | @SuppressWarnings("unchecked") |
---|
[197] | 60 | public List<Processor> getFreeProcessors(){ |
---|
[104] | 61 | try { |
---|
[197] | 62 | return (List<Processor>) getDescendantsByTypeAndStatus(ResourceType.CPU, ResourceStatus.FREE); |
---|
[104] | 63 | } catch (Exception e) { |
---|
| 64 | // TODO Auto-generated catch block |
---|
| 65 | e.printStackTrace(); |
---|
| 66 | } |
---|
| 67 | return null; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | public int getProcessorsNumber() { |
---|
| 71 | return getProcessors().size(); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | public int getFreeProcessorsNumber() { |
---|
| 75 | return getFreeProcessors().size(); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | //MEMORY |
---|
| 80 | public int getFreeMemory() { |
---|
[186] | 81 | return getMemoryUnit().getFreeAmount(); |
---|
[104] | 82 | } |
---|
| 83 | |
---|
| 84 | public int getTotalMemory() { |
---|
[186] | 85 | return getMemoryUnit().getAmount(); |
---|
[104] | 86 | } |
---|
| 87 | |
---|
| 88 | public boolean isMemRequirementSatisfied(int memoryReq) { |
---|
| 89 | if (getFreeMemory() < memoryReq) |
---|
| 90 | return false; |
---|
| 91 | return true; |
---|
| 92 | } |
---|
| 93 | |
---|
[186] | 94 | public Memory getMemoryUnit() { |
---|
[104] | 95 | return (Memory)resourceCharacteristic.getResourceUnit(ResourceParameterName.MEMORY); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | //COST |
---|
| 99 | public int getProcessingCost() { |
---|
[186] | 100 | return getCostUnit().getAmount(); |
---|
[104] | 101 | } |
---|
| 102 | |
---|
[186] | 103 | private Cost getCostUnit() { |
---|
[104] | 104 | return (Cost) getResourceCharacteristic().getResourceUnit(ResourceParameterName.COST); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | public Category getCategory() { |
---|
| 108 | return category; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | /*public void initCharacteristics(ExecResourceDescription resDesc){ |
---|
| 112 | |
---|
| 113 | }*/ |
---|
| 114 | |
---|
| 115 | public Properties getProperties(){ |
---|
| 116 | PropertiesDirector propDirector = new PropertiesDirector(); |
---|
| 117 | propDirector.setPropertiesBuilder(new ComputingNodePropertiesBuilder()); |
---|
| 118 | propDirector.constructProperties(this); |
---|
| 119 | return propDirector.getProperties(); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | public void accept(PowerInterface powIntVis){ |
---|
| 123 | extensionList.add(new EnergyExtension(this, powIntVis, "example.energy.ComputingNodeEnergyEstimationPlugin")); |
---|
| 124 | powIntVis.visit(this); |
---|
| 125 | } |
---|
| 126 | } |
---|