Skip to content

Commit

Permalink
Added a common settings class to initialize plugin settings (#361)
Browse files Browse the repository at this point in the history
* Moved settings to a common singleton class

Signed-off-by: Owais Kazi <[email protected]>
Signed-off-by: owaiskazi19 <[email protected]>

* Removed update retry settings

Signed-off-by: Owais Kazi <[email protected]>

* Used getter for maxRetry value

Signed-off-by: Owais Kazi <[email protected]>
Signed-off-by: owaiskazi19 <[email protected]>

* Removed FeatureEnabledSettings file

Signed-off-by: Owais Kazi <[email protected]>

* Fixed tests

Signed-off-by: owaiskazi19 <[email protected]>

* Moved max workflow step setting to common class

Signed-off-by: Owais Kazi <[email protected]>

---------

Signed-off-by: Owais Kazi <[email protected]>
Signed-off-by: owaiskazi19 <[email protected]>
  • Loading branch information
owaiskazi19 committed Jan 5, 2024
1 parent 8216cb9 commit a8e7ff5
Show file tree
Hide file tree
Showing 30 changed files with 179 additions and 161 deletions.
28 changes: 14 additions & 14 deletions src/main/java/org/opensearch/flowframework/FlowFrameworkPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.env.Environment;
import org.opensearch.env.NodeEnvironment;
import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting;
import org.opensearch.flowframework.common.FlowFrameworkSettings;
import org.opensearch.flowframework.indices.FlowFrameworkIndicesHandler;
import org.opensearch.flowframework.rest.RestCreateWorkflowAction;
import org.opensearch.flowframework.rest.RestDeleteWorkflowAction;
Expand Down Expand Up @@ -82,7 +82,7 @@
*/
public class FlowFrameworkPlugin extends Plugin implements ActionPlugin {

private FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting;
private FlowFrameworkSettings flowFrameworkSettings;

private ClusterService clusterService;

Expand All @@ -107,24 +107,24 @@ public Collection<Object> createComponents(
) {
Settings settings = environment.settings();
this.clusterService = clusterService;
flowFrameworkFeatureEnabledSetting = new FlowFrameworkFeatureEnabledSetting(clusterService, settings);
flowFrameworkSettings = new FlowFrameworkSettings(clusterService, settings);
MachineLearningNodeClient mlClient = new MachineLearningNodeClient(client);
EncryptorUtils encryptorUtils = new EncryptorUtils(clusterService, client);
FlowFrameworkIndicesHandler flowFrameworkIndicesHandler = new FlowFrameworkIndicesHandler(client, clusterService, encryptorUtils);
WorkflowStepFactory workflowStepFactory = new WorkflowStepFactory(
settings,
threadPool,
clusterService,
client,
mlClient,
flowFrameworkIndicesHandler
flowFrameworkIndicesHandler,
flowFrameworkSettings
);
WorkflowProcessSorter workflowProcessSorter = new WorkflowProcessSorter(
workflowStepFactory,
threadPool,
clusterService,
client,
settings
flowFrameworkSettings
);

return List.of(workflowStepFactory, workflowProcessSorter, encryptorUtils, flowFrameworkIndicesHandler);
Expand All @@ -141,14 +141,14 @@ public List<RestHandler> getRestHandlers(
Supplier<DiscoveryNodes> nodesInCluster
) {
return List.of(
new RestCreateWorkflowAction(flowFrameworkFeatureEnabledSetting, settings, clusterService),
new RestDeleteWorkflowAction(flowFrameworkFeatureEnabledSetting),
new RestProvisionWorkflowAction(flowFrameworkFeatureEnabledSetting),
new RestDeprovisionWorkflowAction(flowFrameworkFeatureEnabledSetting),
new RestSearchWorkflowAction(flowFrameworkFeatureEnabledSetting),
new RestGetWorkflowStateAction(flowFrameworkFeatureEnabledSetting),
new RestGetWorkflowAction(flowFrameworkFeatureEnabledSetting),
new RestSearchWorkflowStateAction(flowFrameworkFeatureEnabledSetting)
new RestCreateWorkflowAction(flowFrameworkSettings, settings, clusterService),
new RestDeleteWorkflowAction(flowFrameworkSettings),
new RestProvisionWorkflowAction(flowFrameworkSettings),
new RestDeprovisionWorkflowAction(flowFrameworkSettings),
new RestSearchWorkflowAction(flowFrameworkSettings),
new RestGetWorkflowStateAction(flowFrameworkSettings),
new RestGetWorkflowAction(flowFrameworkSettings),
new RestSearchWorkflowStateAction(flowFrameworkSettings)
);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
*/
package org.opensearch.flowframework.common;

import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;

/** The common settings of flow framework */
public class FlowFrameworkSettings {

private FlowFrameworkSettings() {}
private volatile Boolean isFlowFrameworkEnabled;
/** The maximum number of transport request retries */
private volatile Integer maxRetry;
/** Max workflow steps that can be created*/
private volatile Integer maxWorkflowSteps;

/** The upper limit of max workflows that can be created */
public static final int MAX_WORKFLOWS_LIMIT = 10000;
Expand Down Expand Up @@ -65,4 +71,45 @@ private FlowFrameworkSettings() {}
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

/**
* Instantiate this class.
*
* @param clusterService OpenSearch cluster service
* @param settings OpenSearch settings
*/
public FlowFrameworkSettings(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.
this.isFlowFrameworkEnabled = FLOW_FRAMEWORK_ENABLED.get(settings);
this.maxRetry = MAX_GET_TASK_REQUEST_RETRY.get(settings);
this.maxWorkflowSteps = MAX_WORKFLOW_STEPS.get(settings);
clusterService.getClusterSettings().addSettingsUpdateConsumer(FLOW_FRAMEWORK_ENABLED, it -> isFlowFrameworkEnabled = it);
clusterService.getClusterSettings().addSettingsUpdateConsumer(MAX_GET_TASK_REQUEST_RETRY, it -> maxRetry = it);
clusterService.getClusterSettings().addSettingsUpdateConsumer(MAX_WORKFLOW_STEPS, it -> maxWorkflowSteps = 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;
}

/**
* Getter for max retry count
* @return count of max retry
*/
public Integer getMaxRetry() {
return maxRetry;
}

/**
* Getter for max workflow steps
* @return count of steps
*/
public Integer getMaxWorkflowSteps() {
return maxWorkflowSteps;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting;
import org.opensearch.flowframework.common.FlowFrameworkSettings;
import org.opensearch.flowframework.exception.FlowFrameworkException;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.BytesRestResponse;
Expand Down Expand Up @@ -48,7 +48,7 @@ public abstract class AbstractSearchWorkflowAction<T extends ToXContentObject> e
/** Search action type*/
protected final ActionType<SearchResponse> actionType;
/** Settings to enable FlowFramework API*/
protected final FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting;
protected final FlowFrameworkSettings flowFrameworkFeatureEnabledSetting;

/**
* Instantiates a new AbstractSearchWorkflowAction
Expand All @@ -63,7 +63,7 @@ public AbstractSearchWorkflowAction(
String index,
Class<T> clazz,
ActionType<SearchResponse> actionType,
FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting
FlowFrameworkSettings flowFrameworkFeatureEnabledSetting
) {
this.urlPaths = urlPaths;
this.index = index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting;
import org.opensearch.flowframework.common.FlowFrameworkSettings;
import org.opensearch.flowframework.exception.FlowFrameworkException;
import org.opensearch.flowframework.model.Template;
import org.opensearch.flowframework.transport.CreateWorkflowAction;
Expand All @@ -45,7 +45,7 @@ public class RestCreateWorkflowAction extends AbstractWorkflowAction {
private static final Logger logger = LogManager.getLogger(RestCreateWorkflowAction.class);
private static final String CREATE_WORKFLOW_ACTION = "create_workflow_action";

private FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting;
private FlowFrameworkSettings flowFrameworkFeatureEnabledSetting;

/**
* Instantiates a new RestCreateWorkflowAction
Expand All @@ -54,7 +54,7 @@ public class RestCreateWorkflowAction extends AbstractWorkflowAction {
* @param clusterService clusterService
*/
public RestCreateWorkflowAction(
FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting,
FlowFrameworkSettings flowFrameworkFeatureEnabledSetting,
Settings settings,
ClusterService clusterService
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting;
import org.opensearch.flowframework.common.FlowFrameworkSettings;
import org.opensearch.flowframework.exception.FlowFrameworkException;
import org.opensearch.flowframework.transport.DeleteWorkflowAction;
import org.opensearch.flowframework.transport.WorkflowRequest;
Expand All @@ -39,13 +39,13 @@ public class RestDeleteWorkflowAction extends BaseRestHandler {

private static final String DELETE_WORKFLOW_ACTION = "delete_workflow";
private static final Logger logger = LogManager.getLogger(RestDeleteWorkflowAction.class);
private FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting;
private FlowFrameworkSettings flowFrameworkFeatureEnabledSetting;

/**
* Instantiates a new RestDeleteWorkflowAction
* @param flowFrameworkFeatureEnabledSetting Whether this API is enabled
*/
public RestDeleteWorkflowAction(FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting) {
public RestDeleteWorkflowAction(FlowFrameworkSettings flowFrameworkFeatureEnabledSetting) {
this.flowFrameworkFeatureEnabledSetting = flowFrameworkFeatureEnabledSetting;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting;
import org.opensearch.flowframework.common.FlowFrameworkSettings;
import org.opensearch.flowframework.exception.FlowFrameworkException;
import org.opensearch.flowframework.transport.DeprovisionWorkflowAction;
import org.opensearch.flowframework.transport.WorkflowRequest;
Expand All @@ -39,13 +39,13 @@ public class RestDeprovisionWorkflowAction extends BaseRestHandler {

private static final String DEPROVISION_WORKFLOW_ACTION = "deprovision_workflow";
private static final Logger logger = LogManager.getLogger(RestDeprovisionWorkflowAction.class);
private final FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting;
private final FlowFrameworkSettings flowFrameworkFeatureEnabledSetting;

/**
* Instantiates a new RestDeprovisionWorkflowAction
* @param flowFrameworkFeatureEnabledSetting Whether this API is enabled
*/
public RestDeprovisionWorkflowAction(FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting) {
public RestDeprovisionWorkflowAction(FlowFrameworkSettings flowFrameworkFeatureEnabledSetting) {
this.flowFrameworkFeatureEnabledSetting = flowFrameworkFeatureEnabledSetting;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting;
import org.opensearch.flowframework.common.FlowFrameworkSettings;
import org.opensearch.flowframework.exception.FlowFrameworkException;
import org.opensearch.flowframework.transport.GetWorkflowAction;
import org.opensearch.flowframework.transport.WorkflowRequest;
Expand All @@ -39,13 +39,13 @@ public class RestGetWorkflowAction extends BaseRestHandler {

private static final String GET_WORKFLOW_ACTION = "get_workflow";
private static final Logger logger = LogManager.getLogger(RestGetWorkflowAction.class);
private FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting;
private FlowFrameworkSettings flowFrameworkFeatureEnabledSetting;

/**
* Instantiates a new RestGetWorkflowAction
* @param flowFrameworkFeatureEnabledSetting Whether this API is enabled
*/
public RestGetWorkflowAction(FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting) {
public RestGetWorkflowAction(FlowFrameworkSettings flowFrameworkFeatureEnabledSetting) {
this.flowFrameworkFeatureEnabledSetting = flowFrameworkFeatureEnabledSetting;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting;
import org.opensearch.flowframework.common.FlowFrameworkSettings;
import org.opensearch.flowframework.exception.FlowFrameworkException;
import org.opensearch.flowframework.transport.GetWorkflowStateAction;
import org.opensearch.flowframework.transport.GetWorkflowStateRequest;
Expand All @@ -39,13 +39,13 @@ public class RestGetWorkflowStateAction extends BaseRestHandler {

private static final String GET_WORKFLOW_STATE_ACTION = "get_workflow_state";
private static final Logger logger = LogManager.getLogger(RestGetWorkflowStateAction.class);
private FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting;
private FlowFrameworkSettings flowFrameworkFeatureEnabledSetting;

/**
* Instantiates a new RestGetWorkflowStateAction
* @param flowFrameworkFeatureEnabledSetting Whether this API is enabled
*/
public RestGetWorkflowStateAction(FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting) {
public RestGetWorkflowStateAction(FlowFrameworkSettings flowFrameworkFeatureEnabledSetting) {
this.flowFrameworkFeatureEnabledSetting = flowFrameworkFeatureEnabledSetting;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting;
import org.opensearch.flowframework.common.FlowFrameworkSettings;
import org.opensearch.flowframework.exception.FlowFrameworkException;
import org.opensearch.flowframework.transport.ProvisionWorkflowAction;
import org.opensearch.flowframework.transport.WorkflowRequest;
Expand All @@ -40,14 +40,14 @@ public class RestProvisionWorkflowAction extends BaseRestHandler {

private static final String PROVISION_WORKFLOW_ACTION = "provision_workflow_action";

private FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting;
private FlowFrameworkSettings flowFrameworkFeatureEnabledSetting;

/**
* Instantiates a new RestProvisionWorkflowAction
*
* @param flowFrameworkFeatureEnabledSetting Whether this API is enabled
*/
public RestProvisionWorkflowAction(FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting) {
public RestProvisionWorkflowAction(FlowFrameworkSettings flowFrameworkFeatureEnabledSetting) {
this.flowFrameworkFeatureEnabledSetting = flowFrameworkFeatureEnabledSetting;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
package org.opensearch.flowframework.rest;

import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting;
import org.opensearch.flowframework.common.FlowFrameworkSettings;
import org.opensearch.flowframework.model.Template;
import org.opensearch.flowframework.transport.SearchWorkflowAction;

Expand All @@ -30,7 +30,7 @@ public class RestSearchWorkflowAction extends AbstractSearchWorkflowAction<Templ
*
* @param flowFrameworkFeatureEnabledSetting Whether this API is enabled
*/
public RestSearchWorkflowAction(FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting) {
public RestSearchWorkflowAction(FlowFrameworkSettings flowFrameworkFeatureEnabledSetting) {
super(
List.of(SEARCH_WORKFLOW_PATH),
GLOBAL_CONTEXT_INDEX,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
package org.opensearch.flowframework.rest;

import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting;
import org.opensearch.flowframework.common.FlowFrameworkSettings;
import org.opensearch.flowframework.model.WorkflowState;
import org.opensearch.flowframework.transport.SearchWorkflowStateAction;

Expand All @@ -30,7 +30,7 @@ public class RestSearchWorkflowStateAction extends AbstractSearchWorkflowAction<
*
* @param flowFrameworkFeatureEnabledSetting Whether this API is enabled
*/
public RestSearchWorkflowStateAction(FlowFrameworkFeatureEnabledSetting flowFrameworkFeatureEnabledSetting) {
public RestSearchWorkflowStateAction(FlowFrameworkSettings flowFrameworkFeatureEnabledSetting) {
super(
List.of(SEARCH_WORKFLOW_STATE_PATH),
WORKFLOW_STATE_INDEX,
Expand Down
Loading

0 comments on commit a8e7ff5

Please sign in to comment.