package simulator.workload.reader.resource; import gridsim.ResourceCalendar; import gridsim.gssim.GssimConstants; import gridsim.gssim.ResourceUnitsManagerImpl; import gridsim.gssim.policy.ARAllocationPolicy; import gridsim.gssim.policy.AllocationPolicy; import gridsim.gssim.resource.ARComputingResource; import gridsim.gssim.resource.AbstractComputingResource; import org.qcg.broker.schemas.exception.UnknownParameter; import org.qcg.broker.schemas.hostparams.ComputingResource; import org.qcg.broker.schemas.hostparams.HostParameters; import org.qcg.broker.schemas.hostparams.wrapper.HostParametersWrapper; import org.qcg.broker.schemas.hostparams.wrapper.QueuingSystem; import org.qcg.broker.schemas.hostparams.wrapper.impl.HostParametersWrapperImpl; import org.qcg.broker.schemas.hostparams.wrapper.impl.QueuingSystemImpl; import gssim.schedframe.resources.ComputingResourceDescription; import gssim.schedframe.resources.QueuingSystemDescription; import gssim.schedframe.resources.QueuingSystemDescriptionES; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import org.exolab.castor.xml.MarshalException; import org.exolab.castor.xml.ValidationException; import schedframe.resources.ExecutingResourceDescription; import schedframe.resources.ResourceProvider; import schedframe.resources.providers.LocalSystem; /** * * @author Marcin Krystek * */ public class Grms3ResourceReader implements ResourceReader{ protected Map forecastFinishTimePlugin; protected String defForecastFinishTimePlugin; protected Map localAllocationPolicyPlugin; protected String defLocalAllocationPolicyPlugin; protected ResourceCalendar resourceCalendar; // all resources (ComputingResources and QueuingSystems) extracted from HostParameters xml. protected ArrayList resourcesDescriptions; private int resourceIdx; protected Grms3ResourceReader(){ long seed = 11L * 13L * 17L * 19L * 23L + 1L; double timeZone = 0.0; double peakLoad = 0.0; // the resource load during peak hour double offPeakLoad = 0.0; // the resource load during off-peak hr double holidayLoad = 0.0; // the resource load during holiday // incorporates weekends so the grid resource is on 7 days a week LinkedList Weekends = new LinkedList(); Weekends.add(java.util.Calendar.SATURDAY); Weekends.add(java.util.Calendar.SUNDAY); // incorporates holidays. However, no holidays are set in this example LinkedList Holidays = new LinkedList(); this.resourceCalendar = new ResourceCalendar(timeZone, peakLoad, offPeakLoad, holidayLoad, Weekends, Holidays, seed); } public Grms3ResourceReader(String resourceFile) throws IOException{ this(); resourceIdx = 0; forecastFinishTimePlugin = new HashMap(); localAllocationPolicyPlugin = new HashMap(); defForecastFinishTimePlugin = "not_defined_defaultForecastFinishTimePlugin"; defLocalAllocationPolicyPlugin = "not_defined_defaultLocalAllocationPolicyPlugin"; resourcesDescriptions = new ArrayList(); File file = new File(resourceFile); if(!file.exists()) throw new IOException(resourceFile + " does not exist."); if(!file.isFile()) throw new IOException(resourceFile + " is not a regular file."); try { HostParameters resourceDesription = HostParameters.unmarshalHostParameters(new FileReader(file)); HostParametersWrapper wrapper = new HostParametersWrapperImpl(); wrapper.wrap(resourceDesription); ComputingResource compResources[] = null; // create stand alone computing resources compResources = wrapper.getStandaloneComputingResources(); if(compResources != null){ for(int i = 0; i < compResources.length; i++){ resourcesDescriptions.add(new ComputingResourceDescription(compResources[i])); } } compResources = null; // create queuing systems QueuingSystem queuingSystem = null; compResources = wrapper.getFrontends(); if(compResources != null){ for(int i = 0; i < compResources.length; i++){ queuingSystem = new QueuingSystemImpl(); queuingSystem.create(resourceDesription, compResources[i]); resourcesDescriptions.add(new QueuingSystemDescriptionES(queuingSystem)); } } } catch (MarshalException e) { throw new IOException(e.getMessage()); } catch (ValidationException e) { throw new IOException(e.getMessage()); } catch (UnknownParameter e) { throw new IOException(e.getMessage()); } } public Grms3ResourceReader(String resourceFile, String forecastFinishTimePlugin, String localAllocationPolicyPlugin) throws IOException{ this(resourceFile); defForecastFinishTimePlugin = forecastFinishTimePlugin; defLocalAllocationPolicyPlugin = localAllocationPolicyPlugin; } public AbstractComputingResource read() throws Exception { if(resourceIdx >= resourcesDescriptions.size()) return null; ExecutingResourceDescription executingResourceDesc = resourcesDescriptions.get(resourceIdx++); // get resource id String resourceID = executingResourceDesc.getProvider().getProviderId(); // determine forecast finish time plugin String forecastPlugin = null; if(forecastFinishTimePlugin.containsKey(resourceID)) forecastPlugin = forecastFinishTimePlugin.get(resourceID); else forecastPlugin = defForecastFinishTimePlugin; // determine allocation policy plugin String schedulingPlugin = null; if(localAllocationPolicyPlugin.containsKey(resourceID)) schedulingPlugin = localAllocationPolicyPlugin.get(resourceID); else schedulingPlugin = defLocalAllocationPolicyPlugin; double timeZone = 0.0; ResourceUnitsManagerImpl resConfig = new ResourceUnitsManagerImpl(timeZone, executingResourceDesc); AbstractComputingResource gridRes = null; ResourceProvider provider = new LocalSystem(resourceID, null, null); if(executingResourceDesc.supportReservation()){ ARAllocationPolicy policy = new ARAllocationPolicy(provider, GssimConstants.DEFAULT_RESOURCE_MANAGER_NAME, schedulingPlugin, forecastPlugin, executingResourceDesc); gridRes = new ARComputingResource(provider, 1, resConfig, this.resourceCalendar, policy); } else { AllocationPolicy policy = new AllocationPolicy(provider, GssimConstants.DEFAULT_RESOURCE_MANAGER_NAME, schedulingPlugin, forecastPlugin, executingResourceDesc); gridRes = new gridsim.gssim.resource.ComputingResource( provider, 1, resConfig, this.resourceCalendar, policy); } return gridRes; } public int getNoOfResources(){ return resourcesDescriptions.size(); } public void setCalendar(ResourceCalendar calendar) { this.resourceCalendar = calendar; } public void close() { forecastFinishTimePlugin.clear(); localAllocationPolicyPlugin.clear(); resourcesDescriptions.clear(); resourceIdx = 0; } public void loadPlugins(String fileName) { throw new RuntimeException("Grms3ResourceReader.loadPlugins() is not implemented."); } }