1 | package schedframe.scheduling.plan.impl; |
---|
2 | |
---|
3 | import java.io.StringWriter; |
---|
4 | import java.util.ArrayList; |
---|
5 | |
---|
6 | import org.exolab.castor.xml.MarshalException; |
---|
7 | import org.exolab.castor.xml.ValidationException; |
---|
8 | |
---|
9 | import schedframe.scheduling.plan.AllocationInterface; |
---|
10 | import schedframe.scheduling.plan.ScheduledTaskInterface; |
---|
11 | import schedframe.scheduling.plan.ScheduledTimeInterface; |
---|
12 | import schedframe.scheduling.tasks.WorkloadUnit; |
---|
13 | |
---|
14 | |
---|
15 | import org.qcg.broker.schemas.schedulingplan.types.AllocationStatus; |
---|
16 | |
---|
17 | public class ScheduledTask implements ScheduledTaskInterface<org.qcg.broker.schemas.schedulingplan.Task> { |
---|
18 | |
---|
19 | private static final long serialVersionUID = -9006532413203045991L; |
---|
20 | protected org.qcg.broker.schemas.schedulingplan.Task t; |
---|
21 | |
---|
22 | public ScheduledTask(){ |
---|
23 | t = new org.qcg.broker.schemas.schedulingplan.Task(); |
---|
24 | allocationList = new ArrayList<AllocationInterface>(); |
---|
25 | } |
---|
26 | |
---|
27 | public ScheduledTask(org.qcg.broker.schemas.schedulingplan.Task value){ |
---|
28 | t = value; |
---|
29 | allocationList = new ArrayList<AllocationInterface>(); |
---|
30 | } |
---|
31 | |
---|
32 | |
---|
33 | public org.qcg.broker.schemas.schedulingplan.Task getDescription() { |
---|
34 | return t; |
---|
35 | } |
---|
36 | |
---|
37 | public String getDocument() { |
---|
38 | StringWriter writer = new StringWriter(); |
---|
39 | try { |
---|
40 | t.marshal(writer); |
---|
41 | } catch (MarshalException e) { |
---|
42 | e.printStackTrace(); |
---|
43 | } catch (ValidationException e) { |
---|
44 | e.printStackTrace(); |
---|
45 | } |
---|
46 | return writer.toString(); |
---|
47 | } |
---|
48 | |
---|
49 | public <Allocation_> void addAllocation( |
---|
50 | AllocationInterface<Allocation_> allocation) |
---|
51 | throws IndexOutOfBoundsException { |
---|
52 | t.addAllocation((org.qcg.broker.schemas.schedulingplan.Allocation) allocation.getDescription()); |
---|
53 | allocationList.add(allocation); |
---|
54 | } |
---|
55 | |
---|
56 | public <Allocation_> void addAllocation(int index, AllocationInterface<Allocation_> allocation) |
---|
57 | throws IndexOutOfBoundsException { |
---|
58 | t.addAllocation(index, (org.qcg.broker.schemas.schedulingplan.Allocation) allocation.getDescription()); |
---|
59 | allocationList.add(index, allocation); |
---|
60 | } |
---|
61 | |
---|
62 | public void deleteTopology() { |
---|
63 | t.deleteTopology(); |
---|
64 | } |
---|
65 | |
---|
66 | @SuppressWarnings("unchecked") |
---|
67 | public AllocationInterface<org.qcg.broker.schemas.schedulingplan.Allocation> getAllocation(int index) |
---|
68 | throws IndexOutOfBoundsException { |
---|
69 | return new schedframe.scheduling.plan.impl.Allocation(t.getAllocation(index)); |
---|
70 | } |
---|
71 | |
---|
72 | @SuppressWarnings("unchecked") |
---|
73 | public AllocationInterface<org.qcg.broker.schemas.schedulingplan.Allocation>[] getAllocation() { |
---|
74 | org.qcg.broker.schemas.schedulingplan.Allocation tab[] = t.getAllocation(); |
---|
75 | if(tab == null) return null; |
---|
76 | |
---|
77 | schedframe.scheduling.plan.impl.Allocation ret[] = new schedframe.scheduling.plan.impl.Allocation[tab.length]; |
---|
78 | for(int i = 0; i < tab.length; i++){ |
---|
79 | ret[i] = new schedframe.scheduling.plan.impl.Allocation(tab[i]); |
---|
80 | } |
---|
81 | return ret; |
---|
82 | } |
---|
83 | |
---|
84 | public int getAllocationCount() { |
---|
85 | return t.getAllocationCount(); |
---|
86 | } |
---|
87 | |
---|
88 | public String getJobId() { |
---|
89 | return t.getJobId(); |
---|
90 | } |
---|
91 | |
---|
92 | public AllocationStatus getStatus() { |
---|
93 | return t.getStatus(); |
---|
94 | } |
---|
95 | |
---|
96 | public String getStatusDescription(){ |
---|
97 | return t.getStatusDescription(); |
---|
98 | } |
---|
99 | |
---|
100 | public String getTaskId() { |
---|
101 | return t.getTaskId(); |
---|
102 | } |
---|
103 | |
---|
104 | public int getTopology() { |
---|
105 | return t.getTopology(); |
---|
106 | } |
---|
107 | |
---|
108 | public boolean hasTopology() { |
---|
109 | return t.hasTopology(); |
---|
110 | } |
---|
111 | |
---|
112 | public void removeAllAllocation() { |
---|
113 | t.removeAllAllocation(); |
---|
114 | } |
---|
115 | |
---|
116 | public <Allocation_> boolean removeAllocation( |
---|
117 | AllocationInterface<Allocation_> allocation) { |
---|
118 | return t.removeAllocation((org.qcg.broker.schemas.schedulingplan.Allocation) allocation.getDescription()); |
---|
119 | } |
---|
120 | |
---|
121 | @SuppressWarnings("unchecked") |
---|
122 | public AllocationInterface<org.qcg.broker.schemas.schedulingplan.Allocation> removeAllocationAt(int index) { |
---|
123 | return new schedframe.scheduling.plan.impl.Allocation(t.removeAllocationAt(index)); |
---|
124 | } |
---|
125 | |
---|
126 | public <Allocation_> void setAllocation(int index, |
---|
127 | AllocationInterface<Allocation_> allocation) |
---|
128 | throws IndexOutOfBoundsException { |
---|
129 | t.setAllocation(index, (org.qcg.broker.schemas.schedulingplan.Allocation)allocation.getDescription()); |
---|
130 | allocationList.set(index, allocation); |
---|
131 | } |
---|
132 | |
---|
133 | public <Allocation_> void setAllocation( |
---|
134 | AllocationInterface<Allocation_>[] allocationArray) { |
---|
135 | if(allocationArray == null) return; |
---|
136 | |
---|
137 | org.qcg.broker.schemas.schedulingplan.Allocation tab[] = new org.qcg.broker.schemas.schedulingplan.Allocation[allocationArray.length]; |
---|
138 | for(int i = 0; i < allocationArray.length; i++){ |
---|
139 | tab[i] = (org.qcg.broker.schemas.schedulingplan.Allocation)allocationArray[i].getDescription(); |
---|
140 | } |
---|
141 | t.setAllocation(tab); |
---|
142 | } |
---|
143 | |
---|
144 | public void setJobId(String jobId) { |
---|
145 | t.setJobId(jobId); |
---|
146 | } |
---|
147 | |
---|
148 | public void setStatus(AllocationStatus status) { |
---|
149 | t.setStatus(status); |
---|
150 | } |
---|
151 | |
---|
152 | public void setStatusDescription(String statusDescription){ |
---|
153 | t.setStatusDescription(statusDescription); |
---|
154 | } |
---|
155 | |
---|
156 | public void setTaskId(String taskId) { |
---|
157 | t.setTaskId(taskId); |
---|
158 | } |
---|
159 | |
---|
160 | public void setTopology(int topology) { |
---|
161 | t.setTopology(topology); |
---|
162 | } |
---|
163 | |
---|
164 | @SuppressWarnings("unchecked") |
---|
165 | public ScheduledTimeInterface<org.qcg.broker.schemas.schedulingplan.ScheduledTime> getScheduledTime() { |
---|
166 | org.qcg.broker.schemas.schedulingplan.ScheduledTime time = t.getScheduledTime(); |
---|
167 | if(time == null) |
---|
168 | return null; |
---|
169 | |
---|
170 | ScheduledTime st = new ScheduledTime(time); |
---|
171 | return st; |
---|
172 | } |
---|
173 | |
---|
174 | public <ScheduledTime_> void setScheduledTime( |
---|
175 | ScheduledTimeInterface<ScheduledTime_> scheduledTime) { |
---|
176 | t.setScheduledTime((org.qcg.broker.schemas.schedulingplan.ScheduledTime) scheduledTime.getDescription()); |
---|
177 | } |
---|
178 | |
---|
179 | |
---|
180 | protected WorkloadUnit<?> task; |
---|
181 | protected ArrayList<AllocationInterface> allocationList; |
---|
182 | |
---|
183 | public ScheduledTask(WorkloadUnit<?> task){ |
---|
184 | this(); |
---|
185 | this.task = task; |
---|
186 | } |
---|
187 | |
---|
188 | public ArrayList<AllocationInterface> getAllocations() { |
---|
189 | return this.allocationList; |
---|
190 | } |
---|
191 | |
---|
192 | public WorkloadUnit<?> getTask(){ |
---|
193 | return this.task; |
---|
194 | } |
---|
195 | } |
---|