source: DCWoRMS/trunk/src/test/article/recs/utils/DAO.java @ 665

Revision 665, 2.4 KB checked in by wojtekp, 12 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.article.recs.utils;
2
3import java.io.FileInputStream;
4import java.io.FileNotFoundException;
5import java.io.IOException;
6import java.util.PropertyResourceBundle;
7import java.util.ResourceBundle;
8
9import schedframe.resources.computing.ComputingNode;
10import schedframe.resources.computing.Processor;
11import schedframe.scheduling.tasks.TaskInterface;
12
13public class DAO {
14        private static String TIME_DATA_FILE_NAME = "src/test/article/recs/data/time_data.properties";
15        private static String POWER_DATA_FILE_NAME = "src/test/article/recs/data/power_data.properties";
16       
17        private static ResourceBundle powBundle;
18        private static ResourceBundle timeBundle;
19       
20        private TaskToApp taskToApp = new TaskToApp();
21
22        protected String createQuery(TaskInterface<?> task, ComputingNode node) {
23                String query;
24                query = getApplicationType(task) + "." + getNodeCategory(node) + "." + getFrequency(node) + "." + getCoreCnt(task);
25                return query;
26        }
27
28        private String getApplicationType(TaskInterface<?> task){       
29                AppType appType = taskToApp.getAppType(task);
30                return appType.toString();
31        }
32       
33        private String getNodeCategory(ComputingNode node){
34
35                return node.getCategory();
36        }
37       
38        private int getFrequency(ComputingNode node){
39                Processor proc = (Processor) node.getProcessors().get(0);
40                double freq = proc.getPowerInterface().getFrequency();
41                return Double.valueOf(freq).intValue();
42        }
43       
44        private int getCoreCnt(TaskInterface<?> task){ 
45                double cpuReq;
46                try {
47                        cpuReq = task.getCpuCntRequest();
48                } catch (NoSuchFieldException e) {
49                                cpuReq = 1;
50                }
51                return Double.valueOf(cpuReq).intValue();
52        }
53       
54        public double getMeasuredPower(String query) throws FileNotFoundException, IOException{
55                ResourceBundle powBundle = getPowBundle();
56                return Double.valueOf(powBundle.getString(query)).doubleValue();
57        }
58       
59        private ResourceBundle getPowBundle() throws FileNotFoundException, IOException{
60                if(powBundle == null){
61                         powBundle = new PropertyResourceBundle(new FileInputStream(POWER_DATA_FILE_NAME));
62                }
63                return powBundle;
64        }
65       
66        public double getMeasuredTime(String query) throws FileNotFoundException, IOException{
67                ResourceBundle timeBundle = getTimeBundle();
68                return Double.valueOf(timeBundle.getString(query)).doubleValue();
69        }
70
71        private ResourceBundle getTimeBundle() throws FileNotFoundException, IOException{
72                if(timeBundle == null){
73                        timeBundle = new PropertyResourceBundle(new FileInputStream(TIME_DATA_FILE_NAME));
74                }
75                return timeBundle;
76        }
77}
Note: See TracBrowser for help on using the repository browser.