source: DCWoRMS/branches/coolemall/src/test/article2/recs/utils/TaskToApp.java @ 1200

Revision 1200, 1.8 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 dcworms.schedframe.scheduling.Executable;
8
9import schedframe.scheduling.tasks.TaskInterface;
10
11public class TaskToApp {
12       
13
14        private static int C_RAY = 33;
15        private static int PYBENCH = 66;
16        private static int UNPACK_LINUX = 100;
17        private static Random randType = new Random(5);
18        private static Map<String, AppType> mappingType = new HashMap<String, AppType>();
19       
20        private static Random randLoad = new Random(5);
21        private static Map<String, Double> mappingLoad = new HashMap<String, Double>();
22        private static double [] loadLevels = {0.25, 0.4, 0.5, 0.6, 0.75, 0.9, 1};
23
24        public AppType getAppType(TaskInterface<?> task){
25                AppType appType = null;
26                if(mappingType.get(task.getJobId())!= null){
27                        appType = mappingType.get(task.getJobId());
28                        Executable exec = (Executable) task;
29                        exec.getDescription().getExecution().getExecutable().getApplication().setName(appType.toString());
30                }else{
31                        appType = randomAppType();
32                        mappingType.put(task.getJobId(), appType);
33                }
34                return appType;
35        }
36       
37        private AppType randomAppType(){
38                AppType appType = null;
39                int n = randType.nextInt(100);
40
41                if(n < C_RAY){
42                        appType = AppType.c_ray;
43                }else if(n < PYBENCH){
44                        appType = AppType.pybench;
45                }else if (n < UNPACK_LINUX){
46                        appType = AppType.unpack_linux;
47                }
48                return appType;
49        }
50       
51        public double getAppLoad(TaskInterface<?> task){
52                double appLoad = 0;
53                if(mappingLoad.get(task.getJobId())!= null){
54                        appLoad = mappingLoad.get(task.getJobId());
55                }else{
56                        appLoad = randomAppLoad();
57                        mappingLoad.put(task.getJobId(), appLoad);
58                }return appLoad;
59        }
60       
61        private double randomAppLoad(){
62                double appLoad = 0;
63                int n = randLoad.nextInt(7);
64                appLoad = loadLevels[n];
65                return appLoad;
66        }
67       
68}
Note: See TracBrowser for help on using the repository browser.