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 java.util.Map; import org.exolab.castor.xml.MarshalException; import org.exolab.castor.xml.ValidationException; import schedframe.resources.units.ProcessingElements; import schedframe.resources.units.ResourceUnit; import schedframe.resources.units.ResourceUnitName; import schedframe.resources.units.StandardResourceUnitName; import schedframe.scheduling.manager.resources.utils.ResourceManagerUtils; 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()); } protected Map requestedResources; //protected boolean isProcessing = false; protected String providerName; @Override public void setRequestedResources( Map choosenResources) { requestedResources = choosenResources; if(choosenResources != null){ ResourceManagerUtils.setPendingResources(choosenResources); /*ProcessingElements processingElements = (ProcessingElements)requestedResources.get(StandardResourceUnitName.PE); if(processingElements != null){ isProcessing = true; } */ } } @Override public Map getRequestedResources() { return this.requestedResources; } /*public boolean isProcessing(){ return isProcessing; }*/ @Override public void setProviderName(String providerName) { this.providerName = providerName; } @Override public String getProviderName() { return providerName; } }