source: DCWoRMS/trunk/src/test/article2/recs/utils/TaskToApp.java @ 826

Revision 826, 1.6 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.article2.recs.utils;
2
3import java.util.HashMap;
4import java.util.Map;
5import java.util.Random;
6
7import schedframe.scheduling.tasks.TaskInterface;
8
9public class TaskToApp {
10       
11
12        private static int C_RAY = 33;
13        private static int PYBENCH = 66;
14        private static int UNPACK_LINUX = 100;
15        private static Random randType = new Random(5);
16        private static Map<String, AppType> mappingType = new HashMap<String, AppType>();
17       
18        private static Random randLoad = new Random(5);
19        private static Map<String, Double> mappingLoad = new HashMap<String, Double>();
20        private static double [] loadLevels = {0.25, 0.4, 0.5, 0.6, 0.75, 0.9, 1};
21
22        public AppType getAppType(TaskInterface<?> task){
23                AppType appType = null;
24                if(mappingType.get(task.getJobId())!= null){
25                        appType = mappingType.get(task.getJobId());
26                }else{
27                        appType = randomAppType();
28                        mappingType.put(task.getJobId(), appType);
29                }return appType;
30        }
31       
32        private AppType randomAppType(){
33                AppType appType = null;
34                int n = randType.nextInt(100);
35
36                if(n < C_RAY){
37                        appType = AppType.c_ray;
38                }else if(n < PYBENCH){
39                        appType = AppType.pybench;
40                } else if (n < UNPACK_LINUX){
41                        appType = AppType.unpack_linux;
42                }
43                return appType;
44        }
45       
46        public double getAppLoad(TaskInterface<?> task){
47                double appLoad = 0;
48                if(mappingLoad.get(task.getJobId())!= null){
49                        appLoad = mappingLoad.get(task.getJobId());
50                }else{
51                        appLoad = randomAppLoad();
52                        mappingLoad.put(task.getJobId(), appLoad);
53                }return appLoad;
54        }
55       
56       
57        private double randomAppLoad(){
58                double appLoad = 0;
59                int n = randLoad.nextInt(7);
60                appLoad = loadLevels[n];
61                return appLoad;
62        }
63       
64}
Note: See TracBrowser for help on using the repository browser.