Repository: incubator-eagle Updated Branches: refs/heads/master c57f86dd1 -> 8beda32da
[EAGLE-721] remove duplicate DateTimeUtil https://issues.apache.org/jira/browse/EAGLE-721 Author: Zhao, Qingwen <qingwz...@apache.org> Closes #599 from qingwen220/minor. Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/8beda32d Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/8beda32d Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/8beda32d Branch: refs/heads/master Commit: 8beda32daa55b6bbe148140aaf95c8d17ba7b6ff Parents: c57f86d Author: Zhao, Qingwen <qingwz...@apache.org> Authored: Wed Nov 2 18:03:22 2016 +0800 Committer: Zhao, Qingwen <qingwz...@apache.org> Committed: Wed Nov 2 18:03:22 2016 +0800 ---------------------------------------------------------------------- .../eagle-alert/alert-common/pom.xml | 5 + .../alert/engine/model/AlertStreamEvent.java | 4 +- .../eagle/alert/engine/model/StreamEvent.java | 2 +- .../eagle/alert/metric/entity/MetricEvent.java | 4 +- .../apache/eagle/alert/utils/DateTimeUtil.java | 142 ------------ .../publisher/email/AlertEmailGenerator.java | 3 +- .../publisher/email/AlertEmailSender.java | 2 +- .../alert/engine/runner/AlertPublisherBolt.java | 6 +- .../alert/engine/sorter/BaseStreamWindow.java | 3 +- .../impl/StreamSortWindowHandlerImpl.java | 3 +- .../impl/StreamTimeClockInLocalMemory.java | 2 +- .../sorter/impl/StreamTimeClockManagerImpl.java | 3 +- .../sorter/impl/StreamWindowManagerImpl.java | 2 +- .../alert/engine/router/TestAlertBolt.java | 3 +- .../engine/runner/TestStreamRouterBolt.java | 3 +- .../engine/sorter/StreamSortHandlerTest.java | 3 +- .../sorter/StreamWindowBenchmarkTest.java | 3 +- .../engine/sorter/StreamWindowTestSuite.java | 3 +- .../alert/engine/utils/TimePeriodUtilsTest.java | 2 +- .../org/apache/eagle/common/DateTimeUtil.java | 229 ++++++++++--------- .../topology/storm/TopologyCheckAppSpout.java | 4 +- 21 files changed, 156 insertions(+), 275 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-common/pom.xml ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/pom.xml b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/pom.xml index fd3eccd..f64e64c 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/pom.xml +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/pom.xml @@ -26,6 +26,11 @@ <dependencies> <dependency> + <groupId>org.apache.eagle</groupId> + <artifactId>eagle-common</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>com.typesafe</groupId> <artifactId>config</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/AlertStreamEvent.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/AlertStreamEvent.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/AlertStreamEvent.java index 600643b..e76c195 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/AlertStreamEvent.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/AlertStreamEvent.java @@ -16,10 +16,12 @@ */ package org.apache.eagle.alert.engine.model; +import org.apache.eagle.common.DateTimeUtil; import org.apache.eagle.alert.engine.coordinator.StreamColumn; import org.apache.eagle.alert.engine.coordinator.StreamDefinition; -import org.apache.eagle.alert.utils.DateTimeUtil; + import org.apache.commons.lang3.StringUtils; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/StreamEvent.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/StreamEvent.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/StreamEvent.java index 693050d..8480bc5 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/StreamEvent.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/model/StreamEvent.java @@ -19,7 +19,7 @@ package org.apache.eagle.alert.engine.model; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.eagle.alert.engine.coordinator.StreamDefinition; -import org.apache.eagle.alert.utils.DateTimeUtil; +import org.apache.eagle.common.DateTimeUtil; import java.io.Serializable; import java.util.ArrayList; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/metric/entity/MetricEvent.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/metric/entity/MetricEvent.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/metric/entity/MetricEvent.java index f1262c7..229bbd9 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/metric/entity/MetricEvent.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/metric/entity/MetricEvent.java @@ -16,13 +16,15 @@ */ package org.apache.eagle.alert.metric.entity; -import org.apache.eagle.alert.utils.DateTimeUtil; +import org.apache.eagle.common.DateTimeUtil; + import com.codahale.metrics.Counter; import com.codahale.metrics.Gauge; import com.codahale.metrics.Histogram; import com.codahale.metrics.Meter; import com.codahale.metrics.Snapshot; import com.codahale.metrics.Timer; + import java.util.Map; import java.util.TreeMap; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/utils/DateTimeUtil.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/utils/DateTimeUtil.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/utils/DateTimeUtil.java deleted file mode 100644 index 8b98959..0000000 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/utils/DateTimeUtil.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.eagle.alert.utils; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.TimeZone; - -/** - * be aware that SimpleDateFormat instantiation is expensive, so if that's under a tight loop, probably we need - * a thread local SimpleDateFormat object. - */ -public class DateTimeUtil { - public static final long ONESECOND = 1L * 1000L; - public static final long ONEMINUTE = 1L * 60L * 1000L; - public static final long ONEHOUR = 1L * 60L * 60L * 1000L; - public static final long ONEDAY = 24L * 60L * 60L * 1000L; - private static TimeZone CURRENT_TIME_ZONE = TimeZone.getDefault(); - - public static Date humanDateToDate(String date) throws ParseException { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.setTimeZone(CURRENT_TIME_ZONE); - return sdf.parse(date); - } - - public static long getCurrentTimestamp() { - return System.currentTimeMillis(); - } - - public static String secondsToHumanDate(long seconds) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.setTimeZone(CURRENT_TIME_ZONE); - Date t = new Date(); - t.setTime(seconds * 1000); - return sdf.format(t); - } - - public static String millisecondsToHumanDateWithMilliseconds(long milliseconds) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"); - sdf.setTimeZone(CURRENT_TIME_ZONE); - Date t = new Date(); - t.setTime(milliseconds); - return sdf.format(t); - } - - public static String millisecondsToHumanDateWithSeconds(long milliseconds) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.setTimeZone(CURRENT_TIME_ZONE); - Date t = new Date(); - t.setTime(milliseconds); - return sdf.format(t); - } - - public static long humanDateToSeconds(String date) throws ParseException { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.setTimeZone(CURRENT_TIME_ZONE); - Date d = sdf.parse(date); - return d.getTime() / 1000; - } - - public static long humanDateToMilliseconds(String date) throws ParseException { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"); - sdf.setTimeZone(CURRENT_TIME_ZONE); - Date d = sdf.parse(date); - return d.getTime(); - } - - - public static long humanDateToMillisecondsWithoutException(String date) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"); - sdf.setTimeZone(CURRENT_TIME_ZONE); - Date d = sdf.parse(date); - return d.getTime(); - } catch (ParseException ex) { - return 0L; - } - } - - public static long humanDateToSecondsWithoutException(String date) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdf.setTimeZone(CURRENT_TIME_ZONE); - Date d = sdf.parse(date); - return (d.getTime() / 1000); - } catch (ParseException ex) { - return 0L; - } - } - - /** - * this could be accurate only when timezone is UTC - * for the timezones other than UTC, there is possibly issue, for example - * assume timezone is GMT+8 in China - * When user time is "2014-07-15 05:00:00", it will be converted to timestamp first, - * internally it would be "2014-07-14 21:00:00" in UTC timezone. When rounded down to day, the internal time would - * be changed to "2014-07-14 00:00:00", and that means the user time is "2014-07-14 08:00:00". - * But originally user wants to round it to "2014-07-15 00:00:00" - * - * @param timeInMillis the seconds elapsed since 1970-01-01 00:00:00 - */ - public static long roundDown(int field, long timeInMillis) { - switch (field) { - case Calendar.DAY_OF_MONTH: - case Calendar.DAY_OF_WEEK: - case Calendar.DAY_OF_YEAR: - return (timeInMillis - timeInMillis % (24 * 60 * 60 * 1000)); - case Calendar.HOUR: - return (timeInMillis - timeInMillis % (60 * 60 * 1000)); - case Calendar.MINUTE: - return (timeInMillis - timeInMillis % (60 * 1000)); - case Calendar.SECOND: - return (timeInMillis - timeInMillis % (1000)); - default: - return 0L; - } - } - - public static String format(long milliseconds, String format) { - SimpleDateFormat sdf = new SimpleDateFormat(format); - sdf.setTimeZone(CURRENT_TIME_ZONE); - Date t = new Date(); - t.setTime(milliseconds); - return sdf.format(t); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailGenerator.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailGenerator.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailGenerator.java index e753a54..6b5295c 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailGenerator.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailGenerator.java @@ -20,9 +20,10 @@ */ package org.apache.eagle.alert.engine.publisher.email; +import org.apache.eagle.common.DateTimeUtil; import org.apache.eagle.alert.engine.model.AlertStreamEvent; import org.apache.eagle.alert.engine.publisher.PublishConstants; -import org.apache.eagle.alert.utils.DateTimeUtil; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailSender.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailSender.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailSender.java index d912bfb..1152d24 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailSender.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/publisher/email/AlertEmailSender.java @@ -18,7 +18,7 @@ package org.apache.eagle.alert.engine.publisher.email; import org.apache.eagle.alert.engine.publisher.PublishConstants; -import org.apache.eagle.alert.utils.DateTimeUtil; +import org.apache.eagle.common.DateTimeUtil; import org.apache.velocity.VelocityContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/runner/AlertPublisherBolt.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/runner/AlertPublisherBolt.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/runner/AlertPublisherBolt.java index 2fe5671..9746ea4 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/runner/AlertPublisherBolt.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/runner/AlertPublisherBolt.java @@ -126,9 +126,9 @@ public class AlertPublisherBolt extends AbstractStreamBolt implements AlertPubli private void wrapAlertPublishEvent(AlertStreamEvent event) { Map<String, Object> extraData = new HashedMap(); List<String> appIds = new ArrayList<>(); - if (this.policyDefinitionMap != null) { - PolicyDefinition policyDefinition = policyDefinitionMap.get(event.getPolicyId()); - for ( String inputStreamId : policyDefinition.getInputStreams()) { + PolicyDefinition policyDefinition = policyDefinitionMap.get(event.getPolicyId()); + if (this.policyDefinitionMap != null && policyDefinition != null) { + for (String inputStreamId : policyDefinition.getInputStreams()) { StreamDefinition sd = this.streamDefinitionMap.get(inputStreamId); if (sd != null) { extraData.put(AlertPublishEvent.SITE_ID_KEY, sd.getSiteId()); http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/BaseStreamWindow.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/BaseStreamWindow.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/BaseStreamWindow.java index 0f75b6a..a72f728 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/BaseStreamWindow.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/BaseStreamWindow.java @@ -17,8 +17,9 @@ package org.apache.eagle.alert.engine.sorter; import org.apache.eagle.alert.engine.PartitionedEventCollector; -import org.apache.eagle.alert.utils.DateTimeUtil; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.eagle.common.DateTimeUtil; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamSortWindowHandlerImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamSortWindowHandlerImpl.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamSortWindowHandlerImpl.java index 0ae84b8..fb5ba72 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamSortWindowHandlerImpl.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamSortWindowHandlerImpl.java @@ -23,7 +23,8 @@ import org.apache.eagle.alert.engine.router.StreamSortHandler; import org.apache.eagle.alert.engine.sorter.StreamTimeClock; import org.apache.eagle.alert.engine.sorter.StreamWindow; import org.apache.eagle.alert.engine.sorter.StreamWindowManager; -import org.apache.eagle.alert.utils.DateTimeUtil; +import org.apache.eagle.common.DateTimeUtil; + import org.joda.time.Period; import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamTimeClockInLocalMemory.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamTimeClockInLocalMemory.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamTimeClockInLocalMemory.java index 0c44074..e5be786 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamTimeClockInLocalMemory.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamTimeClockInLocalMemory.java @@ -17,7 +17,7 @@ package org.apache.eagle.alert.engine.sorter.impl; import org.apache.eagle.alert.engine.sorter.StreamTimeClock; -import org.apache.eagle.alert.utils.DateTimeUtil; +import org.apache.eagle.common.DateTimeUtil; import java.util.concurrent.atomic.AtomicLong; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamTimeClockManagerImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamTimeClockManagerImpl.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamTimeClockManagerImpl.java index 49378db..b59918d 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamTimeClockManagerImpl.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamTimeClockManagerImpl.java @@ -19,7 +19,8 @@ package org.apache.eagle.alert.engine.sorter.impl; import org.apache.eagle.alert.engine.sorter.StreamTimeClock; import org.apache.eagle.alert.engine.sorter.StreamTimeClockListener; import org.apache.eagle.alert.engine.sorter.StreamTimeClockManager; -import org.apache.eagle.alert.utils.DateTimeUtil; +import org.apache.eagle.common.DateTimeUtil; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamWindowManagerImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamWindowManagerImpl.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamWindowManagerImpl.java index e8921a2..4c5154b 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamWindowManagerImpl.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/main/java/org/apache/eagle/alert/engine/sorter/impl/StreamWindowManagerImpl.java @@ -22,8 +22,8 @@ import org.apache.eagle.alert.engine.sorter.StreamTimeClock; import org.apache.eagle.alert.engine.sorter.StreamWindow; import org.apache.eagle.alert.engine.sorter.StreamWindowManager; import org.apache.eagle.alert.engine.sorter.StreamWindowRepository; -import org.apache.eagle.alert.utils.DateTimeUtil; import org.apache.eagle.alert.utils.TimePeriodUtils; +import org.apache.eagle.common.DateTimeUtil; import org.apache.commons.lang3.time.StopWatch; import org.joda.time.Period; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertBolt.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertBolt.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertBolt.java index 7eec03a..6529f64 100755 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertBolt.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/router/TestAlertBolt.java @@ -40,7 +40,8 @@ import org.apache.eagle.alert.engine.model.StreamEvent; import org.apache.eagle.alert.engine.runner.AlertBolt; import org.apache.eagle.alert.engine.runner.TestStreamRouterBolt; import org.apache.eagle.alert.engine.serialization.impl.PartitionedEventSerializerImpl; -import org.apache.eagle.alert.utils.DateTimeUtil; +import org.apache.eagle.common.DateTimeUtil; + import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/runner/TestStreamRouterBolt.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/runner/TestStreamRouterBolt.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/runner/TestStreamRouterBolt.java index 830f1f7..a480fcf 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/runner/TestStreamRouterBolt.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/runner/TestStreamRouterBolt.java @@ -37,8 +37,9 @@ import org.apache.eagle.alert.engine.coordinator.StreamSortSpec; import org.apache.eagle.alert.engine.coordinator.impl.AbstractMetadataChangeNotifyService; import org.apache.eagle.alert.engine.model.PartitionedEvent; import org.apache.eagle.alert.engine.model.StreamEvent; -import org.apache.eagle.alert.utils.DateTimeUtil; import org.apache.eagle.alert.utils.StreamIdConversion; +import org.apache.eagle.common.DateTimeUtil; + import org.joda.time.Period; import org.junit.Assert; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamSortHandlerTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamSortHandlerTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamSortHandlerTest.java index 885017a..ff7b8ee 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamSortHandlerTest.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamSortHandlerTest.java @@ -29,7 +29,8 @@ import org.apache.eagle.alert.engine.model.PartitionedEvent; import org.apache.eagle.alert.engine.sorter.impl.PartitionedEventTimeOrderingComparator; import org.apache.eagle.alert.engine.sorter.impl.StreamSortWindowHandlerImpl; import org.apache.eagle.alert.engine.sorter.impl.StreamTimeClockInLocalMemory; -import org.apache.eagle.alert.utils.DateTimeUtil; +import org.apache.eagle.common.DateTimeUtil; + import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamWindowBenchmarkTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamWindowBenchmarkTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamWindowBenchmarkTest.java index 3d32d72..d6d4f22 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamWindowBenchmarkTest.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamWindowBenchmarkTest.java @@ -24,7 +24,8 @@ import com.codahale.metrics.jvm.MemoryUsageGaugeSet; import org.apache.commons.lang.time.StopWatch; import org.apache.eagle.alert.engine.mock.MockSampleMetadataFactory; import org.apache.eagle.alert.engine.model.PartitionedEvent; -import org.apache.eagle.alert.utils.DateTimeUtil; +import org.apache.eagle.common.DateTimeUtil; + import org.junit.After; import org.junit.Before; import org.junit.Ignore; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamWindowTestSuite.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamWindowTestSuite.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamWindowTestSuite.java index 6dc9c9f..57e577c 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamWindowTestSuite.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/sorter/StreamWindowTestSuite.java @@ -22,7 +22,8 @@ import org.apache.eagle.alert.engine.mock.MockSampleMetadataFactory; import org.apache.eagle.alert.engine.model.PartitionedEvent; import org.apache.eagle.alert.engine.sorter.impl.PartitionedEventTimeOrderingComparator; import org.apache.eagle.alert.engine.sorter.impl.StreamTimeClockInLocalMemory; -import org.apache.eagle.alert.utils.DateTimeUtil; +import org.apache.eagle.common.DateTimeUtil; + import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/utils/TimePeriodUtilsTest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/utils/TimePeriodUtilsTest.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/utils/TimePeriodUtilsTest.java index b74e807..b294e0c 100644 --- a/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/utils/TimePeriodUtilsTest.java +++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-engine/src/test/java/org/apache/eagle/alert/engine/utils/TimePeriodUtilsTest.java @@ -16,8 +16,8 @@ */ package org.apache.eagle.alert.engine.utils; -import org.apache.eagle.alert.utils.DateTimeUtil; import org.apache.eagle.alert.utils.TimePeriodUtils; +import org.apache.eagle.common.DateTimeUtil; import org.joda.time.Period; import org.joda.time.Seconds; import org.junit.Assert; http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/DateTimeUtil.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/DateTimeUtil.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/DateTimeUtil.java index 0f5b189..c25a434 100644 --- a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/DateTimeUtil.java +++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/DateTimeUtil.java @@ -15,6 +15,7 @@ * limitations under the License. */ package org.apache.eagle.common; + import org.apache.eagle.common.config.EagleConfigFactory; import java.text.ParseException; @@ -25,126 +26,132 @@ import java.util.TimeZone; /** * be aware that SimpleDateFormat instantiation is expensive, so if that's under a tight loop, probably we need - * a thread local SimpleDateFormat object + * a thread local SimpleDateFormat object. */ public class DateTimeUtil { - public static final long ONESECOND = 1L * 1000L; - public static final long ONEMINUTE = 1L * 60L * 1000L; - public static final long ONEHOUR = 1L * 60L * 60L * 1000L; - public static final long ONEDAY = 24L * 60L * 60L * 1000L; - private static TimeZone CURRENT_TIME_ZONE = EagleConfigFactory.load().getTimeZone(); - - public static Date humanDateToDate(String date) throws ParseException{ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + public static final long ONESECOND = 1L * 1000L; + public static final long ONEMINUTE = 1L * 60L * 1000L; + public static final long ONEHOUR = 1L * 60L * 60L * 1000L; + public static final long ONEDAY = 24L * 60L * 60L * 1000L; + //private static TimeZone CURRENT_TIME_ZONE = EagleConfigFactory.load().getTimeZone(); + private static TimeZone CURRENT_TIME_ZONE = TimeZone.getDefault(); + + public static Date humanDateToDate(String date) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(CURRENT_TIME_ZONE); - return sdf.parse(date); - } - - public static String secondsToHumanDate(long seconds){ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return sdf.parse(date); + } + + public static long getCurrentTimestamp() { + return System.currentTimeMillis(); + } + + public static String secondsToHumanDate(long seconds) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(CURRENT_TIME_ZONE); - Date t = new Date(); - t.setTime(seconds*1000); - return sdf.format(t); - } - - public static String millisecondsToHumanDateWithMilliseconds(long milliseconds){ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"); + Date t = new Date(); + t.setTime(seconds * 1000); + return sdf.format(t); + } + + public static String millisecondsToHumanDateWithMilliseconds(long milliseconds) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"); sdf.setTimeZone(CURRENT_TIME_ZONE); - Date t = new Date(); - t.setTime(milliseconds); - return sdf.format(t); - } - - public static String millisecondsToHumanDateWithSeconds(long milliseconds){ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date t = new Date(); + t.setTime(milliseconds); + return sdf.format(t); + } + + public static String millisecondsToHumanDateWithSeconds(long milliseconds) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(CURRENT_TIME_ZONE); - Date t = new Date(); - t.setTime(milliseconds); - return sdf.format(t); - } - - public static long humanDateToSeconds(String date) throws ParseException{ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date t = new Date(); + t.setTime(milliseconds); + return sdf.format(t); + } + + public static long humanDateToSeconds(String date) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(CURRENT_TIME_ZONE); - Date d = sdf.parse(date); - return d.getTime()/1000; - } - - public static long humanDateToMilliseconds(String date) throws ParseException{ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"); + Date d = sdf.parse(date); + return d.getTime() / 1000; + } + + public static long humanDateToMilliseconds(String date) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"); sdf.setTimeZone(CURRENT_TIME_ZONE); - Date d = sdf.parse(date); - return d.getTime(); - } - - - public static long humanDateToMillisecondsWithoutException(String date){ - try{ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"); + Date d = sdf.parse(date); + return d.getTime(); + } + + + public static long humanDateToMillisecondsWithoutException(String date) { + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"); sdf.setTimeZone(CURRENT_TIME_ZONE); - Date d = sdf.parse(date); - return d.getTime(); - }catch(ParseException ex){ - return 0L; - } - } - - public static long humanDateToSecondsWithoutException(String date){ - try{ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date d = sdf.parse(date); + return d.getTime(); + } catch (ParseException ex) { + return 0L; + } + } + + public static long humanDateToSecondsWithoutException(String date) { + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(CURRENT_TIME_ZONE); - Date d = sdf.parse(date); - return (d.getTime() / 1000); - }catch(ParseException ex){ - return 0L; - } - } - - //For mapr - //exp: 2015-06-06T10:44:22.800Z - public static long maprhumanDateToMilliseconds(String date) throws ParseException{ - date = date.replace('T',' '); - date = date.replace('Z',' '); - date = date.replace('.',','); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS "); - sdf.setTimeZone(CURRENT_TIME_ZONE); - Date d = sdf.parse(date); - return d.getTime(); - } - /** - * this could be accurate only when timezone is UTC - * for the timezones other than UTC, there is possibly issue, for example - * assume timezone is GMT+8 in China - * When user time is "2014-07-15 05:00:00", it will be converted to timestamp first, internally it would be "2014-07-14 21:00:00" in UTC timezone. When rounded down to day, the internal time would - * be changed to "2014-07-14 00:00:00", and that means the user time is "2014-07-14 08:00:00". But originally user wants to round it to "2014-07-15 00:00:00" - * - * @param field - * @param timeInMillis the seconds elapsed since 1970-01-01 00:00:00 - * @return - */ - public static long roundDown(int field, long timeInMillis){ - switch(field){ - case Calendar.DAY_OF_MONTH: - case Calendar.DAY_OF_WEEK: - case Calendar.DAY_OF_YEAR: - return (timeInMillis - timeInMillis % (24*60*60*1000)); - case Calendar.HOUR: - return (timeInMillis - timeInMillis % (60*60*1000)); - case Calendar.MINUTE: - return (timeInMillis - timeInMillis % (60*1000)); - case Calendar.SECOND: - return (timeInMillis - timeInMillis % (1000)); - default: - return 0L; - } - } - - public static String format(long milliseconds, String format) { - SimpleDateFormat sdf = new SimpleDateFormat(format); + Date d = sdf.parse(date); + return (d.getTime() / 1000); + } catch (ParseException ex) { + return 0L; + } + } + + /** + * this could be accurate only when timezone is UTC + * for the timezones other than UTC, there is possibly issue, for example + * assume timezone is GMT+8 in China + * When user time is "2014-07-15 05:00:00", it will be converted to timestamp first, + * internally it would be "2014-07-14 21:00:00" in UTC timezone. When rounded down to day, the internal time would + * be changed to "2014-07-14 00:00:00", and that means the user time is "2014-07-14 08:00:00". + * But originally user wants to round it to "2014-07-15 00:00:00" + * + * @param timeInMillis the seconds elapsed since 1970-01-01 00:00:00 + */ + public static long roundDown(int field, long timeInMillis) { + switch (field) { + case Calendar.DAY_OF_MONTH: + case Calendar.DAY_OF_WEEK: + case Calendar.DAY_OF_YEAR: + return (timeInMillis - timeInMillis % (24 * 60 * 60 * 1000)); + case Calendar.HOUR: + return (timeInMillis - timeInMillis % (60 * 60 * 1000)); + case Calendar.MINUTE: + return (timeInMillis - timeInMillis % (60 * 1000)); + case Calendar.SECOND: + return (timeInMillis - timeInMillis % (1000)); + default: + return 0L; + } + } + + public static String format(long milliseconds, String format) { + SimpleDateFormat sdf = new SimpleDateFormat(format); + sdf.setTimeZone(CURRENT_TIME_ZONE); + Date t = new Date(); + t.setTime(milliseconds); + return sdf.format(t); + } + + //For mapr + //exp: 2015-06-06T10:44:22.800Z + public static long maprhumanDateToMilliseconds(String date) throws ParseException{ + date = date.replace('T',' '); + date = date.replace('Z',' '); + date = date.replace('.',','); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS "); sdf.setTimeZone(CURRENT_TIME_ZONE); - Date t = new Date(); - t.setTime(milliseconds); - return sdf.format(t); - } + Date d = sdf.parse(date); + return d.getTime(); + } } http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/8beda32d/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/storm/TopologyCheckAppSpout.java ---------------------------------------------------------------------- diff --git a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/storm/TopologyCheckAppSpout.java b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/storm/TopologyCheckAppSpout.java index f2f3d41..0a9486f 100644 --- a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/storm/TopologyCheckAppSpout.java +++ b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/storm/TopologyCheckAppSpout.java @@ -23,9 +23,7 @@ import backtype.storm.task.TopologyContext; import backtype.storm.topology.OutputFieldsDeclarer; import backtype.storm.topology.base.BaseRichSpout; import backtype.storm.tuple.Fields; -import backtype.storm.tuple.Values; -import backtype.storm.utils.Utils; -import org.apache.eagle.alert.utils.DateTimeUtil; +import org.apache.eagle.common.DateTimeUtil; import org.apache.eagle.topology.TopologyCheckAppConfig; import org.apache.eagle.topology.TopologyConstants; import org.slf4j.Logger;