forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: data-prepper-core support for secrets refreshment (opensearch-pr…
…oject#3415) * INIT: secrets refreshment infra Signed-off-by: George Chen <[email protected]> * MAINT: add interval and test validity Signed-off-by: George Chen <[email protected]> * MAINT: some more refactoring Signed-off-by: George Chen <[email protected]> * MAINT: delete unused classes Signed-off-by: George Chen <[email protected]> * TST: AwsSecretsPluginConfigPublisherExtensionProviderTest Signed-off-by: George Chen <[email protected]> * MAINT: inject PluginConfigPublisher into PluginCreator Signed-off-by: George Chen <[email protected]> * MAINT: complete test cases for AwsSecretPluginIT Signed-off-by: George Chen <[email protected]> * MAINT: test refresh secrets Signed-off-by: George Chen <[email protected]> * MAINT: refactoring and documentation Signed-off-by: George Chen <[email protected]> * STY: import Signed-off-by: George Chen <[email protected]> * MAINT: fix test cases Signed-off-by: George Chen <[email protected]> * MAINT: missing test case Signed-off-by: George Chen <[email protected]> * MAINT: address minor comments Signed-off-by: George Chen <[email protected]> * REF: PluginConfigurationObservableRegister Signed-off-by: George Chen <[email protected]> --------- Signed-off-by: George Chen <[email protected]>
- Loading branch information
1 parent
52cbd03
commit 71a6956
Showing
32 changed files
with
860 additions
and
55 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...r-api/src/main/java/org/opensearch/dataprepper/model/plugin/PluginComponentRefresher.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,23 @@ | ||
package org.opensearch.dataprepper.model.plugin; | ||
|
||
/** | ||
* An interface to be implemented by pipeline plugins, i.e. {@link org.opensearch.dataprepper.model.source.Source} | ||
* /{@link org.opensearch.dataprepper.model.processor.Processor}/{@link org.opensearch.dataprepper.model.sink.Sink}, | ||
* to refresh their components, e.g. client connection. | ||
* @since 2.5 | ||
*/ | ||
public interface PluginComponentRefresher<PluginComponent, PluginConfig> { | ||
/** | ||
* Returns the refreshed {@link PluginComponent}. | ||
* | ||
* @return An instance of {@link PluginComponent}. | ||
*/ | ||
PluginComponent get(); | ||
|
||
/** | ||
* Updates the {@link PluginComponent} with the new {@link PluginConfig}. | ||
* | ||
* @param pluginConfig The new pluginConfig used to refresh the {@link PluginComponent}. | ||
*/ | ||
void update(PluginConfig pluginConfig); | ||
} |
20 changes: 20 additions & 0 deletions
20
...per-api/src/main/java/org/opensearch/dataprepper/model/plugin/PluginConfigObservable.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,20 @@ | ||
package org.opensearch.dataprepper.model.plugin; | ||
|
||
/** | ||
* An interface used by pipeline plugins, i.e. {@link org.opensearch.dataprepper.model.source.Source} | ||
* /{@link org.opensearch.dataprepper.model.processor.Processor}/{@link org.opensearch.dataprepper.model.sink.Sink}, | ||
* to onboard {@link PluginConfigObserver}. | ||
* @since 2.5 | ||
*/ | ||
public interface PluginConfigObservable { | ||
|
||
/** | ||
* Onboard a new {@link PluginConfigObserver} within the plugin. | ||
*/ | ||
boolean addPluginConfigObserver(PluginConfigObserver pluginConfigObserver); | ||
|
||
/** | ||
* Invoke all {@link PluginConfigObserver}. | ||
*/ | ||
void update(); | ||
} |
16 changes: 16 additions & 0 deletions
16
...epper-api/src/main/java/org/opensearch/dataprepper/model/plugin/PluginConfigObserver.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,16 @@ | ||
package org.opensearch.dataprepper.model.plugin; | ||
|
||
/** | ||
* An interface by pipeline plugins, i.e. {@link org.opensearch.dataprepper.model.source.Source} | ||
* * /{@link org.opensearch.dataprepper.model.processor.Processor}/{@link org.opensearch.dataprepper.model.sink.Sink} | ||
* to implement custom plugin component refreshment logic. | ||
* @since 2.5 | ||
*/ | ||
public interface PluginConfigObserver<T> { | ||
/** | ||
* Update plugin components with a new pluginConfig. | ||
* | ||
* @param pluginConfig The plugin configuration object used as reference for update. | ||
*/ | ||
void update(T pluginConfig); | ||
} |
17 changes: 17 additions & 0 deletions
17
...pper-api/src/main/java/org/opensearch/dataprepper/model/plugin/PluginConfigPublisher.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,17 @@ | ||
package org.opensearch.dataprepper.model.plugin; | ||
|
||
/** | ||
* An interface used to onboard and notify all {@link PluginConfigObservable} to invoke update. | ||
* @since 2.5 | ||
*/ | ||
public interface PluginConfigPublisher { | ||
/** | ||
* Onboard a new {@link PluginConfigObservable}. | ||
*/ | ||
boolean addPluginConfigObservable(PluginConfigObservable pluginConfigObservable); | ||
|
||
/** | ||
* Notify all {@link PluginConfigObservable} to update. | ||
*/ | ||
void notifyAllPluginConfigObservable(); | ||
} |
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
38 changes: 38 additions & 0 deletions
38
...r-core/src/main/java/org/opensearch/dataprepper/plugin/DefaultPluginConfigObservable.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,38 @@ | ||
package org.opensearch.dataprepper.plugin; | ||
|
||
import org.opensearch.dataprepper.model.configuration.PluginSetting; | ||
import org.opensearch.dataprepper.model.plugin.PluginConfigObserver; | ||
import org.opensearch.dataprepper.model.plugin.PluginConfigObservable; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class DefaultPluginConfigObservable implements PluginConfigObservable { | ||
private final Map<PluginConfigObserver, Boolean> pluginConfigObserverBooleanMap | ||
= new ConcurrentHashMap<>(); | ||
private final PluginConfigurationConverter pluginConfigurationConverter; | ||
private final Class<?> pluginConfigClass; | ||
private final PluginSetting rawPluginSettings; | ||
|
||
public DefaultPluginConfigObservable(final PluginConfigurationConverter pluginConfigurationConverter, | ||
final Class<?> pluginConfigClass, | ||
final PluginSetting rawPluginSettings) { | ||
this.pluginConfigurationConverter = pluginConfigurationConverter; | ||
this.pluginConfigClass = pluginConfigClass; | ||
this.rawPluginSettings = rawPluginSettings; | ||
} | ||
|
||
@Override | ||
public boolean addPluginConfigObserver(final PluginConfigObserver pluginConfigObserver) { | ||
pluginConfigObserverBooleanMap.put(pluginConfigObserver, true); | ||
return true; | ||
} | ||
|
||
@Override | ||
public void update() { | ||
final Object newPluginConfiguration = pluginConfigurationConverter.convert( | ||
pluginConfigClass, rawPluginSettings); | ||
pluginConfigObserverBooleanMap.keySet().forEach( | ||
pluginConfigObserver -> pluginConfigObserver.update(newPluginConfiguration)); | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
...src/main/java/org/opensearch/dataprepper/plugin/PluginConfigurationObservableFactory.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,16 @@ | ||
package org.opensearch.dataprepper.plugin; | ||
|
||
import org.opensearch.dataprepper.model.configuration.PluginSetting; | ||
import org.opensearch.dataprepper.model.plugin.PluginConfigObservable; | ||
|
||
import javax.inject.Named; | ||
|
||
@Named | ||
public class PluginConfigurationObservableFactory { | ||
public final PluginConfigObservable createDefaultPluginConfigObservable( | ||
final PluginConfigurationConverter pluginConfigurationConverter, final Class<?> pluginConfigClass, | ||
final PluginSetting rawPluginSettings) { | ||
return new DefaultPluginConfigObservable( | ||
pluginConfigurationConverter, pluginConfigClass, rawPluginSettings); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...rc/main/java/org/opensearch/dataprepper/plugin/PluginConfigurationObservableRegister.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 @@ | ||
package org.opensearch.dataprepper.plugin; | ||
|
||
import org.opensearch.dataprepper.model.plugin.PluginConfigObservable; | ||
import org.opensearch.dataprepper.model.plugin.PluginConfigPublisher; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
import java.util.Arrays; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
@Named | ||
public class PluginConfigurationObservableRegister { | ||
private final Set<PluginConfigPublisher> pluginConfigPublishers; | ||
|
||
@Inject | ||
public PluginConfigurationObservableRegister(final Set<PluginConfigPublisher> pluginConfigPublishers) { | ||
this.pluginConfigPublishers = pluginConfigPublishers; | ||
} | ||
|
||
public void registerPluginConfigurationObservables(final Object[] constructorArguments) { | ||
Optional.ofNullable(constructorArguments).ifPresent(arguments -> Arrays.stream(arguments) | ||
.filter(arg -> arg instanceof PluginConfigObservable) | ||
.forEach(arg -> pluginConfigPublishers.forEach(pluginConfigPublisher -> | ||
pluginConfigPublisher.addPluginConfigObservable( | ||
(PluginConfigObservable) arg))) | ||
); | ||
} | ||
} |
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
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
Oops, something went wrong.