[jira] [Commented] (EAGLE-811) Refactor jdbcMetadataDaoImpl of alert engine metadata

2016-12-02 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/EAGLE-811?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15714744#comment-15714744
 ] 

ASF GitHub Bot commented on EAGLE-811:
--

Github user asfgit closed the pull request at:

https://github.com/apache/incubator-eagle/pull/705


> Refactor jdbcMetadataDaoImpl of alert engine metadata
> -
>
> Key: EAGLE-811
> URL: https://issues.apache.org/jira/browse/EAGLE-811
> Project: Eagle
>  Issue Type: Improvement
>Affects Versions: v0.5.0
>Reporter: Zhao, Qingwen
>Assignee: Zhao, Qingwen
> Fix For: v0.5.0
>
>
> 1. add DDL into creatTables.sql
> 2. rewrite jdbcMetadataImpl of alert engine metadata



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (EAGLE-811) Refactor jdbcMetadataDaoImpl of alert engine metadata

2016-12-01 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/EAGLE-811?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15714034#comment-15714034
 ] 

ASF GitHub Bot commented on EAGLE-811:
--

Github user wujinhu commented on a diff in the pull request:

https://github.com/apache/incubator-eagle/pull/705#discussion_r90587141
  
--- Diff: 
eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcMetadataHandler.java
 ---
