-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Put plugin API behind a feature flag (#142)
* Put plugin API behind a feature flag Signed-off-by: Daniel Widdis <[email protected]> * Add test for feature flag disabled Signed-off-by: Daniel Widdis <[email protected]> --------- Signed-off-by: Daniel Widdis <[email protected]> (cherry picked from commit aad17d0) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
80efe24
commit 32f778f
Showing
8 changed files
with
218 additions
and
8 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
src/main/java/org/opensearch/flowframework/common/FlowFrameworkFeatureEnabledSetting.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,50 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.flowframework.common; | ||
|
||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.settings.Setting; | ||
import org.opensearch.common.settings.Settings; | ||
|
||
/** | ||
* Controls enabling or disabling features of this plugin | ||
*/ | ||
public class FlowFrameworkFeatureEnabledSetting { | ||
|
||
/** This setting enables/disables the Flow Framework REST API */ | ||
public static final Setting<Boolean> FLOW_FRAMEWORK_ENABLED = Setting.boolSetting( | ||
"plugins.flow_framework.enabled", | ||
false, | ||
Setting.Property.NodeScope, | ||
Setting.Property.Dynamic | ||
); | ||
|
||
private volatile Boolean isFlowFrameworkEnabled; | ||
|
||
/** | ||
* Instantiate this class. | ||
* | ||
* @param clusterService OpenSearch cluster service | ||
* @param settings OpenSearch settings | ||
*/ | ||
public FlowFrameworkFeatureEnabledSetting(ClusterService clusterService, Settings settings) { | ||
// Currently this is just an on/off switch for the entire plugin's API. | ||
// If desired more fine-tuned feature settings can be added below. | ||
isFlowFrameworkEnabled = FLOW_FRAMEWORK_ENABLED.get(settings); | ||
clusterService.getClusterSettings().addSettingsUpdateConsumer(FLOW_FRAMEWORK_ENABLED, it -> isFlowFrameworkEnabled = it); | ||
} | ||
|
||
/** | ||
* Whether the flow framework feature is enabled. If disabled, no REST APIs will be availble. | ||
* @return whether Flow Framework is enabled. | ||
*/ | ||
public boolean isFlowFrameworkEnabled() { | ||
return isFlowFrameworkEnabled; | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
...est/java/org/opensearch/flowframework/common/FlowFrameworkFeatureEnabledSettingTests.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,56 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
package org.opensearch.flowframework.common; | ||
|
||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.settings.ClusterSettings; | ||
import org.opensearch.common.settings.Setting; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import java.io.IOException; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class FlowFrameworkFeatureEnabledSettingTests extends OpenSearchTestCase { | ||
|
||
private Settings settings; | ||
private ClusterSettings clusterSettings; | ||
private ClusterService clusterService; | ||
|
||
private FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting; | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
|
||
settings = Settings.builder().build(); | ||
final Set<Setting<?>> settingsSet = Stream.concat( | ||
ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), | ||
Stream.of(FlowFrameworkFeatureEnabledSetting.FLOW_FRAMEWORK_ENABLED) | ||
).collect(Collectors.toSet()); | ||
clusterSettings = new ClusterSettings(settings, settingsSet); | ||
clusterService = mock(ClusterService.class); | ||
when(clusterService.getClusterSettings()).thenReturn(clusterSettings); | ||
flowFrameworkFeatureEnabledSetting = new FlowFrameworkFeatureEnabledSetting(clusterService, settings); | ||
} | ||
|
||
@Override | ||
public void tearDown() throws Exception { | ||
super.tearDown(); | ||
} | ||
|
||
public void testSettings() throws IOException { | ||
assertFalse(flowFrameworkFeatureEnabledSetting.isFlowFrameworkEnabled()); | ||
} | ||
} |
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.