[104] | 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 | |
---|
| 9 | import org.exolab.castor.xml.MarshalException; |
---|
| 10 | import org.exolab.castor.xml.ValidationException; |
---|
| 11 | |
---|
| 12 | import schedframe.scheduling.Reservation; |
---|
| 13 | import schedframe.scheduling.ReservedHost; |
---|
| 14 | import schedframe.scheduling.plan.AllocationInterface; |
---|
| 15 | import schedframe.scheduling.plan.HostInterface; |
---|
| 16 | import schedframe.scheduling.plan.ProcessesMapInterface; |
---|
| 17 | import schedframe.scheduling.plan.PropertiesTypeInterface; |
---|
| 18 | import schedframe.scheduling.plan.ProviderInfoInterface; |
---|
| 19 | |
---|
| 20 | public class Allocation implements AllocationInterface<org.qcg.broker.schemas.schedulingplan.Allocation> { |
---|
| 21 | |
---|
| 22 | private static final long serialVersionUID = 5194463015598737779L; |
---|
| 23 | protected org.qcg.broker.schemas.schedulingplan.Allocation allocation; |
---|
| 24 | |
---|
| 25 | public Allocation(){ |
---|
| 26 | allocation = new org.qcg.broker.schemas.schedulingplan.Allocation(); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | public Allocation(org.qcg.broker.schemas.schedulingplan.Allocation value){ |
---|
| 30 | allocation = value; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | public org.qcg.broker.schemas.schedulingplan.Allocation getDescription() { |
---|
| 34 | return allocation; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | public String getDocument() { |
---|
| 38 | StringWriter sw = new StringWriter(); |
---|
| 39 | try { |
---|
| 40 | allocation.marshal(sw); |
---|
| 41 | } catch (MarshalException e) { |
---|
| 42 | e.printStackTrace(); |
---|
| 43 | } catch (ValidationException e) { |
---|
| 44 | e.printStackTrace(); |
---|
| 45 | } |
---|
| 46 | return sw.toString(); |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | public void deleteProcessQuantity() { |
---|
| 50 | allocation.getAllocationChoice().deleteProcessesCount(); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | @SuppressWarnings("unchecked") |
---|
| 54 | public PropertiesTypeInterface<org.qcg.broker.schemas.schedulingplan.PropertiesType> getAdditionalProperties() { |
---|
| 55 | PropertiesType api = |
---|
| 56 | new PropertiesType(allocation.getAdditionalProperties()); |
---|
| 57 | return api; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | @SuppressWarnings("unchecked") |
---|
| 61 | public HostInterface<org.qcg.broker.schemas.schedulingplan.Host> getHost() { |
---|
| 62 | HostInterface<org.qcg.broker.schemas.schedulingplan.Host> host = new schedframe.scheduling.plan.impl.Host(allocation.getHost()); |
---|
| 63 | return host; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | public String getProcessGroupId() { |
---|
| 67 | return allocation.getProcessGroupId(); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | public int getProcessesCount() { |
---|
| 71 | return allocation.getAllocationChoice().getProcessesCount(); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | @SuppressWarnings("unchecked") |
---|
| 75 | public ProcessesMapInterface<org.qcg.broker.schemas.schedulingplan.ProcessesMap> getProcessesMap(){ |
---|
| 76 | ProcessesMapInterface<org.qcg.broker.schemas.schedulingplan.ProcessesMap> map = |
---|
| 77 | new schedframe.scheduling.plan.impl.ProcessesMap(allocation.getAllocationChoice().getProcessesMap()); |
---|
| 78 | return map; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | public boolean hasProcessesCount() { |
---|
| 82 | return allocation.getAllocationChoice().hasProcessesCount(); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | public boolean hasProcessesMap(){ |
---|
| 86 | return (allocation.getAllocationChoice().getProcessesMap() != null); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | public <Properties_> void setAdditionalProperties( |
---|
| 90 | PropertiesTypeInterface<Properties_> additionalProperties) { |
---|
| 91 | allocation.setAdditionalProperties((org.qcg.broker.schemas.schedulingplan.PropertiesType)additionalProperties.getDescription()); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | public <Host_> void setHost(HostInterface<Host_> host) { |
---|
| 95 | allocation.setHost((org.qcg.broker.schemas.schedulingplan.Host)host.getDescription()); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | public void setProcessGroupId(String processGroupId) { |
---|
| 99 | allocation.setProcessGroupId(processGroupId); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | public void setProcessesCount(int processCount) { |
---|
| 103 | AllocationChoice choice = new AllocationChoice(); |
---|
| 104 | choice.setProcessesCount(processCount); |
---|
| 105 | allocation.setAllocationChoice(choice); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | public <ProcessesMap_> void setProcessesMap(ProcessesMapInterface<ProcessesMap_> processesMap){ |
---|
| 109 | AllocationChoice choice = new AllocationChoice(); |
---|
| 110 | choice.setProcessesMap( |
---|
| 111 | (org.qcg.broker.schemas.schedulingplan.ProcessesMap) processesMap.getDescription()); |
---|
| 112 | allocation.setAllocationChoice(choice); |
---|
| 113 | |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | @SuppressWarnings("unchecked") |
---|
| 117 | public ProviderInfoInterface<org.qcg.broker.schemas.schedulingplan.ProviderInfo> getProviderInfo() { |
---|
| 118 | org.qcg.broker.schemas.schedulingplan.ProviderInfo info = allocation.getProviderInfo(); |
---|
| 119 | if(info == null) |
---|
| 120 | return null; |
---|
| 121 | |
---|
| 122 | ProviderInfoInterface providerInfo = new ProviderInfo(info); |
---|
| 123 | return providerInfo; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | public String getReservationId() { |
---|
| 128 | org.qcg.broker.schemas.schedulingplan.Reservation r = allocation.getReservation(); |
---|
| 129 | return (r == null ? null : r.getId()); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | public <ProviderInfo_> void setProviderInfo( |
---|
| 133 | ProviderInfoInterface<ProviderInfo_> providerInfo) { |
---|
| 134 | allocation.setProviderInfo((org.qcg.broker.schemas.schedulingplan.ProviderInfo)providerInfo.getDescription()); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | public void setReservation(Reservation reservation) { |
---|
| 138 | org.qcg.broker.schemas.schedulingplan.Reservation r = allocation.getReservation(); |
---|
| 139 | if(r == null) { |
---|
| 140 | r = new org.qcg.broker.schemas.schedulingplan.Reservation(); |
---|
| 141 | allocation.setReservation(r); |
---|
| 142 | } |
---|
| 143 | r.setId(reservation.getId()); |
---|
| 144 | |
---|
| 145 | List<ReservedHost> hosts = reservation.getReservedHosts(); |
---|
| 146 | if(hosts != null){ |
---|
| 147 | for(int i = 0; i < hosts.size(); i++){ |
---|
| 148 | ReservedHost host = hosts.get(i); |
---|
| 149 | Node node = new Node(); |
---|
| 150 | node.setContent(host.getName()); |
---|
| 151 | node.setCount(host.getReservedSlotsCount()); |
---|
| 152 | r.addNode(node); |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | } |
---|