mirror of
https://github.com/kestra-io/kestra.git
synced 2025-12-19 18:05:41 -05:00
feat(plugin): add new priority attr on Plugin annotation (#10975)
This commit is contained in:
committed by
GitHub
parent
88acc91323
commit
6e21d650f9
@@ -103,11 +103,13 @@ public class DefaultPluginRegistry implements PluginRegistry {
|
||||
*/
|
||||
@Override
|
||||
public void registerIfAbsent(final Path pluginPath) {
|
||||
long start = System.currentTimeMillis();
|
||||
if (isPluginPathValid(pluginPath) && !isPluginPathScanned(pluginPath)) {
|
||||
List<RegisteredPlugin> scanned = scanner.scan(pluginPath);
|
||||
scanned.forEach(this::register);
|
||||
scannedPluginPaths.add(pluginPath);
|
||||
}
|
||||
log.debug("Registered if absent plugins from path {} in {} ms", pluginPath, System.currentTimeMillis() - start);
|
||||
}
|
||||
|
||||
private boolean isPluginPathScanned(final Path pluginPath) {
|
||||
@@ -119,10 +121,12 @@ public class DefaultPluginRegistry implements PluginRegistry {
|
||||
*/
|
||||
@Override
|
||||
public void register(final Path pluginPath) {
|
||||
long start = System.currentTimeMillis();
|
||||
if (isPluginPathValid(pluginPath)) {
|
||||
List<RegisteredPlugin> scanned = scanner.scan(pluginPath);
|
||||
scanned.forEach(this::register);
|
||||
}
|
||||
log.debug("Registered plugins from path {} in {} ms", pluginPath, System.currentTimeMillis() - start);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,12 @@ class PluginTest {
|
||||
|
||||
@Test
|
||||
void shouldReturnTrueForInternal() {
|
||||
Assertions.assertTrue( io.kestra.core.models.Plugin.isInternal(TestPlugin.class));
|
||||
Assertions.assertTrue(io.kestra.core.models.Plugin.isInternal(TestPlugin.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnTrueForPrimary() {
|
||||
Assertions.assertTrue(io.kestra.core.models.Plugin.isPrimary(TestPlugin.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -18,7 +23,7 @@ class PluginTest {
|
||||
Assertions.assertEquals(Optional.of("test"), io.kestra.core.models.Plugin.getId(TestPlugin.class));
|
||||
}
|
||||
|
||||
@Plugin(internal = true)
|
||||
@Plugin(internal = true, priority = Plugin.Priority.PRIMARY)
|
||||
@Plugin.Id("test")
|
||||
public static class TestPlugin implements io.kestra.core.models.Plugin {
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.kestra.core.models;
|
||||
|
||||
import io.kestra.core.models.annotations.Plugin.Id;
|
||||
import jakarta.annotation.Nullable;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -18,7 +17,7 @@ public interface Plugin {
|
||||
/**
|
||||
* Gets the type of this plugin.
|
||||
*
|
||||
* @return the string type of the plugin.
|
||||
* @return the string type of the plugin.
|
||||
*/
|
||||
@NotNull
|
||||
default String getType() {
|
||||
@@ -28,12 +27,12 @@ public interface Plugin {
|
||||
/**
|
||||
* Static helper method to get the aliases of a given plugin.
|
||||
*
|
||||
* @param plugin The plugin type.
|
||||
* @return {@code true} if the plugin is internal.
|
||||
* @param plugin The plugin type.
|
||||
* @return {@code true} if the plugin is internal.
|
||||
*/
|
||||
static Set<String> getAliases(final Class<?> plugin) {
|
||||
io.kestra.core.models.annotations.Plugin annotation = plugin.getAnnotation(io.kestra.core.models.annotations.Plugin.class);
|
||||
return Optional.ofNullable(annotation)
|
||||
return Optional.ofNullable(annotation)
|
||||
.map(io.kestra.core.models.annotations.Plugin::aliases)
|
||||
.stream()
|
||||
.flatMap(Arrays::stream)
|
||||
@@ -43,8 +42,8 @@ public interface Plugin {
|
||||
/**
|
||||
* Static helper method to check whether a given plugin is internal.
|
||||
*
|
||||
* @param plugin The plugin type.
|
||||
* @return {@code true} if the plugin is internal.
|
||||
* @param plugin The plugin type.
|
||||
* @return {@code true} if the plugin is internal.
|
||||
*/
|
||||
static boolean isInternal(final Class<?> plugin) {
|
||||
Objects.requireNonNull(plugin, "Cannot check if a plugin is internal from null");
|
||||
@@ -57,8 +56,8 @@ public interface Plugin {
|
||||
/**
|
||||
* Static helper method to check whether a given plugin is deprecated.
|
||||
*
|
||||
* @param plugin The plugin type.
|
||||
* @return {@code true} if the plugin is deprecated.
|
||||
* @param plugin The plugin type.
|
||||
* @return {@code true} if the plugin is deprecated.
|
||||
*/
|
||||
static boolean isDeprecated(final Class<?> plugin) {
|
||||
Objects.requireNonNull(plugin, "Cannot check if a plugin is deprecated from null");
|
||||
@@ -66,6 +65,20 @@ public interface Plugin {
|
||||
return annotation != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Static helper method to check whether a given plugin has PRIMARY priority.
|
||||
*
|
||||
* @param plugin The plugin class.
|
||||
* @return {@code true} if the plugin is annotated with {@link Plugin} and its priority is PRIMARY.
|
||||
*/
|
||||
static boolean isPrimary(final Class<?> plugin) {
|
||||
Objects.requireNonNull(plugin, "Cannot check priority on null class");
|
||||
io.kestra.core.models.annotations.Plugin annotation = plugin.getAnnotation(io.kestra.core.models.annotations.Plugin.class);
|
||||
return Optional.ofNullable(annotation)
|
||||
.map(a -> a.priority() == io.kestra.core.models.annotations.Plugin.Priority.PRIMARY)
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static helper method to get the id of a plugin.
|
||||
*
|
||||
|
||||
@@ -36,6 +36,13 @@ public @interface Plugin {
|
||||
*/
|
||||
String[] aliases() default {};
|
||||
|
||||
Priority priority() default Priority.SECONDARY;
|
||||
|
||||
enum Priority {
|
||||
PRIMARY,
|
||||
SECONDARY
|
||||
}
|
||||
|
||||
@Documented
|
||||
@Inherited
|
||||
@Retention(RUNTIME)
|
||||
|
||||
Reference in New Issue
Block a user