This is an automated email from the ASF dual-hosted git repository.
gongchao pushed a commit to branch alarm-1-3
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/alarm-1-3 by this push:
new 54577b04a [improve] update labels
54577b04a is described below
commit 54577b04af639eab26d548d658af384beaec6df9
Author: tomsun28 <[email protected]>
AuthorDate: Fri Jan 3 17:14:46 2025 +0800
[improve] update labels
Signed-off-by: tomsun28 <[email protected]>
---
.../apache/hertzbeat/alert/dto/AlertDefineDTO.java | 4 --
.../impl/AlertDefineExcelImExportServiceImpl.java | 21 +-------
.../controller/NoticeConfigControllerTest.java | 5 --
.../AlertDefineExcelImExportServiceTest.java | 10 ----
.../hertzbeat/common/entity/manager/Bulletin.java | 6 ---
.../entity/manager/JsonTagAttributeConverter.java | 43 ----------------
.../manager/JsonTagListAttributeConverter.java | 58 ----------------------
.../hertzbeat/common/entity/manager/TagItem.java | 41 ---------------
.../apache/hertzbeat/common/util/JsonUtilTest.java | 21 ++------
9 files changed, 7 insertions(+), 202 deletions(-)
diff --git
a/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/dto/AlertDefineDTO.java
b/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/dto/AlertDefineDTO.java
index 0cf72feda..290f3781f 100644
---
a/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/dto/AlertDefineDTO.java
+++
b/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/dto/AlertDefineDTO.java
@@ -21,9 +21,7 @@ import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
-import java.util.List;
import lombok.Data;
-import org.apache.hertzbeat.common.entity.manager.TagItem;
/**
* Data transfer object for alert configuration
@@ -48,8 +46,6 @@ public class AlertDefineDTO {
private Byte priority;
@Excel(name = "Times")
private Integer times;
- @Excel(name = "Tags")
- private List<TagItem> tags;
@Excel(name = "Enable")
private Boolean enable;
@Excel(name = "RecoverNotice")
diff --git
a/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineExcelImExportServiceImpl.java
b/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineExcelImExportServiceImpl.java
index 50540042e..4c2ba2e6f 100644
---
a/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineExcelImExportServiceImpl.java
+++
b/hertzbeat-alerter/src/main/java/org/apache/hertzbeat/alert/service/impl/AlertDefineExcelImExportServiceImpl.java
@@ -19,7 +19,6 @@ package org.apache.hertzbeat.alert.service.impl;
import static
org.apache.hertzbeat.common.constants.ExportFileConstants.ExcelFile.FILE_SUFFIX;
import static
org.apache.hertzbeat.common.constants.ExportFileConstants.ExcelFile.TYPE;
-import com.fasterxml.jackson.core.type.TypeReference;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -29,8 +28,6 @@ import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.hertzbeat.alert.dto.AlertDefineDTO;
import org.apache.hertzbeat.alert.dto.ExportAlertDefineDTO;
-import org.apache.hertzbeat.common.entity.manager.TagItem;
-import org.apache.hertzbeat.common.util.JsonUtil;
import org.apache.hertzbeat.common.util.export.ExcelExportUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
@@ -97,15 +94,6 @@ public class AlertDefineExcelImExportServiceImpl extends
AlertDefineAbstractImEx
}
}
- private List<TagItem> extractTagDataFromRow(Cell cell) {
- String jsonStr = getCellValueAsString(cell);
- if (StringUtils.hasText(jsonStr)) {
- return JsonUtil.fromJson(jsonStr, new TypeReference<>() {
- });
- }
- return null;
- }
-
private String getCellValueAsString(Cell cell) {
if (cell == null) {
@@ -161,7 +149,7 @@ public class AlertDefineExcelImExportServiceImpl extends
AlertDefineAbstractImEx
alertDefineDTO.setExpr(getCellValueAsString(row.getCell(4)));
alertDefineDTO.setPriority(getCellValueAsByte(row.getCell(5)));
alertDefineDTO.setTimes(getCellValueAsInteger(row.getCell(6)));
- alertDefineDTO.setTags(extractTagDataFromRow(row.getCell(7)));
+ // todo labels
alertDefineDTO.setEnable(getCellValueAsBoolean(row.getCell(8)));
alertDefineDTO.setRecoverNotice(getCellValueAsBoolean(row.getCell(9)));
alertDefineDTO.setTemplate(getCellValueAsString(row.getCell(10)));
@@ -211,12 +199,7 @@ public class AlertDefineExcelImExportServiceImpl extends
AlertDefineAbstractImEx
priorityCell.setCellStyle(cellStyle);
Cell timesCell = row.createCell(6);
timesCell.setCellValue(alertDefineDTO.getTimes());
- Cell tagCell = row.createCell(7);
- // get tags
- List<TagItem> tagList = alertDefineDTO.getTags();
- String tagValue = tagList == null || tagList.isEmpty() ? "" :
JsonUtil.toJson(tagList);
- tagCell.setCellValue(tagValue);
- tagCell.setCellStyle(cellStyle);
+ // todo labels
Cell enableCell = row.createCell(8);
enableCell.setCellValue(alertDefineDTO.getEnable() != null
&& alertDefineDTO.getEnable());
diff --git
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/controller/NoticeConfigControllerTest.java
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/controller/NoticeConfigControllerTest.java
index 59001a5fb..5ced52af7 100644
---
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/controller/NoticeConfigControllerTest.java
+++
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/controller/NoticeConfigControllerTest.java
@@ -36,7 +36,6 @@ import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.alerter.NoticeReceiver;
import org.apache.hertzbeat.common.entity.alerter.NoticeRule;
import org.apache.hertzbeat.common.entity.alerter.NoticeTemplate;
-import org.apache.hertzbeat.common.entity.manager.TagItem;
import org.apache.hertzbeat.common.util.JsonUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -66,10 +65,6 @@ class NoticeConfigControllerTest {
public NoticeRule getNoticeRule() {
- TagItem tagItem = new TagItem();
- tagItem.setName("key1");
- tagItem.setValue("value1");
-
NoticeRule noticeRule = new NoticeRule();
noticeRule.setId(87584674384L);
noticeRule.setName("dispatch-1");
diff --git
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/AlertDefineExcelImExportServiceTest.java
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/AlertDefineExcelImExportServiceTest.java
index dd46b3e22..e775baea7 100644
---
a/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/AlertDefineExcelImExportServiceTest.java
+++
b/hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/service/AlertDefineExcelImExportServiceTest.java
@@ -27,7 +27,6 @@ import java.util.List;
import org.apache.hertzbeat.alert.dto.AlertDefineDTO;
import org.apache.hertzbeat.alert.dto.ExportAlertDefineDTO;
import
org.apache.hertzbeat.alert.service.impl.AlertDefineExcelImExportServiceImpl;
-import org.apache.hertzbeat.common.entity.manager.TagItem;
import org.apache.hertzbeat.common.util.export.ExcelExportUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
@@ -91,9 +90,6 @@ public class AlertDefineExcelImExportServiceTest {
assertTrue(alertDefineDTO.getPreset());
assertEquals("expr1", alertDefineDTO.getExpr());
assertEquals(10, alertDefineDTO.getTimes());
- assertEquals(1, alertDefineDTO.getTags().size());
- assertEquals("tag1", alertDefineDTO.getTags().get(0).getName());
- assertEquals("value1", alertDefineDTO.getTags().get(0).getValue());
assertTrue(alertDefineDTO.getEnable());
assertTrue(alertDefineDTO.getRecoverNotice());
assertEquals("template1", alertDefineDTO.getTemplate());
@@ -113,12 +109,6 @@ public class AlertDefineExcelImExportServiceTest {
alertDefineDTO.setExpr("expr1");
alertDefineDTO.setPriority((byte) 1);
alertDefineDTO.setTimes(10);
- List<TagItem> tags = new ArrayList<>();
- TagItem tagItem = new TagItem();
- tagItem.setName("tag1");
- tagItem.setValue("value1");
- tags.add(tagItem);
- alertDefineDTO.setTags(tags);
alertDefineDTO.setEnable(true);
alertDefineDTO.setRecoverNotice(true);
alertDefineDTO.setTemplate("template1");
diff --git
a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/Bulletin.java
b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/Bulletin.java
index b0d724dd8..b98082296 100644
---
a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/Bulletin.java
+++
b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/Bulletin.java
@@ -74,12 +74,6 @@ public class Bulletin {
@Convert(converter = JsonMapListAttributeConverter.class)
private Map<String, List<String>> fields;
- @Schema(description = "Tags(status:success,env:prod)", example = "{name:
key1, value: value1}",
- accessMode = READ_WRITE)
- @Convert(converter = JsonTagListAttributeConverter.class)
- @Column(length = 2048)
- private List<TagItem> tags;
-
@Schema(title = "The creator of this record", example = "tom", accessMode
= READ_WRITE)
@CreatedBy
private String creator;
diff --git
a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/JsonTagAttributeConverter.java
b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/JsonTagAttributeConverter.java
deleted file mode 100644
index b3e21460a..000000000
---
a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/JsonTagAttributeConverter.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hertzbeat.common.entity.manager;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-import jakarta.persistence.AttributeConverter;
-import jakarta.persistence.Converter;
-import org.apache.hertzbeat.common.util.JsonUtil;
-import org.springframework.stereotype.Component;
-
-/**
- * json str to tag item
- */
-@Converter
-@Component
-public class JsonTagAttributeConverter implements AttributeConverter<TagItem,
String> {
-
- @Override
- public String convertToDatabaseColumn(TagItem attribute) {
- return JsonUtil.toJson(attribute);
- }
-
- @Override
- public TagItem convertToEntityAttribute(String dbData) {
- TypeReference<TagItem> typeReference = new TypeReference<>() {};
- return JsonUtil.fromJson(dbData, typeReference);
- }
-}
diff --git
a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/JsonTagListAttributeConverter.java
b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/JsonTagListAttributeConverter.java
deleted file mode 100644
index 50ea299ff..000000000
---
a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/JsonTagListAttributeConverter.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hertzbeat.common.entity.manager;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-import jakarta.persistence.AttributeConverter;
-import jakarta.persistence.Converter;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import org.apache.hertzbeat.common.util.JsonUtil;
-import org.springframework.stereotype.Component;
-
-/**
- * json str to tag list
- */
-@Converter
-@Component
-public class JsonTagListAttributeConverter implements
AttributeConverter<List<TagItem>, String> {
-
- @Override
- public String convertToDatabaseColumn(List<TagItem> attribute) {
- return JsonUtil.toJson(attribute);
- }
-
- @Override
- public List<TagItem> convertToEntityAttribute(String dbData) {
- TypeReference<List<TagItem>> typeReference = new TypeReference<>() {};
- List<TagItem> tagItems = JsonUtil.fromJson(dbData, typeReference);
- if (tagItems == null) {
- TypeReference<Map<String, String>> mapTypeReference = new
TypeReference<>() {};
- Map<String, String> map = JsonUtil.fromJson(dbData,
mapTypeReference);
- if (map != null) {
- return map.entrySet().stream().map(entry -> new
TagItem(entry.getKey(), entry.getValue())).collect(Collectors.toList());
- } else {
- return null;
- }
- } else {
- return tagItems;
- }
-
- }
-}
diff --git
a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/TagItem.java
b/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/TagItem.java
deleted file mode 100644
index dbd9c8a4a..000000000
---
a/hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/TagItem.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hertzbeat.common.entity.manager;
-
-import io.swagger.v3.oas.annotations.media.Schema;
-import jakarta.validation.constraints.NotBlank;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-/**
- * tag item
- */
-@AllArgsConstructor
-@NoArgsConstructor
-@Data
-public class TagItem {
-
- @Schema(title = "Tag Name")
- @NotBlank
- private String name;
-
- @Schema(title = "Tag Value")
- private String value;
-
-}
diff --git
a/hertzbeat-common/src/test/java/org/apache/hertzbeat/common/util/JsonUtilTest.java
b/hertzbeat-common/src/test/java/org/apache/hertzbeat/common/util/JsonUtilTest.java
index a43989b2c..8908485ca 100644
---
a/hertzbeat-common/src/test/java/org/apache/hertzbeat/common/util/JsonUtilTest.java
+++
b/hertzbeat-common/src/test/java/org/apache/hertzbeat/common/util/JsonUtilTest.java
@@ -20,13 +20,10 @@ package org.apache.hertzbeat.common.util;
import static org.apache.hertzbeat.common.util.JsonUtil.isJsonStr;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.fasterxml.jackson.core.type.TypeReference;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.hertzbeat.common.entity.manager.TagItem;
+import java.util.Map;
import org.junit.jupiter.api.Test;
/**
@@ -36,23 +33,16 @@ class JsonUtilTest {
@Test
void toJson() {
- List<TagItem> tagList = new ArrayList<>(4);
- TagItem proTag = new TagItem("test", "pro");
- tagList.add(proTag);
- tagList.add(new TagItem("test", "dev"));
-
-
assertEquals("[{\"name\":\"test\",\"value\":\"pro\"},{\"name\":\"test\",\"value\":\"dev\"}]",
- JsonUtil.toJson(tagList));
+ Map<String, String> map = Map.of("test", "pro");
+
+ assertEquals("{\"test\":\"pro\"}",
+ JsonUtil.toJson(map));
assertNull(JsonUtil.toJson(null));
}
@Test
void testFromJson() {
- String jsonStr =
"[{\"name\":\"test\",\"value\":\"pro\"},{\"name\":\"test\",\"value\":\"dev\"}]";
- List<TagItem> tagItems = JsonUtil.fromJson(jsonStr, new
TypeReference<>() {
- });
- assertEquals("[TagItem(name=test, value=pro), TagItem(name=test,
value=dev)]", tagItems.toString());
assertNull(JsonUtil.fromJson("", new TypeReference<>() {
}));
assertNull(JsonUtil.fromJson(null, new TypeReference<>() {
@@ -62,7 +52,6 @@ class JsonUtilTest {
assertNull(JsonUtil.fromJson(" ", String.class));
assertNull(JsonUtil.fromJson(" "));
assertNull(JsonUtil.fromJson(null));
- assertNotNull(JsonUtil.fromJson(jsonStr));
assertNull(JsonUtil.fromJson("invalid"));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]