1 | package schedframe.scheduling.plan.impl; |
---|
2 | |
---|
3 | import org.qcg.broker.schemas.schedulingplan.AllocationChoice; |
---|
4 | import org.qcg.broker.schemas.schedulingplan.Node; |
---|
5 | |
---|
6 | import java.io.StringWriter; |
---|
7 | import java.util.List; |
---|
8 | import java.util.Map; |
---|
9 | |
---|
10 | import org.exolab.castor.xml.MarshalException; |
---|
11 | import org.exolab.castor.xml.ValidationException; |
---|
12 | |
---|
13 | import schedframe.resources.units.ProcessingElements; |
---|
14 | import schedframe.resources.units.ResourceUnit; |
---|
15 | import schedframe.resources.units.ResourceUnitName; |
---|
16 | import schedframe.resources.units.StandardResourceUnitName; |
---|
17 | import schedframe.scheduling.manager.resources.utils.ResourceManagerUtils; |
---|
18 | import schedframe.scheduling.plan.AllocationInterface; |
---|
19 | import schedframe.scheduling.plan.HostInterface; |
---|
20 | import schedframe.scheduling.plan.ProcessesMapInterface; |
---|
21 | import schedframe.scheduling.plan.PropertiesTypeInterface; |
---|
22 | import schedframe.scheduling.plan.ProviderInfoInterface; |
---|
23 | |
---|
24 | public class Allocation implements AllocationInterface<org.qcg.broker.schemas.schedulingplan.Allocation> { |
---|
25 | |
---|
26 | private static final long serialVersionUID = 5194463015598737779L; |
---|
27 | protected org.qcg.broker.schemas.schedulingplan.Allocation allocation; |
---|
28 | |
---|
29 | public Allocation(){ |
---|
30 | allocation = new org.qcg.broker.schemas.schedulingplan.Allocation(); |
---|
31 | } |
---|
32 | |
---|
33 | public Allocation(org.qcg.broker.schemas.schedulingplan.Allocation value){ |
---|
34 | allocation = value; |
---|
35 | } |
---|
36 | |
---|
37 | public org.qcg.broker.schemas.schedulingplan.Allocation getDescription() { |
---|
38 | return allocation; |
---|
39 | } |
---|
40 | |
---|
41 | public String getDocument() { |
---|
42 | StringWriter sw = new StringWriter(); |
---|
43 | try { |
---|
44 | allocation.marshal(sw); |
---|
45 | } catch (MarshalException e) { |
---|
46 | e.printStackTrace(); |
---|
47 | } catch (ValidationException e) { |
---|
48 | e.printStackTrace(); |
---|
49 | } |
---|
50 | return sw.toString(); |
---|
51 | } |
---|
52 | |
---|
53 | public void deleteProcessQuantity() { |
---|
54 | allocation.getAllocationChoice().deleteProcessesCount(); |
---|
55 | } |
---|
56 | |
---|
57 | @SuppressWarnings("unchecked") |
---|
58 | public PropertiesTypeInterface<org.qcg.broker.schemas.schedulingplan.PropertiesType> getAdditionalProperties() { |
---|
59 | PropertiesType api = |
---|
60 | new PropertiesType(allocation.getAdditionalProperties()); |
---|
61 | return api; |
---|
62 | } |
---|
63 | |
---|
64 | @SuppressWarnings("unchecked") |
---|
65 | public HostInterface<org.qcg.broker.schemas.schedulingplan.Host> getHost() { |
---|
66 | HostInterface<org.qcg.broker.schemas.schedulingplan.Host> host = new schedframe.scheduling.plan.impl.Host(allocation.getHost()); |
---|
67 | return host; |
---|
68 | } |
---|
69 | |
---|
70 | public String getProcessGroupId() { |
---|
71 | return allocation.getProcessGroupId(); |
---|
72 | } |
---|
73 | |
---|
74 | public int getProcessesCount() { |
---|
75 | return allocation.getAllocationChoice().getProcessesCount(); |
---|
76 | } |
---|
77 | |
---|
78 | @SuppressWarnings("unchecked") |
---|
79 | public ProcessesMapInterface<org.qcg.broker.schemas.schedulingplan.ProcessesMap> getProcessesMap(){ |
---|
80 | ProcessesMapInterface<org.qcg.broker.schemas.schedulingplan.ProcessesMap> map = |
---|
81 | new schedframe.scheduling.plan.impl.ProcessesMap(allocation.getAllocationChoice().getProcessesMap()); |
---|
82 | return map; |
---|
83 | } |
---|
84 | |
---|
85 | public boolean hasProcessesCount() { |
---|
86 | return allocation.getAllocationChoice().hasProcessesCount(); |
---|
87 | } |
---|
88 | |
---|
89 | public boolean hasProcessesMap(){ |
---|
90 | return (allocation.getAllocationChoice().getProcessesMap() != null); |
---|
91 | } |
---|
92 | |
---|
93 | public <Properties_> void setAdditionalProperties( |
---|
94 | PropertiesTypeInterface<Properties_> additionalProperties) { |
---|
95 | allocation.setAdditionalProperties((org.qcg.broker.schemas.schedulingplan.PropertiesType)additionalProperties.getDescription()); |
---|
96 | } |
---|
97 | |
---|
98 | public <Host_> void setHost(HostInterface<Host_> host) { |
---|
99 | allocation.setHost((org.qcg.broker.schemas.schedulingplan.Host)host.getDescription()); |
---|
100 | } |
---|
101 | |
---|
102 | public void setProcessGroupId(String processGroupId) { |
---|
103 | allocation.setProcessGroupId(processGroupId); |
---|
104 | } |
---|
105 | |
---|
106 | public void setProcessesCount(int processCount) { |
---|
107 | AllocationChoice choice = new AllocationChoice(); |
---|
108 | choice.setProcessesCount(processCount); |
---|
109 | allocation.setAllocationChoice(choice); |
---|
110 | } |
---|
111 | |
---|
112 | public <ProcessesMap_> void setProcessesMap(ProcessesMapInterface<ProcessesMap_> processesMap){ |
---|
113 | AllocationChoice choice = new AllocationChoice(); |
---|
114 | choice.setProcessesMap( |
---|
115 | (org.qcg.broker.schemas.schedulingplan.ProcessesMap) processesMap.getDescription()); |
---|
116 | allocation.setAllocationChoice(choice); |
---|
117 | |
---|
118 | } |
---|
119 | |
---|
120 | @SuppressWarnings("unchecked") |
---|
121 | public ProviderInfoInterface<org.qcg.broker.schemas.schedulingplan.ProviderInfo> getProviderInfo() { |
---|
122 | org.qcg.broker.schemas.schedulingplan.ProviderInfo info = allocation.getProviderInfo(); |
---|
123 | if(info == null) |
---|
124 | return null; |
---|
125 | |
---|
126 | ProviderInfoInterface providerInfo = new ProviderInfo(info); |
---|
127 | return providerInfo; |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | public String getReservationId() { |
---|
132 | org.qcg.broker.schemas.schedulingplan.Reservation r = allocation.getReservation(); |
---|
133 | return (r == null ? null : r.getId()); |
---|
134 | } |
---|
135 | |
---|
136 | public <ProviderInfo_> void setProviderInfo( |
---|
137 | ProviderInfoInterface<ProviderInfo_> providerInfo) { |
---|
138 | allocation.setProviderInfo((org.qcg.broker.schemas.schedulingplan.ProviderInfo)providerInfo.getDescription()); |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | protected Map<ResourceUnitName, ResourceUnit> requestedResources; |
---|
143 | protected boolean isProcessing = false; |
---|
144 | protected String providerName; |
---|
145 | |
---|
146 | @Override |
---|
147 | public void setSpecificResources( |
---|
148 | Map<ResourceUnitName, ResourceUnit> choosenResources) { |
---|
149 | requestedResources = choosenResources; |
---|
150 | ResourceManagerUtils.setPendingResources(choosenResources); |
---|
151 | ProcessingElements processingElements = (ProcessingElements)requestedResources.get(StandardResourceUnitName.PE); |
---|
152 | if(processingElements != null){ |
---|
153 | isProcessing = true; |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | @Override |
---|
158 | public Map<ResourceUnitName, ResourceUnit> getRequestedResources() { |
---|
159 | return this.requestedResources; |
---|
160 | } |
---|
161 | |
---|
162 | public boolean isProcessing(){ |
---|
163 | return isProcessing; |
---|
164 | } |
---|
165 | |
---|
166 | @Override |
---|
167 | public void setProviderName(String providerName) { |
---|
168 | this.providerName = providerName; |
---|
169 | } |
---|
170 | |
---|
171 | @Override |
---|
172 | public String getProviderName() { |
---|
173 | return providerName; |
---|
174 | } |
---|
175 | |
---|
176 | |
---|
177 | } |
---|