1 | package test.testSOP; |
---|
2 | |
---|
3 | import java.util.Map; |
---|
4 | |
---|
5 | import org.apache.commons.logging.Log; |
---|
6 | import org.apache.commons.logging.LogFactory; |
---|
7 | |
---|
8 | import dcworms.schedframe.scheduling.ExecTask; |
---|
9 | import schedframe.Parameters; |
---|
10 | import schedframe.PluginConfiguration; |
---|
11 | import schedframe.events.scheduling.SchedulingEvent; |
---|
12 | import schedframe.resources.units.PEUnit; |
---|
13 | import schedframe.resources.units.ResourceUnit; |
---|
14 | import schedframe.resources.units.ResourceUnitName; |
---|
15 | import schedframe.resources.units.StandardResourceUnitName; |
---|
16 | import schedframe.scheduling.plugin.estimation.ExecutionTimeEstimationPlugin; |
---|
17 | |
---|
18 | |
---|
19 | public class BaseTimeEstimationPlugin implements ExecutionTimeEstimationPlugin { |
---|
20 | Log log = LogFactory.getLog(BaseTimeEstimationPlugin.class); |
---|
21 | public PluginConfiguration getConfiguration() { |
---|
22 | return null; |
---|
23 | } |
---|
24 | |
---|
25 | public String getName() { |
---|
26 | return getClass().getName(); |
---|
27 | } |
---|
28 | |
---|
29 | public void init(Parameters parameters) { |
---|
30 | } |
---|
31 | |
---|
32 | public double estimateMigrationTime(SchedulingEvent event, ExecTask task, |
---|
33 | Map<ResourceUnitName, ResourceUnit> srcResources, Map<ResourceUnitName, ResourceUnit> dstResources) { |
---|
34 | double time = 0; |
---|
35 | //Test migration 10s |
---|
36 | // log.debug("Migration takes "+time+" seconds."); |
---|
37 | return time; |
---|
38 | } |
---|
39 | |
---|
40 | /* |
---|
41 | * This method should return an estimation of time required to execute the task. |
---|
42 | * Requested calculation should be done based on the resources allocated for the task, |
---|
43 | * task description and task completion percentage. |
---|
44 | * |
---|
45 | * Example implementation calculate the estimation based on cpu processing power. |
---|
46 | * There is also a simple assumption, that cpu processing power is a linear function |
---|
47 | * of number of allocated cpus and their speed. |
---|
48 | */ |
---|
49 | public double execTimeEstimation(SchedulingEvent event, ExecTask task, |
---|
50 | Map<ResourceUnitName, ResourceUnit> allocatedResources, |
---|
51 | double completionPercentage) { |
---|
52 | |
---|
53 | // collect all information necessary to do the calculation |
---|
54 | PEUnit peUnit = (PEUnit) allocatedResources.get(StandardResourceUnitName.PE); |
---|
55 | |
---|
56 | // obtain single pe speed |
---|
57 | int speed = peUnit.getSpeed(); |
---|
58 | |
---|
59 | // number of used pe |
---|
60 | int cnt = peUnit.getUsedAmount(); |
---|
61 | |
---|
62 | // estimate remainingTaskLength |
---|
63 | double remainingLength = task.getLength() * (1 - completionPercentage/100); |
---|
64 | |
---|
65 | // do the calculation |
---|
66 | double execTime = (remainingLength / (cnt * speed)); |
---|
67 | |
---|
68 | // if the result is very close to 0, but less then one millisecond then round this result to 0.001 |
---|
69 | if (Double.compare(execTime, 0.001) < 0) { |
---|
70 | execTime = 0.001; |
---|
71 | } |
---|
72 | |
---|
73 | // time is measured in integer units, so get the nearest execTime int value. |
---|
74 | execTime = Math.round(execTime); |
---|
75 | return execTime; |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | } |
---|