diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/controller/PluginController.java b/manager/src/main/java/org/apache/hertzbeat/manager/controller/PluginController.java index 0bd5d83c6fd..496ebfb5bad 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/controller/PluginController.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/controller/PluginController.java @@ -26,9 +26,9 @@ import lombok.RequiredArgsConstructor; import org.apache.hertzbeat.common.entity.dto.Message; import org.apache.hertzbeat.common.entity.dto.PluginUpload; -import org.apache.hertzbeat.common.entity.manager.ParamDefine; import org.apache.hertzbeat.common.entity.manager.PluginMetadata; import org.apache.hertzbeat.manager.pojo.dto.PluginParam; +import org.apache.hertzbeat.manager.pojo.dto.PluginParametersVO; import org.apache.hertzbeat.manager.service.PluginService; import org.springframework.data.domain.Page; import org.springframework.http.ResponseEntity; @@ -90,8 +90,8 @@ public ResponseEntity> updatePluginStatus(@RequestBody PluginMetad @GetMapping("/getParamDefine") @Operation(summary = "get param define", description = "get param define by jar path") - public ResponseEntity>> getParamDefine(@RequestParam Long pluginMetadataId) { - List plugins = pluginService.getParamDefine(pluginMetadataId); + public ResponseEntity> getParamDefine(@RequestParam Long pluginMetadataId) { + PluginParametersVO plugins = pluginService.getParamDefine(pluginMetadataId); return ResponseEntity.ok(Message.success(plugins)); } diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/dao/PluginParamDao.java b/manager/src/main/java/org/apache/hertzbeat/manager/dao/PluginParamDao.java index d7fbeaa96af..4eeec26b192 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/dao/PluginParamDao.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/dao/PluginParamDao.java @@ -38,11 +38,11 @@ public interface PluginParamDao extends JpaRepository { * Remove the parameter list associated with the pluginMetadata ID based on it * @param pluginMetadataId Monitor Id */ - void deleteParamsByPluginMetadataId(long pluginMetadataId); + void deletePluginParamsByPluginMetadataId(long pluginMetadataId); /** * Remove the parameter list associated with the pluginMetadata ID list based on it * @param pluginMetadataIds Monitoring ID List */ - void deleteParamsByPluginMetadataIdIn(Set pluginMetadataIds); + void deletePluginParamsByPluginMetadataIdIn(Set pluginMetadataIds); } diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/PluginParametersVO.java b/manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/PluginParametersVO.java new file mode 100644 index 00000000000..ba3f2f9ffa1 --- /dev/null +++ b/manager/src/main/java/org/apache/hertzbeat/manager/pojo/dto/PluginParametersVO.java @@ -0,0 +1,43 @@ +/* + * 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.manager.pojo.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.hertzbeat.common.entity.manager.ParamDefine; +import java.util.List; + +/** + * Popup rendering and parameter values + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class PluginParametersVO { + + /** + * Stencil rendering + */ + private List paramDefines; + + /** + * specific parameter + */ + private List pluginParams; +} diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/service/PluginService.java b/manager/src/main/java/org/apache/hertzbeat/manager/service/PluginService.java index 42254d7b532..a7f0c706e4f 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/service/PluginService.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/service/PluginService.java @@ -23,9 +23,9 @@ import java.util.function.Consumer; import org.apache.hertzbeat.common.entity.dto.PluginUpload; import org.apache.hertzbeat.common.entity.job.Configmap; -import org.apache.hertzbeat.common.entity.manager.ParamDefine; import org.apache.hertzbeat.common.entity.manager.PluginMetadata; import org.apache.hertzbeat.manager.pojo.dto.PluginParam; +import org.apache.hertzbeat.manager.pojo.dto.PluginParametersVO; import org.springframework.data.domain.Page; /** @@ -78,7 +78,7 @@ public interface PluginService { * get param define * @param pluginMetadataId plugin id */ - List getParamDefine(Long pluginMetadataId); + PluginParametersVO getParamDefine(Long pluginMetadataId); /** * save plugin param diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/PluginServiceImpl.java b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/PluginServiceImpl.java index 3ebd6d8a69b..5838bb260d9 100644 --- a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/PluginServiceImpl.java +++ b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/PluginServiceImpl.java @@ -60,12 +60,14 @@ import org.apache.hertzbeat.manager.dao.PluginMetadataDao; import org.apache.hertzbeat.manager.dao.PluginParamDao; import org.apache.hertzbeat.manager.pojo.dto.PluginParam; +import org.apache.hertzbeat.manager.pojo.dto.PluginParametersVO; import org.apache.hertzbeat.manager.service.PluginService; import org.apache.hertzbeat.plugin.Plugin; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.yaml.snakeyaml.Yaml; @@ -131,12 +133,12 @@ public void deletePlugins(Set ids) { // delete metadata metadataDao.deleteById(plugin.getId()); syncPluginParamMap(plugin.getId(), null, true); - pluginParamDao.deleteParamsByPluginMetadataId(plugin.getId()); } catch (IOException e) { throw new RuntimeException(e); } } + pluginParamDao.deletePluginParamsByPluginMetadataIdIn(ids); syncPluginStatus(); // reload classloader loadJarToClassLoader(); @@ -166,19 +168,26 @@ public void updateStatus(PluginMetadata plugin) { } @Override - public List getParamDefine(Long pluginMetadataId) { + public PluginParametersVO getParamDefine(Long pluginMetadataId) { + + PluginParametersVO pluginParametersVO = new PluginParametersVO(); if (PARAMS_Define_MAP.containsKey(pluginMetadataId)) { - return PARAMS_Define_MAP.get(pluginMetadataId); + List paramDefines = PARAMS_Define_MAP.get(pluginMetadataId); + List paramsByPluginMetadataId = pluginParamDao.findParamsByPluginMetadataId(pluginMetadataId); + pluginParametersVO.setParamDefines(paramDefines); + pluginParametersVO.setPluginParams(paramsByPluginMetadataId); + return pluginParametersVO; } - return List.of(); + return pluginParametersVO; } @Override + @Transactional public void savePluginParam(List params) { if (CollectionUtils.isEmpty(params)) { return; } - pluginParamDao.deleteParamsByPluginMetadataId(params.get(0).getPluginMetadataId()); + pluginParamDao.deletePluginParamsByPluginMetadataId(params.get(0).getPluginMetadataId()); pluginParamDao.saveAll(params); syncPluginParamMap(params.get(0).getPluginMetadataId(), params, false); }