1 | package test.rewolucja.resources.reader.test; |
---|
2 | |
---|
3 | import java.io.File; |
---|
4 | import java.io.FileInputStream; |
---|
5 | import java.io.FileNotFoundException; |
---|
6 | import java.io.IOException; |
---|
7 | import java.util.ArrayList; |
---|
8 | import java.util.HashMap; |
---|
9 | import java.util.Map; |
---|
10 | import java.util.MissingResourceException; |
---|
11 | import java.util.PropertyResourceBundle; |
---|
12 | import java.util.ResourceBundle; |
---|
13 | |
---|
14 | |
---|
15 | public class TempResourceDescriptionReader { |
---|
16 | |
---|
17 | public static final String FIRST_LAYER = "firstLayer"; |
---|
18 | public static final String SECOND_LAYER = "secondLayer"; |
---|
19 | public static final String THIRD_LAYER = "thirdLayer"; |
---|
20 | public static final String FOURTH_LAYER = "fourthLayer"; |
---|
21 | public static final String FIFTH_LAYER = "fifthLayer"; |
---|
22 | public static final String SIXTH_LAYER = "sixthLayer"; |
---|
23 | |
---|
24 | public static final String GRIDS = "grids"; |
---|
25 | public static final String DATA_CENTERS = "dataCenters"; |
---|
26 | public static final String RACKS = "racks"; |
---|
27 | public static final String NODES = "nodes"; |
---|
28 | public static final String CPUS = "cpus"; |
---|
29 | public static final String CORES = "cores"; |
---|
30 | |
---|
31 | /*public static final String COMPUTING_GRID = "computingGrid"; |
---|
32 | public static final String COMPUTING_RESOURCE = "computingResource"; |
---|
33 | public static final String RACK = "rack"; |
---|
34 | public static final String COMPUTING_NODE = "computingNode"; |
---|
35 | public static final String CPU = "cpu"; |
---|
36 | public static final String CORE = "core";*/ |
---|
37 | |
---|
38 | public ArrayList<String> resources = null; |
---|
39 | public Map<String, String> res_amount; |
---|
40 | public Map<String, String> layer_management; |
---|
41 | |
---|
42 | public String grids = null; |
---|
43 | public String dataCenters = null; |
---|
44 | public String racks = null; |
---|
45 | public static String nodes = null; |
---|
46 | public String cpus= null; |
---|
47 | public String cores = null; |
---|
48 | |
---|
49 | public static final String MODEL_A = "modelA"; |
---|
50 | public static final String MODEL_B = "modelB"; |
---|
51 | public static final String MODEL_C = "modelC"; |
---|
52 | |
---|
53 | public static String modelA = null; |
---|
54 | public static String modelB = null; |
---|
55 | public static String modelC = null; |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | protected TempResourceDescriptionReader() { |
---|
60 | |
---|
61 | resources = new ArrayList<String>(); |
---|
62 | res_amount = new HashMap<String, String>(); |
---|
63 | layer_management = new HashMap<String, String>(); |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | public static TempResourceDescriptionReader getConfiguration(String resBundleFileName) { |
---|
68 | |
---|
69 | TempResourceDescriptionReader co = new TempResourceDescriptionReader(); |
---|
70 | File resBundleFile = new File(resBundleFileName); |
---|
71 | ResourceBundle bundle = null; |
---|
72 | try { |
---|
73 | bundle = new PropertyResourceBundle(new FileInputStream(resBundleFile)); |
---|
74 | } catch (FileNotFoundException e) { |
---|
75 | e.printStackTrace(); |
---|
76 | return null; |
---|
77 | } catch (IOException e) { |
---|
78 | e.printStackTrace(); |
---|
79 | return null; |
---|
80 | } |
---|
81 | |
---|
82 | /********LAYERS*******/ |
---|
83 | |
---|
84 | try { |
---|
85 | co.resources.add (bundle |
---|
86 | .getString(FIRST_LAYER)); |
---|
87 | } catch(MissingResourceException e){ |
---|
88 | //co.firstLayer = null; |
---|
89 | } |
---|
90 | |
---|
91 | try { |
---|
92 | co.resources.add(bundle |
---|
93 | .getString(SECOND_LAYER)); |
---|
94 | } catch(MissingResourceException e){ |
---|
95 | //co.secondLayer = null; |
---|
96 | } |
---|
97 | |
---|
98 | try { |
---|
99 | co.resources.add(bundle |
---|
100 | .getString(THIRD_LAYER)); |
---|
101 | } catch(MissingResourceException e){ |
---|
102 | //co.thirdLayer = null; |
---|
103 | } |
---|
104 | |
---|
105 | try { |
---|
106 | co.resources.add(bundle |
---|
107 | .getString(FOURTH_LAYER)); |
---|
108 | } catch(MissingResourceException e){ |
---|
109 | //co.fourthLayer = null; |
---|
110 | } |
---|
111 | |
---|
112 | try { |
---|
113 | co.resources.add(bundle |
---|
114 | .getString(FIFTH_LAYER)); |
---|
115 | } catch(MissingResourceException e){ |
---|
116 | //co.fifthLayer = null; |
---|
117 | } |
---|
118 | |
---|
119 | try { |
---|
120 | co.resources.add(bundle |
---|
121 | .getString(SIXTH_LAYER)); |
---|
122 | } catch(MissingResourceException e){ |
---|
123 | //co.sixthLayer = null; |
---|
124 | } |
---|
125 | |
---|
126 | /********CHARACTERISTIC*******/ |
---|
127 | |
---|
128 | try { |
---|
129 | co.grids = bundle |
---|
130 | .getString(GRIDS); |
---|
131 | co.res_amount.put("COMPUTING_GRID",co.grids); |
---|
132 | } catch(MissingResourceException e){ |
---|
133 | co.grids = null; |
---|
134 | } |
---|
135 | |
---|
136 | try { |
---|
137 | co.dataCenters = bundle |
---|
138 | .getString(DATA_CENTERS); |
---|
139 | co.res_amount.put("DATA_CENTER", co.dataCenters); |
---|
140 | } catch(MissingResourceException e){ |
---|
141 | co.dataCenters = null; |
---|
142 | } |
---|
143 | |
---|
144 | try { |
---|
145 | co.racks = bundle |
---|
146 | .getString(RACKS); |
---|
147 | co.res_amount.put("RACK", co.racks); |
---|
148 | } catch(MissingResourceException e){ |
---|
149 | co.racks = null; |
---|
150 | } |
---|
151 | |
---|
152 | try { |
---|
153 | TempResourceDescriptionReader.nodes = bundle |
---|
154 | .getString(NODES); |
---|
155 | co.res_amount.put("COMPUTING_NODE", TempResourceDescriptionReader.nodes); |
---|
156 | } catch(MissingResourceException e){ |
---|
157 | TempResourceDescriptionReader.nodes = null; |
---|
158 | } |
---|
159 | |
---|
160 | try { |
---|
161 | co.cpus = bundle |
---|
162 | .getString(CPUS); |
---|
163 | co.res_amount.put("CPU", co.cpus); |
---|
164 | } catch(MissingResourceException e){ |
---|
165 | co.cpus = null; |
---|
166 | } |
---|
167 | |
---|
168 | try { |
---|
169 | co.cores = bundle |
---|
170 | .getString(CORES); |
---|
171 | co.res_amount.put("CORE", co.cores); |
---|
172 | } catch(MissingResourceException e){ |
---|
173 | co.cores = null; |
---|
174 | } |
---|
175 | |
---|
176 | /********MANAGEMENT*******/ |
---|
177 | |
---|
178 | /*try { |
---|
179 | co.layer_management.put("COMPUTING_GRID",bundle |
---|
180 | .getString(COMPUTING_GRID)); |
---|
181 | } catch(MissingResourceException e){ |
---|
182 | //co.grids = null; |
---|
183 | } |
---|
184 | |
---|
185 | try { |
---|
186 | co.layer_management.put("COMPUTING_RESOURCE", bundle |
---|
187 | .getString(COMPUTING_RESOURCE)); |
---|
188 | } catch(MissingResourceException e){ |
---|
189 | //co.dataCenters = null; |
---|
190 | } |
---|
191 | |
---|
192 | try { |
---|
193 | co.layer_management.put("RACK", bundle |
---|
194 | .getString(RACK)); |
---|
195 | } catch(MissingResourceException e){ |
---|
196 | //co.racks = null; |
---|
197 | } |
---|
198 | |
---|
199 | try { |
---|
200 | co.layer_management.put("COMPUTING_NODE", bundle |
---|
201 | .getString(COMPUTING_NODE)); |
---|
202 | } catch(MissingResourceException e){ |
---|
203 | //co.nodes = null; |
---|
204 | } |
---|
205 | |
---|
206 | try { |
---|
207 | co.layer_management.put("CPU", bundle |
---|
208 | .getString(CPU)); |
---|
209 | } catch(MissingResourceException e){ |
---|
210 | //co.cpus = null; |
---|
211 | }* |
---|
212 | |
---|
213 | try { |
---|
214 | co.layer_management.put("CORE", bundle |
---|
215 | .getString(CORE)); |
---|
216 | } catch(MissingResourceException e){ |
---|
217 | //co.cores = null; |
---|
218 | } |
---|
219 | |
---|
220 | /********MODELS*******/ |
---|
221 | |
---|
222 | try { |
---|
223 | TempResourceDescriptionReader.modelA = bundle |
---|
224 | .getString(MODEL_A); |
---|
225 | } catch(MissingResourceException e){ |
---|
226 | Integer nrOfNodes = Integer.parseInt(nodes); |
---|
227 | TempResourceDescriptionReader.modelA = String.valueOf(nrOfNodes/3); |
---|
228 | } |
---|
229 | |
---|
230 | try { |
---|
231 | TempResourceDescriptionReader.modelB = bundle |
---|
232 | .getString(MODEL_B); |
---|
233 | } catch(MissingResourceException e){ |
---|
234 | Integer nrOfNodes = Integer.parseInt(nodes); |
---|
235 | TempResourceDescriptionReader.modelB = String.valueOf(nrOfNodes/3); |
---|
236 | } |
---|
237 | |
---|
238 | try { |
---|
239 | TempResourceDescriptionReader.modelC = bundle |
---|
240 | .getString(MODEL_C); |
---|
241 | } catch(MissingResourceException e){ |
---|
242 | Integer nrOfNodes = Integer.parseInt(nodes); |
---|
243 | TempResourceDescriptionReader.modelC = String.valueOf(nrOfNodes/3); |
---|
244 | } |
---|
245 | |
---|
246 | return co; |
---|
247 | } |
---|
248 | |
---|
249 | public static String getSeparatorTerminatedPath(String path) { |
---|
250 | if (path.endsWith(File.separator)) |
---|
251 | return new String(path); |
---|
252 | else { |
---|
253 | StringBuilder result = new StringBuilder(path.length() |
---|
254 | + File.separator.length()); |
---|
255 | result.append(path); |
---|
256 | result.append(File.separator); |
---|
257 | return result.toString(); |
---|
258 | } |
---|
259 | } |
---|
260 | |
---|
261 | } |
---|