package schedframe.resources.computing; import java.util.ArrayList; import java.util.List; import java.util.Properties; import schedframe.resources.ResourceStatus; import schedframe.resources.StandardResourceType; import schedframe.resources.computing.description.ComputingResourceDescription; import schedframe.resources.computing.extensions.ExtensionType; import schedframe.resources.computing.profiles.energy.EnergyExtension; import schedframe.resources.computing.profiles.energy.power.ui.NodePowerInterface; import schedframe.resources.computing.properties.NodePropertiesBuilder; import schedframe.resources.computing.properties.PropertiesDirector; import schedframe.resources.units.Cost; import schedframe.resources.units.Memory; import schedframe.resources.units.StandardResourceUnitName; public class Node extends ComputingResource{ public Node (ComputingResourceDescription resDesc) { super(resDesc); //extensionList.add(new EnergyExtension(this, resDesc.getPowerInterface(), resDesc.getEnergyEstimationPlugin())); //PowerInterface pi = PowerInterfaceFactory.createPowerInterface(this, resDesc.getPowerProfile()); //AirThroughputInterface ai = AirThroughputInterfaceFactory.createAirThroughputInterface(this, resDesc.getAirThroughputProfile()); //accept(new EnergyExtension(pi, resDesc.getPowerProfile())); //accept(new EnergyExtension(pi, resDesc.getPowerProfile(), ai, resDesc.getAirThroughputProfile())); } public NodePowerInterface getPowerInterface(){ NodePowerInterface powerInterface = null; if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){ EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION); powerInterface = (NodePowerInterface)ee.getPowerInterface(); } return powerInterface; } @SuppressWarnings("unchecked") public List getProcessors(){ return (List) getDescendantsByType(StandardResourceType.Processor); } @SuppressWarnings("unchecked") public List getFreeProcessors(){ return (List) getDescendantsByTypeAndStatus(StandardResourceType.Processor, ResourceStatus.FREE); } public List getCores(){ List cores = new ArrayList(); for(Processor proc: getProcessors()){ cores.addAll(proc.getCores()); } return cores; } public List getFreeCores(){ List freeCores = new ArrayList(); for(Processor proc: getProcessors()){ freeCores.addAll(proc.getFreeCores()); } return freeCores; } public int getProcessorsNumber() { return getProcessors().size(); } public int getFreeProcessorsNumber() { return getFreeProcessors().size(); } //MEMORY public int getFreeMemory() throws NoSuchFieldException { return getMemory().getFreeAmount(); } public int getTotalMemory() throws NoSuchFieldException { return getMemory().getAmount(); } public boolean isMemRequirementSatisfied(int memoryReq) throws NoSuchFieldException { if (getFreeMemory() < memoryReq) return false; return true; } public Memory getMemory() throws NoSuchFieldException { return (Memory) ((ComputingResourceCharacteristics)resourceCharacteristic).getResourceUnit(StandardResourceUnitName.MEMORY); } //COST public int getProcessingCost() throws NoSuchFieldException { return getCost().getAmount(); } private Cost getCost() throws NoSuchFieldException { return (Cost) ((ComputingResourceCharacteristics)resourceCharacteristic).getResourceUnit(StandardResourceUnitName.COST); } public Properties getProperties(){ PropertiesDirector propDirector = new PropertiesDirector(); propDirector.setPropertiesBuilder(new NodePropertiesBuilder()); propDirector.constructProperties(this); return propDirector.getProperties(); } /*private void accept(EnergyExtension e){ extensionList.add(e); e.setResource(this); }*/ }