X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Freports%2FReport.java;h=67e1596334c02a91b8eb22a376347ea029a66180;hb=4261823d84c2b911b68cdf4cb4dc3be429ebe285;hp=f4e0255e09ce75a13a9f1a5d09945a989db9fa5c;hpb=13639e1b05d8c8b5b1e9efd543573834501aefaa;p=dmaap%2Fdatarouter.git diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/Report.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/Report.java index f4e0255e..67e15963 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/Report.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/Report.java @@ -7,9 +7,9 @@ * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at - * * + * * * * http://www.apache.org/licenses/LICENSE-2.0 - * * + * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -36,120 +36,121 @@ import java.util.TimeZone; * @version $Id: Report.java,v 1.2 2013/11/06 16:23:55 eby Exp $ */ public class Report { - /** - * Generate .csv report files from the database. Usage: - *
-	 * java org.onap.dmaap.datarouter.reports.Report [ -t type ] [ -o outfile ] [ fromdate [ todate ]]
-	 * 
- * type should be volume for a {@link VolumeReport}, - * feed for a {@link FeedReport}, - * latency for a {@link LatencyReport}, or - * dailyLatency for a {@link DailyLatencyReport}. - * If outfile is not specified, the report goes into a file /tmp/nnnnnnnnnnnnn.csv, - * where nnnnnnnnnnnnn is the current time in milliseconds. - * If from and to are not specified, then the report is limited to the last weeks worth of data. - * from can be the keyword ALL to specify all data in the DB, or the keyword yesterday. - * Otherwise, from and to should match the pattern YYYY-MM-DD. - * @param args the command line arguments - */ - public static void main(String[] args) { - ReportBase report = new VolumeReport(); - String outfile = "/tmp/" + System.currentTimeMillis() + ".csv"; - String from = null, to = null; + /** + * Generate .csv report files from the database. Usage: + *
+     * java org.onap.dmaap.datarouter.reports.Report [ -t type ] [ -o outfile ] [ fromdate [ todate ]]
+     * 
+ * type should be volume for a {@link VolumeReport}, + * feed for a {@link FeedReport}, + * latency for a {@link LatencyReport}, or + * dailyLatency for a {@link DailyLatencyReport}. + * If outfile is not specified, the report goes into a file /tmp/nnnnnnnnnnnnn.csv, + * where nnnnnnnnnnnnn is the current time in milliseconds. + * If from and to are not specified, then the report is limited to the last weeks worth of data. + * from can be the keyword ALL to specify all data in the DB, or the keyword yesterday. + * Otherwise, from and to should match the pattern YYYY-MM-DD. + * + * @param args the command line arguments + */ + public static void main(String[] args) { + ReportBase report = new VolumeReport(); + String outfile = "/tmp/" + System.currentTimeMillis() + ".csv"; + String from = null, to = null; - for (int i = 0; i < args.length; i++) { - if (args[i].equals("-?")) { - System.err.println("usage: java org.onap.dmaap.datarouter.reports.Report [ -t type ] [ -o outfile ] [ fromdate [ todate ]]"); - System.exit(0); - } else if (args[i].equals("-o")) { - if (++i < args.length) { - outfile = args[i]; - } - } else if (args[i].equals("-t")) { - if (++i < args.length) { - String base = args[i]; - base = Character.toUpperCase(base.charAt(0)) + base.substring(1); - base = "org.onap.dmaap.datarouter.reports."+base+"Report"; - try { - @SuppressWarnings("unchecked") - Class cl = (Class) Class.forName(base); - Constructor con = cl.getConstructor(); - report = con.newInstance(); - } catch (Exception e) { - System.err.println("Unknown report type: "+args[i]); - System.exit(1); - } - } - } else if (from == null) { - from = args[i]; - } else { - to = args[i]; - } - } - long lfrom = 0, lto = 0; - if (from == null) { - // last 7 days - TimeZone utc = TimeZone.getTimeZone("UTC"); - Calendar cal = new GregorianCalendar(utc); - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - cal.set(Calendar.MILLISECOND, 0); - lfrom = cal.getTimeInMillis() - (7 * 24 * 60 * 60 * 1000L); // 1 week - lto = cal.getTimeInMillis() - 1; - } else if (to == null) { - try { - String[] dates = getDates(from); - lfrom = Long.parseLong(dates[0]); - lto = Long.parseLong(dates[1]); - } catch (Exception e) { - System.err.println("Invalid date: "+from); - System.exit(1); - } - } else { - String[] dates; - try { - dates = getDates(from); - lfrom = Long.parseLong(dates[0]); - } catch (Exception e) { - System.err.println("Invalid date: "+from); - System.exit(1); - } - try { - dates = getDates(to); - lto = Long.parseLong(dates[0]); - } catch (Exception e) { - System.err.println("Invalid date: "+to); - System.exit(1); - } - } + for (int i = 0; i < args.length; i++) { + if (args[i].equals("-?")) { + System.err.println("usage: java org.onap.dmaap.datarouter.reports.Report [ -t type ] [ -o outfile ] [ fromdate [ todate ]]"); + System.exit(0); + } else if (args[i].equals("-o")) { + if (++i < args.length) { + outfile = args[i]; + } + } else if (args[i].equals("-t")) { + if (++i < args.length) { + String base = args[i]; + base = Character.toUpperCase(base.charAt(0)) + base.substring(1); + base = "org.onap.dmaap.datarouter.reports." + base + "Report"; + try { + @SuppressWarnings("unchecked") + Class cl = (Class) Class.forName(base); + Constructor con = cl.getConstructor(); + report = con.newInstance(); + } catch (Exception e) { + System.err.println("Unknown report type: " + args[i]); + System.exit(1); + } + } + } else if (from == null) { + from = args[i]; + } else { + to = args[i]; + } + } + long lfrom = 0, lto = 0; + if (from == null) { + // last 7 days + TimeZone utc = TimeZone.getTimeZone("UTC"); + Calendar cal = new GregorianCalendar(utc); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + lfrom = cal.getTimeInMillis() - (7 * 24 * 60 * 60 * 1000L); // 1 week + lto = cal.getTimeInMillis() - 1; + } else if (to == null) { + try { + String[] dates = getDates(from); + lfrom = Long.parseLong(dates[0]); + lto = Long.parseLong(dates[1]); + } catch (Exception e) { + System.err.println("Invalid date: " + from); + System.exit(1); + } + } else { + String[] dates; + try { + dates = getDates(from); + lfrom = Long.parseLong(dates[0]); + } catch (Exception e) { + System.err.println("Invalid date: " + from); + System.exit(1); + } + try { + dates = getDates(to); + lto = Long.parseLong(dates[0]); + } catch (Exception e) { + System.err.println("Invalid date: " + to); + System.exit(1); + } + } - report.setFrom(lfrom); - report.setTo(lto); - report.setOutputFile(outfile); - report.run(); - } + report.setFrom(lfrom); + report.setTo(lto); + report.setOutputFile(outfile); + report.run(); + } - private static String[] getDates(String d) throws Exception { - if (d.equals("ALL")) - return new String[] { "1", ""+System.currentTimeMillis() }; + private static String[] getDates(String d) throws Exception { + if (d.equals("ALL")) + return new String[]{"1", "" + System.currentTimeMillis()}; - TimeZone utc = TimeZone.getTimeZone("UTC"); - Calendar cal = new GregorianCalendar(utc); - if (d.matches("20\\d\\d-\\d\\d-\\d\\d")) { - cal.set(Calendar.YEAR, Integer.parseInt(d.substring(0, 4))); - cal.set(Calendar.MONTH, Integer.parseInt(d.substring(5, 7))-1); - cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(d.substring(8, 10))); - } else if (d.equals("yesterday")) { - cal.add(Calendar.DAY_OF_YEAR, -1); - } else - throw new Exception("wa?"); - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - cal.set(Calendar.MILLISECOND, 0); - long start = cal.getTimeInMillis(); - long end = start + (24 * 60 * 60 * 1000L) - 1; - return new String[] { ""+start, ""+end }; - } + TimeZone utc = TimeZone.getTimeZone("UTC"); + Calendar cal = new GregorianCalendar(utc); + if (d.matches("20\\d\\d-\\d\\d-\\d\\d")) { + cal.set(Calendar.YEAR, Integer.parseInt(d.substring(0, 4))); + cal.set(Calendar.MONTH, Integer.parseInt(d.substring(5, 7)) - 1); + cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(d.substring(8, 10))); + } else if (d.equals("yesterday")) { + cal.add(Calendar.DAY_OF_YEAR, -1); + } else + throw new Exception("wa?"); + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + long start = cal.getTimeInMillis(); + long end = start + (24 * 60 * 60 * 1000L) - 1; + return new String[]{"" + start, "" + end}; + } }