[104] | 1 | package test.rewolucja.resources.description; |
---|
| 2 | |
---|
| 3 | import gridsim.gssim.GssimConstants; |
---|
| 4 | |
---|
| 5 | import java.util.ArrayList; |
---|
| 6 | import java.util.HashMap; |
---|
| 7 | import java.util.List; |
---|
| 8 | |
---|
| 9 | import org.qcg.broker.schemas.exception.NoSuchParamException; |
---|
| 10 | import org.qcg.broker.schemas.hostparams.ComputingResource; |
---|
| 11 | import org.qcg.broker.schemas.hostparams.ComputingResourceParameterType; |
---|
| 12 | import org.qcg.broker.schemas.hostparams.Property; |
---|
| 13 | import org.qcg.broker.schemas.hostparams.types.ComputingParameterName; |
---|
| 14 | import org.qcg.broker.schemas.hostparams.wrapper.impl.ComputingResourceParamExplorerImpl; |
---|
| 15 | |
---|
| 16 | import schedframe.resources.units.ResourceUnit; |
---|
| 17 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
| 18 | import simulator.utils.InstanceFactory; |
---|
| 19 | import test.rewolucja.energy.profile.PowerInterface; |
---|
| 20 | import test.rewolucja.energy.profile.PowerProfileFactory; |
---|
| 21 | import test.rewolucja.resources.Category; |
---|
| 22 | import test.rewolucja.resources.ResourceType; |
---|
| 23 | import test.rewolucja.resources.reader.test.TempResourceDescriptionReader; |
---|
| 24 | import test.rewolucja.resources.utils.ResourceIDGenerator; |
---|
| 25 | import test.rewolucja.scheduling.queue.GSSIMQueue; |
---|
| 26 | import test.rewolucja.scheduling.queue.QueueList; |
---|
| 27 | |
---|
| 28 | public class ExecResourceDescription extends AbstractResourceDescription { |
---|
| 29 | |
---|
| 30 | // private Log log = LogFactory.getLog(ExecResourceDescription.class); |
---|
| 31 | protected QueueList accesQueues; |
---|
| 32 | protected Category category; |
---|
| 33 | |
---|
| 34 | public PowerInterface getPowerProfile() { |
---|
| 35 | return powerProfile; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | protected PowerInterface powerProfile; |
---|
| 39 | |
---|
| 40 | public ExecResourceDescription(ExecResourceDescription parentDescription, ComputingResource nativeDescription, |
---|
| 41 | String resLayerName) { |
---|
| 42 | super(ResourceType.valueOf(resLayerName)); |
---|
| 43 | String uniqueId = String.valueOf(ResourceIDGenerator.getID(ResourceType.valueOf(resLayerName))); |
---|
| 44 | try { |
---|
| 45 | ComputingResourceParamExplorerImpl explorer = new ComputingResourceParamExplorerImpl(); |
---|
| 46 | explorer.explore(nativeDescription); |
---|
| 47 | ComputingResourceParameterType cpuHostParam = explorer.getHostParam(ComputingParameterName.CPUCOUNT); |
---|
| 48 | |
---|
| 49 | this.accesQueues = null; |
---|
| 50 | |
---|
| 51 | this.resourceId = type.toString() + "_" + uniqueId; |
---|
| 52 | |
---|
| 53 | if (this.getType() == ResourceType.COMPUTING_NODE) { |
---|
| 54 | if (Integer.parseInt(uniqueId) < Integer.parseInt(TempResourceDescriptionReader.modelA)) |
---|
| 55 | category = new Category("A"); |
---|
| 56 | else if (Integer.parseInt(uniqueId) >= Integer.parseInt(TempResourceDescriptionReader.modelA) |
---|
| 57 | && Integer.parseInt(uniqueId) < (Integer.parseInt(TempResourceDescriptionReader.modelA) + Integer |
---|
| 58 | .parseInt(TempResourceDescriptionReader.modelB))) |
---|
| 59 | category = new Category("B"); |
---|
| 60 | else |
---|
| 61 | category = new Category("C"); |
---|
| 62 | } else if (parentDescription != null && parentDescription.getType() == ResourceType.COMPUTING_NODE) { |
---|
| 63 | category = ((ExecResourceDescription) parentDescription).getCategory(); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | String cpuPowerClass = getPropertyValue(cpuHostParam, GssimConstants.RESOURCE_CONFIG_POWER_PROFILE); |
---|
| 67 | |
---|
| 68 | if (cpuPowerClass != null) { |
---|
| 69 | powerProfile = (PowerInterface) InstanceFactory.createInstance(cpuPowerClass, PowerInterface.class); |
---|
| 70 | if (powerProfile == null) { |
---|
| 71 | powerProfile = PowerProfileFactory.createPowerProfile(type, category); |
---|
| 72 | // log.info("Using default cpu power profile: " + |
---|
| 73 | // CPUPowerProfile.class.getName()); |
---|
| 74 | |
---|
| 75 | } else { |
---|
| 76 | String cpuPPconfig = getPropertyValue(cpuHostParam, |
---|
| 77 | GssimConstants.RESOURCE_CONFIG_POWER_PROFILE_CONFIG); |
---|
| 78 | powerProfile.init(cpuPPconfig); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | } else { |
---|
| 82 | powerProfile = PowerProfileFactory.createPowerProfile(type, category); |
---|
| 83 | // log.info("Using default cpu power profile: " + |
---|
| 84 | // CPUPowerProfile.class.getName()); |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | } catch (NoSuchParamException e) { |
---|
| 88 | |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * |
---|
| 94 | * @return list of queues. These are the queues in which tasks submitted to |
---|
| 95 | * this resource are waiting for local scheduling decision |
---|
| 96 | */ |
---|
| 97 | public QueueList getAccessQueues() { |
---|
| 98 | if (this.accesQueues == null) { |
---|
| 99 | this.accesQueues = new QueueList(); |
---|
| 100 | GSSIMQueue queue = new GSSIMQueue(false); |
---|
| 101 | accesQueues.add(queue); |
---|
| 102 | } |
---|
| 103 | return this.accesQueues; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | protected String getPropertyValue(ComputingResourceParameterType paramType, String propertyName) { |
---|
| 107 | |
---|
| 108 | Property properties[] = paramType.getProperty(); |
---|
| 109 | for (int j = 0; j < properties.length; j++) { |
---|
| 110 | Property p = properties[j]; |
---|
| 111 | String name = p.getName(); |
---|
| 112 | if (propertyName.equalsIgnoreCase(name)) { |
---|
| 113 | return p.getValue(0); |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | return null; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | @Override |
---|
| 121 | public long getQueueLoad(String queueName) throws NoSuchFieldException { |
---|
| 122 | // TODO Auto-generated method stub |
---|
| 123 | return 0; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | // public abstract boolean supportReservation(); |
---|
| 127 | |
---|
| 128 | public void addResourceUnit(ResourceUnit unit) { |
---|
| 129 | if (this.resUnits == null) |
---|
| 130 | this.resUnits = new HashMap<ResourceParameterName, List<ResourceUnit>>(1); |
---|
| 131 | List<ResourceUnit> list = null; |
---|
| 132 | if (this.resUnits.containsKey(unit.getName())) { |
---|
| 133 | list = this.resUnits.get(unit.getName()); |
---|
| 134 | } else { |
---|
| 135 | list = new ArrayList<ResourceUnit>(1); |
---|
| 136 | this.resUnits.put(unit.getName(), list); |
---|
| 137 | } |
---|
| 138 | list.add(unit); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | public String getId() { |
---|
| 142 | return resourceId; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | public Category getCategory() { |
---|
| 146 | return category; |
---|
| 147 | } |
---|
| 148 | } |
---|