source: xssim/trunk/src/simulator/workload/reader/resource/Grms3ResourceReader.java @ 227

Revision 227, 7.2 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package simulator.workload.reader.resource;
2
3import gridsim.ResourceCalendar;
4import gridsim.gssim.GssimConstants;
5import gridsim.gssim.ResourceUnitsManagerImpl;
6import gridsim.gssim.policy.ARAllocationPolicy;
7import gridsim.gssim.policy.AllocationPolicy;
8import gridsim.gssim.resource.ARComputingResource;
9import gridsim.gssim.resource.AbstractComputingResource;
10import org.qcg.broker.schemas.exception.UnknownParameter;
11import org.qcg.broker.schemas.hostparams.ComputingResource;
12import org.qcg.broker.schemas.hostparams.HostParameters;
13import org.qcg.broker.schemas.hostparams.wrapper.HostParametersWrapper;
14import org.qcg.broker.schemas.hostparams.wrapper.QueuingSystem;
15import org.qcg.broker.schemas.hostparams.wrapper.impl.HostParametersWrapperImpl;
16import org.qcg.broker.schemas.hostparams.wrapper.impl.QueuingSystemImpl;
17import gssim.schedframe.resources.ComputingResourceDescription;
18import gssim.schedframe.resources.QueuingSystemDescriptionES;
19
20import java.io.File;
21import java.io.FileReader;
22import java.io.IOException;
23import java.util.ArrayList;
24import java.util.HashMap;
25import java.util.LinkedList;
26import java.util.Map;
27
28import org.exolab.castor.xml.MarshalException;
29import org.exolab.castor.xml.ValidationException;
30
31import schedframe.resources.ExecutingResourceDescription;
32import schedframe.resources.ResourceProvider;
33import schedframe.resources.providers.LocalSystem;
34
35/**
36 *
37 * @author Marcin Krystek
38 *
39 */
40public class Grms3ResourceReader implements ResourceReader<AbstractComputingResource, ResourceCalendar>{
41
42        protected Map <String, String>forecastFinishTimePlugin;
43        protected String defForecastFinishTimePlugin;
44
45        protected Map <String, String>localAllocationPolicyPlugin;
46        protected String defLocalAllocationPolicyPlugin;
47       
48        protected ResourceCalendar resourceCalendar;
49       
50        // all resources (ComputingResources and QueuingSystems) extracted from HostParameters xml.
51        protected ArrayList<ExecutingResourceDescription> resourcesDescriptions;
52
53        private int resourceIdx;
54       
55        protected Grms3ResourceReader(){
56                long seed = 11L * 13L * 17L * 19L * 23L + 1L;
57                double timeZone = 0.0;
58                double peakLoad = 0.0; // the resource load during peak hour
59                double offPeakLoad = 0.0; // the resource load during off-peak hr
60                double holidayLoad = 0.0; // the resource load during holiday
61               
62                // incorporates weekends so the grid resource is on 7 days a week
63                LinkedList<Integer> Weekends = new LinkedList<Integer>();
64                Weekends.add(java.util.Calendar.SATURDAY);
65                Weekends.add(java.util.Calendar.SUNDAY);
66
67                // incorporates holidays. However, no holidays are set in this example
68                LinkedList<Integer> Holidays = new LinkedList<Integer>();
69                this.resourceCalendar = new ResourceCalendar(timeZone, peakLoad, offPeakLoad,
70                                                                                                                        holidayLoad, Weekends, Holidays, seed);
71        }
72       
73        public Grms3ResourceReader(String resourceFile) throws IOException{
74                this();
75                resourceIdx = 0;
76                forecastFinishTimePlugin = new HashMap<String, String>();
77                localAllocationPolicyPlugin = new HashMap<String, String>();
78               
79                defForecastFinishTimePlugin = "not_defined_defaultForecastFinishTimePlugin";
80                defLocalAllocationPolicyPlugin = "not_defined_defaultLocalAllocationPolicyPlugin";
81               
82                resourcesDescriptions = new ArrayList<ExecutingResourceDescription>();
83               
84                File file = new File(resourceFile);
85                if(!file.exists())
86                        throw new IOException(resourceFile + " does not exist.");
87                if(!file.isFile())
88                        throw new IOException(resourceFile + " is not a regular file.");
89               
90                try {
91                        HostParameters resourceDesription = HostParameters.unmarshalHostParameters(new FileReader(file));
92                        HostParametersWrapper wrapper = new HostParametersWrapperImpl();
93                        wrapper.wrap(resourceDesription);
94                        ComputingResource compResources[] = null;
95                       
96                        // create stand alone computing resources
97                        compResources = wrapper.getStandaloneComputingResources();
98                        if(compResources != null){
99                                for(int i = 0; i < compResources.length; i++){
100                                        resourcesDescriptions.add(new ComputingResourceDescription(compResources[i]));
101                                }
102                        }
103                        compResources = null;
104                       
105                        // create queuing systems
106                        QueuingSystem queuingSystem = null;
107                        compResources = wrapper.getFrontends();
108                        if(compResources != null){
109                                for(int i = 0; i < compResources.length; i++){
110                                        queuingSystem = new QueuingSystemImpl();
111                                        queuingSystem.create(resourceDesription, compResources[i]);
112                                        resourcesDescriptions.add(new QueuingSystemDescriptionES(queuingSystem));
113                                }
114                        }
115                       
116                       
117                } catch (MarshalException e) {
118                        throw new IOException(e.getMessage());
119                } catch (ValidationException e) {
120                        throw new IOException(e.getMessage());
121                } catch (UnknownParameter e) {
122                        throw new IOException(e.getMessage());
123                }
124               
125        }
126       
127        public Grms3ResourceReader(String resourceFile, String forecastFinishTimePlugin, String localAllocationPolicyPlugin) throws IOException{
128                this(resourceFile);
129                defForecastFinishTimePlugin = forecastFinishTimePlugin;
130                defLocalAllocationPolicyPlugin = localAllocationPolicyPlugin;
131        }
132       
133       
134        public AbstractComputingResource read() throws Exception {
135                if(resourceIdx >= resourcesDescriptions.size())
136                        return null;
137               
138                ExecutingResourceDescription executingResourceDesc = resourcesDescriptions.get(resourceIdx++);
139
140                // get resource id
141                String resourceID = executingResourceDesc.getProvider().getProviderId();
142               
143                // determine forecast finish time plugin
144                String forecastPlugin = null;
145                if(forecastFinishTimePlugin.containsKey(resourceID))
146                        forecastPlugin = forecastFinishTimePlugin.get(resourceID);
147                else
148                        forecastPlugin = defForecastFinishTimePlugin;
149               
150                // determine allocation policy plugin
151                String schedulingPlugin = null;
152                if(localAllocationPolicyPlugin.containsKey(resourceID))
153                        schedulingPlugin = localAllocationPolicyPlugin.get(resourceID);
154                else
155                        schedulingPlugin = defLocalAllocationPolicyPlugin;
156               
157                double timeZone = 0.0;
158                ResourceUnitsManagerImpl resConfig = new ResourceUnitsManagerImpl(timeZone, executingResourceDesc);
159               
160                AbstractComputingResource gridRes = null;
161               
162                ResourceProvider provider = new LocalSystem(resourceID, null, null);
163
164                if(executingResourceDesc.supportReservation()){
165                       
166                        ARAllocationPolicy policy = new ARAllocationPolicy(provider,
167                                                                                        GssimConstants.DEFAULT_RESOURCE_MANAGER_NAME,
168                                                                                        schedulingPlugin,
169                                                                                        forecastPlugin,
170                                                                                        executingResourceDesc);
171                       
172                        gridRes = new ARComputingResource(provider,
173                                                                                        1,
174                                                                                        resConfig,
175                                                                                        this.resourceCalendar,
176                                                                                        policy);
177                } else {
178                        AllocationPolicy policy = new AllocationPolicy(provider,
179                                                                                GssimConstants.DEFAULT_RESOURCE_MANAGER_NAME,
180                                                                                schedulingPlugin,
181                                                                                forecastPlugin,
182                                                                                executingResourceDesc);
183                       
184                        gridRes = new gridsim.gssim.resource.ComputingResource(
185                                                                                provider,
186                                                                                1,
187                                                                                resConfig,
188                                                                                this.resourceCalendar,
189                                                                                policy);
190                }
191               
192                return gridRes;
193        }
194       
195        public int getNoOfResources(){
196                return resourcesDescriptions.size();
197        }
198
199        public void setCalendar(ResourceCalendar calendar) {
200                this.resourceCalendar = calendar;
201        }
202       
203        public void close() {
204                forecastFinishTimePlugin.clear();
205                localAllocationPolicyPlugin.clear();
206                resourcesDescriptions.clear();
207                resourceIdx = 0;
208        }
209       
210       
211        public void loadPlugins(String fileName) {
212                throw new RuntimeException("Grms3ResourceReader.loadPlugins() is not implemented.");
213        }
214
215}
Note: See TracBrowser for help on using the repository browser.