source: xssim/trunk/src/test/rewolucja/resources/description/ExecResourceDescription.java @ 160

Revision 160, 5.0 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.rewolucja.resources.description;
2
3import gridsim.gssim.GssimConstants;
4
5import java.util.ArrayList;
6import java.util.HashMap;
7import java.util.List;
8
9import org.qcg.broker.schemas.exception.NoSuchParamException;
10import org.qcg.broker.schemas.hostparams.ComputingResource;
11import org.qcg.broker.schemas.hostparams.ComputingResourceParameterType;
12import org.qcg.broker.schemas.hostparams.Property;
13import org.qcg.broker.schemas.hostparams.types.ComputingParameterName;
14import org.qcg.broker.schemas.hostparams.wrapper.impl.ComputingResourceParamExplorerImpl;
15
16import schedframe.resources.units.ResourceUnit;
17import schedframe.scheduling.utils.ResourceParameterName;
18import simulator.utils.InstanceFactory;
19import test.rewolucja.energy.profile.PowerInterface;
20import test.rewolucja.energy.profile.PowerProfileFactory;
21import test.rewolucja.resources.Category;
22import test.rewolucja.resources.ResourceType;
23import test.rewolucja.resources.reader.test.TempResourceDescriptionReader;
24import test.rewolucja.resources.utils.ResourceIDGenerator;
25import test.rewolucja.scheduling.queue.Queue;
26import test.rewolucja.scheduling.queue.QueueList;
27
28public 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                        Queue queue = new Queue(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}
Note: See TracBrowser for help on using the repository browser.