package simulator.factory; import java.util.ArrayList; import java.util.HashMap; import qcg.qcg_broker.types.HostParametersItem; import qcg.qcg_broker.types.hostspec.ClusterMachines; import qcg.qcg_broker.types.hostspec.Queue; import qcg.qcg_broker.types.hostspec.QueueResourcesCollective; import qcg.qcg_broker.types.hostspec.QueueingSystem; import qcg.qcg_broker.types.hostspec.QueuesGroup; import qcg.qcg_broker.types.hostspec.QueuesGroupChoice; import org.qcg.broker.schemas.hostparams.HostParameters; import simulator.RandomNumbers; import simulator.hostspec.ForecastFinishTimePluginName; import simulator.hostspec.LocalAllocationPolicyPluginName; import simulator.hostspec.Plugins; /** * This factory can create qcg.qcg_broker.types.hostspec.QueueingSystem * based on simulator.hostspec.QueueingSystem description * @author Marcin Krystek * */ public class QueueingSystemFactory { public static String QUEUE_GROUP = "queueGroup"; public static String QUEUE = "queue"; public static String PRIORITY = "priority"; public static String MAX_JOBS = "maxJobs"; public static String MAX_RUNNING = "maxRunning"; public static String MAX_PENDING = "maxPending"; public static String TOTAL_CPUS = "totalCpus"; public static String NODE_TOTAL_MEMORY = "nodeTotalMemory"; protected simulator.hostspec.QueueingSystem queueSystem; protected RandomNumbers randNumbers; protected HashMap forecastFinishTimePlugin; protected HashMap localAllocationPolicyPlugin; public QueueingSystemFactory(simulator.hostspec.QueueingSystem queueSystem, RandomNumbers randNumbers){ this.queueSystem = queueSystem; this.randNumbers = randNumbers; this.forecastFinishTimePlugin = new HashMap(); this.localAllocationPolicyPlugin = new HashMap(); } public HostParametersItem[] createQueueingSystem() throws IllegalAccessException { if(queueSystem == null) return null; ArrayList retList = new ArrayList(); int systemCount = queueSystem.getTotalResourceCount(); int arSystemCount = queueSystem.getARResourceCount(); Double value; String resName; Plugins plugins = queueSystem.getPlugins(); int timePluginIndex = 0; ForecastFinishTimePluginName timePlugin; ForecastFinishTimePluginName timePluginName[] = plugins.getForecastFinishTimePluginName(); int allocationPluginIndex = 0; LocalAllocationPolicyPluginName allocationPlugin; LocalAllocationPolicyPluginName allocationPluginName[] = plugins.getLocalAllocationPolicyPluginName(); for(int i = 0; i < systemCount; i++){ HostParametersItem item = new HostParametersItem(); QueueingSystem system = new QueueingSystem(); value = new Double(randNumbers.getRandomValue(QueueingSystemFactory.QUEUE_GROUP)); if(value.intValue() <= 0) return null; for(int j = 0; j < value.intValue(); j++){ QueuesGroup group = new QueuesGroup(); group = createQues(group); group = createQueuesGroupChoice(group); system.addQueuesGroup(group); } if(arSystemCount > 0) system.setReservationAvailable(true); else system.setReservationAvailable(true); arSystemCount--; resName = "queueingSystem_"+i; system = setName(system, resName); item.setQueueingSystem(system); retList.add(item); timePlugin = timePluginName[timePluginIndex]; forecastFinishTimePlugin.put(resName, timePlugin.getName()); timePlugin.setResourcesCountWithThisPlugin( timePlugin.getResourcesCountWithThisPlugin() - 1); if(timePlugin.getResourcesCountWithThisPlugin() == 0) timePluginIndex++; allocationPlugin = allocationPluginName[allocationPluginIndex]; localAllocationPolicyPlugin.put(resName, allocationPlugin.getName()); allocationPlugin.setResourcesCountWithThisPlugin( allocationPlugin.getResourcesCountWithThisPlugin() - 1); if(allocationPlugin.getResourcesCountWithThisPlugin() == 0) allocationPluginIndex++; } HostParametersItem tab[] = new HostParametersItem[retList.size()]; return retList.toArray(tab); } public HostParameters createQueueingSystem(HostParameters hostParameters) throws IllegalAccessException { HostParametersItem tab[] = null; tab = createQueueingSystem(); if (tab == null) return hostParameters; for(int i = 0; i < tab.length; i++){ hostParameters.addHostParametersItem(tab[i]); } return hostParameters; } protected QueuesGroup createQues(QueuesGroup group) throws IllegalAccessException{ Double queueCount = randNumbers.getRandomValue(QueueingSystemFactory.QUEUE); Double value; Queue queue; if(queueCount.intValue() <= 0) return group; for(int i = 0; i < queueCount.intValue(); i++){ queue = new Queue(); value = new Double(randNumbers.getRandomValue(QueueingSystemFactory.PRIORITY)); queue.setPriority(value.intValue()); value = new Double(randNumbers.getRandomValue(QueueingSystemFactory.MAX_JOBS)); queue.setMaxJobs(value.intValue()); value = new Double(randNumbers.getRandomValue(QueueingSystemFactory.MAX_RUNNING)); queue.setMaxRunning(value.intValue()); value = new Double(randNumbers.getRandomValue(QueueingSystemFactory.MAX_PENDING)); queue.setMaxPending(value.intValue()); group.addQueue(queue); } return group; } protected QueuesGroup createQueuesGroupChoice(QueuesGroup group) throws IllegalAccessException{ QueuesGroupChoice choice = new QueuesGroupChoice(); QueueResourcesCollective collective = new QueueResourcesCollective(); ClusterMachines machines = new ClusterMachines(); Double value; value = randNumbers.getRandomValue(QueueingSystemFactory.TOTAL_CPUS); machines.setTotalCpus(value.intValue()); value = randNumbers.getRandomValue(QueueingSystemFactory.NODE_TOTAL_MEMORY); machines.setNodeTotalMemory(value.intValue()); collective.setClusterMachines(machines); choice.setQueueResourcesCollective(collective); group.setQueuesGroupChoice(choice); return group; } /** * Name of QueueingSystem is name of first Queue in first QueuesGroup * @param queueingSystem * @return */ public static String getName(QueueingSystem queueingSystem){ String ret = ""; ret = queueingSystem.getResManContact(); return ret; } public static QueueingSystem setName(QueueingSystem queueingSystem, String name){ queueingSystem.setResManContact(name); return queueingSystem; } public HashMap getForecastFinishTimePlugin(){ return forecastFinishTimePlugin; } public HashMap getLocalAllocationPolicyPlugin(){ return localAllocationPolicyPlugin; } }