package test.article.recs.utils; import java.util.HashMap; import java.util.Map; import java.util.Random; import java.util.TreeMap; import dcworms.schedframe.scheduling.Executable; import schedframe.scheduling.tasks.TaskInterface; public class TaskToApp { private static int ABINIT = 20; private static int C_RAY = 40; private static int TAR = 60; private static int LIN_3GB = 70; private static int LIN_TINY = 80; private static int FFT = 100; private static Random rand = new Random(5); private static Map mapping = new TreeMap(); private static Random randLoad = new Random(5); private static Map loadMapping = new HashMap(); private static double [] loadLevels = {0.25, 0.5, 0.75, 1}; public AppType getAppType(TaskInterface task){ AppType appType = null; if(mapping.get(task.getJobId())!= null){ appType = mapping.get(task.getJobId()); Executable exec = (Executable) task; exec.getDescription().getExecution().getExecutable().getApplication().setName(appType.toString()); }else{ appType = randomAppType(); mapping.put(task.getJobId(), appType); } return appType; } private AppType randomAppType(){ AppType appType = null; int n = rand.nextInt(100); if(n < ABINIT){ appType = AppType.abinit; }else if(n < C_RAY){ appType = AppType.c_ray; }else if(n < TAR){ appType = AppType.tar; }else if(n < LIN_3GB){ appType = AppType.lin_3gb; }else if(n < LIN_TINY){ appType = AppType.lin_tiny; }else if(n < FFT){ appType = AppType.fft; } return appType; } public double getAppLoad(TaskInterface task){ double appLoad = 0; if(loadMapping.get(task.getJobId())!= null){ appLoad = loadMapping.get(task.getJobId()); }else{ appLoad = randomAppLoad(); loadMapping.put(task.getJobId(), appLoad); }return appLoad; } private double randomAppLoad(){ double appLoad = 0; int n = randLoad.nextInt(7); appLoad = loadLevels[n]; return appLoad; } }