@@ -0,0 +1,533 @@
+/*
+ * 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.metadata.impl;
+
+import org.apache.commons.collections.map.HashedMap;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.eagle.alert.coordination.model.Kafka2TupleMetadata;
+import org.apache.eagle.alert.coordination.model.ScheduleState;
+import org.apache.eagle.alert.coordination.model.internal.PolicyAssignment;
+import org.apache.eagle.alert.coordination.model.internal.Topology;
+import org.apache.eagle.alert.engine.coordinator.*;
+import org.apache.eagle.alert.engine.model.AlertPublishEvent;
+import org.apache.eagle.alert.metadata.MetadataUtils;
+import org.apache.eagle.alert.metadata.resource.OpResult;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.typesafe.config.Config;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.sql.DataSource;
+import java.io.IOException;
+import java.sql.*;
+import java.util.*;
+import java.util.function.Function;
+
+public class JdbcMetadataHandler {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(JdbcMetadataHandler.class);
+// general model
+private static final String INSERT_STATEMENT = "INSERT INTO 
%s(content, id) VALUES (?, ?)";
+private static final String DELETE_STATEMENT = "DELETE FROM %s WHERE 
id=?";
+private static final String UPDATE_STATEMENT = "UPDATE %s set 
content=? WHERE id=?";
+private static final String QUERY_ALL_STATEMENT = "SELECT content FROM 
%s";
+private static final String QUERY_CONDITION_STATEMENT = "SELECT 
content FROM %s WHERE id=?";
+private static final String QUERY_ORDERBY_STATEMENT = "SELECT content 
FROM %s ORDER BY id %s";
+
+// customized model
+private static final String CLEAR_SCHEDULESTATES_STATEMENT = "DELETE 
FROM schedule_state WHERE id NOT IN (SELECT id from (SELECT id FROM 
schedule_state ORDER BY id DESC limit ?) as states)";
+private static final String INSERT_ALERT_STATEMENT = "INSERT INTO 
alert_event(alertId, siteId, appIds, policyId, alertTimestamp, policyValue, 
alertData) VALUES (?, ?, ?, ?, ?, ?, ?)";
+private static final String QUERY_ALERT_STATEMENT = "SELECT * FROM 
alert_event order by alertTimestamp DESC limit ?";
+private static final String QUERY_ALERT_BY_ID_STATEMENT = "SELECT * 
FROM alert_event WHERE alertId=? order by alertTimestamp DESC limit ?";
+private static final String QUERY_ALERT_BY_POLICY_STATEMENT = "SELECT 
* FROM alert_event WHERE policyId=? order by alertTimestamp DESC limit ?";
+private static final String INSERT_POLICYPUBLISHMENT_STATEMENT = 
"INSERT INTO policy_publishment(policyId, publishmentName) VALUES (?, ?)";
+private static final String DELETE_PUBLISHMENT_STATEMENT = "DELETE 
FROM policy_publishment WHERE policyId=?";
+private static final String QUERY_PUBLISHMENT_BY_POLICY_STATEMENT = 
"SELECT content FROM publishment a INNER JOIN policy_publishment b ON 
a.id=b.publishmentName and b.policyId=?";
+private static final String QUERY_PUBLISHMENT_STATEMENT = "SELECT 
a.content, b.policyId FROM publishment a LEFT JOIN policy_publishment b ON 
a.id=b.publishmentName";
+
+public enum SortType { DESC, ASC }
+
+private static 

[jira] [Commented] (EAGLE-811) Refactor jdbcMetadataDaoImpl of alert engine metadata

2016-12-01 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/EAGLE-811?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15714033#comment-15714033
 ] 

ASF GitHub Bot commented on EAGLE-811:
--

Github user wujinhu commented on a diff in the pull request:

https://github.com/apache/incubator-eagle/pull/705#discussion_r90581922
  
--- Diff: 
eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcMetadataHandler.java
 ---
@@ -0,0 +1,533 @@
+/*
+ * 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.metadata.impl;
+
+import org.apache.commons.collections.map.HashedMap;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.eagle.alert.coordination.model.Kafka2TupleMetadata;
+import org.apache.eagle.alert.coordination.model.ScheduleState;
+import org.apache.eagle.alert.coordination.model.internal.PolicyAssignment;
+import org.apache.eagle.alert.coordination.model.internal.Topology;
+import org.apache.eagle.alert.engine.coordinator.*;
+import org.apache.eagle.alert.engine.model.AlertPublishEvent;
+import org.apache.eagle.alert.metadata.MetadataUtils;
+import org.apache.eagle.alert.metadata.resource.OpResult;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.typesafe.config.Config;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.sql.DataSource;
+import java.io.IOException;
+import java.sql.*;
+import java.util.*;
+import java.util.function.Function;
+
+public class JdbcMetadataHandler {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(JdbcMetadataHandler.class);
+// general model
+private static final String INSERT_STATEMENT = "INSERT INTO 
%s(content, id) VALUES (?, ?)";
+private static final String DELETE_STATEMENT = "DELETE FROM %s WHERE 
id=?";
+private static final String UPDATE_STATEMENT = "UPDATE %s set 
content=? WHERE id=?";
+private static final String QUERY_ALL_STATEMENT = "SELECT content FROM 
%s";
+private static final String QUERY_CONDITION_STATEMENT = "SELECT 
content FROM %s WHERE id=?";
+private static final String QUERY_ORDERBY_STATEMENT = "SELECT content 
FROM %s ORDER BY id %s";
+
+// customized model
+private static final String CLEAR_SCHEDULESTATES_STATEMENT = "DELETE 
FROM schedule_state WHERE id NOT IN (SELECT id from (SELECT id FROM 
schedule_state ORDER BY id DESC limit ?) as states)";
+private static final String INSERT_ALERT_STATEMENT = "INSERT INTO 
alert_event(alertId, siteId, appIds, policyId, alertTimestamp, policyValue, 
alertData) VALUES (?, ?, ?, ?, ?, ?, ?)";
+private static final String QUERY_ALERT_STATEMENT = "SELECT * FROM 
alert_event order by alertTimestamp DESC limit ?";
+private static final String QUERY_ALERT_BY_ID_STATEMENT = "SELECT * 
FROM alert_event WHERE alertId=? order by alertTimestamp DESC limit ?";
+private static final String QUERY_ALERT_BY_POLICY_STATEMENT = "SELECT 
* FROM alert_event WHERE policyId=? order by alertTimestamp DESC limit ?";
+private static final String INSERT_POLICYPUBLISHMENT_STATEMENT = 
"INSERT INTO policy_publishment(policyId, publishmentName) VALUES (?, ?)";
+private static final String DELETE_PUBLISHMENT_STATEMENT = "DELETE 
FROM policy_publishment WHERE policyId=?";
+private static final String QUERY_PUBLISHMENT_BY_POLICY_STATEMENT = 
"SELECT content FROM publishment a INNER JOIN policy_publishment b ON 
a.id=b.publishmentName and b.policyId=?";
+private static final String QUERY_PUBLISHMENT_STATEMENT = "SELECT 
a.content, b.policyId FROM publishment a LEFT JOIN policy_publishment b ON 
a.id=b.publishmentName";
+
+public enum SortType { DESC, ASC }
+
+private static 

[jira] [Commented] (EAGLE-811) Refactor jdbcMetadataDaoImpl of alert engine metadata

2016-12-01 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/EAGLE-811?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15714031#comment-15714031
 ] 

ASF GitHub Bot commented on EAGLE-811:
--

Github user wujinhu commented on a diff in the pull request:

https://github.com/apache/incubator-eagle/pull/705#discussion_r90586834
  
--- Diff: 
eagle-core/eagle-alert-parent/eagle-alert/alert-metadata-parent/alert-metadata/src/main/java/org/apache/eagle/alert/metadata/impl/JdbcMetadataHandler.java
 ---
@@ -0,0 +1,533 @@
+/*
+ * 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.metadata.impl;
+
+import org.apache.commons.collections.map.HashedMap;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.eagle.alert.coordination.model.Kafka2TupleMetadata;
+import org.apache.eagle.alert.coordination.model.ScheduleState;
+import org.apache.eagle.alert.coordination.model.internal.PolicyAssignment;
+import org.apache.eagle.alert.coordination.model.internal.Topology;
+import org.apache.eagle.alert.engine.coordinator.*;
+import org.apache.eagle.alert.engine.model.AlertPublishEvent;
+import org.apache.eagle.alert.metadata.MetadataUtils;
+import org.apache.eagle.alert.metadata.resource.OpResult;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.typesafe.config.Config;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.sql.DataSource;
+import java.io.IOException;
+import java.sql.*;
+import java.util.*;
+import java.util.function.Function;
+
+public class JdbcMetadataHandler {
+
+private static final Logger LOG = 
LoggerFactory.getLogger(JdbcMetadataHandler.class);
+// general model
+private static final String INSERT_STATEMENT = "INSERT INTO 
%s(content, id) VALUES (?, ?)";
+private static final String DELETE_STATEMENT = "DELETE FROM %s WHERE 
id=?";
+private static final String UPDATE_STATEMENT = "UPDATE %s set 
content=? WHERE id=?";
+private static final String QUERY_ALL_STATEMENT = "SELECT content FROM 
%s";
+private static final String QUERY_CONDITION_STATEMENT = "SELECT 
content FROM %s WHERE id=?";
+private static final String QUERY_ORDERBY_STATEMENT = "SELECT content 
FROM %s ORDER BY id %s";
+
+// customized model
+private static final String CLEAR_SCHEDULESTATES_STATEMENT = "DELETE 
FROM schedule_state WHERE id NOT IN (SELECT id from (SELECT id FROM 
schedule_state ORDER BY id DESC limit ?) as states)";
+private static final String INSERT_ALERT_STATEMENT = "INSERT INTO 
alert_event(alertId, siteId, appIds, policyId, alertTimestamp, policyValue, 
alertData) VALUES (?, ?, ?, ?, ?, ?, ?)";
+private static final String QUERY_ALERT_STATEMENT = "SELECT * FROM 
alert_event order by alertTimestamp DESC limit ?";
+private static final String QUERY_ALERT_BY_ID_STATEMENT = "SELECT * 
FROM alert_event WHERE alertId=? order by alertTimestamp DESC limit ?";
+private static final String QUERY_ALERT_BY_POLICY_STATEMENT = "SELECT 
* FROM alert_event WHERE policyId=? order by alertTimestamp DESC limit ?";
+private static final String INSERT_POLICYPUBLISHMENT_STATEMENT = 
"INSERT INTO policy_publishment(policyId, publishmentName) VALUES (?, ?)";
+private static final String DELETE_PUBLISHMENT_STATEMENT = "DELETE 
FROM policy_publishment WHERE policyId=?";
+private static final String QUERY_PUBLISHMENT_BY_POLICY_STATEMENT = 
"SELECT content FROM publishment a INNER JOIN policy_publishment b ON 
a.id=b.publishmentName and b.policyId=?";
+private static final String QUERY_PUBLISHMENT_STATEMENT = "SELECT 
a.content, b.policyId FROM publishment a LEFT JOIN policy_publishment b ON 
a.id=b.publishmentName";
+
+public enum SortType { DESC, ASC }
+
+private static