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

fix ci #2630

Merged
merged 4 commits into from
Aug 29, 2024
Merged

fix ci #2630

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ public ResponseEntity<Message<Void>> updatePluginStatus(@RequestBody PluginMetad
return ResponseEntity.ok(Message.success("Update success"));
}

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

@PostMapping("/saveParams")
@PostMapping("/params")
@Operation(summary = "get param define", description = "get param define by jar path")
public ResponseEntity<Message<Boolean>> saveParams(@RequestBody List<PluginParam> pluginParams) {
pluginService.savePluginParam(pluginParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.error.YAMLException;

/**
* plugin service
Expand All @@ -95,7 +96,7 @@ public class PluginServiceImpl implements PluginService {
/**
* plugin param define
*/
private static final Map<Long, List<ParamDefine>> PARAMS_Define_MAP = new ConcurrentHashMap<>();
private static final Map<Long, List<ParamDefine>> PARAMS_DEFINE_MAP = new ConcurrentHashMap<>();

/**
* plugin params
Expand Down Expand Up @@ -172,8 +173,8 @@ public void updateStatus(PluginMetadata plugin) {
public PluginParametersVO getParamDefine(Long pluginMetadataId) {

PluginParametersVO pluginParametersVO = new PluginParametersVO();
if (PARAMS_Define_MAP.containsKey(pluginMetadataId)) {
List<ParamDefine> paramDefines = PARAMS_Define_MAP.get(pluginMetadataId);
if (PARAMS_DEFINE_MAP.containsKey(pluginMetadataId)) {
List<ParamDefine> paramDefines = PARAMS_DEFINE_MAP.get(pluginMetadataId);
List<PluginParam> paramsByPluginMetadataId = pluginParamDao.findParamsByPluginMetadataId(pluginMetadataId);
pluginParametersVO.setParamDefines(paramDefines);
pluginParametersVO.setPluginParams(paramsByPluginMetadataId);
Expand Down Expand Up @@ -217,8 +218,9 @@ public List<PluginItem> validateJarFile(File jarFile) {
try {
URL jarUrl = new URL("file:" + jarFile.getAbsolutePath());
try (URLClassLoader classLoader = new URLClassLoader(new URL[]{jarUrl}, this.getClass().getClassLoader());
JarFile jar = new JarFile(jarFile)) {
JarFile jar = new JarFile(jarFile)) {
Enumeration<JarEntry> entries = jar.entries();
Yaml yaml = new Yaml();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (entry.getName().endsWith(".class")) {
Expand All @@ -236,6 +238,11 @@ public List<PluginItem> validateJarFile(File jarFile) {
System.err.println("Failed to load class: " + className);
}
}
if ((entry.getName().contains("define")) && (entry.getName().endsWith(".yml") || entry.getName().endsWith(".yaml"))) {
try (InputStream ymlInputStream = jar.getInputStream(entry)) {
yaml.loadAs(ymlInputStream, List.class);
}
}
}
if (pluginItems.isEmpty()) {
throw new CommonException("Illegal plug-ins, please refer to https://hertzbeat.apache.org/docs/help/plugin/");
Expand All @@ -247,6 +254,8 @@ public List<PluginItem> validateJarFile(File jarFile) {
} catch (MalformedURLException e) {
log.error("Invalid JAR file URL: {}", jarFile.getAbsoluteFile(), e);
throw new CommonException("Invalid JAR file URL: " + jarFile.getAbsolutePath());
} catch (YAMLException e) {
throw new CommonException("YAML the file format is incorrect");
}
return pluginItems;
}
Expand All @@ -259,6 +268,7 @@ private void validateMetadata(PluginMetadata metadata) {

@Override
@SneakyThrows
@Transactional
public void savePlugin(PluginUpload pluginUpload) {
String jarPath = new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getAbsolutePath();
Path extLibPath = Paths.get(new File(jarPath).getParent(), "plugin-lib");
Expand Down Expand Up @@ -376,7 +386,7 @@ private void loadJarToClassLoader() {
pluginClassLoaders.clear();
System.gc();
}
PARAMS_Define_MAP.clear();
PARAMS_DEFINE_MAP.clear();
List<PluginMetadata> plugins = metadataDao.findPluginMetadataByEnableStatusTrue();
for (PluginMetadata metadata : plugins) {
List<URL> urls = loadLibInPlugin(metadata.getJarFilePath(), metadata.getId());
Expand Down Expand Up @@ -431,7 +441,7 @@ private List<URL> loadLibInPlugin(String pluginJarPath, Long pluginMetadataId) {
if ((entry.getName().contains("define")) && (entry.getName().endsWith(".yml") || entry.getName().endsWith(".yaml"))) {
try (InputStream ymlInputStream = jarFile.getInputStream(entry)) {
List<ParamDefine> params = yaml.loadAs(ymlInputStream, List.class);
PARAMS_Define_MAP.putIfAbsent(pluginMetadataId, params);
PARAMS_DEFINE_MAP.put(pluginMetadataId, params);
}
}
}
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions web-app/src/app/service/plugin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export class PluginService {
pluginMetadataId: pluginId
});
const options = { params: httpParams };
return this.http.get<Message<any>>(`${plugin_uri}/getParamDefine`, options);
return this.http.get<Message<any>>(`${plugin_uri}/params/define`, options);
}

public savePluginParamDefine(body: any): Observable<Message<any>> {
return this.http.post<Message<any>>(`${plugin_uri}/saveParams`, body);
return this.http.post<Message<any>>(`${plugin_uri}/params`, body);
}
}