package test.rewolucja.resources.physical.implementation; import java.util.List; import java.util.Properties; import schedframe.resources.units.Cost; import schedframe.resources.units.Memory; import schedframe.scheduling.utils.ResourceParameterName; import test.rewolucja.energy.extension.EnergyExtension; import test.rewolucja.energy.profile.PowerInterface; import test.rewolucja.energy.profile.implementation.ComputingNodePowerProfile; import test.rewolucja.extensions.ExtensionType; import test.rewolucja.resources.Category; import test.rewolucja.resources.ResourceCharacteristics; import test.rewolucja.resources.ResourceStatus; import test.rewolucja.resources.ResourceType; import test.rewolucja.resources.description.ExecResourceDescription; import test.rewolucja.resources.physical.base.ComputingResource; import test.rewolucja.resources.properties.ComputingNodePropertiesBuilder; import test.rewolucja.resources.properties.PropertiesDirector; public class ComputingNode extends ComputingResource{ Category category; public ComputingNode (ExecResourceDescription resDesc) { super(resDesc); category = resDesc.getCategory(); accept(resDesc.getPowerProfile()); } /*public ComputingNode (String resourceName, ResourceCharacteristics resourceCharacteristic, Category cat, PowerInterface powerInterface) { super(resourceName, ResourceType.COMPUTING_NODE, resourceCharacteristic); category = cat; accept(powerInterface); // extensionList.add(new EnergyExtension(this, "example.energy.ComputingNodeEnergyEstimationPlugin")); }*/ public ComputingNodePowerProfile getPowerInterface(){ ComputingNodePowerProfile powerProfile = null; if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){ EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION); powerProfile = (ComputingNodePowerProfile)ee.getPowerInterface(); } return powerProfile; } @SuppressWarnings("unchecked") public List getProcessors(){ try { return (List) getDescendantsByType(ResourceType.CPU); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @SuppressWarnings("unchecked") public List getFreeProcessors(){ try { return (List) getDescendantsByTypeAndStatus(ResourceType.CPU, ResourceStatus.FREE); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } public int getProcessorsNumber() { return getProcessors().size(); } public int getFreeProcessorsNumber() { return getFreeProcessors().size(); } //MEMORY public int getFreeMemory() { return getMemory().getFreeAmount(); } public int getTotalMemory() { return getMemory().getAmount(); } public boolean isMemRequirementSatisfied(int memoryReq) { if (getFreeMemory() < memoryReq) return false; return true; } public Memory getMemory () { return (Memory)resourceCharacteristic.getResourceUnit(ResourceParameterName.MEMORY); } //COST public int getProcessingCost() { return getCost().getAmount(); } protected Cost getCost() { return (Cost) getResourceCharacteristic().getResourceUnit(ResourceParameterName.COST); } public Category getCategory() { return category; } /*public void initCharacteristics(ExecResourceDescription resDesc){ }*/ public Properties getProperties(){ PropertiesDirector propDirector = new PropertiesDirector(); propDirector.setPropertiesBuilder(new ComputingNodePropertiesBuilder()); propDirector.constructProperties(this); return propDirector.getProperties(); } public void accept(PowerInterface powIntVis){ extensionList.add(new EnergyExtension(this, powIntVis, "example.energy.ComputingNodeEnergyEstimationPlugin")); powIntVis.visit(this); } }