package test.rewolucja.resources.description; import gridsim.gssim.GssimConstants; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.qcg.broker.schemas.exception.NoSuchParamException; import org.qcg.broker.schemas.hostparams.ComputingResource; import org.qcg.broker.schemas.hostparams.ComputingResourceParameterType; import org.qcg.broker.schemas.hostparams.Property; import org.qcg.broker.schemas.hostparams.types.ComputingParameterName; import org.qcg.broker.schemas.hostparams.wrapper.impl.ComputingResourceParamExplorerImpl; import schedframe.resources.units.ResourceUnit; import schedframe.scheduling.utils.ResourceParameterName; import simulator.utils.InstanceFactory; import test.rewolucja.energy.profile.PowerInterface; import test.rewolucja.energy.profile.PowerProfileFactory; import test.rewolucja.resources.Category; import test.rewolucja.resources.ResourceType; import test.rewolucja.resources.reader.test.TempResourceDescriptionReader; import test.rewolucja.resources.utils.ResourceIDGenerator; import test.rewolucja.scheduling.queue.Queue; import test.rewolucja.scheduling.queue.QueueList; public class ExecResourceDescription extends AbstractResourceDescription { // private Log log = LogFactory.getLog(ExecResourceDescription.class); protected QueueList accesQueues; protected Category category; public PowerInterface getPowerProfile() { return powerProfile; } protected PowerInterface powerProfile; public ExecResourceDescription(ExecResourceDescription parentDescription, ComputingResource nativeDescription, String resLayerName) { super(ResourceType.valueOf(resLayerName)); String uniqueId = String.valueOf(ResourceIDGenerator.getID(ResourceType.valueOf(resLayerName))); try { ComputingResourceParamExplorerImpl explorer = new ComputingResourceParamExplorerImpl(); explorer.explore(nativeDescription); ComputingResourceParameterType cpuHostParam = explorer.getHostParam(ComputingParameterName.CPUCOUNT); this.accesQueues = null; this.resourceId = type.toString() + "_" + uniqueId; if (this.getType() == ResourceType.COMPUTING_NODE) { if (Integer.parseInt(uniqueId) < Integer.parseInt(TempResourceDescriptionReader.modelA)) category = new Category("A"); else if (Integer.parseInt(uniqueId) >= Integer.parseInt(TempResourceDescriptionReader.modelA) && Integer.parseInt(uniqueId) < (Integer.parseInt(TempResourceDescriptionReader.modelA) + Integer .parseInt(TempResourceDescriptionReader.modelB))) category = new Category("B"); else category = new Category("C"); } else if (parentDescription != null && parentDescription.getType() == ResourceType.COMPUTING_NODE) { category = ((ExecResourceDescription) parentDescription).getCategory(); } String cpuPowerClass = getPropertyValue(cpuHostParam, GssimConstants.RESOURCE_CONFIG_POWER_PROFILE); if (cpuPowerClass != null) { powerProfile = (PowerInterface) InstanceFactory.createInstance(cpuPowerClass, PowerInterface.class); if (powerProfile == null) { powerProfile = PowerProfileFactory.createPowerProfile(type, category); // log.info("Using default cpu power profile: " + // CPUPowerProfile.class.getName()); } else { String cpuPPconfig = getPropertyValue(cpuHostParam, GssimConstants.RESOURCE_CONFIG_POWER_PROFILE_CONFIG); powerProfile.init(cpuPPconfig); } } else { powerProfile = PowerProfileFactory.createPowerProfile(type, category); // log.info("Using default cpu power profile: " + // CPUPowerProfile.class.getName()); } } catch (NoSuchParamException e) { } } /** * * @return list of queues. These are the queues in which tasks submitted to * this resource are waiting for local scheduling decision */ public QueueList getAccessQueues() { if (this.accesQueues == null) { this.accesQueues = new QueueList(); Queue queue = new Queue(false); accesQueues.add(queue); } return this.accesQueues; } protected String getPropertyValue(ComputingResourceParameterType paramType, String propertyName) { Property properties[] = paramType.getProperty(); for (int j = 0; j < properties.length; j++) { Property p = properties[j]; String name = p.getName(); if (propertyName.equalsIgnoreCase(name)) { return p.getValue(0); } } return null; } @Override public long getQueueLoad(String queueName) throws NoSuchFieldException { // TODO Auto-generated method stub return 0; } // public abstract boolean supportReservation(); public void addResourceUnit(ResourceUnit unit) { if (this.resUnits == null) this.resUnits = new HashMap>(1); List list = null; if (this.resUnits.containsKey(unit.getName())) { list = this.resUnits.get(unit.getName()); } else { list = new ArrayList(1); this.resUnits.put(unit.getName(), list); } list.add(unit); } public String getId() { return resourceId; } public Category getCategory() { return category; } }