Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve]:fix bug #2615

Merged
merged 11 commits into from
Aug 27, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,8 +90,8 @@ public ResponseEntity<Message<Void>> updatePluginStatus(@RequestBody PluginMetad

@GetMapping("/getParamDefine")
@Operation(summary = "get param define", description = "get param define by jar path")
public ResponseEntity<Message<List<ParamDefine>>> getParamDefine(@RequestParam Long pluginMetadataId) {
List<ParamDefine> plugins = pluginService.getParamDefine(pluginMetadataId);
public ResponseEntity<Message<PluginParametersVO>> getParamDefine(@RequestParam Long pluginMetadataId) {
PluginParametersVO plugins = pluginService.getParamDefine(pluginMetadataId);
return ResponseEntity.ok(Message.success(plugins));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public interface PluginParamDao extends JpaRepository<PluginParam, Long> {
* 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<Long> pluginMetadataIds);
void deletePluginParamsByPluginMetadataIdIn(Set<Long> pluginMetadataIds);
}
Original file line number Diff line number Diff line change
@@ -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<ParamDefine> paramDefines;

/**
* specific parameter
*/
private List<PluginParam> pluginParams;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -78,7 +78,7 @@ public interface PluginService {
* get param define
* @param pluginMetadataId plugin id
*/
List<ParamDefine> getParamDefine(Long pluginMetadataId);
PluginParametersVO getParamDefine(Long pluginMetadataId);

/**
* save plugin param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -131,12 +133,12 @@ public void deletePlugins(Set<Long> 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();
Expand Down Expand Up @@ -166,19 +168,26 @@ public void updateStatus(PluginMetadata plugin) {
}

@Override
public List<ParamDefine> 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<ParamDefine> paramDefines = PARAMS_Define_MAP.get(pluginMetadataId);
List<PluginParam> paramsByPluginMetadataId = pluginParamDao.findParamsByPluginMetadataId(pluginMetadataId);
pluginParametersVO.setParamDefines(paramDefines);
pluginParametersVO.setPluginParams(paramsByPluginMetadataId);
return pluginParametersVO;
}
return List.of();
return pluginParametersVO;
}

@Override
@Transactional
public void savePluginParam(List<PluginParam> 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);
}
Expand Down