This is an automated email from the ASF dual-hosted git repository. jihao pushed a commit to branch severity-alerter in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
commit 6ef83eaff74c0f2106d01690cdb159d0880a2687 Author: Jihao Zhang <[email protected]> AuthorDate: Fri Aug 21 15:23:17 2020 -0700 add anomaly notification table --- ...nomalySubscriptionGroupNotificationManager.java | 28 ++++++++ ...lySubscriptionGroupNotificationManagerImpl.java | 34 +++++++++ .../thirdeye/datalayer/dao/GenericPojoDao.java | 4 ++ .../AnomalySubscriptionGroupNotificationDTO.java | 27 +++++++ .../AnomalySubscriptionGroupNotificationIndex.java | 42 +++++++++++ .../AnomalySubscriptionGroupNotificationBean.java | 82 ++++++++++++++++++++++ .../thirdeye/datalayer/util/DaoProviderUtil.java | 3 + .../pinot/thirdeye/datasource/DAORegistry.java | 5 ++ .../thirdeye/detection/DetectionResource.java | 13 ++++ .../src/main/resources/schema/create-schema.sql | 12 ++++ 10 files changed, 250 insertions(+) diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/bao/AnomalySubscriptionGroupNotificationManager.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/bao/AnomalySubscriptionGroupNotificationManager.java new file mode 100644 index 0000000..28afb75 --- /dev/null +++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/bao/AnomalySubscriptionGroupNotificationManager.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * 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.pinot.thirdeye.datalayer.bao; + +import org.apache.pinot.thirdeye.datalayer.dto.AnomalySubscriptionGroupNotificationDTO; + + +public interface AnomalySubscriptionGroupNotificationManager + extends AbstractManager<AnomalySubscriptionGroupNotificationDTO> { +} diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/bao/jdbc/AnomalySubscriptionGroupNotificationManagerImpl.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/bao/jdbc/AnomalySubscriptionGroupNotificationManagerImpl.java new file mode 100644 index 0000000..2aa434c --- /dev/null +++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/bao/jdbc/AnomalySubscriptionGroupNotificationManagerImpl.java @@ -0,0 +1,34 @@ +/* + * 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.pinot.thirdeye.datalayer.bao.jdbc; + +import org.apache.pinot.thirdeye.datalayer.bao.AnomalySubscriptionGroupNotificationManager; +import org.apache.pinot.thirdeye.datalayer.dto.AnomalySubscriptionGroupNotificationDTO; +import org.apache.pinot.thirdeye.datalayer.pojo.AnomalySubscriptionGroupNotificationBean; + + +public class AnomalySubscriptionGroupNotificationManagerImpl + extends AbstractManagerImpl<AnomalySubscriptionGroupNotificationDTO> + implements AnomalySubscriptionGroupNotificationManager { + public AnomalySubscriptionGroupNotificationManagerImpl() { + super(AnomalySubscriptionGroupNotificationDTO.class, AnomalySubscriptionGroupNotificationBean.class); + } +} diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/dao/GenericPojoDao.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/dao/GenericPojoDao.java index 2aedbdd..fe80559 100644 --- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/dao/GenericPojoDao.java +++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/dao/GenericPojoDao.java @@ -33,6 +33,7 @@ import org.apache.pinot.thirdeye.datalayer.entity.AlertConfigIndex; import org.apache.pinot.thirdeye.datalayer.entity.AlertSnapshotIndex; import org.apache.pinot.thirdeye.datalayer.entity.AnomalyFeedbackIndex; import org.apache.pinot.thirdeye.datalayer.entity.AnomalyFunctionIndex; +import org.apache.pinot.thirdeye.datalayer.entity.AnomalySubscriptionGroupNotificationIndex; import org.apache.pinot.thirdeye.datalayer.entity.ApplicationIndex; import org.apache.pinot.thirdeye.datalayer.entity.ClassificationConfigIndex; import org.apache.pinot.thirdeye.datalayer.entity.ConfigIndex; @@ -61,6 +62,7 @@ import org.apache.pinot.thirdeye.datalayer.pojo.AlertConfigBean; import org.apache.pinot.thirdeye.datalayer.pojo.AlertSnapshotBean; import org.apache.pinot.thirdeye.datalayer.pojo.AnomalyFeedbackBean; import org.apache.pinot.thirdeye.datalayer.pojo.AnomalyFunctionBean; +import org.apache.pinot.thirdeye.datalayer.pojo.AnomalySubscriptionGroupNotificationBean; import org.apache.pinot.thirdeye.datalayer.pojo.ApplicationBean; import org.apache.pinot.thirdeye.datalayer.pojo.ClassificationConfigBean; import org.apache.pinot.thirdeye.datalayer.pojo.ConfigBean; @@ -167,6 +169,8 @@ public class GenericPojoDao { newPojoInfo(DEFAULT_BASE_TABLE_NAME, EvaluationIndex.class)); pojoInfoMap.put(RootcauseTemplateBean.class, newPojoInfo(DEFAULT_BASE_TABLE_NAME, RootcauseTemplateIndex.class)); + pojoInfoMap.put(AnomalySubscriptionGroupNotificationBean.class, + newPojoInfo(DEFAULT_BASE_TABLE_NAME, AnomalySubscriptionGroupNotificationIndex.class)); } private static PojoInfo newPojoInfo(String baseTableName, diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/dto/AnomalySubscriptionGroupNotificationDTO.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/dto/AnomalySubscriptionGroupNotificationDTO.java new file mode 100644 index 0000000..f1834a3 --- /dev/null +++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/dto/AnomalySubscriptionGroupNotificationDTO.java @@ -0,0 +1,27 @@ +/* + * 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.pinot.thirdeye.datalayer.dto; + +import org.apache.pinot.thirdeye.datalayer.pojo.AnomalySubscriptionGroupNotificationBean; + + +public class AnomalySubscriptionGroupNotificationDTO extends AnomalySubscriptionGroupNotificationBean { +} diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/entity/AnomalySubscriptionGroupNotificationIndex.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/entity/AnomalySubscriptionGroupNotificationIndex.java new file mode 100644 index 0000000..8bd68b1 --- /dev/null +++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/entity/AnomalySubscriptionGroupNotificationIndex.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.pinot.thirdeye.datalayer.entity; + +public class AnomalySubscriptionGroupNotificationIndex extends AbstractIndexEntity { + long anomalyId; + long detectionConfigId; + + public long getAnomalyId() { + return anomalyId; + } + + public void setAnomalyId(long anomalyId) { + this.anomalyId = anomalyId; + } + + public long getDetectionConfigId() { + return detectionConfigId; + } + + public void setDetectionConfigId(long detectionConfigId) { + this.detectionConfigId = detectionConfigId; + } +} diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/pojo/AnomalySubscriptionGroupNotificationBean.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/pojo/AnomalySubscriptionGroupNotificationBean.java new file mode 100644 index 0000000..4d7413e --- /dev/null +++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/pojo/AnomalySubscriptionGroupNotificationBean.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.pinot.thirdeye.datalayer.pojo; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + + +@JsonIgnoreProperties(ignoreUnknown=true) +public class AnomalySubscriptionGroupNotificationBean extends AbstractBean { + private Long anomalyId; + private Long detectionConfigId; + private List<Long> notifiedSubscriptionGroupIds = new ArrayList<>(); + + public Long getAnomalyId() { + return anomalyId; + } + + public void setAnomalyId(Long anomalyId) { + this.anomalyId = anomalyId; + } + + public Long getDetectionConfigId() { + return detectionConfigId; + } + + public void setDetectionConfigId(Long detectionConfigId) { + this.detectionConfigId = detectionConfigId; + } + + public List<Long> getNotifiedSubscriptionGroupIds() { + return notifiedSubscriptionGroupIds; + } + + public void setNotifiedSubscriptionGroupIds(List<Long> notifiedSubscriptionGroupIds) { + this.notifiedSubscriptionGroupIds = notifiedSubscriptionGroupIds; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AnomalySubscriptionGroupNotificationBean that = (AnomalySubscriptionGroupNotificationBean) o; + return Objects.equals(anomalyId, that.anomalyId) && Objects.equals(detectionConfigId, that.detectionConfigId) + && Objects.equals(notifiedSubscriptionGroupIds, that.notifiedSubscriptionGroupIds); + } + + @Override + public int hashCode() { + return Objects.hash(anomalyId, detectionConfigId, notifiedSubscriptionGroupIds); + } + + @Override + public String toString() { + return "AnomalySubscriptionGroupNotificationBean{" + "anomalyId=" + anomalyId + ", detectionConfigId=" + + detectionConfigId + ", notifiedSubscriptionGroupIds=" + notifiedSubscriptionGroupIds + '}'; + } +} diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/util/DaoProviderUtil.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/util/DaoProviderUtil.java index ebe4e03..7f6e5c5 100644 --- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/util/DaoProviderUtil.java +++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datalayer/util/DaoProviderUtil.java @@ -30,6 +30,7 @@ import org.apache.pinot.thirdeye.datalayer.entity.AlertConfigIndex; import org.apache.pinot.thirdeye.datalayer.entity.AlertSnapshotIndex; import org.apache.pinot.thirdeye.datalayer.entity.AnomalyFeedbackIndex; import org.apache.pinot.thirdeye.datalayer.entity.AnomalyFunctionIndex; +import org.apache.pinot.thirdeye.datalayer.entity.AnomalySubscriptionGroupNotificationIndex; import org.apache.pinot.thirdeye.datalayer.entity.ApplicationIndex; import org.apache.pinot.thirdeye.datalayer.entity.ClassificationConfigIndex; import org.apache.pinot.thirdeye.datalayer.entity.ConfigIndex; @@ -206,6 +207,8 @@ public abstract class DaoProviderUtil { convertCamelCaseToUnderscore(EvaluationIndex.class.getSimpleName())); entityMappingHolder.register(conn, RootcauseTemplateIndex.class, convertCamelCaseToUnderscore(RootcauseTemplateIndex.class.getSimpleName())); + entityMappingHolder.register(conn, AnomalySubscriptionGroupNotificationIndex.class, + convertCamelCaseToUnderscore(AnomalySubscriptionGroupNotificationIndex.class.getSimpleName())); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datasource/DAORegistry.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datasource/DAORegistry.java index 3234994..78f79d2 100644 --- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datasource/DAORegistry.java +++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datasource/DAORegistry.java @@ -22,6 +22,7 @@ package org.apache.pinot.thirdeye.datasource; import org.apache.pinot.thirdeye.datalayer.bao.AlertConfigManager; import org.apache.pinot.thirdeye.datalayer.bao.AlertSnapshotManager; import org.apache.pinot.thirdeye.datalayer.bao.AnomalyFunctionManager; +import org.apache.pinot.thirdeye.datalayer.bao.AnomalySubscriptionGroupNotificationManager; import org.apache.pinot.thirdeye.datalayer.bao.ApplicationManager; import org.apache.pinot.thirdeye.datalayer.bao.ClassificationConfigManager; import org.apache.pinot.thirdeye.datalayer.bao.ConfigManager; @@ -47,6 +48,7 @@ import org.apache.pinot.thirdeye.datalayer.bao.TaskManager; import org.apache.pinot.thirdeye.datalayer.bao.jdbc.AlertConfigManagerImpl; import org.apache.pinot.thirdeye.datalayer.bao.jdbc.AlertSnapshotManagerImpl; import org.apache.pinot.thirdeye.datalayer.bao.jdbc.AnomalyFunctionManagerImpl; +import org.apache.pinot.thirdeye.datalayer.bao.jdbc.AnomalySubscriptionGroupNotificationManagerImpl; import org.apache.pinot.thirdeye.datalayer.bao.jdbc.ApplicationManagerImpl; import org.apache.pinot.thirdeye.datalayer.bao.jdbc.ClassificationConfigManagerImpl; import org.apache.pinot.thirdeye.datalayer.bao.jdbc.ConfigManagerImpl; @@ -197,4 +199,7 @@ public class DAORegistry { return DaoProviderUtil.getInstance(EvaluationManagerImpl.class); } + public AnomalySubscriptionGroupNotificationManager getAnomalySubscriptionGroupNotificationManager() { + return DaoProviderUtil.getInstance(AnomalySubscriptionGroupNotificationManagerImpl.class); + } } diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionResource.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionResource.java index 6db047b..c0fdb51 100644 --- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionResource.java +++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/DetectionResource.java @@ -55,6 +55,7 @@ import org.apache.pinot.thirdeye.dashboard.resources.v2.ResourceUtils; import org.apache.pinot.thirdeye.dashboard.resources.v2.rootcause.AnomalyEventFormatter; import org.apache.pinot.thirdeye.dataframe.DataFrame; import org.apache.pinot.thirdeye.dataframe.util.MetricSlice; +import org.apache.pinot.thirdeye.datalayer.bao.AnomalySubscriptionGroupNotificationManager; import org.apache.pinot.thirdeye.datalayer.bao.DatasetConfigManager; import org.apache.pinot.thirdeye.datalayer.bao.DetectionAlertConfigManager; import org.apache.pinot.thirdeye.datalayer.bao.DetectionConfigManager; @@ -64,6 +65,7 @@ import org.apache.pinot.thirdeye.datalayer.bao.MergedAnomalyResultManager; import org.apache.pinot.thirdeye.datalayer.bao.MetricConfigManager; import org.apache.pinot.thirdeye.datalayer.bao.TaskManager; import org.apache.pinot.thirdeye.datalayer.dto.AnomalyFeedbackDTO; +import org.apache.pinot.thirdeye.datalayer.dto.AnomalySubscriptionGroupNotificationDTO; import org.apache.pinot.thirdeye.datalayer.dto.DatasetConfigDTO; import org.apache.pinot.thirdeye.datalayer.dto.DetectionAlertConfigDTO; import org.apache.pinot.thirdeye.datalayer.dto.DetectionConfigDTO; @@ -570,4 +572,15 @@ public class DetectionResource { } return Response.ok(health).build(); } + + @GET + @Path(value = "/alert") + public Response alert() { + AnomalySubscriptionGroupNotificationManager anomalySubscriptionGroupNotificationManager = DAORegistry.getInstance().getAnomalySubscriptionGroupNotificationManager(); + AnomalySubscriptionGroupNotificationDTO anomalySubscriptionGroupNotificationDTO = new AnomalySubscriptionGroupNotificationDTO(); + anomalySubscriptionGroupNotificationDTO.setAnomalyId(1L); + anomalySubscriptionGroupNotificationDTO.setDetectionConfigId(2L); + anomalySubscriptionGroupNotificationManager.save(anomalySubscriptionGroupNotificationDTO); + return Response.ok().build(); + } } diff --git a/thirdeye/thirdeye-pinot/src/main/resources/schema/create-schema.sql b/thirdeye/thirdeye-pinot/src/main/resources/schema/create-schema.sql index 22941c6..70fd555 100644 --- a/thirdeye/thirdeye-pinot/src/main/resources/schema/create-schema.sql +++ b/thirdeye/thirdeye-pinot/src/main/resources/schema/create-schema.sql @@ -437,3 +437,15 @@ create index rootcause_template_id_idx ON rootcause_template_index(base_id); create index rootcause_template_owner_idx ON rootcause_template_index(owner); create index rootcause_template_metric_idx on rootcause_template_index(metric_id); create index rootcause_template_config_application_idx ON rootcause_template_index(`application`); + +create table if not exists anomaly_subscription_group_notification_index ( + base_id bigint(20) not null, + anomaly_id bigint(20) not null, + detection_config_id bigint(20) not null, + create_time timestamp default 0, + update_time timestamp default current_timestamp, + version int(10) +) ENGINE=InnoDB; +ALTER TABLE `anomaly_subscription_group_notification_index` ADD UNIQUE `anomaly_subscription_group_notification_index`(anomaly_id); +create index anomaly_subscription_group_anomaly_idx ON anomaly_subscription_group_notification_index(anomaly_id); +create index anomaly_subscription_group_detection_config_idx ON anomaly_subscription_group_notification_index(anomaly_id) \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
