package schedframe.scheduling.plan.impl; import org.qcg.broker.schemas.schedulingplan.AllocationChoice; import org.qcg.broker.schemas.schedulingplan.Node; import java.io.StringWriter; import java.util.List; import org.exolab.castor.xml.MarshalException; import org.exolab.castor.xml.ValidationException; import schedframe.scheduling.Reservation; import schedframe.scheduling.ReservedHost; import schedframe.scheduling.plan.AllocationInterface; import schedframe.scheduling.plan.HostInterface; import schedframe.scheduling.plan.ProcessesMapInterface; import schedframe.scheduling.plan.PropertiesTypeInterface; import schedframe.scheduling.plan.ProviderInfoInterface; public class Allocation implements AllocationInterface { private static final long serialVersionUID = 5194463015598737779L; protected org.qcg.broker.schemas.schedulingplan.Allocation allocation; public Allocation(){ allocation = new org.qcg.broker.schemas.schedulingplan.Allocation(); } public Allocation(org.qcg.broker.schemas.schedulingplan.Allocation value){ allocation = value; } public org.qcg.broker.schemas.schedulingplan.Allocation getDescription() { return allocation; } public String getDocument() { StringWriter sw = new StringWriter(); try { allocation.marshal(sw); } catch (MarshalException e) { e.printStackTrace(); } catch (ValidationException e) { e.printStackTrace(); } return sw.toString(); } public void deleteProcessQuantity() { allocation.getAllocationChoice().deleteProcessesCount(); } @SuppressWarnings("unchecked") public PropertiesTypeInterface getAdditionalProperties() { PropertiesType api = new PropertiesType(allocation.getAdditionalProperties()); return api; } @SuppressWarnings("unchecked") public HostInterface getHost() { HostInterface host = new schedframe.scheduling.plan.impl.Host(allocation.getHost()); return host; } public String getProcessGroupId() { return allocation.getProcessGroupId(); } public int getProcessesCount() { return allocation.getAllocationChoice().getProcessesCount(); } @SuppressWarnings("unchecked") public ProcessesMapInterface getProcessesMap(){ ProcessesMapInterface map = new schedframe.scheduling.plan.impl.ProcessesMap(allocation.getAllocationChoice().getProcessesMap()); return map; } public boolean hasProcessesCount() { return allocation.getAllocationChoice().hasProcessesCount(); } public boolean hasProcessesMap(){ return (allocation.getAllocationChoice().getProcessesMap() != null); } public void setAdditionalProperties( PropertiesTypeInterface additionalProperties) { allocation.setAdditionalProperties((org.qcg.broker.schemas.schedulingplan.PropertiesType)additionalProperties.getDescription()); } public void setHost(HostInterface host) { allocation.setHost((org.qcg.broker.schemas.schedulingplan.Host)host.getDescription()); } public void setProcessGroupId(String processGroupId) { allocation.setProcessGroupId(processGroupId); } public void setProcessesCount(int processCount) { AllocationChoice choice = new AllocationChoice(); choice.setProcessesCount(processCount); allocation.setAllocationChoice(choice); } public void setProcessesMap(ProcessesMapInterface processesMap){ AllocationChoice choice = new AllocationChoice(); choice.setProcessesMap( (org.qcg.broker.schemas.schedulingplan.ProcessesMap) processesMap.getDescription()); allocation.setAllocationChoice(choice); } @SuppressWarnings("unchecked") public ProviderInfoInterface getProviderInfo() { org.qcg.broker.schemas.schedulingplan.ProviderInfo info = allocation.getProviderInfo(); if(info == null) return null; ProviderInfoInterface providerInfo = new ProviderInfo(info); return providerInfo; } public String getReservationId() { org.qcg.broker.schemas.schedulingplan.Reservation r = allocation.getReservation(); return (r == null ? null : r.getId()); } public void setProviderInfo( ProviderInfoInterface providerInfo) { allocation.setProviderInfo((org.qcg.broker.schemas.schedulingplan.ProviderInfo)providerInfo.getDescription()); } public void setReservation(Reservation reservation) { org.qcg.broker.schemas.schedulingplan.Reservation r = allocation.getReservation(); if(r == null) { r = new org.qcg.broker.schemas.schedulingplan.Reservation(); allocation.setReservation(r); } r.setId(reservation.getId()); List hosts = reservation.getReservedHosts(); if(hosts != null){ for(int i = 0; i < hosts.size(); i++){ ReservedHost host = hosts.get(i); Node node = new Node(); node.setContent(host.getName()); node.setCount(host.getReservedSlotsCount()); r.addNode(node); } } } }