Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 81A00200CE7 for ; Wed, 12 Jul 2017 23:00:57 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 80537169E36; Wed, 12 Jul 2017 21:00:57 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CC65B169E31 for ; Wed, 12 Jul 2017 23:00:56 +0200 (CEST) Received: (qmail 3474 invoked by uid 500); 12 Jul 2017 21:00:56 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 3159 invoked by uid 99); 12 Jul 2017 21:00:55 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Jul 2017 21:00:55 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D9211F323B; Wed, 12 Jul 2017 21:00:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rlevas@apache.org To: commits@ambari.apache.org Date: Wed, 12 Jul 2017 21:00:57 -0000 Message-Id: <402e804d316c4661bf051ae9524da61b@git.apache.org> In-Reply-To: <1a289b122d47424891a0dbe790790937@git.apache.org> References: <1a289b122d47424891a0dbe790790937@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/6] ambari git commit: AMBARI-21447 Log Feeder should support logs without date (time only) (mgergely) archived-at: Wed, 12 Jul 2017 21:00:57 -0000 AMBARI-21447 Log Feeder should support logs without date (time only) (mgergely) Change-Id: I853447134873b10fdd3fd604fd84630a9caf9d03 Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9f788c38 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9f788c38 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9f788c38 Branch: refs/heads/branch-feature-AMBARI-20859 Commit: 9f788c386667bfeb82fff7c35287a5fdb175c349 Parents: 31b9d77 Author: Miklos Gergely Authored: Wed Jul 12 16:55:48 2017 +0200 Committer: Miklos Gergely Committed: Wed Jul 12 16:55:48 2017 +0200 ---------------------------------------------------------------------- .../ambari/logfeeder/mapper/MapperDate.java | 42 +++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/9f788c38/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/mapper/MapperDate.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/mapper/MapperDate.java b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/mapper/MapperDate.java index 305688b..e099161 100644 --- a/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/mapper/MapperDate.java +++ b/ambari-logsearch/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/mapper/MapperDate.java @@ -19,6 +19,7 @@ package org.apache.ambari.logfeeder.mapper; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; @@ -79,20 +80,7 @@ public class MapperDate extends Mapper { jsonObj.put(LogFeederConstants.IN_MEMORY_TIMESTAMP, ((Date) value).getTime()); } else if (targetDateFormatter != null) { if (srcDateFormatter != null) { - Date srcDate = srcDateFormatter.parse(value.toString()); - //set year in src_date when src_date does not have year component - if (!srcDateFormatter.toPattern().contains("yy")) { - Calendar currentCalendar = Calendar.getInstance(); - Calendar logDateCalendar = Calendar.getInstance(); - logDateCalendar.setTimeInMillis(srcDate.getTime()); - if (logDateCalendar.get(Calendar.MONTH) > currentCalendar.get(Calendar.MONTH)) { - // set previous year as a log year when log month is grater than current month - srcDate = DateUtils.setYears(srcDate, currentCalendar.get(Calendar.YEAR) - 1); - } else { - // set current year as a log year - srcDate = DateUtils.setYears(srcDate, currentCalendar.get(Calendar.YEAR)); - } - } + Date srcDate = getSourceDate(value); value = targetDateFormatter.format(srcDate); jsonObj.put(LogFeederConstants.IN_MEMORY_TIMESTAMP, srcDate.getTime()); } else { @@ -111,4 +99,30 @@ public class MapperDate extends Mapper { } return value; } + + private Date getSourceDate(Object value) throws ParseException { + Date srcDate = srcDateFormatter.parse(value.toString()); + + Calendar currentCalendar = Calendar.getInstance(); + + if (!srcDateFormatter.toPattern().contains("dd")) { + //set year/month/date in src_date when src_date does not have date component + srcDate = DateUtils.setYears(srcDate, currentCalendar.get(Calendar.YEAR)); + srcDate = DateUtils.setMonths(srcDate, currentCalendar.get(Calendar.MONTH)); + srcDate = DateUtils.setDays(srcDate, currentCalendar.get(Calendar.DAY_OF_MONTH)); + // if with the current date the time stamp is after the current one, it must be previous day + if (srcDate.getTime() > currentCalendar.getTimeInMillis()) { + srcDate = DateUtils.addDays(srcDate, -1); + } + } else if (!srcDateFormatter.toPattern().contains("yy")) { + //set year in src_date when src_date does not have year component + srcDate = DateUtils.setYears(srcDate, currentCalendar.get(Calendar.YEAR)); + // if with the current year the time stamp is after the current one, it must be previous year + if (srcDate.getTime() > currentCalendar.getTimeInMillis()) { + srcDate = DateUtils.addYears(srcDate, -1); + } + } + + return srcDate; + } }