source: xssim/src/simulator/factory/QueueingSystemFactory.java @ 104

Revision 104, 6.6 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package simulator.factory;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5
6import qcg.qcg_broker.types.HostParametersItem;
7import qcg.qcg_broker.types.hostspec.ClusterMachines;
8import qcg.qcg_broker.types.hostspec.Queue;
9import qcg.qcg_broker.types.hostspec.QueueResourcesCollective;
10import qcg.qcg_broker.types.hostspec.QueueingSystem;
11import qcg.qcg_broker.types.hostspec.QueuesGroup;
12import qcg.qcg_broker.types.hostspec.QueuesGroupChoice;
13import org.qcg.broker.schemas.hostparams.HostParameters;
14import simulator.RandomNumbers;
15import simulator.hostspec.ForecastFinishTimePluginName;
16import simulator.hostspec.LocalAllocationPolicyPluginName;
17import simulator.hostspec.Plugins;
18
19
20/**
21 * This factory can create qcg.qcg_broker.types.hostspec.QueueingSystem
22 * based on simulator.hostspec.QueueingSystem description
23 * @author Marcin Krystek
24 *
25 */
26
27public class QueueingSystemFactory {
28        public static String QUEUE_GROUP = "queueGroup";
29        public static String QUEUE = "queue";
30        public static String PRIORITY = "priority";
31        public static String MAX_JOBS = "maxJobs";
32        public static String MAX_RUNNING = "maxRunning";
33        public static String MAX_PENDING = "maxPending";
34        public static String TOTAL_CPUS = "totalCpus";
35        public static String NODE_TOTAL_MEMORY = "nodeTotalMemory";
36       
37        protected simulator.hostspec.QueueingSystem queueSystem;
38        protected RandomNumbers randNumbers;
39        protected HashMap <String, String>forecastFinishTimePlugin;
40        protected HashMap <String, String>localAllocationPolicyPlugin;
41       
42        public QueueingSystemFactory(simulator.hostspec.QueueingSystem queueSystem, RandomNumbers randNumbers){
43                this.queueSystem = queueSystem;
44                this.randNumbers = randNumbers;
45                this.forecastFinishTimePlugin = new HashMap<String, String>();
46                this.localAllocationPolicyPlugin = new HashMap<String, String>();
47        }
48       
49        public HostParametersItem[] createQueueingSystem() throws IllegalAccessException {
50                if(queueSystem == null)
51                        return null;
52               
53                ArrayList<HostParametersItem> retList = new ArrayList<HostParametersItem>();
54               
55                int systemCount = queueSystem.getTotalResourceCount();
56                int arSystemCount = queueSystem.getARResourceCount();
57                Double value;
58                String resName;
59               
60                Plugins plugins = queueSystem.getPlugins();
61               
62                int timePluginIndex = 0;
63                ForecastFinishTimePluginName timePlugin;
64                ForecastFinishTimePluginName timePluginName[]  =
65                                plugins.getForecastFinishTimePluginName();
66               
67                int allocationPluginIndex = 0;
68                LocalAllocationPolicyPluginName allocationPlugin;
69                LocalAllocationPolicyPluginName allocationPluginName[] =
70                                plugins.getLocalAllocationPolicyPluginName();
71               
72                for(int i = 0; i < systemCount; i++){
73                        HostParametersItem item = new HostParametersItem();
74                        QueueingSystem system = new QueueingSystem();
75                       
76                        value = new Double(randNumbers.getRandomValue(QueueingSystemFactory.QUEUE_GROUP));
77
78                        if(value.intValue() <= 0)
79                                return null;
80                       
81                        for(int j = 0; j < value.intValue(); j++){
82                               
83                                QueuesGroup group = new QueuesGroup();
84                               
85                                group = createQues(group);
86                                group = createQueuesGroupChoice(group);
87                                system.addQueuesGroup(group);
88                        }
89                       
90                        if(arSystemCount > 0)
91                                system.setReservationAvailable(true);
92                        else
93                                system.setReservationAvailable(true);
94                        arSystemCount--;
95                       
96                        resName = "queueingSystem_"+i;
97                        system = setName(system, resName);
98                        item.setQueueingSystem(system);
99                        retList.add(item);
100                       
101                        timePlugin = timePluginName[timePluginIndex];
102                        forecastFinishTimePlugin.put(resName, timePlugin.getName());
103                       
104                        timePlugin.setResourcesCountWithThisPlugin(
105                                        timePlugin.getResourcesCountWithThisPlugin() - 1);
106                        if(timePlugin.getResourcesCountWithThisPlugin() == 0)
107                                timePluginIndex++;
108                       
109                        allocationPlugin = allocationPluginName[allocationPluginIndex];
110                        localAllocationPolicyPlugin.put(resName, allocationPlugin.getName());
111                       
112                        allocationPlugin.setResourcesCountWithThisPlugin(
113                                        allocationPlugin.getResourcesCountWithThisPlugin() - 1);
114                        if(allocationPlugin.getResourcesCountWithThisPlugin() == 0)
115                                allocationPluginIndex++;
116                }
117                HostParametersItem tab[] = new HostParametersItem[retList.size()];
118                return retList.toArray(tab);
119        }
120       
121       
122        public HostParameters createQueueingSystem(HostParameters hostParameters) throws IllegalAccessException {
123                HostParametersItem tab[] = null;
124                tab = createQueueingSystem();
125               
126                if (tab == null)
127                        return hostParameters;
128               
129                for(int i = 0; i < tab.length; i++){
130                        hostParameters.addHostParametersItem(tab[i]);
131                }
132               
133                return hostParameters;
134        }
135       
136       
137        protected QueuesGroup createQues(QueuesGroup group) throws IllegalAccessException{
138                Double queueCount = randNumbers.getRandomValue(QueueingSystemFactory.QUEUE);
139                Double value;
140                Queue queue;
141               
142                if(queueCount.intValue() <= 0)
143                        return group;
144               
145                for(int i = 0; i < queueCount.intValue(); i++){
146                        queue = new Queue();
147                        value = new Double(randNumbers.getRandomValue(QueueingSystemFactory.PRIORITY));
148                        queue.setPriority(value.intValue());
149                       
150                        value = new Double(randNumbers.getRandomValue(QueueingSystemFactory.MAX_JOBS));
151                        queue.setMaxJobs(value.intValue());
152                       
153                        value = new Double(randNumbers.getRandomValue(QueueingSystemFactory.MAX_RUNNING));
154                        queue.setMaxRunning(value.intValue());
155                       
156                        value = new Double(randNumbers.getRandomValue(QueueingSystemFactory.MAX_PENDING));
157                        queue.setMaxPending(value.intValue());
158               
159                        group.addQueue(queue);
160                }
161                return group;
162        }
163       
164        protected QueuesGroup createQueuesGroupChoice(QueuesGroup group) throws IllegalAccessException{
165                QueuesGroupChoice choice = new QueuesGroupChoice();
166                QueueResourcesCollective collective = new QueueResourcesCollective();
167                ClusterMachines machines = new ClusterMachines();
168                Double value;
169                        value = randNumbers.getRandomValue(QueueingSystemFactory.TOTAL_CPUS);
170                        machines.setTotalCpus(value.intValue());
171                       
172                        value = randNumbers.getRandomValue(QueueingSystemFactory.NODE_TOTAL_MEMORY);
173                        machines.setNodeTotalMemory(value.intValue());
174                       
175                collective.setClusterMachines(machines);
176                choice.setQueueResourcesCollective(collective);
177                group.setQueuesGroupChoice(choice);
178                return group;
179        }
180       
181        /**
182         * Name of QueueingSystem is name of first Queue in first QueuesGroup
183         * @param queueingSystem
184         * @return
185         */
186        public static String getName(QueueingSystem queueingSystem){
187                String ret = "";
188                ret = queueingSystem.getResManContact();
189                return ret;
190        }
191
192       
193        public static QueueingSystem setName(QueueingSystem queueingSystem, String name){
194                queueingSystem.setResManContact(name);
195                return queueingSystem;
196        }
197       
198        public HashMap<String, String> getForecastFinishTimePlugin(){
199                return forecastFinishTimePlugin;
200        }
201       
202        public HashMap<String, String> getLocalAllocationPolicyPlugin(){
203                return localAllocationPolicyPlugin;
204        }
205}
Note: See TracBrowser for help on using the repository browser.