package test.article.recs.utils; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.PropertyResourceBundle; import java.util.ResourceBundle; import schedframe.resources.computing.ComputingNode; import schedframe.resources.computing.Processor; import schedframe.scheduling.tasks.TaskInterface; public class DAO { private static String TIME_DATA_FILE_NAME = "src/test/article/recs/data/time_data.properties"; private static String POWER_DATA_FILE_NAME = "src/test/article/recs/data/power_data.properties"; private static ResourceBundle powBundle; private static ResourceBundle timeBundle; private TaskToApp taskToApp = new TaskToApp(); protected String createQuery(TaskInterface task, ComputingNode node) { String query; query = getApplicationType(task) + "." + getNodeCategory(node) + "." + getFrequency(node) + "." + getCoreCnt(task); return query; } private String getApplicationType(TaskInterface task){ AppType appType = taskToApp.getAppType(task); return appType.toString(); } private String getNodeCategory(ComputingNode node){ return node.getCategory(); } private int getFrequency(ComputingNode node){ Processor proc = (Processor) node.getProcessors().get(0); double freq = proc.getPowerInterface().getFrequency(); return Double.valueOf(freq).intValue(); } private int getCoreCnt(TaskInterface task){ double cpuReq; try { cpuReq = task.getCpuCntRequest(); } catch (NoSuchFieldException e) { cpuReq = 1; } return Double.valueOf(cpuReq).intValue(); } public double getMeasuredPower(String query) throws FileNotFoundException, IOException{ ResourceBundle powBundle = getPowBundle(); return Double.valueOf(powBundle.getString(query)).doubleValue(); } private ResourceBundle getPowBundle() throws FileNotFoundException, IOException{ if(powBundle == null){ powBundle = new PropertyResourceBundle(new FileInputStream(POWER_DATA_FILE_NAME)); } return powBundle; } public double getMeasuredTime(String query) throws FileNotFoundException, IOException{ ResourceBundle timeBundle = getTimeBundle(); return Double.valueOf(timeBundle.getString(query)).doubleValue(); } private ResourceBundle getTimeBundle() throws FileNotFoundException, IOException{ if(timeBundle == null){ timeBundle = new PropertyResourceBundle(new FileInputStream(TIME_DATA_FILE_NAME)); } return timeBundle; } }