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

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