1 | package schedframe.resources; |
---|
2 | |
---|
3 | import gridsim.gssim.resource.ResourceProcessors; |
---|
4 | import org.qcg.broker.schemas.exception.NoSuchParamException; |
---|
5 | import org.qcg.broker.schemas.hostparams.ComputingResourceParameterType; |
---|
6 | import org.qcg.broker.schemas.hostparams.Property; |
---|
7 | import org.qcg.broker.schemas.hostparams.types.ComputingParameterName; |
---|
8 | import org.qcg.broker.schemas.hostparams.wrapper.impl.ComputingResourceParamExplorerImpl; |
---|
9 | |
---|
10 | import java.util.ArrayList; |
---|
11 | import java.util.HashMap; |
---|
12 | import java.util.List; |
---|
13 | import java.util.Map; |
---|
14 | |
---|
15 | import org.apache.commons.logging.Log; |
---|
16 | import org.apache.commons.logging.LogFactory; |
---|
17 | |
---|
18 | import schedframe.resources.units.Processor; |
---|
19 | import schedframe.scheduling.Queue; |
---|
20 | import schedframe.scheduling.TaskInterface; |
---|
21 | |
---|
22 | /** |
---|
23 | * |
---|
24 | * @author Marcin Krystek |
---|
25 | * |
---|
26 | */ |
---|
27 | public abstract class ExecutingResourceDescription extends ResourceDescription { |
---|
28 | |
---|
29 | private Log log = LogFactory.getLog(ExecutingResourceDescription.class); |
---|
30 | |
---|
31 | protected List<Queue<? extends TaskInterface<?>>> accesQueues; |
---|
32 | |
---|
33 | protected Map<String, PowerInterface> nodesPowerProfilesMap; |
---|
34 | |
---|
35 | public ExecutingResourceDescription(){ |
---|
36 | this.accesQueues = new ArrayList<Queue<? extends TaskInterface<?>>>(); |
---|
37 | this.nodesPowerProfilesMap = new HashMap<String, PowerInterface>(); |
---|
38 | } |
---|
39 | |
---|
40 | /** |
---|
41 | * |
---|
42 | * @return list of queues. These are the queues in which tasks submitted |
---|
43 | * to this resource are waiting for local scheduling decision |
---|
44 | */ |
---|
45 | public List<Queue<? extends TaskInterface<?>>> getAccessQueues(){ |
---|
46 | return this.accesQueues; |
---|
47 | } |
---|
48 | |
---|
49 | protected int getCorecountParameterValue(ComputingResourceParamExplorerImpl explorer){ |
---|
50 | |
---|
51 | try { |
---|
52 | |
---|
53 | ComputingResourceParameterType paramType = explorer.getHostParam(ComputingParameterName.CPUCOUNT); |
---|
54 | Property properties[] = paramType.getProperty(); |
---|
55 | for(int j = 0; j < properties.length; j++){ |
---|
56 | Property p = properties[j]; |
---|
57 | String name = p.getName(); |
---|
58 | if("corecount".equalsIgnoreCase(name)){ |
---|
59 | int count = Integer.parseInt(p.getValue(0)); |
---|
60 | System.out.println("corecount: " + count); |
---|
61 | return count; |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | } catch (NoSuchParamException e) { |
---|
66 | log.error(e.getMessage()); |
---|
67 | } |
---|
68 | |
---|
69 | return 1; |
---|
70 | } |
---|
71 | |
---|
72 | protected String getPropertyValue(ComputingResourceParameterType paramType, String propertyName){ |
---|
73 | |
---|
74 | Property properties[] = paramType.getProperty(); |
---|
75 | for(int j = 0; j < properties.length; j++){ |
---|
76 | Property p = properties[j]; |
---|
77 | String name = p.getName(); |
---|
78 | if(propertyName.equalsIgnoreCase(name)){ |
---|
79 | return p.getValue(0); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | return null; |
---|
84 | } |
---|
85 | |
---|
86 | public Map<String, PowerInterface> getNodePowerProfiles(){ |
---|
87 | return this.nodesPowerProfilesMap; |
---|
88 | } |
---|
89 | |
---|
90 | public abstract boolean supportReservation(); |
---|
91 | |
---|
92 | protected class ExecResourceProcessors extends ResourceProcessors{ |
---|
93 | |
---|
94 | public ExecResourceProcessors(String resId, Processor p, |
---|
95 | int cpuCnt, int coreCnt, boolean uniqe) { |
---|
96 | super(resId); |
---|
97 | this.areUnique = uniqe; |
---|
98 | this.processors = new ArrayList<Processor>(cpuCnt * coreCnt); |
---|
99 | |
---|
100 | for(int i = 0; i < cpuCnt; i++){ |
---|
101 | for(int j = 0; j < coreCnt; j++){ |
---|
102 | Processor cpu = new Processor(i, j); |
---|
103 | cpu.setComputingNodeId(p.getComputingNodeId()); |
---|
104 | cpu.accept(p.getPowerProfile().clone()); |
---|
105 | this.processors.add(cpu); |
---|
106 | } |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | } |
---|
111 | } |
---|