-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces the experimental plugin feature, allowing plugin developer…
…s to mark plugins as experimental. Resolves #2695. Signed-off-by: David Venable <[email protected]>
- Loading branch information
Showing
15 changed files
with
476 additions
and
10 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...-prepper-api/src/main/java/org/opensearch/dataprepper/model/annotations/Experimental.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.model.annotations; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Marks a Data Prepper plugin as experimental. | ||
* <p> | ||
* Experimental plugins do not have the same compatibility guarantees as other plugins and may be unstable. | ||
* They may have breaking changes between minor versions and may even be removed. | ||
* <p> | ||
* Data Prepper administrators must enable experimental plugins in order to use them. | ||
* Otherwise, they are not available to use with pipelines. | ||
* | ||
* @since 2.11 | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
public @interface Experimental { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...prepper-core/src/test/java/org/opensearch/dataprepper/plugins/TestExperimentalPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins; | ||
|
||
import org.opensearch.dataprepper.model.annotations.DataPrepperPlugin; | ||
import org.opensearch.dataprepper.model.annotations.Experimental; | ||
import org.opensearch.dataprepper.plugin.TestPluggableInterface; | ||
|
||
@DataPrepperPlugin(name = "test_experimental_plugin", pluginType = TestPluggableInterface.class) | ||
@Experimental | ||
public class TestExperimentalPlugin { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...epper-plugin-framework/src/main/java/org/opensearch/dataprepper/plugin/DefinedPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugin; | ||
|
||
import java.util.Objects; | ||
|
||
class DefinedPlugin<T> { | ||
private final Class<? extends T> pluginClass; | ||
private final String pluginName; | ||
|
||
public DefinedPlugin(final Class<? extends T> pluginClass, final String pluginName) { | ||
this.pluginClass = Objects.requireNonNull(pluginClass); | ||
this.pluginName = Objects.requireNonNull(pluginName); | ||
} | ||
|
||
public Class<? extends T> getPluginClass() { | ||
return pluginClass; | ||
} | ||
|
||
public String getPluginName() { | ||
return pluginName; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...n-framework/src/main/java/org/opensearch/dataprepper/plugin/DeprecatedPluginDetector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugin; | ||
|
||
import org.opensearch.dataprepper.model.annotations.DataPrepperPlugin; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.inject.Named; | ||
import java.util.function.Consumer; | ||
|
||
@Named | ||
class DeprecatedPluginDetector implements Consumer<DefinedPlugin<?>> { | ||
private static final Logger LOG = LoggerFactory.getLogger(DeprecatedPluginDetector.class); | ||
|
||
@Override | ||
public void accept(final DefinedPlugin<?> definedPlugin) { | ||
logDeprecatedPluginsNames(definedPlugin.getPluginClass(), definedPlugin.getPluginName()); | ||
} | ||
|
||
private void logDeprecatedPluginsNames(final Class<?> pluginClass, final String pluginName) { | ||
final String deprecatedName = pluginClass.getAnnotation(DataPrepperPlugin.class).deprecatedName(); | ||
final String name = pluginClass.getAnnotation(DataPrepperPlugin.class).name(); | ||
if (deprecatedName.equals(pluginName)) { | ||
LOG.warn("Plugin name '{}' is deprecated and will be removed in the next major release. Consider using the updated plugin name '{}'.", deprecatedName, name); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...-framework/src/main/java/org/opensearch/dataprepper/plugin/ExperimentalConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugin; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* Data Prepper configurations for experimental features. | ||
* | ||
* @since 2.11 | ||
*/ | ||
public class ExperimentalConfiguration { | ||
@JsonProperty("enable_all") | ||
private boolean enableAll = false; | ||
|
||
public static ExperimentalConfiguration defaultConfiguration() { | ||
return new ExperimentalConfiguration(); | ||
} | ||
|
||
/** | ||
* Gets whether all experimental features are enabled. | ||
* @return true if all experimental features are enabled, false otherwise | ||
* @since 2.11 | ||
*/ | ||
public boolean isEnableAll() { | ||
return enableAll; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...k/src/main/java/org/opensearch/dataprepper/plugin/ExperimentalConfigurationContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugin; | ||
|
||
/** | ||
* Interface to decouple how an experimental configuration is defined from | ||
* usage of those configurations. | ||
* | ||
* @since 2.11 | ||
*/ | ||
public interface ExperimentalConfigurationContainer { | ||
/** | ||
* Gets the experimental configuration. | ||
* @return the experimental configuration | ||
* @since 2.11 | ||
*/ | ||
ExperimentalConfiguration getExperimental(); | ||
} |
33 changes: 33 additions & 0 deletions
33
...ramework/src/main/java/org/opensearch/dataprepper/plugin/ExperimentalPluginValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugin; | ||
|
||
import org.opensearch.dataprepper.model.annotations.Experimental; | ||
import org.opensearch.dataprepper.model.plugin.NoPluginFoundException; | ||
|
||
import javax.inject.Named; | ||
import java.util.function.Consumer; | ||
|
||
@Named | ||
class ExperimentalPluginValidator implements Consumer<DefinedPlugin<?>> { | ||
private final ExperimentalConfiguration experimentalConfiguration; | ||
|
||
ExperimentalPluginValidator(final ExperimentalConfigurationContainer experimentalConfigurationContainer) { | ||
this.experimentalConfiguration = experimentalConfigurationContainer.getExperimental(); | ||
} | ||
|
||
@Override | ||
public void accept(final DefinedPlugin<?> definedPlugin) { | ||
if(isPluginDisallowedAsExperimental(definedPlugin.getPluginClass())) { | ||
throw new NoPluginFoundException("Unable to create experimental plugin " + definedPlugin.getPluginName() + | ||
". You must enable experimental plugins in data-prepper-config.yaml in order to use them."); | ||
} | ||
} | ||
|
||
private boolean isPluginDisallowedAsExperimental(final Class<?> pluginClass) { | ||
return pluginClass.isAnnotationPresent(Experimental.class) && !experimentalConfiguration.isEnableAll(); | ||
} | ||
} |
Oops, something went wrong.