eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h..@apache.org
Subject [49/55] [abbrv] [partial] incubator-eagle git commit: [EAGLE-46] Rename package name as "org.apache.eagle"
Date Thu, 19 Nov 2015 10:47:56 GMT
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertDefinitionAPIEntity.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertDefinitionAPIEntity.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertDefinitionAPIEntity.java
deleted file mode 100644
index 5d4586f..0000000
--- a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertDefinitionAPIEntity.java
+++ /dev/null
@@ -1,181 +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 eagle.alert.entity;
-
-import eagle.alert.common.AlertConstants;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.codehaus.jackson.annotate.JsonIgnoreProperties;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-
-import eagle.log.base.taggedlog.TaggedLogAPIEntity;
-import eagle.log.entity.meta.Column;
-import eagle.log.entity.meta.ColumnFamily;
-import eagle.log.entity.meta.Index;
-import eagle.log.entity.meta.Indexes;
-import eagle.log.entity.meta.Prefix;
-import eagle.log.entity.meta.Service;
-import eagle.log.entity.meta.Table;
-import eagle.log.entity.meta.Tags;
-import eagle.log.entity.meta.TimeSeries;
-
-/**
- * site: site name
- * dataSource: data source name
- *
- * alertExecutorId: Group Policy by alertExecutorId, the policy definition with the sample ["site", "dataSource", "alertExecutorId"] should run on the sample alert executor
- *
- * policyId: policy name, should be unique
- * policyType: policy engine implementation type
- */
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
-@Table("alertdef")
-@ColumnFamily("f")
-@Prefix("alertdef")
-@Service(AlertConstants.ALERT_DEFINITION_SERVICE_ENDPOINT_NAME)
-@JsonIgnoreProperties(ignoreUnknown = true)
-@TimeSeries(false)
-@Tags({"site", "dataSource", "alertExecutorId", "policyId", "policyType"})
-@Indexes({
-	@Index(name="Index_1_alertExecutorId", columns = { "alertExecutorID" }, unique = true),
-})
-public class AlertDefinitionAPIEntity extends TaggedLogAPIEntity{
-	@Column("a")
-	private String desc;
-	@Column("b")
-	private String policyDef;
-	@Column("c")
-	private String dedupeDef;
-	@Column("d")
-	private String notificationDef;
-	@Column("e")
-	private String remediationDef;
-	@Column("f")
-	private boolean enabled;
-	@Column("g")
-	private String owner;	
-	@Column("h")
-	private long lastModifiedDate;
-	@Column("i")
-	private long severity;
-	@Column("j")
-	private long createdTime;
-
-	public String getDesc() {
-		return desc;
-	}
-	public void setDesc(String desc) {
-		this.desc = desc;
-		valueChanged("desc");
-	}
-	public String getPolicyDef() {
-		return policyDef;
-	}
-	public void setPolicyDef(String policyDef) {
-		this.policyDef = policyDef;
-		valueChanged("policyDef");
-	}
-	public String getDedupeDef() {
-		return dedupeDef;
-	}
-	public void setDedupeDef(String dedupeDef) {
-		this.dedupeDef = dedupeDef;
-		valueChanged("dedupeDef");
-	}
-	public String getNotificationDef() {
-		return notificationDef;
-	}
-	public void setNotificationDef(String notificationDef) {
-		this.notificationDef = notificationDef;
-		valueChanged("notificationDef");
-	}
-	public String getRemediationDef() {
-		return remediationDef;
-	}
-	public void setRemediationDef(String remediationDef) {
-		this.remediationDef = remediationDef;
-		valueChanged("remediationDef");
-	}
-	public boolean isEnabled() {
-		return enabled;
-	}
-	public void setEnabled(boolean enabled) {
-		this.enabled = enabled;
-		valueChanged("enabled");
-	}
-	public String getOwner() {
-		return owner;
-	}
-	public void setOwner(String owner) {
-		this.owner = owner;
-		valueChanged("owner");
-	}	
-	public long getLastModifiedDate() {
-		return lastModifiedDate;
-	}
-	public void setLastModifiedDate(long lastModifiedDate) {
-		this.lastModifiedDate = lastModifiedDate;
-		valueChanged("lastModifiedDate");
-	}	
-	public long getSeverity() {
-		return severity;
-	}
-	public void setSeverity(long severity) {
-		this.severity = severity;
-		valueChanged("severity");
-	}	
-	public long getCreatedTime() {
-		return createdTime;
-	}
-	public void setCreatedTime(long createdTime) {
-		this.createdTime = createdTime;
-		valueChanged("createdTime");
-	}
-	public boolean equals(Object o){
-		if(o == this)
-			return true;
-		if(!(o instanceof AlertDefinitionAPIEntity))
-			return false;
-		AlertDefinitionAPIEntity that = (AlertDefinitionAPIEntity)o;
-		if(that.enabled == this.enabled &&
-				compare(that.policyDef, this.policyDef) &&
-				compare(that.dedupeDef, this.dedupeDef) &&
-				compare(that.notificationDef, this.notificationDef) &&
-				compare(that.remediationDef, this.remediationDef))
-			return true;
-		return false;
-	}
-	
-	private boolean compare(String a, String b){
-		if(a == b)
-			return true;
-		if(a == null || b == null)
-			return false;
-		if(a.equals(b))
-			return true;
-		return false;
-	}
-	
-	public int hashCode(){
-		HashCodeBuilder builder = new HashCodeBuilder();
-		builder.append(enabled);
-		builder.append(policyDef);
-		builder.append(dedupeDef);
-		builder.append(notificationDef);
-		builder.append(remediationDef);
-		return builder.toHashCode();
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertEntityRepository.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertEntityRepository.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertEntityRepository.java
deleted file mode 100644
index ecdc53f..0000000
--- a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertEntityRepository.java
+++ /dev/null
@@ -1,32 +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 eagle.alert.entity;
-
-import eagle.common.metric.AlertContext;
-import eagle.log.entity.repo.EntityRepository;
-
-public class AlertEntityRepository extends EntityRepository {
-	public AlertEntityRepository() {
-		serDeserMap.put(AlertContext.class, new AlertContextSerDeser());
-		entitySet.add(AlertAPIEntity.class);
-		entitySet.add(AlertDefinitionAPIEntity.class);
-		entitySet.add(AlertStreamSchemaEntity.class);
-		entitySet.add(AlertStreamEntity.class);
-		entitySet.add(AlertDataSourceEntity.class);
-        entitySet.add(AlertExecutorEntity.class);
-	}
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertExecutorEntity.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertExecutorEntity.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertExecutorEntity.java
deleted file mode 100644
index 8bf76d5..0000000
--- a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertExecutorEntity.java
+++ /dev/null
@@ -1,45 +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 eagle.alert.entity;
-
-import eagle.alert.common.AlertConstants;
-import eagle.log.base.taggedlog.TaggedLogAPIEntity;
-import eagle.log.entity.meta.*;
-import org.codehaus.jackson.annotate.JsonIgnoreProperties;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
-@Table("alertExecutor")
-@ColumnFamily("f")
-@Prefix("alertExecutor")
-@Service(AlertConstants.ALERT_EXECUTOR_SERVICE_ENDPOINT_NAME)
-@JsonIgnoreProperties(ignoreUnknown = true)
-@TimeSeries(false)
-@Tags({"dataSource", "alertExecutorId", "streamName"})
-public class AlertExecutorEntity extends TaggedLogAPIEntity{
-    @Column("a")
-    private String desc;
-
-    public String getDesc() {
-        return desc;
-    }
-
-    public void setDesc(String desc) {
-        this.desc = desc;
-        valueChanged("desc");
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertStreamEntity.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertStreamEntity.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertStreamEntity.java
deleted file mode 100644
index 9314078..0000000
--- a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertStreamEntity.java
+++ /dev/null
@@ -1,51 +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 eagle.alert.entity;
-
-import org.codehaus.jackson.annotate.JsonIgnoreProperties;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-
-import eagle.alert.common.AlertConstants;
-import eagle.log.base.taggedlog.TaggedLogAPIEntity;
-import eagle.log.entity.meta.Column;
-import eagle.log.entity.meta.ColumnFamily;
-import eagle.log.entity.meta.Prefix;
-import eagle.log.entity.meta.Service;
-import eagle.log.entity.meta.Table;
-import eagle.log.entity.meta.Tags;
-import eagle.log.entity.meta.TimeSeries;
-
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
-@Table("alertStream")
-@ColumnFamily("f")
-@Prefix("alertStream")
-@Service(AlertConstants.ALERT_STREAM_SERVICE_ENDPOINT_NAME)
-@JsonIgnoreProperties(ignoreUnknown = true)
-@TimeSeries(false)
-@Tags({"dataSource", "streamName"})
-public class AlertStreamEntity extends TaggedLogAPIEntity{
-	@Column("a")
-	private String desc;	
-
-	public String getDesc() {
-		return desc;
-	}
-	public void setDesc(String desc) {
-		this.desc = desc;
-		valueChanged("desc");
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertStreamSchemaEntity.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertStreamSchemaEntity.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertStreamSchemaEntity.java
deleted file mode 100644
index 61a9a96..0000000
--- a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/eagle/alert/entity/AlertStreamSchemaEntity.java
+++ /dev/null
@@ -1,111 +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 eagle.alert.entity;
-
-import org.codehaus.jackson.annotate.JsonIgnoreProperties;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-
-import eagle.alert.common.AlertConstants;
-import eagle.log.base.taggedlog.TaggedLogAPIEntity;
-import eagle.log.entity.meta.Column;
-import eagle.log.entity.meta.ColumnFamily;
-import eagle.log.entity.meta.Prefix;
-import eagle.log.entity.meta.Service;
-import eagle.log.entity.meta.Table;
-import eagle.log.entity.meta.Tags;
-import eagle.log.entity.meta.TimeSeries;
-
-/**
- * ddl to create streammetadata table
- * 
- * create 'alertStreamSchema', {NAME => 'f', BLOOMFILTER => 'ROW', VERSIONS => '1', COMPRESSION => 'SNAPPY'}
- */
-@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
-@Table("alertStreamSchema")
-@ColumnFamily("f")
-@Prefix("alertStreamSchema")
-@Service(AlertConstants.ALERT_STREAM_SCHEMA_SERVICE_ENDPOINT_NAME)
-@JsonIgnoreProperties(ignoreUnknown = true)
-@TimeSeries(false)
-@Tags({"dataSource", "streamName", "attrName"})
-public class AlertStreamSchemaEntity extends TaggedLogAPIEntity{
-	@Column("a")
-	private String attrType;
-	@Column("b")
-	private String category;
-	@Column("c")
-	private String attrValueResolver;
-	/* all tags form the key for alert de-duplication */
-	@Column("d")
-	private Boolean usedAsTag;
-	@Column("e")
-	private String attrDescription;
-	@Column("f")
-	private String attrDisplayName;	
-	@Column("g")
-	private String defaultValue;
-
-	public String getAttrType() {
-		return attrType;
-	}
-	public void setAttrType(String attrType) {
-		this.attrType = attrType;
-		valueChanged("attrType");
-	}
-	public String getCategory() {
-		return category;
-	}
-	public void setCategory(String category) {
-		this.category = category;
-		valueChanged("category");
-	}
-	public String getAttrValueResolver() {
-		return attrValueResolver;
-	}
-	public void setAttrValueResolver(String attrValueResolver) {
-		this.attrValueResolver = attrValueResolver;
-		valueChanged("attrValueResolver");
-	}
-	public Boolean getUsedAsTag() {
-		return usedAsTag;
-	}
-	public void setUsedAsTag(Boolean usedAsTag) {
-		this.usedAsTag = usedAsTag;
-		valueChanged("usedAsTag");
-	}
-	public String getAttrDescription() {
-		return attrDescription;
-	}
-	public void setAttrDescription(String attrDescription) {
-		this.attrDescription = attrDescription;
-		valueChanged("attrDescription");
-	}
-	public String getAttrDisplayName() {
-		return attrDisplayName;
-	}
-	public void setAttrDisplayName(String attrDisplayName) {
-		this.attrDisplayName = attrDisplayName;
-		valueChanged("attrDisplayName");
-	}
-	public String getDefaultValue() {
-		return defaultValue;
-	}
-	public void setDefaultValue(String defaultValue) {
-		this.defaultValue = defaultValue;
-		valueChanged("defaultValue");
-	}
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/common/AlertConstants.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/common/AlertConstants.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/common/AlertConstants.java
new file mode 100644
index 0000000..44728ea
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/common/AlertConstants.java
@@ -0,0 +1,64 @@
+/*
+ * 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.common;
+
+public class AlertConstants {
+	public final static String ALERT_SERVICE_ENDPOINT_NAME = "AlertService";
+	public final static String ALERT_DEFINITION_SERVICE_ENDPOINT_NAME = "AlertDefinitionService";
+	public final static String ALERT_STREAM_SCHEMA_SERVICE_ENDPOINT_NAME = "AlertStreamSchemaService";
+	public final static String ALERT_DATA_SOURCE_SERVICE_ENDPOINT_NAME = "AlertDataSourceService";
+	public final static String ALERT_EXECUTOR_SERVICE_ENDPOINT_NAME = "AlertExecutorService";
+	public final static String ALERT_STREAM_SERVICE_ENDPOINT_NAME = "AlertStreamService";
+	public static final String ALERT_EMAIL_ORIGIN_PROPERTY = "alertEmailOrigin";
+	public static final String ALERT_TIMESTAMP_PROPERTY = "alertTimestamp";
+
+	public static final String ALERT_EMAIL_TIME_PROPERTY = "timestamp";
+	public static final String ALERT_EMAIL_COUNT_PROPERTY = "count";
+	public static final String ALERT_EMAIL_ALERTLIST_PROPERTY = "alertList";
+
+	public static final String URL = "url";
+	public static final String ALERT_SOURCE = "alertSource";
+	public static final String ALERT_MESSAGE = "alertMessage";
+	public static final String SUBJECT = "subject";
+	public static final String ALERT_EXECUTOR_ID = "alertExecutorId";
+	public static final String POLICY_NAME = "policyName";
+	public static final String POLICY_ID = "policyId";
+    public static final String SOURCE_STREAMS = "sourceStreams";
+    public static final String ALERT_EVENT = "alertEvent";
+	public static final String POLICY_DETAIL_URL = "policyDetailUrl";
+	public static final String ALERT_DETAIL_URL = "alertDetailUrl";
+
+	public static final String POLICY_DEFINITION = "policyDefinition";
+	public static final String POLICY_TYPE = "policyType";
+	public static final String STREAM_NAME = "streamName";
+	public static final String ATTR_NAME = "attrName";
+
+	public static final String ALERT_EXECUTOR_CONFIGS = "alertExecutorConfigs";
+	public static final String PARALLELISM = "parallelism";
+	public static final String PARTITIONER = "partitioner";
+	public static final String SOURCE = "source";
+	public static final String PARTITIONSEQ = "partitionSeq";
+
+	public enum policyType {
+		siddhiCEPEngine,
+		MachineLearning;
+
+		policyType() {
+		}
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/common/AlertEmailSender.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/common/AlertEmailSender.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/common/AlertEmailSender.java
new file mode 100644
index 0000000..c812f0e
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/common/AlertEmailSender.java
@@ -0,0 +1,158 @@
+/*
+ * 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.common;
+
+import java.lang.management.ManagementFactory;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.eagle.alert.email.AlertEmailContext;
+import org.apache.velocity.VelocityContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.eagle.alert.email.AlertEmailComponent;
+import org.apache.eagle.common.DateTimeUtil;
+import org.apache.eagle.common.email.EagleMailClient;
+import com.netflix.config.ConcurrentMapConfiguration;
+import com.typesafe.config.ConfigObject;
+
+public class AlertEmailSender implements Runnable {
+	
+	protected final List<Map<String, String>> alertContexts = new ArrayList<Map<String, String>>();
+	protected final String configFileName;
+	protected final String subject;
+	protected final String sender;
+	protected final String recipents;
+	protected final String cc;
+	protected final String origin;
+	protected boolean sentSuccessfully = false;
+
+	private final static Logger LOG = LoggerFactory.getLogger(AlertEmailSender.class);
+	private final static int MAX_RETRY_COUNT = 3;
+		
+	private static final String MAIL_HOST = "mail.host";	
+	private static final String MAIL_PORT = "mail.smtp.port";
+	private static final String MAIL_DEBUG = "mail.debug";
+	
+	private static final String CONF_KEY_MAIL_HOST = "mailHost";	
+	private static final String CONF_KEY_MAIL_PORT = "mailSmtpPort";
+	private static final String CONF_KEY_MAIL_DEBUG = "mailDebug";
+
+	private ConfigObject eagleProps;
+
+
+    private String threadName;
+	/**
+	 * Derived class may have some additional context properties to add
+	 * @param context velocity context
+	 * @param env environment
+	 */
+	protected void additionalContext(VelocityContext context, String env) {
+		// By default there's no additional context added
+	}
+
+	public AlertEmailSender(AlertEmailContext alertEmail){
+		this.recipents = alertEmail.getRecipients();
+		this.configFileName = alertEmail.getVelocityTplFile();
+		this.subject = alertEmail.getSubject();
+		this.sender = alertEmail.getSender();
+		this.cc = alertEmail.getCc();
+		for(AlertEmailComponent bean : alertEmail.getComponents()){
+			this.alertContexts.add(bean.getAlertContext().getProperties());
+		}
+		String tmp = ManagementFactory.getRuntimeMXBean().getName();
+		this.origin = tmp.split("@")[1] + "(pid:" + tmp.split("@")[0] + ")";
+        threadName = Thread.currentThread().getName();
+		LOG.info("Initialized "+threadName+": origin is : " + this.origin+", recipient of the email: " + this.recipents+", velocity TPL file: " + this.configFileName);
+	}
+
+	public AlertEmailSender(AlertEmailContext alertEmail, ConfigObject eagleProps){
+		this(alertEmail);
+		this.eagleProps = eagleProps;
+	}
+
+	@Override
+	public void run() {
+		int count = 0;
+		boolean success = false;
+		while(count++ < MAX_RETRY_COUNT && !success){
+			LOG.info("Sending email, tried: " + count+", max: "+MAX_RETRY_COUNT);
+			try {
+				final EagleMailClient client;
+				if (eagleProps != null) {
+					ConcurrentMapConfiguration con = new ConcurrentMapConfiguration();					
+					con.addProperty(MAIL_HOST, eagleProps.get(CONF_KEY_MAIL_HOST).unwrapped());
+					con.addProperty(MAIL_PORT, eagleProps.get(CONF_KEY_MAIL_PORT).unwrapped());
+					if (eagleProps.get(CONF_KEY_MAIL_DEBUG) != null) {
+						con.addProperty(MAIL_DEBUG, eagleProps.get(CONF_KEY_MAIL_DEBUG).unwrapped());
+					}
+					client = new EagleMailClient(con);
+				}
+				else {
+					client = new EagleMailClient();
+				}
+				String env = "prod";
+				if (eagleProps != null && eagleProps.get("env") != null) {
+					env = (String) eagleProps.get("env").unwrapped();
+				}
+				LOG.info("Env is: " + env);
+				final VelocityContext context = new VelocityContext();
+				generateCommonContext(context);
+				LOG.info("After calling generateCommonContext...");
+				additionalContext(context, env);
+				
+				if (recipents == null || recipents.equals("")) {
+					LOG.error("Recipients is null, skip sending emails ");
+					return;
+				}
+				String title = subject;
+				if (!env.trim().equals("prod")) {
+					title = "[" + env + "]" + title; 				
+				}
+				success = client.send(sender, recipents, cc, title, configFileName, context, null);
+				LOG.info("Success of sending email: " + success);
+				if(!success && count < MAX_RETRY_COUNT) {
+					LOG.info("Sleep for a while before retrying");
+					Thread.sleep(10*1000);
+				}
+			}
+			catch (Exception e){
+				LOG.warn("Sending mail exception", e);
+			}
+		}
+
+		if(success){
+			sentSuccessfully = true;
+            LOG.info(String.format("Successfully send email, thread: %s",threadName));
+		}else{
+			LOG.warn(String.format("Fail sending email after tries %s times, thread: %s",MAX_RETRY_COUNT,threadName));
+		}
+	}
+	
+	private void generateCommonContext(VelocityContext context) {
+		context.put(AlertConstants.ALERT_EMAIL_TIME_PROPERTY, DateTimeUtil.millisecondsToHumanDateWithSeconds( System.currentTimeMillis() ));
+		context.put(AlertConstants.ALERT_EMAIL_COUNT_PROPERTY, alertContexts.size());
+		context.put(AlertConstants.ALERT_EMAIL_ALERTLIST_PROPERTY, alertContexts);
+		context.put(AlertConstants.ALERT_EMAIL_ORIGIN_PROPERTY, origin);
+	}
+
+	public boolean sentSuccessfully(){
+		return this.sentSuccessfully;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDataSourceDAO.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDataSourceDAO.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDataSourceDAO.java
new file mode 100644
index 0000000..4196d7f
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDataSourceDAO.java
@@ -0,0 +1,25 @@
+/*
+ * 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.dao;
+
+import org.apache.eagle.alert.entity.AlertDataSourceEntity;
+
+import java.util.List;
+
+public interface AlertDataSourceDAO {
+    List<AlertDataSourceEntity> findAlertDataSourceBySite(String site) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDataSourceDAOImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDataSourceDAOImpl.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDataSourceDAOImpl.java
new file mode 100644
index 0000000..97323dd
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDataSourceDAOImpl.java
@@ -0,0 +1,83 @@
+/*
+ * 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.dao;
+
+import com.typesafe.config.Config;
+import org.apache.eagle.alert.common.AlertConstants;
+import org.apache.eagle.alert.entity.AlertDataSourceEntity;
+import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
+import org.apache.eagle.common.config.EagleConfigConstants;
+import org.apache.eagle.service.client.IEagleServiceClient;
+import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
+import org.apache.commons.lang.time.DateUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+public class AlertDataSourceDAOImpl implements AlertDataSourceDAO{
+    private final Logger LOG = LoggerFactory.getLogger(AlertDataSourceDAOImpl.class);
+
+    private final String eagleServiceHost;
+    private final Integer eagleServicePort;
+    private String username;
+    private String password;
+
+    public AlertDataSourceDAOImpl(String eagleServiceHost, Integer eagleServicePort, String username, String password) {
+        this.eagleServiceHost = eagleServiceHost;
+        this.eagleServicePort = eagleServicePort;
+        this.username = username;
+        this.password = password;
+    }
+
+    public AlertDataSourceDAOImpl(String eagleServiceHost, Integer eagleServicePort) {
+        this(eagleServiceHost,eagleServicePort, null, null);
+    }
+
+    public AlertDataSourceDAOImpl(Config config) {
+        this.eagleServiceHost = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.HOST);
+        this.eagleServicePort = config.getInt(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PORT);
+        if (config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME) &&
+            config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD)) {
+            this.username = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME);
+            this.password = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD);
+        }
+    }
+
+    @Override
+    public List<AlertDataSourceEntity> findAlertDataSourceBySite(String site) throws Exception{
+        try {
+            IEagleServiceClient client = new EagleServiceClientImpl(eagleServiceHost, eagleServicePort, username, password);
+            String query = AlertConstants.ALERT_STREAM_SERVICE_ENDPOINT_NAME + "[@site=\"" + site + "\"]{*}";
+            GenericServiceAPIResponseEntity<AlertDataSourceEntity> response =  client.search()
+                    .startTime(0)
+                    .endTime(10 * DateUtils.MILLIS_PER_DAY)
+                    .pageSize(Integer.MAX_VALUE)
+                    .query(query)
+                    .send();
+            client.close();
+            if (response.getException() != null) {
+                throw new Exception("Got an exception when query eagle service: " + response.getException());
+            }
+            return response.getObj();
+        }
+        catch (Exception ex) {
+            LOG.error("Got an exception when query stream metadata service ", ex);
+            throw new IllegalStateException(ex);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDefinitionDAO.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDefinitionDAO.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDefinitionDAO.java
new file mode 100644
index 0000000..44f081a
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDefinitionDAO.java
@@ -0,0 +1,39 @@
+/*
+ * 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.dao;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.eagle.alert.entity.AlertDefinitionAPIEntity;
+
+public interface AlertDefinitionDAO extends Serializable{
+	/**
+	 * find list of active alert definitions for one specific site and dataSource
+	 * @return
+	 */
+	List<AlertDefinitionAPIEntity> findActiveAlertDefs(String site, String dataSource) throws Exception;
+	
+	/**
+	 * find map from alertExecutorId to map from policy Id to alert definition for one specific site and dataSource
+	 * Map from alertExecutorId to map from policyId to policy definition
+       (site,dataSource) => Map[alertExecutorId,Map[policyId,alertDefinition]]
+	 * @return
+	 */
+	Map<String, Map<String, AlertDefinitionAPIEntity>> findActiveAlertDefsGroupbyAlertExecutorId(String site, String dataSource) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDefinitionDAOImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDefinitionDAOImpl.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDefinitionDAOImpl.java
new file mode 100644
index 0000000..5461bd0
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertDefinitionDAOImpl.java
@@ -0,0 +1,104 @@
+/*
+ * 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.dao;
+
+import com.typesafe.config.Config;
+import org.apache.eagle.alert.common.AlertConstants;
+import org.apache.eagle.alert.entity.AlertDefinitionAPIEntity;
+import org.apache.eagle.common.config.EagleConfigConstants;
+import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
+import org.apache.eagle.service.client.IEagleServiceClient;
+import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Utility methods to load alert definitions for a program
+ */
+public class AlertDefinitionDAOImpl implements AlertDefinitionDAO {
+	private final String eagleServiceHost;
+	private final Integer eagleServicePort;
+	private String username;
+	private String password;
+	private final Logger LOG = LoggerFactory.getLogger(AlertDefinitionDAOImpl.class);
+
+	public AlertDefinitionDAOImpl(String eagleServiceHost, Integer eagleServicePort) {
+		this(eagleServiceHost, eagleServicePort, null, null);
+	}
+
+	public AlertDefinitionDAOImpl(String eagleServiceHost, Integer eagleServicePort, String username, String password) {
+		this.eagleServiceHost = eagleServiceHost;
+		this.eagleServicePort = eagleServicePort;
+		this.username = username;
+		this.password = password;
+	}
+
+	public AlertDefinitionDAOImpl(Config config){
+		this.eagleServiceHost = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.HOST);
+		this.eagleServicePort = config.getInt(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PORT);
+		if (config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME) &&
+			config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD)) {
+			this.username = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME);
+			this.password = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD);
+		}
+	}
+
+    @Override
+	public List<AlertDefinitionAPIEntity> findActiveAlertDefs(String site, String dataSource) throws Exception {
+		try {
+			IEagleServiceClient client = new EagleServiceClientImpl(eagleServiceHost, eagleServicePort, username, password);
+			String query = AlertConstants.ALERT_DEFINITION_SERVICE_ENDPOINT_NAME + "[@site=\"" + site + "\" AND @dataSource=\"" + dataSource + "\"]{*}";
+			GenericServiceAPIResponseEntity<AlertDefinitionAPIEntity> response =  client.search()
+																		                .pageSize(Integer.MAX_VALUE)
+																		                .query(query)
+																	                    .send();
+			client.close();
+			if (response.getException() != null) {
+				throw new Exception("Got an exception when query eagle service: " + response.getException()); 
+			}
+			List<AlertDefinitionAPIEntity> list = response.getObj();
+			List<AlertDefinitionAPIEntity> enabledList = new ArrayList<AlertDefinitionAPIEntity>();
+			for (AlertDefinitionAPIEntity entity : list) {
+				if (entity.isEnabled()) enabledList.add(entity);
+			}
+			return enabledList;
+		}
+		catch (Exception ex) {
+			LOG.error("Got an exception when query alert Def service", ex);
+			throw new IllegalStateException(ex);
+		}					   
+	}
+
+    @Override
+	public Map<String, Map<String, AlertDefinitionAPIEntity>> findActiveAlertDefsGroupbyAlertExecutorId(String site, String dataSource) throws Exception {
+		List<AlertDefinitionAPIEntity> list = findActiveAlertDefs(site, dataSource);
+		Map<String, Map<String, AlertDefinitionAPIEntity>> map = new HashMap<String, Map<String, AlertDefinitionAPIEntity>>();
+			for (AlertDefinitionAPIEntity entity : list) {
+				String executorID = entity.getTags().get(AlertConstants.ALERT_EXECUTOR_ID);
+				if (map.get(executorID) == null) {
+					map.put(executorID, new HashMap<String, AlertDefinitionAPIEntity>());
+				}
+				map.get(executorID).put(entity.getTags().get("policyId"), entity);
+			}
+		return map;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertExecutorDAO.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertExecutorDAO.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertExecutorDAO.java
new file mode 100644
index 0000000..7fc1469
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertExecutorDAO.java
@@ -0,0 +1,26 @@
+/*
+ * 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.dao;
+
+import org.apache.eagle.alert.entity.AlertExecutorEntity;
+
+import java.util.List;
+
+public interface AlertExecutorDAO {
+    List<AlertExecutorEntity> findAlertExecutorByDataSource(String dataSource) throws Exception;
+    List<AlertExecutorEntity> findAlertExecutor(String dataSource, String alertExecutorId) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertExecutorDAOImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertExecutorDAOImpl.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertExecutorDAOImpl.java
new file mode 100644
index 0000000..ee8bc21
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertExecutorDAOImpl.java
@@ -0,0 +1,108 @@
+/*
+ * 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.dao;
+
+import com.typesafe.config.Config;
+import org.apache.eagle.alert.common.AlertConstants;
+import org.apache.eagle.alert.entity.AlertExecutorEntity;
+import org.apache.eagle.common.config.EagleConfigConstants;
+import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
+import org.apache.eagle.service.client.IEagleServiceClient;
+import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
+import org.apache.commons.lang.time.DateUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+public class AlertExecutorDAOImpl implements AlertExecutorDAO{
+    private final Logger LOG = LoggerFactory.getLogger(AlertDataSourceDAOImpl.class);
+
+    private final String eagleServiceHost;
+    private final Integer eagleServicePort;
+    private String username;
+    private String password;
+
+    public AlertExecutorDAOImpl(String eagleServiceHost, Integer eagleServicePort) {
+        this(eagleServiceHost, eagleServicePort, null, null);
+    }
+
+    public AlertExecutorDAOImpl(String eagleServiceHost, Integer eagleServicePort, String username, String password) {
+        this.eagleServiceHost = eagleServiceHost;
+        this.eagleServicePort = eagleServicePort;
+        this.username = username;
+        this.password = password;
+    }
+
+    public AlertExecutorDAOImpl(Config config) {
+        this.eagleServiceHost = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.HOST);
+        this.eagleServicePort = config.getInt(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PORT);
+        if (config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME) &&
+                config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD)) {
+            this.username = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME);
+            this.password = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD);
+        }
+    }
+
+    @Override
+    public List<AlertExecutorEntity> findAlertExecutorByDataSource(String dataSource) throws Exception{
+        try {
+            IEagleServiceClient client = new EagleServiceClientImpl(eagleServiceHost, eagleServicePort, username, password);
+            String query = AlertConstants.ALERT_EXECUTOR_SERVICE_ENDPOINT_NAME + "[@dataSource=\"" + dataSource + "\"]{*}";
+            GenericServiceAPIResponseEntity<AlertExecutorEntity> response =  client.search()
+                    .startTime(0)
+                    .endTime(10 * DateUtils.MILLIS_PER_DAY)
+                    .pageSize(Integer.MAX_VALUE)
+                    .query(query)
+                    .send();
+            client.close();
+            if (response.getException() != null) {
+                throw new Exception("Got an exception when query eagle service: " + response.getException());
+            }
+            return response.getObj();
+        }
+        catch (Exception ex) {
+            LOG.error("Got an exception when query stream metadata service ", ex);
+            throw new IllegalStateException(ex);
+        }
+    }
+
+    @Override
+    public List<AlertExecutorEntity> findAlertExecutor(String dataSource, String alertExecutorId) throws Exception{
+        try {
+            IEagleServiceClient client = new EagleServiceClientImpl(eagleServiceHost, eagleServicePort, username, password);
+            String query = AlertConstants.ALERT_EXECUTOR_SERVICE_ENDPOINT_NAME + "[@dataSource=\"" + dataSource + "\""
+                    + " AND @alertExecutorId=\"" + alertExecutorId + "\""
+                    + "]{*}";
+            GenericServiceAPIResponseEntity<AlertExecutorEntity> response =  client.search()
+                    .startTime(0)
+                    .endTime(10 * DateUtils.MILLIS_PER_DAY)
+                    .pageSize(Integer.MAX_VALUE)
+                    .query(query)
+                    .send();
+            client.close();
+            if (response.getException() != null) {
+                throw new Exception("Got an exception when query eagle service: " + response.getException());
+            }
+            return response.getObj();
+        }
+        catch (Exception ex) {
+            LOG.error("Got an exception when query stream metadata service ", ex);
+            throw new IllegalStateException(ex);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamDAO.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamDAO.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamDAO.java
new file mode 100644
index 0000000..17bdef0
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamDAO.java
@@ -0,0 +1,25 @@
+/*
+ * 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.dao;
+
+import org.apache.eagle.alert.entity.AlertStreamEntity;
+
+import java.util.List;
+
+public interface AlertStreamDAO {
+    List<AlertStreamEntity> findAlertStreamByDataSource(String dataSource) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamDAOImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamDAOImpl.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamDAOImpl.java
new file mode 100644
index 0000000..8842481
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamDAOImpl.java
@@ -0,0 +1,82 @@
+/*
+ * 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.dao;
+
+import com.typesafe.config.Config;
+import org.apache.eagle.alert.common.AlertConstants;
+import org.apache.eagle.alert.entity.AlertStreamEntity;
+import org.apache.eagle.common.config.EagleConfigConstants;
+import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
+import org.apache.eagle.service.client.IEagleServiceClient;
+import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
+import org.apache.commons.lang.time.DateUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+public class AlertStreamDAOImpl implements AlertStreamDAO{
+    private final Logger LOG = LoggerFactory.getLogger(AlertStreamDAOImpl.class);
+
+    private final String eagleServiceHost;
+    private final Integer eagleServicePort;
+    private String username;
+    private String password;
+
+    public AlertStreamDAOImpl(String eagleServiceHost, Integer eagleServicePort) {
+        this(eagleServiceHost, eagleServicePort, null, null);
+    }
+
+    public AlertStreamDAOImpl(String eagleServiceHost, Integer eagleServicePort, String username, String password) {
+        this.eagleServiceHost = eagleServiceHost;
+        this.eagleServicePort = eagleServicePort;
+        this.username = username;
+        this.password = password;
+    }
+
+    public AlertStreamDAOImpl(Config config) {
+        this.eagleServiceHost = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.HOST);
+        this.eagleServicePort = config.getInt(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PORT);
+        if (config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME) &&
+            config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD)) {
+            this.username = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME);
+            this.password = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD);
+        }
+    }
+
+    public List<AlertStreamEntity> findAlertStreamByDataSource(String dataSource) throws Exception{
+        try {
+            IEagleServiceClient client = new EagleServiceClientImpl(eagleServiceHost, eagleServicePort, username, password);
+            String query = AlertConstants.ALERT_STREAM_SERVICE_ENDPOINT_NAME + "[@dataSource=\"" + dataSource + "\"]{*}";
+            GenericServiceAPIResponseEntity<AlertStreamEntity> response =  client.search()
+                    .startTime(0)
+                    .endTime(10 * DateUtils.MILLIS_PER_DAY)
+                    .pageSize(Integer.MAX_VALUE)
+                    .query(query)
+                    .send();
+            client.close();
+            if (response.getException() != null) {
+                throw new Exception("Got an exception when query eagle service: " + response.getException());
+            }
+            return response.getObj();
+        }
+        catch (Exception ex) {
+            LOG.error("Got an exception when query stream metadata service ", ex);
+            throw new IllegalStateException(ex);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamSchemaDAO.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamSchemaDAO.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamSchemaDAO.java
new file mode 100644
index 0000000..0e69d89
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamSchemaDAO.java
@@ -0,0 +1,25 @@
+/*
+ * 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.dao;
+
+import java.util.List;
+
+import org.apache.eagle.alert.entity.AlertStreamSchemaEntity;
+
+public interface AlertStreamSchemaDAO {
+	List<AlertStreamSchemaEntity> findAlertStreamSchemaByDataSource(String dataSource) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamSchemaDAOImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamSchemaDAOImpl.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamSchemaDAOImpl.java
new file mode 100644
index 0000000..4c252b7
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/dao/AlertStreamSchemaDAOImpl.java
@@ -0,0 +1,83 @@
+/*
+ * 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.dao;
+
+import com.typesafe.config.Config;
+import org.apache.eagle.alert.common.AlertConstants;
+import org.apache.eagle.alert.entity.AlertStreamSchemaEntity;
+import org.apache.eagle.common.config.EagleConfigConstants;
+import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
+import org.apache.eagle.service.client.IEagleServiceClient;
+import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
+import org.apache.commons.lang.time.DateUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+public class AlertStreamSchemaDAOImpl implements AlertStreamSchemaDAO {
+	private final Logger LOG = LoggerFactory.getLogger(AlertStreamSchemaDAOImpl.class);
+	
+	private final String eagleServiceHost;
+	private final Integer eagleServicePort;
+	private String username;
+	private String password;
+
+	public AlertStreamSchemaDAOImpl(String eagleServiceHost, Integer eagleServicePort) {
+		this(eagleServiceHost, eagleServicePort, null, null);
+	}
+
+	public AlertStreamSchemaDAOImpl(String eagleServiceHost, Integer eagleServicePort, String username, String password) {
+		this.eagleServiceHost = eagleServiceHost;
+		this.eagleServicePort = eagleServicePort;
+		this.username = username;
+		this.password = password;
+	}
+
+	public AlertStreamSchemaDAOImpl(Config config) {
+		this.eagleServiceHost = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.HOST);
+		this.eagleServicePort = config.getInt(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PORT);
+		if (config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME) &&
+			config.hasPath(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD)) {
+			this.username = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.USERNAME);
+			this.password = config.getString(EagleConfigConstants.EAGLE_PROPS + "." + EagleConfigConstants.EAGLE_SERVICE + "." + EagleConfigConstants.PASSWORD);
+		}
+	}
+	
+	@Override
+	public List<AlertStreamSchemaEntity> findAlertStreamSchemaByDataSource(String dataSource) throws Exception {
+		try {
+			IEagleServiceClient client = new EagleServiceClientImpl(eagleServiceHost, eagleServicePort, username, password);
+			String query = AlertConstants.ALERT_STREAM_SCHEMA_SERVICE_ENDPOINT_NAME + "[@dataSource=\"" + dataSource + "\"]{*}";
+			GenericServiceAPIResponseEntity<AlertStreamSchemaEntity> response =  client.search()
+																		                .startTime(0)
+																		                .endTime(10 * DateUtils.MILLIS_PER_DAY)
+																		                .pageSize(Integer.MAX_VALUE)
+																		                .query(query)
+																	                    .send();
+			client.close();
+			if (response.getException() != null) {
+				throw new Exception("Got an exception when query eagle service: " + response.getException()); 
+			}			
+			return response.getObj();
+		}
+		catch (Exception ex) {
+			LOG.error("Got an exception when query stream metadata service ", ex);
+			throw new IllegalStateException(ex);
+		}					   
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailComponent.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailComponent.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailComponent.java
new file mode 100644
index 0000000..c4537b7
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailComponent.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.alert.email;
+
+import org.apache.eagle.common.metric.AlertContext;
+
+/**
+ * Alert email component is one part of an email, which could be an individual alert
+ */
+public class AlertEmailComponent {
+	private AlertContext alertContext;
+	public AlertContext getAlertContext() {
+		return alertContext;
+	}
+	public void setAlertContext(AlertContext alertContext) {
+		this.alertContext = alertContext;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailContext.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailContext.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailContext.java
new file mode 100644
index 0000000..5d0609b
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/email/AlertEmailContext.java
@@ -0,0 +1,69 @@
+/*
+ * 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.email;
+
+import java.util.List;
+
+/**
+ * alert email bean
+ * one email consists of a list of email component
+ */
+public class AlertEmailContext {
+	private List<AlertEmailComponent> components;
+	private String sender;
+	private String subject;
+	private String recipients;
+	private String velocityTplFile;
+	private String cc;
+	
+	public List<AlertEmailComponent> getComponents() {
+		return components;
+	}
+	public void setComponents(List<AlertEmailComponent> components) {
+		this.components = components;
+	}
+	public String getVelocityTplFile() {
+		return velocityTplFile;
+	}
+	public void setVelocityTplFile(String velocityTplFile) {
+		this.velocityTplFile = velocityTplFile;
+	}
+	public String getRecipients() {
+		return recipients;
+	}
+	public void setRecipients(String recipients) {
+		this.recipients = recipients;
+	}
+	public String getSender() {
+		return sender;
+	}
+	public void setSender(String sender) {
+		this.sender = sender;
+	}
+	public String getSubject() {
+		return subject;
+	}
+	public void setSubject(String subject) {
+		this.subject = subject;
+	}
+	public String getCc() {
+		return cc;
+	}
+	public void setCc(String cc) {
+		this.cc = cc;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertAPIEntity.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertAPIEntity.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertAPIEntity.java
new file mode 100644
index 0000000..7b51f8d
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertAPIEntity.java
@@ -0,0 +1,84 @@
+/*
+ * 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.entity;
+
+import org.apache.eagle.alert.common.AlertConstants;
+import org.apache.eagle.common.metric.AlertContext;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
+import org.apache.eagle.log.entity.meta.Column;
+import org.apache.eagle.log.entity.meta.ColumnFamily;
+import org.apache.eagle.log.entity.meta.Prefix;
+import org.apache.eagle.log.entity.meta.Service;
+import org.apache.eagle.log.entity.meta.Table;
+import org.apache.eagle.log.entity.meta.TimeSeries;
+
+@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@Table("alertdetail")
+@ColumnFamily("f")
+@Prefix("hadoop")
+@Service(AlertConstants.ALERT_SERVICE_ENDPOINT_NAME)
+@TimeSeries(true)
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class AlertAPIEntity extends TaggedLogAPIEntity{
+	@Column("description")
+	private String description;
+	@Column("remediationID")
+	private String remediationID;
+	@Column("remediationCallback")
+	private String remediationCallback;
+	@Column("alertContext")
+	private AlertContext alertContext;
+
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+		_pcs.firePropertyChange("description", null, null);
+	}
+
+	public String getRemediationID() {
+		return remediationID;
+	}
+
+	public void setRemediationID(String remediationID) {
+		this.remediationID = remediationID;
+		_pcs.firePropertyChange("remediationID", null, null);
+	}
+
+	public String getRemediationCallback() {
+		return remediationCallback;
+	}
+
+	public void setRemediationCallback(String remediationCallback) {
+		this.remediationCallback = remediationCallback;
+		_pcs.firePropertyChange("remediationCallback", null, null);
+	}
+
+	public AlertContext getAlertContext() {
+		return alertContext;
+	}
+	
+	public void setAlertContext(AlertContext alertContext) {
+		this.alertContext = alertContext;
+		_pcs.firePropertyChange("alertContext", null, null);
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertContextSerDeser.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertContextSerDeser.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertContextSerDeser.java
new file mode 100644
index 0000000..f001725
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertContextSerDeser.java
@@ -0,0 +1,98 @@
+/*
+ * 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.entity;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.eagle.common.metric.AlertContext;
+import org.apache.hadoop.hbase.util.Bytes;
+
+import org.apache.eagle.log.entity.meta.EntitySerDeser;
+
+public class AlertContextSerDeser implements EntitySerDeser<AlertContext> {
+
+	@Override
+	public AlertContext deserialize(byte[] bytes) {
+		AlertContext context = new AlertContext();
+		Map<String, String> properties = new HashMap<String, String>();
+		final int length = bytes.length;
+		if (length < 4) { return context; }
+		int size = Bytes.toInt(bytes, 0, 4);
+		
+		int offset = 4;
+		for (int i = 0; i < size; i++) {
+			int keySize =  Bytes.toInt(bytes, offset, 4);
+			offset += 4;
+			int valueSize =  Bytes.toInt(bytes, offset, 4);
+			offset += 4;
+			String key = Bytes.toString(bytes, offset, keySize);
+			offset += keySize;
+			String value =Bytes.toString(bytes, offset, valueSize);
+			offset += valueSize;
+			properties.put(key, value);
+		}
+		context.addAll(properties);
+		return context;
+	}
+
+	@Override
+	public byte[] serialize(AlertContext context) {
+		
+		final Map<String, String> pair = context.getProperties();
+		int totalSize = 4;
+		for (Entry<String, String> entry : pair.entrySet()) {
+			String key = entry.getKey();
+			String value = entry.getValue();
+            int keySize = 0;
+            if(key!=null) keySize = key.getBytes().length;
+			int valueSize = 0;
+            if(value!=null) valueSize = value.getBytes().length;
+			totalSize += keySize + valueSize + 8;
+		}
+		byte[] buffer = new byte[totalSize];
+		
+		Bytes.putInt(buffer, 0, pair.size());
+		int offset = 4;
+		for (Entry<String, String> entry : pair.entrySet()) {
+			String key = entry.getKey();
+			String value = entry.getValue();
+
+			int keySize = key !=null ? key.getBytes().length : 0;
+            int valueSize = value != null ? value.getBytes().length:0;
+
+            Bytes.putInt(buffer, offset, keySize);
+			offset += 4;
+			Bytes.putInt(buffer, offset, valueSize);
+			offset += 4;
+
+
+            Bytes.putBytes(buffer, offset, key != null ? key.getBytes() : new byte[0], 0, keySize);
+			offset += keySize;
+			Bytes.putBytes(buffer, offset, value != null ? value.getBytes() : new byte[0], 0, valueSize);
+			offset += valueSize;
+		}
+		return buffer;
+	}
+
+
+	@Override
+	public Class<AlertContext> type(){
+		return AlertContext.class;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertDataSourceEntity.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertDataSourceEntity.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertDataSourceEntity.java
new file mode 100644
index 0000000..ec7d432
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertDataSourceEntity.java
@@ -0,0 +1,67 @@
+/*
+ * 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.entity;
+
+import org.apache.eagle.alert.common.AlertConstants;
+import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
+import org.apache.eagle.log.entity.meta.*;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@Table("alertDataSource")
+@ColumnFamily("f")
+@Prefix("alertDataSource")
+@Service(AlertConstants.ALERT_DATA_SOURCE_SERVICE_ENDPOINT_NAME)
+@JsonIgnoreProperties(ignoreUnknown = true)
+@TimeSeries(false)
+@Tags({"site", "dataSource"})
+public class AlertDataSourceEntity extends TaggedLogAPIEntity{
+    @Column("a")
+    private boolean enabled;
+    @Column("b")
+    private String config;
+    @Column("c")
+    private String desc;
+
+    public String getConfig() {
+        return config;
+    }
+
+    public void setConfig(String config) {
+        this.config = config;
+        valueChanged("config");
+    }
+
+    public boolean isEnabled() {
+        return enabled;
+    }
+
+    public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+        valueChanged("enabled");
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+
+    public void setDesc(String desc) {
+        this.desc = desc;
+        valueChanged("desc");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertDefinitionAPIEntity.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertDefinitionAPIEntity.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertDefinitionAPIEntity.java
new file mode 100644
index 0000000..61a5ae2
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertDefinitionAPIEntity.java
@@ -0,0 +1,181 @@
+/*
+ * 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.entity;
+
+import org.apache.eagle.alert.common.AlertConstants;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
+import org.apache.eagle.log.entity.meta.Column;
+import org.apache.eagle.log.entity.meta.ColumnFamily;
+import org.apache.eagle.log.entity.meta.Index;
+import org.apache.eagle.log.entity.meta.Indexes;
+import org.apache.eagle.log.entity.meta.Prefix;
+import org.apache.eagle.log.entity.meta.Service;
+import org.apache.eagle.log.entity.meta.Table;
+import org.apache.eagle.log.entity.meta.Tags;
+import org.apache.eagle.log.entity.meta.TimeSeries;
+
+/**
+ * site: site name
+ * dataSource: data source name
+ *
+ * alertExecutorId: Group Policy by alertExecutorId, the policy definition with the sample ["site", "dataSource", "alertExecutorId"] should run on the sample alert executor
+ *
+ * policyId: policy name, should be unique
+ * policyType: policy engine implementation type
+ */
+@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@Table("alertdef")
+@ColumnFamily("f")
+@Prefix("alertdef")
+@Service(AlertConstants.ALERT_DEFINITION_SERVICE_ENDPOINT_NAME)
+@JsonIgnoreProperties(ignoreUnknown = true)
+@TimeSeries(false)
+@Tags({"site", "dataSource", "alertExecutorId", "policyId", "policyType"})
+@Indexes({
+	@Index(name="Index_1_alertExecutorId", columns = { "alertExecutorID" }, unique = true),
+})
+public class AlertDefinitionAPIEntity extends TaggedLogAPIEntity{
+	@Column("a")
+	private String desc;
+	@Column("b")
+	private String policyDef;
+	@Column("c")
+	private String dedupeDef;
+	@Column("d")
+	private String notificationDef;
+	@Column("e")
+	private String remediationDef;
+	@Column("f")
+	private boolean enabled;
+	@Column("g")
+	private String owner;	
+	@Column("h")
+	private long lastModifiedDate;
+	@Column("i")
+	private long severity;
+	@Column("j")
+	private long createdTime;
+
+	public String getDesc() {
+		return desc;
+	}
+	public void setDesc(String desc) {
+		this.desc = desc;
+		valueChanged("desc");
+	}
+	public String getPolicyDef() {
+		return policyDef;
+	}
+	public void setPolicyDef(String policyDef) {
+		this.policyDef = policyDef;
+		valueChanged("policyDef");
+	}
+	public String getDedupeDef() {
+		return dedupeDef;
+	}
+	public void setDedupeDef(String dedupeDef) {
+		this.dedupeDef = dedupeDef;
+		valueChanged("dedupeDef");
+	}
+	public String getNotificationDef() {
+		return notificationDef;
+	}
+	public void setNotificationDef(String notificationDef) {
+		this.notificationDef = notificationDef;
+		valueChanged("notificationDef");
+	}
+	public String getRemediationDef() {
+		return remediationDef;
+	}
+	public void setRemediationDef(String remediationDef) {
+		this.remediationDef = remediationDef;
+		valueChanged("remediationDef");
+	}
+	public boolean isEnabled() {
+		return enabled;
+	}
+	public void setEnabled(boolean enabled) {
+		this.enabled = enabled;
+		valueChanged("enabled");
+	}
+	public String getOwner() {
+		return owner;
+	}
+	public void setOwner(String owner) {
+		this.owner = owner;
+		valueChanged("owner");
+	}	
+	public long getLastModifiedDate() {
+		return lastModifiedDate;
+	}
+	public void setLastModifiedDate(long lastModifiedDate) {
+		this.lastModifiedDate = lastModifiedDate;
+		valueChanged("lastModifiedDate");
+	}	
+	public long getSeverity() {
+		return severity;
+	}
+	public void setSeverity(long severity) {
+		this.severity = severity;
+		valueChanged("severity");
+	}	
+	public long getCreatedTime() {
+		return createdTime;
+	}
+	public void setCreatedTime(long createdTime) {
+		this.createdTime = createdTime;
+		valueChanged("createdTime");
+	}
+	public boolean equals(Object o){
+		if(o == this)
+			return true;
+		if(!(o instanceof AlertDefinitionAPIEntity))
+			return false;
+		AlertDefinitionAPIEntity that = (AlertDefinitionAPIEntity)o;
+		if(that.enabled == this.enabled &&
+				compare(that.policyDef, this.policyDef) &&
+				compare(that.dedupeDef, this.dedupeDef) &&
+				compare(that.notificationDef, this.notificationDef) &&
+				compare(that.remediationDef, this.remediationDef))
+			return true;
+		return false;
+	}
+	
+	private boolean compare(String a, String b){
+		if(a == b)
+			return true;
+		if(a == null || b == null)
+			return false;
+		if(a.equals(b))
+			return true;
+		return false;
+	}
+	
+	public int hashCode(){
+		HashCodeBuilder builder = new HashCodeBuilder();
+		builder.append(enabled);
+		builder.append(policyDef);
+		builder.append(dedupeDef);
+		builder.append(notificationDef);
+		builder.append(remediationDef);
+		return builder.toHashCode();
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertEntityRepository.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertEntityRepository.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertEntityRepository.java
new file mode 100644
index 0000000..ad518e9
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertEntityRepository.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.alert.entity;
+
+import org.apache.eagle.common.metric.AlertContext;
+import org.apache.eagle.log.entity.repo.EntityRepository;
+
+public class AlertEntityRepository extends EntityRepository {
+	public AlertEntityRepository() {
+		serDeserMap.put(AlertContext.class, new AlertContextSerDeser());
+		entitySet.add(AlertAPIEntity.class);
+		entitySet.add(AlertDefinitionAPIEntity.class);
+		entitySet.add(AlertStreamSchemaEntity.class);
+		entitySet.add(AlertStreamEntity.class);
+		entitySet.add(AlertDataSourceEntity.class);
+        entitySet.add(AlertExecutorEntity.class);
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertExecutorEntity.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertExecutorEntity.java b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertExecutorEntity.java
new file mode 100644
index 0000000..60d51c7
--- /dev/null
+++ b/eagle-core/eagle-alert/eagle-alert-base/src/main/java/org/apache/eagle/alert/entity/AlertExecutorEntity.java
@@ -0,0 +1,45 @@
+/*
+ * 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.entity;
+
+import org.apache.eagle.alert.common.AlertConstants;
+import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
+import org.apache.eagle.log.entity.meta.*;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
+@Table("alertExecutor")
+@ColumnFamily("f")
+@Prefix("alertExecutor")
+@Service(AlertConstants.ALERT_EXECUTOR_SERVICE_ENDPOINT_NAME)
+@JsonIgnoreProperties(ignoreUnknown = true)
+@TimeSeries(false)
+@Tags({"dataSource", "alertExecutorId", "streamName"})
+public class AlertExecutorEntity extends TaggedLogAPIEntity{
+    @Column("a")
+    private String desc;
+
+    public String getDesc() {
+        return desc;
+    }
+
+    public void setDesc(String desc) {
+        this.desc = desc;
+        valueChanged("desc");
+    }
+}



Mime
View raw message