source: xssim/src/gssim/schedframe/resources/QueuingSystemDescription.java @ 104

Revision 104, 6.5 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
RevLine 
[104]1package gssim.schedframe.resources;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import org.apache.commons.logging.Log;
7import org.apache.commons.logging.LogFactory;
8
9import gridsim.gssim.GssimConstants;
10import gridsim.gssim.SubmittedTask;
11import gridsim.gssim.resource.ResourceProcessors;
12import org.qcg.broker.schemas.exception.NoSuchParamException;
13import org.qcg.broker.schemas.exception.UnknownParameter;
14import org.qcg.broker.schemas.hostparams.OtherParameterType;
15import org.qcg.broker.schemas.hostparams.QueueResource;
16import org.qcg.broker.schemas.hostparams.wrapper.QueueResourceParamExplorer;
17import org.qcg.broker.schemas.hostparams.wrapper.QueuingSystem;
18import org.qcg.broker.schemas.hostparams.wrapper.exception.NotHomogeneous;
19import org.qcg.broker.schemas.hostparams.wrapper.impl.ComputingResourceParamExplorerImpl;
20import org.qcg.broker.schemas.hostparams.wrapper.impl.QueueResourceParamExplorerImpl;
21import gssim.schedframe.scheduling.queues.SubmittedTaskQueue;
22import schedframe.resources.ExecutingResourceDescription;
23import schedframe.resources.providers.LocalSystem;
24import schedframe.resources.units.Cost;
25import schedframe.resources.units.Memory;
26import schedframe.resources.units.Processor;
27import schedframe.resources.units.ResourceUnit;
28import schedframe.scheduling.Queue;
29import schedframe.scheduling.TaskInterface;
30
31
32/**
33 *
34 * @author Marcin Krystek
35 *
36 */
37public class QueuingSystemDescription extends ExecutingResourceDescription {
38
39        protected Log log = LogFactory.getLog(QueuingSystemDescription.class);
40        protected boolean supportReservation;
41       
42        protected QueuingSystemDescription(){
43        };
44       
45        public QueuingSystemDescription(QueuingSystem nativeDescription){
46               
47                LocalSystem provider = new LocalSystem();
48                provider.setProviderId(nativeDescription.getFrontendId());
49                this.provider = provider;
50               
51                // create resource units
52                ResourceProcessors processors = null;
53                try {
54                       
55                        int cpucount = Double.valueOf(nativeDescription.getCpuCnt()).intValue();
56                        log.warn("ADD CPU CORE DESCRIPTION SUPPORT FOR QUEUING SYSTEM");
57                       
58                       
59                        int cpuspeed = 1;
60                        try {
61                                cpuspeed = Double.valueOf(nativeDescription.getCpuSpeed()).intValue();
62                        } catch (NoSuchParamException e) {
63                                if(log.isWarnEnabled())
64                                        log.warn("Queuing system " + nativeDescription.getFrontendId() +
65                                                " cpu speed parameter is not defined, assuming that cpuspeed = "+cpuspeed);
66                        } catch (NotHomogeneous e){
67                                if(log.isWarnEnabled())
68                                        log.warn("Queuing system " + nativeDescription.getFrontendId() +
69                                                " is not homogeneous, therefore spuspeed can not be determined. Assuming default = "+cpuspeed);
70                        } catch (UnknownParameter e){
71                                if(log.isWarnEnabled())
72                                        log.warn("Queuing system  cpu speed parameter is not defined, assuming that cpuspeed = "+cpuspeed);
73                        }
74                       
75                //      Processor exampleProc = new Processor(-1, -1, cpuspeed, null);
76                //      processors = new ExecResourceProcessors(null, exampleProc, cpucount, 1, false);
77                        log.warn("ADD CPU DISTINGUISH DESCRIPTION SUPPORT FOR QUEUING SYSTEM");
78
79                        addResourceUnit(processors);
80                       
81                } catch (NoSuchParamException e){
82                        if(log.isWarnEnabled())
83                                log.warn("Number od cpu's is not defined for " +
84                                                nativeDescription.getFrontendId() +
85                                                " resource. Assuming that cpuCount = 0");
86                } catch (UnknownParameter e) {
87                        if(log.isWarnEnabled())
88                                log.warn("Number od cpu's is not defined for " +
89                                                nativeDescription.getFrontendId() +
90                                                " resource. Assuming that cpuCount = 0");
91                }
92               
93               
94                try {
95                       
96                        int totalMemory = Double.valueOf(nativeDescription.getMemory()).intValue();
97                        Memory memory = new Memory(totalMemory, 0);
98                       
99                        addResourceUnit(memory);
100                       
101                } catch (NoSuchParamException e) {
102                        if(log.isWarnEnabled())
103                                log.warn("Queuing system " +
104                                                nativeDescription.getFrontendId() +
105                                                " memory parameter is not defined, assuming that totalMemory = 0");
106                } catch (UnknownParameter e) {
107                        if(log.isWarnEnabled())
108                                log.warn("Queuing system " +
109                                                nativeDescription.getFrontendId() +
110                                                " memory parameter is not defined, assuming that totalMemory = 0");
111                }
112               
113                float c = GssimConstants.DEFAULT_RESOURCE_PROCESSING_COST;
114                Cost cost = new Cost(Float.valueOf(c).intValue());
115                addResourceUnit(cost);
116
117               
118                // create access queues
119               
120                ComputingResourceParamExplorerImpl frontendExplorer = new ComputingResourceParamExplorerImpl();
121                frontendExplorer.explore(nativeDescription.getFrontend());
122                supportReservation = false;
123                try {
124                        OtherParameterType otherParam = frontendExplorer.getOtherParam("reservation");
125                        String value = otherParam.getParamValue(0);
126                        if("true".equals(value)){
127                                supportReservation = true;
128                        }
129                } catch (NoSuchParamException e) {
130                }
131               
132                processors.enableReservation(supportReservation);
133               
134                try {
135                        QueueResource qu[] = nativeDescription.getQueues();
136                        QueueResourceParamExplorer explorer = new QueueResourceParamExplorerImpl();
137                       
138                        for (int i = 0; i < qu.length; i++) {
139                               
140                                explorer.explore(qu[i]);
141                                int priority = 1;
142                               
143                                try {
144                                        int priorities[] = explorer.getPriority();
145                                        priority = new Float(priorities[0]).intValue();
146                                       
147                                } catch (NoSuchParamException e){
148                                        if(log.isErrorEnabled())
149                                                log.error("Priority for queue "+
150                                                                qu[i].getResourceId() +
151                                                                " is not defined. Assuming default priority = " + priority);
152                                }
153                               
154                                String queueName = qu[i].getResourceId();
155                                SubmittedTaskQueue queue = new SubmittedTaskQueue(supportReservation);
156                                queue.setName(queueName);
157                                queue.setPriority(priority);
158                               
159                                addAccessQueue(queue);
160                        }
161                       
162                } catch(UnknownParameter e){
163                        log.error(e.getMessage());
164                }
165               
166        }
167       
168        public void addResourceUnit(ResourceUnit unit){
169                List<ResourceUnit> list = null;
170                if(this.resUnits.containsKey(unit.getName())){
171                        list = this.resUnits.get(unit.getName());
172                } else {
173                        list = new ArrayList<ResourceUnit>();
174                        this.resUnits.put(unit.getName(), list);
175                }
176                list.add(unit);
177
178        }
179       
180        public void addAccessQueue(Queue<SubmittedTask> queue){
181                this.accesQueues.add(queue);
182        }
183       
184        public ResourceType getType(){
185                return ResourceType.QUEUING_SYSTEM;
186        }
187
188        public boolean supportReservation() {
189                return supportReservation;
190        }
191       
192        public long getQueueLoad(String queueName) throws NoSuchFieldException{
193                int load = 0;
194                if(queueName == null){
195                        for(Queue<? extends TaskInterface<?>> queue: this.accesQueues){
196                                load += queue.size();   
197                        }
198                        return load;
199                }
200                else {
201                        for(Queue<? extends TaskInterface<?>> queue: this.accesQueues){
202                                if(queue.getName().equals(queueName))
203                                        return queue.size();
204                        }
205                }
206                throw new NoSuchFieldException("Queue " + queueName +
207                                                " is not available in resource " + provider.getProviderId());
208
209        }
210       
211}
Note: See TracBrowser for help on using the repository browser.