You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eagle.apache.org by ha...@apache.org on 2016/07/21 12:28:50 UTC
[06/11] incubator-eagle git commit: [EAGLE-382][EAGLE-385] Monitoring
Application Framework Core
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-application-management/eagle-stream-application-manager/src/test/scala/org/apache/eagle/stream/application/scheduler/TestScheduler.scala
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-application-management/eagle-stream-application-manager/src/test/scala/org/apache/eagle/stream/application/scheduler/TestScheduler.scala b/eagle-core/eagle-application-management/eagle-stream-application-manager/src/test/scala/org/apache/eagle/stream/application/scheduler/TestScheduler.scala
deleted file mode 100644
index 3db2d67..0000000
--- a/eagle-core/eagle-application-management/eagle-stream-application-manager/src/test/scala/org/apache/eagle/stream/application/scheduler/TestScheduler.scala
+++ /dev/null
@@ -1,61 +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.stream.application.scheduler
-
-import akka.actor.{ActorSystem, Props}
-import akka.testkit.{TestActorRef, TestKit}
-import com.typesafe.config.ConfigFactory
-import org.scalatest.{Ignore, BeforeAndAfterAll, MustMatchers, WordSpecLike}
-
-@Ignore
-class TestSchedulerSpec extends TestKit(ActorSystem("stream-app-scheduler"))
-with WordSpecLike with MustMatchers with BeforeAndAfterAll {
-
- "A Scheduler actor" must {
- "Forward a message it receives" in {
- val coordinator = TestActorRef[StreamAppCoordinator]
- coordinator ! CommandLoaderEvent
- expectNoMsg()
- }
- }
-
- "A Integrated test" must {
- "run end-to-end" in {
- val coordinator = system.actorOf(Props[StreamAppCoordinator])
- coordinator ! CommandLoaderEvent
- expectNoMsg()
- }
- }
-
- override def afterAll(): Unit = {
- super.afterAll()
- system.shutdown()
- }
-}
-
-@Ignore
-object TestStreamAppScheduler extends App {
- val conf: String = """
- akka.loglevel = "DEBUG"
- akka.actor.debug {
- receive = on
- lifecycle = on
- }
- """
- new ApplicationScheduler().start(ConfigFactory.parseString(conf))
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-application-management/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-application-management/pom.xml b/eagle-core/eagle-application-management/pom.xml
deleted file mode 100644
index 5bb8e72..0000000
--- a/eagle-core/eagle-application-management/pom.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- ~
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <artifactId>eagle-core</artifactId>
- <groupId>org.apache.eagle</groupId>
- <version>0.5.0-incubating-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>eagle-application-management</artifactId>
- <packaging>pom</packaging>
- <description>Eagle Application Management</description>
-
- <modules>
- <module>eagle-stream-application-manager</module>
- <module>eagle-application-service</module>
- </modules>
-
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/pom.xml b/eagle-core/eagle-common/pom.xml
new file mode 100644
index 0000000..a8b8124
--- /dev/null
+++ b/eagle-core/eagle-common/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.eagle</groupId>
+ <artifactId>eagle-query-parent</artifactId>
+ <version>0.5.0-incubating-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>eagle-common</artifactId>
+ <packaging>jar</packaging>
+ <name>eagle-common</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hbase</groupId>
+ <artifactId>hbase-client</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.netflix.archaius</groupId>
+ <artifactId>archaius-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.typesafe</groupId>
+ <artifactId>config</artifactId>
+ </dependency>
+ </dependencies>
+</project>
+
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/META-INF/MANIFEST.MF
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/META-INF/MANIFEST.MF b/eagle-core/eagle-common/src/main/java/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..c67816b
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/META-INF/MANIFEST.MF
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+Manifest-Version: 1.0
+Class-Path:
+
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/Base64.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/Base64.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/Base64.java
new file mode 100644
index 0000000..aec84a3
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/Base64.java
@@ -0,0 +1,44 @@
+/*
+ * 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.common;
+
+import java.io.UnsupportedEncodingException;
+
+import javax.xml.bind.DatatypeConverter;
+
+public class Base64 {
+
+ public static String decode(String salted) {
+ try {
+ return new String(DatatypeConverter.parseBase64Binary(salted), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("UTF-8 must be supported", e);
+ }
+ }
+
+ public static String encode(String plain) {
+ try {
+ return DatatypeConverter.printBase64Binary(plain.getBytes("UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("UTF-8 must be supported", e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/ByteUtil.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/ByteUtil.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/ByteUtil.java
new file mode 100644
index 0000000..c1d4976
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/ByteUtil.java
@@ -0,0 +1,178 @@
+/*
+ * 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.common;
+
+public class ByteUtil {
+
+ public static double bytesToDouble(byte[] bytes, int offset){
+ return Double.longBitsToDouble(bytesToLong(bytes, offset));
+ }
+
+ public static double bytesToDouble(byte[] bytes){
+ return Double.longBitsToDouble(bytesToLong(bytes));
+ }
+
+ public static void doubleToBytes(double v, byte[] bytes){
+ doubleToBytes(v, bytes, 0);
+ }
+
+ public static void doubleToBytes(double v, byte[] bytes, int offset){
+ longToBytes(Double.doubleToLongBits(v), bytes, offset);
+ }
+
+ public static byte[] doubleToBytes(double v){
+ return longToBytes(Double.doubleToLongBits(v));
+ }
+
+ public static long bytesToLong(byte[] bytes){
+ return bytesToLong(bytes, 0);
+ }
+
+ public static long bytesToLong(byte[] bytes, int offset){
+ long value = 0;
+ for(int i=0; i<8; i++){
+ value <<= 8;
+ value |= (bytes[i+offset] & 0xFF);
+ }
+ return value;
+ }
+
+ public static void longToBytes(long v, byte[] bytes){
+ longToBytes(v, bytes, 0);
+ }
+
+ public static void longToBytes(long v, byte[] bytes, int offset){
+ long tmp = v;
+ for(int i=0; i<8; i++){
+ bytes[offset + 7 - i] = (byte)(tmp & 0xFF);
+ tmp >>= 8;
+ }
+ }
+
+ public static byte[] longToBytes(long v){
+ long tmp = v;
+ byte[] b = new byte[8];
+ for(int i=0; i<8; i++){
+ b[7-i] = (byte)(tmp & 0xFF);
+ tmp >>= 8;
+ }
+ return b;
+ }
+
+ public static int bytesToInt(byte[] bytes){
+ return bytesToInt(bytes, 0);
+ }
+
+ public static int bytesToInt(byte[] bytes, int offset){
+ int value = 0;
+ for(int i=0; i<4; i++){
+ value <<= 8;
+ value |= (bytes[i+offset] & 0xFF);
+ }
+ return value;
+ }
+
+ public static void intToBytes(int v, byte[] bytes){
+ intToBytes(v, bytes, 0);
+ }
+
+ public static void intToBytes(int v, byte[] bytes, int offset){
+ int tmp = v;
+ for(int i=0; i<4; i++){
+ bytes[offset + 3 - i] = (byte)(tmp & 0xFF);
+ tmp >>= 8;
+ }
+ }
+
+ public static byte[] intToBytes(int v){
+ int tmp = v;
+ byte[] b = new byte[4];
+ for(int i=0; i<4; i++){
+ b[3-i] = (byte)(tmp & 0xFF);
+ tmp >>= 8;
+ }
+ return b;
+ }
+
+ //////
+
+ public static short bytesToShort(byte[] bytes){
+ return bytesToShort(bytes, 0);
+ }
+
+ public static short bytesToShort(byte[] bytes, int offset){
+ short value = 0;
+ for(int i=0; i < 2; i++){
+ value <<= 8;
+ value |= (bytes[i+offset] & 0xFF);
+ }
+ return value;
+ }
+
+ public static void shortToBytes(short v, byte[] bytes){
+ shortToBytes(v, bytes, 0);
+ }
+
+ public static void shortToBytes(short v, byte[] bytes, int offset){
+ int tmp = v;
+ for(int i=0; i < 2; i++){
+ bytes[offset + 1 - i] = (byte)(tmp & 0xFF);
+ tmp >>= 8;
+ }
+ }
+
+ public static byte[] shortToBytes(short v){
+ int tmp = v;
+ byte[] b = new byte[2];
+ for(int i=0; i<2; i++){
+ b[1-i] = (byte)(tmp & 0xFF);
+ tmp >>= 8;
+ }
+ return b;
+ }
+
+ public static byte[] concat(byte[]... arrays) {
+ int length = 0;
+ for (byte[] array : arrays) {
+ length += array.length;
+ }
+ byte[] result = new byte[length];
+ int pos = 0;
+ for (byte[] array : arrays) {
+ System.arraycopy(array, 0, result, pos, array.length);
+ pos += array.length;
+ }
+ return result;
+ }
+
+// public static void main(String[] args){
+// int a = "ThreadName".hashCode();
+// byte[] b = intToBytes(a);
+// byte[] c = intToBytes(1676687583);
+// String s = new String(b);
+// System.out.println(s);
+
+// byte[] d = intToBytes(8652353);
+// System.out.println(bytesToInt(d));
+
+// byte[] e = longToBytes(12131513513l);
+// System.out.println(bytesToLong(e));
+// if(12131513513l == bytesToLong(e)){
+// System.out.println("yes");
+// }
+// }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/CircularArrayList.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/CircularArrayList.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/CircularArrayList.java
new file mode 100644
index 0000000..49695e5
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/CircularArrayList.java
@@ -0,0 +1,149 @@
+/*
+ * 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.common;
+
+import java.util.AbstractList;
+import java.util.RandomAccess;
+
+/**
+ * Circular array implementation
+ *
+ * @param <E>
+ */
+public class CircularArrayList<E> extends AbstractList<E> implements RandomAccess {
+
+ private final E[] buf; // a List implementing RandomAccess
+ private int head = 0;
+ private int tail = 0;
+ private boolean full = false;
+
+ public CircularArrayList(E[] array) {
+ buf = array;
+ full = (buf.length == 0);
+ }
+
+ public int capacity() {
+ return buf.length;
+ }
+
+ public int head() {
+ return head;
+ }
+
+ public int tail() {
+ return tail;
+ }
+
+ public boolean isFull() {
+ return full;
+ }
+
+ @Override
+ public void clear() {
+ head = 0;
+ tail = 0;
+ full = false;
+ for (int i = 0; i < buf.length; ++i) {
+ buf[i] = null;
+ }
+ }
+
+ private int wrapIndex(int i) {
+ int m = i % buf.length;
+ if (m < 0) { // java modulus can be negative
+ throw new IndexOutOfBoundsException();
+ }
+ return m;
+ }
+
+ // This method is O(n) but will never be called if the
+ // CircularArrayList is used in its typical/intended role.
+ private void shiftBlock(int startIndex, int endIndex) {
+ assert (endIndex > startIndex);
+ for (int i = endIndex - 1; i >= startIndex; i--) {
+ set(i + 1, get(i));
+ }
+ }
+
+ public int find(E e) {
+ final int size = size();
+ for (int i = 0; i < size; ++i) {
+ if (e.equals(get(i))) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public int size() {
+ if (full) {
+ return buf.length;
+ }
+ return tail - head + (tail < head ? buf.length : 0);
+ }
+
+ @Override
+ public E get(int i) {
+ if (i < 0 || i >= size()) {
+ throw new IndexOutOfBoundsException();
+ }
+ return buf[wrapIndex(head + i)];
+ }
+
+ @Override
+ public E set(int i, E e) {
+ if (i < 0 || i >= size()) {
+ throw new IndexOutOfBoundsException();
+ }
+ return buf[wrapIndex(head + i)] = e;
+ }
+
+ @Override
+ public void add(int i, E e) {
+ int s = size();
+ if (s == buf.length) {
+ throw new IllegalStateException("Cannot add element."
+ + " CircularArrayList is filled to capacity.");
+ }
+ full = (s + 1 == buf.length);
+ if (i < 0 || i > s) {
+ throw new IndexOutOfBoundsException();
+ }
+ tail = wrapIndex(tail + 1);
+ if (i < s) {
+ shiftBlock(i, s);
+ }
+ set(i, e);
+ }
+
+ @Override
+ public E remove(int i) {
+ int s = size();
+ if (i < 0 || i >= s) {
+ throw new IndexOutOfBoundsException();
+ }
+ final E e = get(i);
+ if (i > 0) {
+ shiftBlock(0, i);
+ }
+ buf[head] = null;
+ head = wrapIndex(head + 1);
+ full = false;
+ return e;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/CircularArrayListSortedSet.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/CircularArrayListSortedSet.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/CircularArrayListSortedSet.java
new file mode 100644
index 0000000..ef47624
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/CircularArrayListSortedSet.java
@@ -0,0 +1,106 @@
+/*
+ * 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.common;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+public class CircularArrayListSortedSet<E> {
+
+ private final CircularArrayList<E> list;
+ private final Comparator<? super E> comparator;
+
+ public CircularArrayListSortedSet(E[] array) {
+ this.list = new CircularArrayList<E>(array);
+ this.comparator = null;
+ }
+
+ public CircularArrayListSortedSet(E[] array, Comparator<? super E> comparator) {
+ this.list = new CircularArrayList<E>(array);
+ this.comparator = comparator;
+ }
+
+ public int capacity() {
+ return list.capacity();
+ }
+
+ public int head() {
+ return list.head();
+ }
+
+ public int tail() {
+ return list.tail();
+ }
+
+ public boolean isFull() {
+ return list.isFull();
+ }
+
+ public void clear() {
+ list.clear();
+ }
+
+ public int size() {
+ return list.size();
+ }
+
+ public E get(int i) {
+ return list.get(i);
+ }
+
+ @SuppressWarnings("unchecked")
+ public int binarySearch(E e) {
+ if (comparator != null) {
+ return Collections.binarySearch(list, e, comparator);
+ } else {
+ return Collections.binarySearch((List<? extends Comparable<? super E>>)list, e);
+ }
+ }
+
+ public int replace(E e) {
+ int index = binarySearch(e);
+ if (index < 0) {
+ return -1;
+ }
+ list.set(index, e);
+ return index;
+ }
+
+ public int insert(E e) {
+ int index = binarySearch(e);
+ if (index > 0) {
+ return -1;
+ }
+ index = 0 - index - 1;
+ list.add(index, e);
+ return index;
+ }
+
+ public E remove(int i) {
+ return list.remove(i);
+ }
+
+ public int remove(E e) {
+ final int index = binarySearch(e);
+ if (index > 0) {
+ list.remove(index);
+ return index;
+ }
+ return -1;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/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
new file mode 100644
index 0000000..0f5b189
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/DateTimeUtil.java
@@ -0,0 +1,150 @@
+/*
+ * 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.common;
+import org.apache.eagle.common.config.EagleConfigFactory;
+
+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 = EagleConfigFactory.load().getTimeZone();
+
+ 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");
+ 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;
+ }
+ }
+
+ //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);
+ 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/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/EagleBase64Wrapper.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/EagleBase64Wrapper.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/EagleBase64Wrapper.java
new file mode 100644
index 0000000..e31ef99
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/EagleBase64Wrapper.java
@@ -0,0 +1,32 @@
+/*
+ * 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.common;
+
+import org.apache.commons.net.util.Base64;
+
+/**
+ * wrap base64 encoding and decoding, so reduce the confuse of using many Base64 methods.
+ */
+public class EagleBase64Wrapper {
+ public static String encodeByteArray2URLSafeString(byte[] bytes){
+ return Base64.encodeBase64URLSafeString(bytes);
+ }
+
+ public static byte[] decode(String input){
+ return Base64.decodeBase64(input);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/EagleExceptionWrapper.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/EagleExceptionWrapper.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/EagleExceptionWrapper.java
new file mode 100644
index 0000000..1fc4e85
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/EagleExceptionWrapper.java
@@ -0,0 +1,42 @@
+/*
+ * 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.common;
+
+public class EagleExceptionWrapper {
+ private final static int MAX_DEPTH = 10;
+
+ public static String wrap(Exception ex){
+ return wrap(ex, EagleExceptionWrapper.MAX_DEPTH);
+ }
+
+ public static String wrap(Exception ex, int maxdepth){
+ int d = maxdepth;
+ if(d <= 0)
+ d = EagleExceptionWrapper.MAX_DEPTH;
+ int index = 0;
+ StringBuffer sb = new StringBuffer();
+ sb.append(ex);
+ sb.append(System.getProperty("line.separator"));
+ for(StackTraceElement element : ex.getStackTrace()){
+ sb.append(element.toString());
+ sb.append(System.getProperty("line.separator"));
+ if(++index >= d)
+ break;
+ }
+ return sb.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/Environment.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/Environment.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/Environment.java
new file mode 100644
index 0000000..dd69ed5
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/Environment.java
@@ -0,0 +1,23 @@
+/*
+ * 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.common;
+
+public enum Environment {
+ dev,
+ test,
+ prod,
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/OS.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/OS.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/OS.java
new file mode 100644
index 0000000..05e8db1
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/OS.java
@@ -0,0 +1,41 @@
+/*
+ * 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.common;
+
+public class OS {
+
+ private final static String os = System.getProperty("os.name")
+ .toLowerCase();
+
+ public static boolean isWindows() {
+ return (os.indexOf("win") >= 0);
+ }
+
+ public static boolean isMac() {
+ return (os.indexOf("mac") >= 0);
+ }
+
+ public static boolean isUnix() {
+ return (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0 || os
+ .indexOf("aix") > 0);
+ }
+
+ public static boolean isSolaris() {
+ return (os.indexOf("sunos") >= 0);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/SerializableUtils.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/SerializableUtils.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/SerializableUtils.java
new file mode 100644
index 0000000..c5823ea
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/SerializableUtils.java
@@ -0,0 +1,126 @@
+/*
+ *
+ * * 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.common;
+
+import org.xerial.snappy.SnappyInputStream;
+import org.xerial.snappy.SnappyOutputStream;
+
+import java.io.*;
+
+/**
+ * Utilities for working with Serializables.
+ *
+ * Derived from "com.google.cloud.dataflow.sdk.util.SerializableUtils":
+ * https://github.com/apache/incubator-beam/blob/master/sdks/java/core/src/main/java/com/google/cloud/dataflow/sdk/util/SerializableUtils.java
+ */
+public class SerializableUtils {
+ /**
+ * Serializes the argument into an array of bytes, and returns it.
+ *
+ * @throws IllegalArgumentException if there are errors when serializing
+ */
+ public static byte[] serializeToCompressedByteArray(Object value) {
+ try {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ try (ObjectOutputStream oos = new ObjectOutputStream(new SnappyOutputStream(buffer))) {
+ oos.writeObject(value);
+ }
+ return buffer.toByteArray();
+ } catch (IOException exn) {
+ throw new IllegalArgumentException(
+ "unable to serialize " + value,
+ exn);
+ }
+ }
+
+ /**
+ * Serializes the argument into an array of bytes, and returns it.
+ *
+ * @throws IllegalArgumentException if there are errors when serializing
+ */
+ public static byte[] serializeToByteArray(Object value) {
+ try {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ try (ObjectOutputStream oos = new ObjectOutputStream(buffer)) {
+ oos.writeObject(value);
+ }
+ return buffer.toByteArray();
+ } catch (IOException exn) {
+ throw new IllegalArgumentException("unable to serialize " + value, exn);
+ }
+ }
+
+ /**
+ * Deserializes an object from the given array of bytes, e.g., as
+ * serialized using {@link #serializeToCompressedByteArray}, and returns it.
+ *
+ * @throws IllegalArgumentException if there are errors when
+ * deserializing, using the provided description to identify what
+ * was being deserialized
+ */
+ public static Object deserializeFromByteArray(byte[] encodedValue,
+ String description) {
+ try {
+ try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(encodedValue))) {
+ return ois.readObject();
+ }
+ } catch (IOException | ClassNotFoundException exn) {
+ throw new IllegalArgumentException(
+ "unable to deserialize " + description,
+ exn);
+ }
+ }
+
+ /**
+ * Deserializes an object from the given array of bytes, e.g., as
+ * serialized using {@link #serializeToCompressedByteArray}, and returns it.
+ *
+ * @throws IllegalArgumentException if there are errors when
+ * deserializing, using the provided description to identify what
+ * was being deserialized
+ */
+ public static Object deserializeFromCompressedByteArray(byte[] encodedValue,
+ String description) {
+ try {
+ try (ObjectInputStream ois = new ObjectInputStream(
+ new SnappyInputStream(new ByteArrayInputStream(encodedValue)))) {
+ return ois.readObject();
+ }
+ } catch (IOException | ClassNotFoundException exn) {
+ throw new IllegalArgumentException(
+ "unable to deserialize " + description,
+ exn);
+ }
+ }
+
+ public static <T extends Serializable> T ensureSerializable(T value) {
+ @SuppressWarnings("unchecked")
+ T copy = (T) deserializeFromCompressedByteArray(serializeToCompressedByteArray(value),
+ value.toString());
+ return copy;
+ }
+
+ public static <T extends Serializable> T clone(T value) {
+ @SuppressWarnings("unchecked")
+ T copy = (T) deserializeFromCompressedByteArray(serializeToCompressedByteArray(value),
+ value.toString());
+ return copy;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfig.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfig.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfig.java
new file mode 100755
index 0000000..6226057
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfig.java
@@ -0,0 +1,60 @@
+/*
+ * 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.common.config;
+
+import com.typesafe.config.Config;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.client.HTableInterface;
+
+import java.util.TimeZone;
+import java.util.concurrent.ThreadPoolExecutor;
+
+public interface EagleConfig {
+
+ boolean isCoprocessorEnabled();
+
+ HTableInterface getHTable(String tableName);
+
+ Configuration getHbaseConf();
+
+ String getStorageType();
+
+ ThreadPoolExecutor getExecutor();
+
+ String getZKQuorum();
+
+ String getZKPort();
+
+ String getServiceHost();
+
+ int getServicePort();
+
+ String getEnv();
+
+ boolean isTableNamePrefixedWithEnvironment();
+
+ int getHBaseClientScanCacheSize();
+
+ TimeZone getTimeZone();
+
+ boolean isServiceAuditingEnabled();
+
+ /**
+ * @return root config
+ */
+ Config getConfig();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfigConstants.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfigConstants.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfigConstants.java
new file mode 100644
index 0000000..26d7b49
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfigConstants.java
@@ -0,0 +1,65 @@
+/*
+ * 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.common.config;
+
+public final class EagleConfigConstants {
+ public final static String SERVICE_ENV = "eagle.service.env";
+ public final static String SERVICE_HOST = "eagle.service.host";
+ public final static String SERVICE_PORT = "eagle.service.port";
+ public final static String SERVICE_HBASE_ZOOKEEPER_QUORUM = "eagle.service.hbase-zookeeper-quorum";
+ public final static String SERVICE_HBASE_ZOOKEEPER_PROPERTY_CLIENTPORT = "eagle.service.hbase-zookeeper-property-clientPort";
+ public final static String SERVICE_ZOOKEEPER_ZNODE_PARENT = "eagle.service.zookeeper-znode-parent";
+ public final static String SERVICE_HBASE_CLIENT_IPC_POOL_SIZE = "eagle.service.hbase-client-ipc-pool-size";
+ public final static String SERVICE_STORAGE_TYPE = "eagle.service.storage-type";
+ public final static String SERVICE_COPROCESSOR_ENABLED = "eagle.service.coprocessor-enabled";
+ public final static String SERVICE_TABLE_NAME_PREFIXED_WITH_ENVIRONMENT = "eagle.service.table-name-prefixed-with-environment";
+ public final static String SERVICE_HBASE_CLIENT_SCAN_CACHE_SIZE = "eagle.service.hbase-client-scan-cache-size";
+ public final static String SERVICE_THREADPOOL_CORE_SIZE = "eagle.service.threadpool-core-size";
+ public final static String SERVICE_THREADPOOL_MAX_SIZE = "eagle.service.threadpool-max-size";
+ public final static String SERVICE_THREADPOOL_SHRINK_SIZE = "eagle.service.threadpool-shrink-size";
+ public final static String SERVICE_AUDITING_ENABLED = "eagle.service.audit-enabled";
+
+ public final static String EAGLE_TIME_ZONE = "eagle.timezone";
+ public final static String DEFAULT_EAGLE_TIME_ZONE = "UTC";
+
+ public final static int DEFAULT_THREAD_POOL_CORE_SIZE = 10;
+ public final static int DEFAULT_THREAD_POOL_MAX_SIZE = 20;
+ public final static long DEFAULT_THREAD_POOL_SHRINK_TIME = 60000L;
+ public final static String DEFAULT_SERVICE_HOST = "localhost";
+ public final static String DEFAULT_STORAGE_TYPE = "hbase";
+ public final static int DEFAULT_SERVICE_PORT = 8080;
+ public final static String DEFAULT_ZOOKEEPER_ZNODE_PARENT = "/hbase-unsecure";
+
+ public final static String EAGLE_PROPS="eagleProps";
+ public final static String EAGLE_SERVICE = "eagleService";
+ public final static String HOST = "host";
+ public final static String PORT = "port";
+ public final static String USERNAME = "username";
+ public final static String PASSWORD = "password";
+
+ public final static String SITE = "site";
+ @Deprecated
+ public final static String DATA_SOURCE = "dataSource";
+ public final static String APPLICATION = "application";
+
+ public final static String WEB_CONFIG = "web";
+ public final static String APP_CONFIG = "app";
+ public final static String CLASSIFICATION_CONFIG = "classification";
+
+ public final static String LOCAL_MODE = "local";
+ public final static String CLUSTER_MODE = "cluster";
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfigFactory.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfigFactory.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfigFactory.java
new file mode 100755
index 0000000..0d73743
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfigFactory.java
@@ -0,0 +1,198 @@
+/*
+ * 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.common.config;
+
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hbase.client.HTablePool;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.TimeZone;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+public class EagleConfigFactory implements EagleConfig {
+ private static final Logger LOG = LoggerFactory.getLogger(EagleConfigFactory.class);
+
+ private String env;
+ private String zkQuorum;
+ private String zkPort;
+
+ private Configuration hbaseConf;
+ private String eagleServiceHost;
+ private int eagleServicePort;
+ private String storageType;
+ private Config config;
+ private TimeZone timeZone;
+
+ public boolean isCoprocessorEnabled() {
+ return isCoprocessorEnabled;
+ }
+
+ private boolean isCoprocessorEnabled;
+
+ private boolean tableNamePrefixedWithEnv;
+
+ private HTablePool pool;
+ private int hbaseClientScanCacheSize = 1000;
+
+ private ThreadPoolExecutor executor = null;
+
+ private static EagleConfigFactory manager = new EagleConfigFactory();
+
+ private EagleConfigFactory(){
+ init();
+ if(this.getStorageType() == null || this.getStorageType().equalsIgnoreCase("hbase")) {
+ this.pool = new HTablePool(this.hbaseConf, 10);
+ }
+ }
+
+ public static EagleConfig load(){
+ return manager;
+ }
+
+ public HTableInterface getHTable(String tableName){
+ return pool.getTable(tableName);
+ }
+
+ private String getString(Config config,String path,String defaultValue){
+ if(config.hasPath(path)){
+ return config.getString(path);
+ }else{
+ return defaultValue;
+ }
+ }
+
+ public String getStorageType() {
+ return storageType;
+ }
+
+ public ThreadPoolExecutor getExecutor() {
+ return executor;
+ }
+
+ private void init(){
+ this.config = ConfigFactory.load();
+ this.timeZone = TimeZone.getTimeZone((config.hasPath(EagleConfigConstants.EAGLE_TIME_ZONE)? config.getString(EagleConfigConstants.EAGLE_TIME_ZONE): EagleConfigConstants.DEFAULT_EAGLE_TIME_ZONE));
+ this.env = config.hasPath(EagleConfigConstants.SERVICE_ENV) ? config.getString(EagleConfigConstants.SERVICE_ENV):"dev";
+ this.zkQuorum = config.hasPath(EagleConfigConstants.SERVICE_HBASE_ZOOKEEPER_QUORUM) ? config.getString(EagleConfigConstants.SERVICE_HBASE_ZOOKEEPER_QUORUM):null;
+ this.zkPort = config.hasPath(EagleConfigConstants.SERVICE_HBASE_ZOOKEEPER_PROPERTY_CLIENTPORT) ? config.getString(EagleConfigConstants.SERVICE_HBASE_ZOOKEEPER_PROPERTY_CLIENTPORT): null;
+ String zkZnodeParent = config.hasPath(EagleConfigConstants.SERVICE_ZOOKEEPER_ZNODE_PARENT)? config.getString(EagleConfigConstants.SERVICE_ZOOKEEPER_ZNODE_PARENT): EagleConfigConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT;
+ String clientIPCPoolSize = getString(config, EagleConfigConstants.SERVICE_HBASE_CLIENT_IPC_POOL_SIZE, "10");
+ this.hbaseConf = HBaseConfiguration.create();
+
+ if (this.zkQuorum != null)
+ this.hbaseConf.set("hbase.zookeeper.quorum", this.zkQuorum);
+
+ if (this.zkPort != null)
+ this.hbaseConf.set("hbase.zookeeper.property.clientPort", this.zkPort);
+
+ if(zkZnodeParent != null)
+ this.hbaseConf.set("zookeeper.znode.parent", zkZnodeParent);
+ else
+ this.hbaseConf.set("zookeeper.znode.parent", EagleConfigConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
+
+ this.hbaseConf.set("hbase.client.ipc.pool.size", clientIPCPoolSize);
+
+ this.eagleServiceHost = config.hasPath(EagleConfigConstants.SERVICE_HOST) ? config.getString(EagleConfigConstants.SERVICE_HOST) : EagleConfigConstants.DEFAULT_SERVICE_HOST;
+ this.storageType = config.hasPath(EagleConfigConstants.SERVICE_STORAGE_TYPE) ? config.getString(EagleConfigConstants.SERVICE_STORAGE_TYPE) : EagleConfigConstants.DEFAULT_STORAGE_TYPE;
+ this.isCoprocessorEnabled = config.hasPath(EagleConfigConstants.SERVICE_COPROCESSOR_ENABLED) && config.getBoolean(EagleConfigConstants.SERVICE_COPROCESSOR_ENABLED);
+ this.eagleServicePort = config.hasPath(EagleConfigConstants.SERVICE_PORT) ? config.getInt(EagleConfigConstants.SERVICE_PORT) : EagleConfigConstants.DEFAULT_SERVICE_PORT;
+ this.tableNamePrefixedWithEnv = config.hasPath(EagleConfigConstants.SERVICE_TABLE_NAME_PREFIXED_WITH_ENVIRONMENT) && config.getBoolean(EagleConfigConstants.SERVICE_TABLE_NAME_PREFIXED_WITH_ENVIRONMENT);
+ this.hbaseClientScanCacheSize = config.hasPath(EagleConfigConstants.SERVICE_HBASE_CLIENT_SCAN_CACHE_SIZE)? config.getInt(EagleConfigConstants.SERVICE_HBASE_CLIENT_SCAN_CACHE_SIZE) : hbaseClientScanCacheSize;
+ // initilize eagle service thread pool for parallel execution of hbase scan etc.
+ int threadPoolCoreSize = config.hasPath(EagleConfigConstants.SERVICE_THREADPOOL_CORE_SIZE)? config.getInt(EagleConfigConstants.SERVICE_THREADPOOL_CORE_SIZE): EagleConfigConstants.DEFAULT_THREAD_POOL_CORE_SIZE;
+ int threadPoolMaxSize = config.hasPath(EagleConfigConstants.SERVICE_THREADPOOL_MAX_SIZE) ? config.getInt(EagleConfigConstants.SERVICE_THREADPOOL_MAX_SIZE) : EagleConfigConstants.DEFAULT_THREAD_POOL_MAX_SIZE;
+ long threadPoolShrinkTime = config.hasPath(EagleConfigConstants.SERVICE_THREADPOOL_SHRINK_SIZE) ? config.getLong(EagleConfigConstants.SERVICE_THREADPOOL_SHRINK_SIZE) : EagleConfigConstants.DEFAULT_THREAD_POOL_SHRINK_TIME;
+ this.isServiceAuditingEnabled = config.hasPath(EagleConfigConstants.SERVICE_AUDITING_ENABLED) && config.getBoolean(EagleConfigConstants.SERVICE_AUDITING_ENABLED);
+
+ this.executor = new ThreadPoolExecutor(threadPoolCoreSize, threadPoolMaxSize, threadPoolShrinkTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
+
+ LOG.info("Successfully initialized config");
+
+ if(LOG.isDebugEnabled()) {
+ if(this.isCoprocessorEnabled){
+ LOG.debug("Eagle HBase Coprocessor is enabled");
+ }else{
+ LOG.debug("Eagle HBase Coprocessor is disabled");
+ }
+ }
+ }
+
+ @Override
+ public Configuration getHbaseConf() {
+ return hbaseConf;
+ }
+
+ @Override
+ public String getZKQuorum(){
+ return this.zkQuorum;
+ }
+
+ @Override
+ public String getZKPort(){
+ return this.zkPort;
+ }
+
+ @Override
+ public String getServiceHost() {
+ return eagleServiceHost;
+ }
+
+ @Override
+ public int getServicePort() {
+ return eagleServicePort;
+ }
+
+ @Override
+ public String getEnv() {
+ return env;
+ }
+
+ @Override
+ public boolean isTableNamePrefixedWithEnvironment(){
+ return this.tableNamePrefixedWithEnv;
+ }
+
+ @Override
+ public int getHBaseClientScanCacheSize(){
+ return this.hbaseClientScanCacheSize;
+ }
+
+ @Override
+ public TimeZone getTimeZone() {
+ return this.timeZone;
+ }
+
+ @Override
+ public Config getConfig() {
+ return this.config;
+ }
+
+ // added for jira EAGLE-47
+ boolean isServiceAuditingEnabled;
+
+ @Override
+ public boolean isServiceAuditingEnabled() {
+ return isServiceAuditingEnabled;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfigHelper.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfigHelper.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfigHelper.java
new file mode 100644
index 0000000..fe3e190
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/config/EagleConfigHelper.java
@@ -0,0 +1,51 @@
+/*
+ *
+ * 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.common.config;
+
+import com.typesafe.config.Config;
+
+public class EagleConfigHelper {
+
+ public static String getServiceHost(Config config) {
+ return config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.HOST);
+ }
+
+ public static int getServicePort(Config config) {
+ return config.getInt(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PORT);
+ }
+
+ public static String getServiceUser(Config config) {
+ return config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME) ?
+ config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME) : null;
+ }
+
+ public static String getServicePassword(Config config) {
+ return config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD) ?
+ config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD) : null;
+ }
+
+ public static String getSite(Config config) {
+ return config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.SITE);
+ }
+
+ public static String getApplication(Config config) {
+ return config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.APPLICATION);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/email/EagleMailClient.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/email/EagleMailClient.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/email/EagleMailClient.java
new file mode 100755
index 0000000..6edac0a
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/email/EagleMailClient.java
@@ -0,0 +1,253 @@
+/*
+ * 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.common.email;
+
+import java.io.File;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.activation.FileDataSource;
+import javax.mail.Authenticator;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.PasswordAuthentication;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
+import org.apache.commons.configuration.AbstractConfiguration;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.netflix.config.ConcurrentMapConfiguration;
+
+public class EagleMailClient {
+// private static final String CONFIG_FILE = "config.properties";
+ private static final String BASE_PATH = "templates/";
+ private static final String AUTH_CONFIG = "mail.smtp.auth";
+ private static final String DEBUG_CONFIG = "mail.debug";
+ private static final String USER_CONFIG = "mail.user";
+ private static final String PASSWORD_CONFIG = "mail.password";
+
+ private VelocityEngine velocityEngine;
+ private Session session;
+ private static final Logger LOG = LoggerFactory.getLogger(EagleMailClient.class);
+
+ public EagleMailClient() {
+ this(new ConcurrentMapConfiguration());
+ }
+
+ public EagleMailClient(AbstractConfiguration configuration) {
+ try {
+ ConcurrentMapConfiguration con = (ConcurrentMapConfiguration)configuration;
+ velocityEngine = new VelocityEngine();
+ velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
+ velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
+ velocityEngine.init();
+
+ con.setProperty("mail.transport.protocol", "smtp");
+ final Properties config = con.getProperties();
+ if(Boolean.parseBoolean(config.getProperty(AUTH_CONFIG))){
+ session = Session.getDefaultInstance(config, new Authenticator() {
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication(config.getProperty(USER_CONFIG), config.getProperty(PASSWORD_CONFIG));
+ }
+ });
+ }
+ else session = Session.getDefaultInstance(config, new Authenticator() {});
+ final String debugMode = config.getProperty(DEBUG_CONFIG, "false");
+ final boolean debug = Boolean.parseBoolean(debugMode);
+ session.setDebug(debug);
+ } catch (Exception e) {
+ LOG.error("Failed connect to smtp server",e);
+ }
+ }
+
+ private boolean _send(String from, String to, String cc, String title,
+ String content) {
+ Message msg = new MimeMessage(session);
+ try {
+ msg.setFrom(new InternetAddress(from));
+ msg.setSubject(title);
+ if (to != null) {
+ msg.setRecipients(Message.RecipientType.TO,
+ InternetAddress.parse(to));
+ }
+ if (cc != null) {
+ msg.setRecipients(Message.RecipientType.CC,
+ InternetAddress.parse(cc));
+ }
+ //msg.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(DEFAULT_BCC_ADDRESS));
+ msg.setContent(content, "text/html;charset=utf-8");
+ LOG.info(String.format("Going to send mail: from[%s], to[%s], cc[%s], title[%s]", from, to, cc, title));
+
+ Transport.send(msg);
+
+ return true;
+ } catch (AddressException e) {
+ LOG.info("Send mail failed, got an AddressException: " + e.getMessage(), e);
+ return false;
+ } catch (MessagingException e) {
+ LOG.info("Send mail failed, got an AddressException: " + e.getMessage(), e);
+ return false;
+ }
+ }
+
+ private boolean _send(String from,String to,String cc,String title,String content,List<MimeBodyPart> attachments){
+ MimeMessage mail = new MimeMessage(session);
+ try {
+ mail.setFrom(new InternetAddress(from));
+ mail.setSubject(title);
+ if (to != null) {
+ mail.setRecipients(Message.RecipientType.TO,
+ InternetAddress.parse(to));
+ }
+ if (cc != null) {
+ mail.setRecipients(Message.RecipientType.CC,
+ InternetAddress.parse(cc));
+ }
+
+ //mail.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(DEFAULT_BCC_ADDRESS));
+
+ MimeBodyPart mimeBodyPart = new MimeBodyPart();
+ mimeBodyPart.setContent(content,"text/html;charset=utf-8");
+
+ Multipart multipart = new MimeMultipart();
+ multipart.addBodyPart(mimeBodyPart);
+
+ for(MimeBodyPart attachment:attachments){
+ multipart.addBodyPart(attachment);
+ }
+
+ mail.setContent(multipart);
+// mail.setContent(content, "text/html;charset=utf-8");
+ LOG.info(String.format("Going to send mail: from[%s], to[%s], cc[%s], title[%s]", from, to, cc, title));
+
+ Transport.send(mail);
+
+ return true;
+ } catch (AddressException e) {
+ LOG.info("Send mail failed, got an AddressException: " + e.getMessage(), e);
+ return false;
+ } catch (MessagingException e) {
+ LOG.info("Send mail failed, got an AddressException: " + e.getMessage(), e);
+ return false;
+ }
+ }
+
+ public boolean send(String from, String to, String cc, String title,
+ String content) {
+ return this._send(from, to, cc, title, content);
+ }
+
+ public boolean send(String from, String to, String cc, String title,
+ String templatePath, VelocityContext context) {
+ Template t = null;
+ try {
+ t = velocityEngine.getTemplate(BASE_PATH + templatePath);
+ } catch (ResourceNotFoundException ex) {
+
+ }
+ if (t == null) {
+ try {
+ t = velocityEngine.getTemplate(templatePath);
+ } catch (ResourceNotFoundException e) {
+ t = velocityEngine.getTemplate("/" + templatePath);
+ }
+ }
+ final StringWriter writer = new StringWriter();
+ t.merge(context, writer);
+ if(LOG.isDebugEnabled()) LOG.debug(writer.toString());
+ return this.send(from, to, cc, title, writer.toString());
+ }
+
+ public boolean send(String from, String to, String cc, String title,
+ String templatePath, VelocityContext context, Map<String,File> attachments) {
+ if (attachments == null || attachments.isEmpty()) {
+ return send(from, to, cc, title, templatePath, context);
+ }
+ Template t = null;
+
+ List<MimeBodyPart> mimeBodyParts = new ArrayList<MimeBodyPart>();
+ Map<String,String> cid = new HashMap<String,String>();
+
+ for (Map.Entry<String,File> entry : attachments.entrySet()) {
+ final String attachment = entry.getKey();
+ final File attachmentFile = entry.getValue();
+ final MimeBodyPart mimeBodyPart = new MimeBodyPart();
+ if(attachmentFile !=null && attachmentFile.exists()){
+ DataSource source = new FileDataSource(attachmentFile);
+ try {
+ mimeBodyPart.setDataHandler(new DataHandler(source));
+ mimeBodyPart.setFileName(attachment);
+ mimeBodyPart.setDisposition(MimeBodyPart.ATTACHMENT);
+ mimeBodyPart.setContentID(attachment);
+ cid.put(attachment,mimeBodyPart.getContentID());
+ mimeBodyParts.add(mimeBodyPart);
+ } catch (MessagingException e) {
+ LOG.error("Generate mail failed, got exception while attaching files: " + e.getMessage(), e);
+ }
+ }else{
+ LOG.error("Attachment: " + attachment + " is null or not exists");
+ }
+ }
+ //TODO remove cid, because not used at all
+ if(LOG.isDebugEnabled()) LOG.debug("Cid maps: "+cid);
+ context.put("cid", cid);
+
+ try {
+ t = velocityEngine.getTemplate(BASE_PATH + templatePath);
+ } catch (ResourceNotFoundException ex) {
+// LOGGER.error("Template not found:"+BASE_PATH + templatePath, ex);
+ }
+
+ if (t == null) {
+ try {
+ t = velocityEngine.getTemplate(templatePath);
+ } catch (ResourceNotFoundException e) {
+ try {
+ t = velocityEngine.getTemplate("/" + templatePath);
+ }
+ catch (Exception ex) {
+ LOG.error("Template not found:"+ "/" + templatePath, ex);
+ }
+ }
+ }
+
+ final StringWriter writer = new StringWriter();
+ t.merge(context, writer);
+ if(LOG.isDebugEnabled()) LOG.debug(writer.toString());
+ return this._send(from, to, cc, title, writer.toString(), mimeBodyParts);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/metric/AlertContext.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/metric/AlertContext.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/metric/AlertContext.java
new file mode 100644
index 0000000..f8b11c3
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/metric/AlertContext.java
@@ -0,0 +1,94 @@
+/*
+ * 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.common.metric;
+
+import org.codehaus.jackson.map.ObjectMapper;
+import org.slf4j.Logger;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * not thread safe
+ */
+public class AlertContext implements Serializable{
+ private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(AlertContext.class);
+
+ private Map<String, String> properties = new HashMap<String, String>();
+
+ public AlertContext(){
+ }
+
+ public AlertContext(AlertContext context){
+ this.properties = new HashMap<String, String>(context.properties);
+ }
+
+ public String removeProperty(String name)
+ {
+ return properties.remove(name);
+ }
+
+ public AlertContext addProperty(String name, String value){
+ properties.put(name, value);
+ return this;
+ }
+
+ public AlertContext addAll(Map<String,String> propHash){
+ this.properties.putAll(propHash);
+ return this;
+ }
+
+ public String toJsonString(){
+ ObjectMapper objectMapper = new ObjectMapper();
+ try {
+ return objectMapper.writeValueAsString(properties);
+ }catch(Exception ex){
+ LOG.error("fail converting alertcontext into string", ex);
+ return null;
+ }
+ }
+
+ public static AlertContext fromJsonString(String json){
+ ObjectMapper objectMapper = new ObjectMapper();
+ try{
+ Map m = objectMapper.readValue(json, Map.class);
+ AlertContext c = new AlertContext();
+ c.addAll(m);
+ return c;
+ }catch(Exception ex){
+ LOG.error("fail converting string into alertcontext", ex);
+ return null;
+ }
+ }
+
+ public String getProperty(String name){
+ return properties.get(name);
+ }
+
+ public String toString(){
+ return properties.toString();
+ }
+
+ public Map<String, String> getProperties(){
+ return properties;
+ }
+
+ public void setProperties(Map<String, String> properties){
+ this.properties = properties;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/CommonGuiceModule.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/CommonGuiceModule.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/CommonGuiceModule.java
new file mode 100644
index 0000000..c44ca01
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/CommonGuiceModule.java
@@ -0,0 +1,28 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.common.module;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Singleton;
+import com.typesafe.config.Config;
+
+public class CommonGuiceModule extends AbstractModule{
+ @Override
+ protected void configure() {
+ bind(Config.class).toProvider(ConfigServiceProvider.class).in(Singleton.class);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/ConfigServiceProvider.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/ConfigServiceProvider.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/ConfigServiceProvider.java
new file mode 100644
index 0000000..37da582
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/ConfigServiceProvider.java
@@ -0,0 +1,30 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.common.module;
+
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigFactory;
+
+@Singleton
+public class ConfigServiceProvider implements Provider<Config> {
+ @Override
+ public Config get() {
+ return ConfigFactory.load();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/service/HadoopAccountService.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/service/HadoopAccountService.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/service/HadoopAccountService.java
new file mode 100644
index 0000000..0b4893a
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/service/HadoopAccountService.java
@@ -0,0 +1,23 @@
+/*
+ * 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.common.service;
+
+import java.util.List;
+
+public interface HadoopAccountService {
+ public List<HadoopUser> searchByUsername(List<String> username);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/e21b073f/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/service/HadoopUser.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/service/HadoopUser.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/service/HadoopUser.java
new file mode 100644
index 0000000..2e84f77
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/service/HadoopUser.java
@@ -0,0 +1,44 @@
+/*
+ * 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.common.service;
+
+import java.util.List;
+
+/**
+ * @since : 7/11/14,2014
+ */
+public class HadoopUser {
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ protected String username;
+
+ public List<String> getEmail() {
+ return email;
+ }
+
+ public void setEmail(List<String> emails) {
+ this.email = emails;
+ }
+
+ protected List<String> email;
+}
\ No newline at end of file