package schedframe.resources.computing; 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.airthroughput.AirThroughputInterfaceFactory; import schedframe.resources.computing.profiles.energy.airthroughput.ui.AirThroughputInterface; import schedframe.resources.computing.profiles.energy.power.PowerInterfaceFactory; import schedframe.resources.computing.profiles.energy.power.ui.ComputingNodePowerInterface; import schedframe.resources.computing.profiles.energy.power.ui.PowerInterface; import schedframe.resources.computing.properties.ComputingNodePropertiesBuilder; import schedframe.resources.computing.properties.PropertiesDirector; import schedframe.resources.units.Cost; import schedframe.resources.units.Memory; import schedframe.resources.units.StandardResourceUnitName; public class ComputingNode extends ComputingResource{ public ComputingNode (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 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 ComputingNodePowerInterface getPowerInterface(){ ComputingNodePowerInterface powerInterface = null; if(extensionList.isExtensionAvailable(ExtensionType.ENERGY_EXTENSION)){ EnergyExtension ee = (EnergyExtension)extensionList.getExtension(ExtensionType.ENERGY_EXTENSION); powerInterface = (ComputingNodePowerInterface)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 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) resourceCharacteristic.getResourceUnit(StandardResourceUnitName.MEMORY); } //COST public int getProcessingCost() throws NoSuchFieldException { return getCost().getAmount(); } private Cost getCost() throws NoSuchFieldException { return (Cost) resourceCharacteristic.getResourceUnit(StandardResourceUnitName.COST); } public Properties getProperties(){ PropertiesDirector propDirector = new PropertiesDirector(); propDirector.setPropertiesBuilder(new ComputingNodePropertiesBuilder()); propDirector.constructProperties(this); return propDirector.getProperties(); } /*private void accept(EnergyExtension e){ extensionList.add(e); e.setResource(this); }*/ }