package test.drs_tst.recs.utils; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.PropertyResourceBundle; import java.util.Random; import java.util.ResourceBundle; 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 HashMap(); private static String JOB_APPS_MAPPINGS_FILE_NAME = "src/test/drs_tst/recs/data/job_apps_mappings.properties"; private ResourceBundle mappingsBundle; public TaskToApp(){ loadMappings(); } public AppType getAppType(TaskInterface task){ AppType appType = null; if(mapping.get(task.getJobId())!= null){ appType = mapping.get(task.getJobId()); }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; } private void loadMappings(){ try { ResourceBundle rb = getMappingsBundle(); for(String key : rb.keySet()){ mapping.put(key, AppType.valueOf(rb.getString(key))); } } catch (IOException e) { e.printStackTrace(); } } private ResourceBundle getMappingsBundle() throws FileNotFoundException, IOException{ if(mappingsBundle == null){ mappingsBundle = new PropertyResourceBundle(new FileInputStream(JOB_APPS_MAPPINGS_FILE_NAME)); } return mappingsBundle; } }