Line | Hits | Source |
---|---|---|
1 | /* | |
2 | ||
3 | Copyright (C) 2008 NTT DATA Corporation | |
4 | ||
5 | This program is free software; you can redistribute it and/or | |
6 | Modify it under the terms of the GNU General Public License | |
7 | as published by the Free Software Foundation, version 2. | |
8 | ||
9 | This program is distributed in the hope that it will be | |
10 | useful, but WITHOUT ANY WARRANTY; without even the implied | |
11 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
12 | PURPOSE. See the GNU General Public License for more details. | |
13 | ||
14 | */ | |
15 | ||
16 | package com.clustercontrol.performance.rrdtool; | |
17 | ||
18 | import java.io.BufferedOutputStream; | |
19 | import java.io.BufferedReader; | |
20 | import java.io.FileOutputStream; | |
21 | import java.io.FileReader; | |
22 | import java.io.IOException; | |
23 | import java.nio.channels.FileChannel; | |
24 | import java.rmi.RemoteException; | |
25 | import java.text.DecimalFormat; | |
26 | import java.text.SimpleDateFormat; | |
27 | import java.util.ArrayList; | |
28 | import java.util.Arrays; | |
29 | import java.util.Collections; | |
30 | import java.util.Date; | |
31 | import java.util.HashMap; | |
32 | import java.util.StringTokenizer; | |
33 | import java.util.regex.Pattern; | |
34 | ||
35 | import javax.naming.NamingException; | |
36 | ||
37 | import org.apache.commons.logging.Log; | |
38 | import org.apache.commons.logging.LogFactory; | |
39 | import org.jnp.interfaces.NamingContext; | |
40 | ||
41 | import com.clustercontrol.bean.FacilityTreeItem; | |
42 | import com.clustercontrol.performance.bean.CollectedDataInfo; | |
43 | import com.clustercontrol.performance.bean.CollectorItemInfo; | |
44 | import com.clustercontrol.performance.bean.CollectorProperty; | |
45 | import com.clustercontrol.performance.ejb.session.CollectorController; | |
46 | import com.clustercontrol.performance.ejb.session.CollectorControllerHome; | |
47 | import com.clustercontrol.performance.rrdtool.csv.CSVColumn; | |
48 | import com.clustercontrol.performance.rrdtool.util.CollectedDataInfoDateComparator; | |
49 | import com.clustercontrol.performance.rrdtool.util.Config; | |
50 | import com.clustercontrol.performance.rrdtool.util.LoginManager; | |
51 | ||
52 | /** | |
53 | * Hinemos Addon for RRDTool<br> | |
54 | * CSVファイル出力?? 実行クラス<br> | |
55 | * | |
56 | * @since 3.0.0 | |
57 | */ | |
58 | 1 | public class PerformanceCSVExport { |
59 | ||
60 | // main関数に与えられる引数の格納変数 | |
61 | 1 | private static String collectorID = null; |
62 | 1 | private static String facilityID = null; |
63 | 1 | private static String listFilePath = null; |
64 | 1 | private static String outputFilePath = null; |
65 | 1 | private static String startDateEpochStr = null; |
66 | 1 | private static String endDateEpochStr = null; |
67 | ||
68 | // main関数に与えられる引数を変換した変数 | |
69 | 1 | private static long startDateEpoch = 0; |
70 | 1 | private static long endDateEpoch = 0; |
71 | ||
72 | // 実行ログ出力用クラス | |
73 | 1 | private static Log log = LogFactory.getLog(PerformanceCSVExport.class); |
74 | ||
75 | /** | |
76 | * CSV出力実行関数<br> | |
77 | * | |
78 | * @param args | |
79 | */ | |
80 | public static void main(String args[]) { | |
81 | ||
82 | // 出力??目定義格納変数 | |
83 | 23 | ArrayList<CSVColumn> csvCols = new ArrayList<CSVColumn>(); |
84 | ||
85 | // 収集設定変数 | |
86 | 23 | CollectorProperty property = null; |
87 | ||
88 | // 不正出力??目?目存在フラグ | |
89 | 23 | boolean invalidColFlg = false; |
90 | ||
91 | // 収集性能値の格納変数 | |
92 | 23 | ArrayList<CollectedDataInfo> collectedDataInfos = null; |
93 | ||
94 | // 出力??目の性能値存在フラグ | |
95 | 23 | HashMap<CSVColumn, Boolean> csvColFlg = null; |
96 | ||
97 | // マネージャとのセ?ション?報 | |
98 | 23 | NamingContext m_ctx = null; |
99 | 23 | CollectorController collector = null; |
100 | ||
101 | // 実行ログを記? | |
102 | 23 | log.info(Config.getMsg("RRDTool.ExportCSV.Exec") + " : " + Arrays.toString(args)); |
103 | ||
104 | // 引数の数の確? | |
105 | 23 | if (args.length != 6) { |
106 | 3 | log.error(Config.getMsg("RRDTool.ExportCSV.ArgsInvalid")); |
107 | 3 | System.exit(11); |
108 | } | |
109 | ||
110 | // 引数の格? | |
111 | 20 | collectorID = args[0]; |
112 | 20 | facilityID = args[1]; |
113 | 20 | listFilePath = args[2]; |
114 | 20 | startDateEpochStr = args[3]; |
115 | 20 | endDateEpochStr = args[4]; |
116 | 20 | outputFilePath = args[5]; |
117 | ||
118 | // エクスポ?ト期間?確? | |
119 | try { | |
120 | 20 | startDateEpoch = Long.decode(startDateEpochStr); |
121 | 18 | endDateEpoch = Long.decode(endDateEpochStr); |
122 | ||
123 | 16 | if (startDateEpoch <= 0 || endDateEpoch <= 0 || endDateEpoch < startDateEpoch) { |
124 | // 検索日時が正数??0より大きい?でな?、もしくは検索終?日時が検索開始日時より前である場? | |
125 | 2 | log.error(Config.getMsg("RRDTool.ExportCSV.DateFormatInvalid")); |
126 | 2 | System.exit(52); |
127 | } | |
128 | ||
129 | // ミリ秒へ変換 | |
130 | 14 | startDateEpoch *= 1000; |
131 | 14 | endDateEpoch *= 1000; |
132 | 4 | } catch (NumberFormatException e) { |
133 | // 検索日時が整数でな?場合?Long型として読み込めな?場合? | |
134 | 4 | log.error(Config.getMsg("RRDTool.ExportCSV.DateFormatInvalid"), e); |
135 | 4 | System.exit(52); |
136 | } | |
137 | ||
138 | // 出力??目定義ファイルの読み込み | |
139 | 14 | csvCols = readColumnDefFile(listFilePath); |
140 | ||
141 | // マネージャーへの接? | |
142 | try { | |
143 | 28 | m_ctx = LoginManager.getContextManager().getNamingContext(Config.getConfig("Login.USER"), |
144 | 14 | Config.getConfig("Login.PASSWORD"), Config.getConfig("Login.URL")); |
145 | 22 | collector = (CollectorController) ((CollectorControllerHome) m_ctx.lookup(CollectorControllerHome.JNDI_NAME)) |
146 | 9 | .create(); |
147 | 5 | } catch (Exception e) { |
148 | 5 | log.error(Config.getMsg("RRDTool.ExportCSV.ConnectManagerFailed"), e); |
149 | 5 | System.exit(14); |
150 | } | |
151 | ||
152 | try { | |
153 | // 収集プロパティの取得を試み、取得できな?場合?エラー処?を実施する | |
154 | 9 | property = collector.getCollectorProperty(collectorID); |
155 | ||
156 | // ?定?収集IDの収集が存在しな?場合?、nullが返る | |
157 | 8 | if (property == null) { |
158 | 1 | log.error(Config.getMsg("RRDTool.ExportCSV.CollectorIDNotFound")); |
159 | 1 | System.exit(53); |
160 | } | |
161 | ||
162 | 1 | } catch (RemoteException e) { |
163 | 1 | log.error(Config.getMsg("RRDTool.ExportCSV.ConnectManagerFailed"), e); |
164 | 1 | System.exit(14); |
165 | } | |
166 | ||
167 | // ファシリ?ィIDの妥当?確? | |
168 | 7 | if (!checkFacilityDefinition(property, facilityID)) { |
169 | 1 | log.error(Config.getMsg("RRDTool.ExportCSV.FacilityIDNotFound")); |
170 | 1 | System.exit(54); |
171 | } | |
172 | ||
173 | // 出力??目の妥当?確? | |
174 | 6 | invalidColFlg = !checkCollectorDefinition(property, csvCols); |
175 | ||
176 | // 収集性能値の格? | |
177 | try { | |
178 | 12 | collectedDataInfos = (ArrayList<CollectedDataInfo>) collector.getRecordCollectedData(collectorID, facilityID, |
179 | 6 | new Date(startDateEpoch), new Date(endDateEpoch)); |
180 | 1 | } catch (RemoteException e) { |
181 | 1 | log.error(Config.getMsg("RRDTool.ExportCSV.ConnectManagerFailed"), e); |
182 | 1 | System.exit(14); |
183 | } | |
184 | ||
185 | // 不要な性能値の除去 | |
186 | 5 | csvColFlg = examineCollectedDataInfo(collectedDataInfos, csvCols); |
187 | ||
188 | // 出力??目の 収集性能値?1つも存在しな?場? | |
189 | 5 | if (collectedDataInfos.size() == 0) { |
190 | 1 | log.error(Config.getMsg("RRDTool.ExportCSV.ColValueNotFound")); |
191 | 1 | System.exit(55); |
192 | } | |
193 | ||
194 | // 性能値の日時ソー? | |
195 | 4 | Collections.sort(collectedDataInfos, new CollectedDataInfoDateComparator()); |
196 | ||
197 | // CSVファイルの出? | |
198 | 4 | writeCSVFile(outputFilePath, csvCols, collectedDataInfos); |
199 | ||
200 | // マネージャー接続??断 | |
201 | try { | |
202 | 4 | LoginManager.getContextManager().logout(); |
203 | 0 | } catch (NamingException e) { |
204 | 0 | log.warn(Config.getMsg("RRDTool.ExportCSV.DisconnectManagerFailed"), e); |
205 | } | |
206 | ||
207 | 4 | if (invalidColFlg) { |
208 | // 不正な出力??目定義がある?? | |
209 | 1 | System.exit(101); |
210 | 3 | } else if (csvColFlg.containsValue(false)) { |
211 | // 性能値のな?出力??目がある?? | |
212 | 1 | System.exit(102); |
213 | } else { | |
214 | // 正常終? | |
215 | 2 | log.info(Config.getMsg("RRDTool.ExportCSV.Exit")); |
216 | 2 | System.exit(0); |
217 | } | |
218 | 2 | } |
219 | ||
220 | /** | |
221 | * 出力??目定義ファイルを読み込んで、?力??目?報を取得する?? | |
222 | * | |
223 | * @param fileName | |
224 | * 出力??目定義ファイルのファイルパス?絶対パス、相対パスともに可?? | |
225 | * @return 出力??目?報の配?(?力??目?に格納されて?る? | |
226 | */ | |
227 | public static ArrayList<CSVColumn> readColumnDefFile(String fileName) { | |
228 | ||
229 | // 返り値 | |
230 | 29 | ArrayList<CSVColumn> ret = new ArrayList<CSVColumn>(); |
231 | ||
232 | // ファイル読み込み用変数 | |
233 | 29 | BufferedReader br = null; |
234 | 29 | String line = null; |
235 | 29 | String colName = null; |
236 | 29 | String itemCode = null; |
237 | 29 | String deviceName = null; |
238 | ||
239 | // 出力??目定義のフォーマット確認用変数 | |
240 | 29 | StringTokenizer defTokenizer = null; |
241 | 29 | String tokenStr = "\t"; |
242 | 29 | Pattern colNamePattern = Pattern.compile("^[^\t\",]+$"); |
243 | 29 | boolean invalidDefFormat = false; |
244 | ||
245 | try { | |
246 | // 出力??目定義ファイルを開? | |
247 | 29 | br = new BufferedReader(new FileReader(fileName)); |
248 | ||
249 | 259 | while ((line = br.readLine()) != null) { |
250 | ||
251 | // カラ?数の確? | |
252 | 203 | defTokenizer = new StringTokenizer(line, tokenStr, false); |
253 | 203 | if (defTokenizer.countTokens() == 2) { |
254 | // 出力??目?<tab>?目コード?場? | |
255 | 156 | colName = defTokenizer.nextToken(); |
256 | 156 | itemCode = defTokenizer.nextToken(); |
257 | 156 | deviceName = ""; |
258 | 47 | } else if (defTokenizer.countTokens() == 3) { |
259 | // 出力??目?<tab>?目コー?<tab>?バイス名?場? | |
260 | 42 | colName = defTokenizer.nextToken(); |
261 | 42 | itemCode = defTokenizer.nextToken(); |
262 | 42 | deviceName = defTokenizer.nextToken(); |
263 | } else { | |
264 | // 不正な書式?行?場? | |
265 | 5 | colName = null; |
266 | 5 | itemCode = null; |
267 | 5 | deviceName = null; |
268 | 5 | log.error(Config.getMsg("RRDTool.ExportCSV.LineFormatInvalid") + " : " + line); |
269 | 5 | invalidDefFormat = true; |
270 | } | |
271 | ||
272 | // 出力??目名?書式確? | |
273 | 203 | if (colName != null && !colNamePattern.matcher(colName).matches()) { |
274 | // 出力??目名に不正な場? | |
275 | 2 | log.error(Config.getMsg("RRDTool.ExportCSV.ColNameFormatInvalid") + " : " + colName); |
276 | 2 | invalidDefFormat = true; |
277 | } | |
278 | ||
279 | // 出力カラ?定義の格? | |
280 | 203 | if (!invalidDefFormat) { |
281 | 193 | ret.add(new CSVColumn(colName, itemCode, deviceName)); |
282 | } | |
283 | ||
284 | } | |
285 | ||
286 | 1 | } catch (Exception e) { |
287 | // ファイルの読み込み処?に失敗した?? | |
288 | 1 | log.error(Config.getMsg("RRDTool.ExportCSV.ReadFileFailed"), e); |
289 | 1 | System.exit(12); |
290 | 0 | } finally { |
291 | try { | |
292 | // 出力??目定義ファイルを閉じる | |
293 | 29 | if (br != null) { |
294 | 28 | br.close(); |
295 | } | |
296 | 1 | } catch (IOException e) { |
297 | // ファイルの読み込み処?に失敗した?? | |
298 | 1 | log.error(Config.getMsg("RRDTool.ExportCSV.ReadFileFailed"), e); |
299 | 1 | System.exit(12); |
300 | } | |
301 | 29 | if (invalidDefFormat) { |
302 | // 不正な?目定義が存在した場? | |
303 | 7 | System.exit(13); |
304 | } | |
305 | 0 | } |
306 | ||
307 | 29 | return ret; |
308 | } | |
309 | ||
310 | /** | |
311 | * 性能収集定義に該当する収?対象?収?ID, ?バイス名)が存在するかど?かを確認する?? | |
312 | * | |
313 | * @param property | |
314 | * 性能収集定義オブジェク? | |
315 | * @param csvCols | |
316 | * 出力??目?報の配?(?力??目?に格納されて?る? | |
317 | * @return 不正な出力??目?報が?とつでも存在する場?false, それ以外?true | |
318 | */ | |
319 | public static boolean checkCollectorDefinition(CollectorProperty property, ArrayList<CSVColumn> csvCols) { | |
320 | ||
321 | 15 | boolean ret = true; |
322 | 15 | boolean invalidColumn = false; |
323 | ||
324 | // 出力??目が?能収集定義に含まれるかど?かを確認す? | |
325 | 153 | for (CSVColumn csvCol : csvCols) { |
326 | 123 | invalidColumn = true; |
327 | 1166 | for (CollectorItemInfo collectorItemInfo : (ArrayList<CollectorItemInfo>) property.getItemList()) { |
328 | 1037 | if (csvCol.equalsCollection(collectorItemInfo.getItemCode(), collectorItemInfo.getDeviceName())) { |
329 | 117 | invalidColumn = false; |
330 | 117 | break; |
331 | } | |
332 | } | |
333 | 123 | if (invalidColumn) { |
334 | // 性能収集定義に含まれな?出力??目の場? | |
335 | 12 | log.warn(Config.getMsg("RRDTool.ExportCSV.ColDefinitionInvalid") + " : " + csvCol.getItemCode() + ", " |
336 | 6 | + csvCol.getDeviceName()); |
337 | 6 | ret = false; |
338 | } | |
339 | } | |
340 | ||
341 | 15 | return ret; |
342 | } | |
343 | ||
344 | /** | |
345 | * 性能収集定義に該当するファシリ?ィIDが存在するかど?かを確認する?? | |
346 | * | |
347 | * @param property | |
348 | * 性能収集定義オブジェク? | |
349 | * @param facilityId | |
350 | * 出力対象ノ?ド?ファシリ?ィID | |
351 | * @return ファシリ?ィIDが存在しな?場?false, それ以外?true | |
352 | */ | |
353 | public static boolean checkFacilityDefinition(CollectorProperty property, String facilityId) { | |
354 | // 収集対象スコープ?下?スコープツリーを取? | |
355 | 7 | FacilityTreeItem tree = property.getCollectorData().getFacilityTree(); |
356 | ||
357 | // トップ?ファシリ?ィから?番に子要?を?帰?に調べ? | |
358 | 7 | return checkChildFacility(tree, facilityId); |
359 | } | |
360 | ||
361 | /** | |
362 | * ?定ファシリ?ィ?リーの配下に該当?ファシリ?ィIDの要?が存在するか否かを再帰?に調べる?? | |
363 | * | |
364 | * @param treeItem | |
365 | * ファシリ?ィ?リー?報 | |
366 | * @param facilityId | |
367 | * ファシリ?ィID | |
368 | * @return | |
369 | */ | |
370 | private static boolean checkChildFacility(FacilityTreeItem treeItem, String facilityId) { | |
371 | // ?致するも?が見つかった?合?、trueを返す | |
372 | 23 | if (treeItem.getData().getFacilityId().equals(facilityId)) { |
373 | 6 | return true; |
374 | } | |
375 | ||
376 | 21 | for (int i = 0; i < treeItem.getChildren().length; i++) { |
377 | 16 | FacilityTreeItem child = treeItem.getChildren()[i]; |
378 | ||
379 | // 子要?を?帰?に捜査し?見つかった?合にはtrueを返す | |
380 | // falseの場合?継続して捜査を実? | |
381 | 16 | if (checkChildFacility(child, facilityId) == true) { |
382 | 12 | return true; |
383 | } | |
384 | } | |
385 | ||
386 | // ?致するも?が見つからなかった?合?nullを返す | |
387 | 5 | return false; |
388 | } | |
389 | ||
390 | /** | |
391 | * 出力??目定義に存在しな?性能?報を??から取り除き?各出力??目における?能?報が存在するかど?かを定義した連想配?を返す? | |
392 | * | |
393 | * @param collectedDataInfos | |
394 | * 収集性能値の格納??? | |
395 | * @param csvCols | |
396 | * 出力??目定義オブジェク? | |
397 | * @return 出力??目オブジェクトをキーとして、収?性能値?1つ以上存在すればtrue, 存在しなければfalseを?とする連想配?? | |
398 | */ | |
399 | public static HashMap<CSVColumn, Boolean> examineCollectedDataInfo(ArrayList<CollectedDataInfo> collectedDataInfos, | |
400 | ArrayList<CSVColumn> csvCols) { | |
401 | ||
402 | 16 | boolean valueExistFlg = false; |
403 | 16 | CollectedDataInfo collectedDataInfo = null; |
404 | 16 | HashMap<CSVColumn, Boolean> ret = new HashMap<CSVColumn, Boolean>(); |
405 | ||
406 | // すべての出力??目の収集性能値存在フラグをfalseとする | |
407 | 169 | for (CSVColumn csvCol : csvCols) { |
408 | 137 | ret.put(csvCol, false); |
409 | } | |
410 | ||
411 | // すべての収集性能値オブジェクトが収集?目に含まれるかど?かを確認す? | |
412 | 1908 | for (int i = 0; i < collectedDataInfos.size(); i++) { |
413 | 1892 | collectedDataInfo = collectedDataInfos.get(i); |
414 | 1892 | valueExistFlg = false; |
415 | 37264 | for (CSVColumn csvCol : csvCols) { |
416 | 33480 | if (csvCol.equalsCollection(collectedDataInfo.getItemCode(), collectedDataInfo.getDeviceName())) { |
417 | 2989 | valueExistFlg = true; |
418 | 2989 | ret.put(csvCol, true); |
419 | } | |
420 | } | |
421 | // 出力??目に含まれな?収集性能値オブジェクトを取り除? | |
422 | 1892 | if (!valueExistFlg) { |
423 | 206 | collectedDataInfos.remove(i); |
424 | 206 | i--; |
425 | } | |
426 | } | |
427 | ||
428 | 16 | return ret; |
429 | } | |
430 | ||
431 | /** | |
432 | * 収集性能値をCSVファイルに出力する??<br> | |
433 | * <br> - 出力?<br> | |
434 | * "Date","Time","CPU_ALL","SWAP_ALL","PCK_RCV eth0"[LF]<br> | |
435 | * "08/05/30","0:00",0.64,0.00,22.27,11.07[LF]<br> | |
436 | * "08/05/30","0:30",1.00,0.00,26.40,12.93[LF]<br> | |
437 | * <br> | |
438 | * ただし??"Date", "Time"は性能収集の予定日時ではなく?実際に収集した日時である?<br> | |
439 | * また?何らか?原因により収集?延が発生し?1?間?中で??yyyy-MM-dd HH:mm?に<br> | |
440 | * 同?キー??collector_id, item_code,device_name)に対する?数の性能値が存在する場合?<br> | |
441 | * ?も古?日時?性能値を?力??容とする。(古?日時?性能値のほ?が計測時間が長く?信頼性が高いため?? | |
442 | * | |
443 | * @param filePath | |
444 | * CSVファイルのファイルパス?絶対パス、相対パスともに可?? | |
445 | * @param csvCols | |
446 | * 出力??目定義オブジェク? | |
447 | * @param collectedDataInfos | |
448 | * 収集性能値の格納??(た?し?日時でソートされており、?力??目以外?収集性能値が存在しな?こと。また??能値がnullでな?こと。? | |
449 | */ | |
450 | public static void writeCSVFile(String filePath, ArrayList<CSVColumn> csvCols, | |
451 | ArrayList<CollectedDataInfo> collectedDataInfos) { | |
452 | ||
453 | // ファイル書き込み用変数 | |
454 | 21 | FileOutputStream fos = null; |
455 | 21 | BufferedOutputStream bos = null; |
456 | 21 | FileChannel channel = null; |
457 | 21 | StringBuffer line = new StringBuffer(); |
458 | ||
459 | // 日付書式用変数 | |
460 | 21 | SimpleDateFormat dateformat = new SimpleDateFormat("yy/MM/dd"); |
461 | 21 | SimpleDateFormat timeformat = new SimpleDateFormat("H:mm"); |
462 | 21 | SimpleDateFormat hashKeyformat = new SimpleDateFormat("yyyy/MM/dd HH:mm"); |
463 | ||
464 | // 収集性能値書式用変数 | |
465 | 21 | DecimalFormat valueformat = new DecimalFormat("#.00"); |
466 | ||
467 | // 日時文字??yyyy-MM-dd hh:mm?をキーとした収集性能値の連想配?? | |
468 | 21 | HashMap<String, ArrayList<CollectedDataInfo>> dataHash = new HashMap<String, ArrayList<CollectedDataInfo>>(); |
469 | 21 | String hashKey = null; |
470 | 21 | ArrayList<String> hashKeys = new ArrayList<String>(); |
471 | ||
472 | // 連想配?への収集性能値の格? | |
473 | 2500 | for (CollectedDataInfo collectedDataInfo : collectedDataInfos) { |
474 | 2458 | hashKey = hashKeyformat.format(collectedDataInfo.getDate()); |
475 | 2458 | if (!dataHash.containsKey(hashKey)) { |
476 | 352 | dataHash.put(hashKey, new ArrayList<CollectedDataInfo>()); |
477 | } | |
478 | 2458 | dataHash.get(hashKey).add(collectedDataInfo); |
479 | 2458 | if (!hashKeys.contains(hashKey)) { |
480 | 352 | hashKeys.add(hashKey); |
481 | } | |
482 | } | |
483 | ||
484 | // CSVファイルへの出? | |
485 | try { | |
486 | // 出力ファイルを開? | |
487 | 21 | fos = new FileOutputStream(filePath); |
488 | ||
489 | // ファイルの排他制御?排他ロ?クを取得? | |
490 | 20 | channel = fos.getChannel(); |
491 | 20 | if (channel.tryLock() == null) { |
492 | // ロ?クに失敗した?? | |
493 | 1 | log.error(Config.getMsg("RRDTool.ExportCSV.LockFileFailed")); |
494 | 1 | System.exit(51); |
495 | } | |
496 | 20 | bos = new BufferedOutputStream(fos); |
497 | ||
498 | // ヘッ?ー行?出? | |
499 | 20 | line.delete(0, line.length()); |
500 | 20 | line.append("\"Date\",\"Time\","); |
501 | 162 | for (int i = 0; i < csvCols.size(); i++) { |
502 | 142 | line.append("\"" + csvCols.get(i).getColumnName() + "\""); |
503 | 142 | if (i < csvCols.size() - 1) { |
504 | 122 | line.append(","); |
505 | } | |
506 | } | |
507 | // ?終行以外では末尾にLFを付与す? | |
508 | 20 | if (hashKeys.size() != 0) { |
509 | 19 | line.append("\n"); |
510 | } | |
511 | 20 | bos.write(line.toString().getBytes()); |
512 | ||
513 | // 性能値の出? | |
514 | 388 | for (String datekey : hashKeys) { |
515 | 350 | line.delete(0, line.length()); |
516 | 350 | line.append("\"" + dateformat.format(dataHash.get(datekey).get(0).getDate()) + "\","); |
517 | 350 | line.append("\"" + timeformat.format(dataHash.get(datekey).get(0).getDate()) + "\","); |
518 | // 出力??目ごとに出? | |
519 | 6008 | for (int i = 0; i < csvCols.size(); i++) { |
520 | // 該当日時文字?キーに性能値が存在する場合??? | |
521 | 32589 | for (CollectedDataInfo collectedDataInfo : dataHash.get(datekey)) { |
522 | 49002 | if (csvCols.get(i).equalsCollection(collectedDataInfo.getItemCode(), |
523 | 24501 | collectedDataInfo.getDeviceName())) { |
524 | 3228 | line.append(valueformat.format(collectedDataInfo.getValue())); |
525 | 3228 | break; |
526 | } | |
527 | } | |
528 | 5658 | if (i < csvCols.size() - 1) { |
529 | 5308 | line.append(","); |
530 | } | |
531 | } | |
532 | 350 | line.append("\n"); |
533 | 350 | bos.write(line.toString().getBytes()); |
534 | } | |
535 | ||
536 | 2 | } catch (Exception e) { |
537 | // ファイルの書き込み処?に失敗した?? | |
538 | 2 | log.error(Config.getMsg("RRDTool.ExportCSV.WriteFileFailed"), e); |
539 | 2 | System.exit(51); |
540 | 0 | } finally { |
541 | try { | |
542 | // 出力ファイルに書き?し??容を反?して閉じ? | |
543 | 21 | if (bos != null) { |
544 | 20 | bos.flush(); |
545 | 19 | bos.close(); |
546 | } | |
547 | 2 | } catch (IOException e) { |
548 | // ファイルの書き込み処?に失敗した?? | |
549 | 2 | log.error(Config.getMsg("RRDTool.ExportCSV.WriteFileFailed"), e); |
550 | 2 | System.exit(51); |
551 | } | |
552 | 0 | } |
553 | ||
554 | 21 | return; |
555 | } | |
556 | ||
557 | } |
this report was generated by version @product.version@ of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |