source: DCWoRMS/branches/coolemall/src/test/drs_tst/recs/utils/TaskToApp.java @ 1120

Revision 1120, 2.0 KB checked in by dresiu, 12 years ago (diff)

dresiu init commit

Line 
1package test.drs_tst.recs.utils;
2
3import java.io.FileInputStream;
4import java.io.FileNotFoundException;
5import java.io.IOException;
6import java.util.HashMap;
7import java.util.Map;
8import java.util.PropertyResourceBundle;
9import java.util.Random;
10import java.util.ResourceBundle;
11
12import schedframe.scheduling.tasks.TaskInterface;
13
14public class TaskToApp {
15       
16        private static int ABINIT = 20;
17        private static int C_RAY = 40;
18        private static int TAR = 60;
19        private static int LIN_3GB = 70;
20        private static int LIN_TINY = 80;
21        private static int FFT = 100;
22        private static Random rand = new Random(5);
23        private static Map<String, AppType> mapping = new HashMap<String, AppType>();
24       
25        private static String JOB_APPS_MAPPINGS_FILE_NAME = "src/test/drs_tst/recs/data/job_apps_mappings.properties";
26        private ResourceBundle mappingsBundle;
27       
28        public TaskToApp(){
29                loadMappings();
30        }
31
32        public AppType getAppType(TaskInterface<?> task){
33                AppType appType = null;
34                if(mapping.get(task.getJobId())!= null){
35                        appType = mapping.get(task.getJobId());
36                }else{
37                        appType = randomAppType();
38                        mapping.put(task.getJobId(), appType);
39                }return appType;
40        }
41       
42        private AppType randomAppType(){
43                AppType appType = null;
44                int n = rand.nextInt(100);
45                if(n < ABINIT) {
46                        appType = AppType.abinit;
47                }else if(n < C_RAY){
48                        appType = AppType.c_ray;
49                }else if(n < TAR){
50                        appType = AppType.tar;
51                } else if (n < LIN_3GB){
52                        appType = AppType.lin_3gb;
53                } else if (n < LIN_TINY){
54                        appType = AppType.lin_tiny;
55                } else if (n < FFT){
56                        appType = AppType.fft;
57                } 
58                return appType;
59        }
60       
61        private void loadMappings(){
62                try {
63                        ResourceBundle rb = getMappingsBundle();
64                        for(String key : rb.keySet()){
65                                mapping.put(key, AppType.valueOf(rb.getString(key)));
66                        }
67                } catch (IOException e) {
68                        e.printStackTrace();
69                }
70               
71        }
72       
73        private ResourceBundle getMappingsBundle() throws FileNotFoundException, IOException{
74                if(mappingsBundle == null){
75                         mappingsBundle = new PropertyResourceBundle(new FileInputStream(JOB_APPS_MAPPINGS_FILE_NAME));
76                }
77                return mappingsBundle;
78        }
79}
Note: See TracBrowser for help on using the repository browser.