-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ruirui Zhang <[email protected]>
- Loading branch information
Showing
21 changed files
with
1,128 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
opensearchplugin { | ||
description 'OpenSearch Workload Management Plugin.' | ||
classname 'org.opensearch.plugin.wlm.action.WorkloadManagementPlugin' | ||
} | ||
|
||
dependencies { | ||
} |
37 changes: 37 additions & 0 deletions
37
...rkload-management/src/main/java/org/opensearch/plugin/wlm/action/GetQueryGroupAction.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,37 @@ | ||
/* | ||
* 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.plugin.wlm.action; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
/** | ||
* Transport action to get QueryGroup | ||
* | ||
* @opensearch.api | ||
*/ | ||
public class GetQueryGroupAction extends ActionType<GetQueryGroupResponse> { | ||
|
||
/** | ||
/** | ||
* An instance of GetQueryGroupAction | ||
*/ | ||
public static final GetQueryGroupAction INSTANCE = new GetQueryGroupAction(); | ||
|
||
/** | ||
* Name for GetQueryGroupAction | ||
*/ | ||
public static final String NAME = "cluster:admin/opensearch/query_group/wlm/_get"; | ||
|
||
/** | ||
* Default constructor | ||
*/ | ||
private GetQueryGroupAction() { | ||
super(NAME, GetQueryGroupResponse::new); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...kload-management/src/main/java/org/opensearch/plugin/wlm/action/GetQueryGroupRequest.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,66 @@ | ||
/* | ||
* 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.plugin.wlm.action; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* A request for get QueryGroup | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class GetQueryGroupRequest extends ActionRequest implements Writeable.Reader<GetQueryGroupRequest> { | ||
String name; | ||
|
||
/** | ||
* Default constructor for GetQueryGroupRequest | ||
* @param name - name for the QueryGroup to get | ||
*/ | ||
public GetQueryGroupRequest(String name) { | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Constructor for GetQueryGroupRequest | ||
* @param in - A {@link StreamInput} object | ||
*/ | ||
public GetQueryGroupRequest(StreamInput in) throws IOException { | ||
super(in); | ||
name = in.readOptionalString(); | ||
} | ||
|
||
@Override | ||
public GetQueryGroupRequest read(StreamInput in) throws IOException { | ||
return new GetQueryGroupRequest(in); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
/** | ||
* Name getter | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeOptionalString(name); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...load-management/src/main/java/org/opensearch/plugin/wlm/action/GetQueryGroupResponse.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,82 @@ | ||
/* | ||
* 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.plugin.wlm.action; | ||
|
||
import org.opensearch.cluster.metadata.QueryGroup; | ||
import org.opensearch.core.action.ActionResponse; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.rest.RestStatus; | ||
import org.opensearch.core.xcontent.ToXContent; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* Response for the get API for QueryGroup | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class GetQueryGroupResponse extends ActionResponse implements ToXContent, ToXContentObject { | ||
private final List<QueryGroup> queryGroups; | ||
private RestStatus restStatus; | ||
|
||
/** | ||
* Constructor for GetQueryGroupResponse | ||
* @param queryGroups - The QueryGroup list to be fetched | ||
* @param restStatus - The rest status of the request | ||
*/ | ||
public GetQueryGroupResponse(final List<QueryGroup> queryGroups, RestStatus restStatus) { | ||
this.queryGroups = queryGroups; | ||
this.restStatus = restStatus; | ||
} | ||
|
||
/** | ||
* Constructor for GetQueryGroupResponse | ||
* @param in - A {@link StreamInput} object | ||
*/ | ||
public GetQueryGroupResponse(StreamInput in) throws IOException { | ||
this.queryGroups = in.readList(QueryGroup::new); | ||
restStatus = RestStatus.readFrom(in); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeList(queryGroups); | ||
RestStatus.writeTo(out, restStatus); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.startArray("query_groups"); | ||
for (QueryGroup group : queryGroups) { | ||
group.toXContent(builder, params); | ||
} | ||
builder.endArray(); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
/** | ||
* queryGroups getter | ||
*/ | ||
public List<QueryGroup> getQueryGroups() { | ||
return queryGroups; | ||
} | ||
|
||
/** | ||
* restStatus getter | ||
*/ | ||
public RestStatus getRestStatus() { | ||
return restStatus; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...nagement/src/main/java/org/opensearch/plugin/wlm/action/TransportGetQueryGroupAction.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,58 @@ | ||
/* | ||
* 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.plugin.wlm.action; | ||
|
||
import org.opensearch.action.support.ActionFilters; | ||
import org.opensearch.action.support.HandledTransportAction; | ||
import org.opensearch.cluster.metadata.QueryGroup; | ||
import org.opensearch.common.inject.Inject; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.plugin.wlm.action.service.Persistable; | ||
import org.opensearch.tasks.Task; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.transport.TransportService; | ||
|
||
/** | ||
* Transport action for get QueryGroup | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class TransportGetQueryGroupAction extends HandledTransportAction<GetQueryGroupRequest, GetQueryGroupResponse> { | ||
|
||
private final ThreadPool threadPool; | ||
private final Persistable<QueryGroup> queryGroupPersistenceService; | ||
|
||
/** | ||
* Constructor for TransportGetQueryGroupAction | ||
* | ||
* @param actionName - action name | ||
* @param transportService - a {@link TransportService} object | ||
* @param actionFilters - a {@link ActionFilters} object | ||
* @param threadPool - a {@link ThreadPool} object | ||
* @param queryGroupPersistenceService - a {@link Persistable} object | ||
*/ | ||
@Inject | ||
public TransportGetQueryGroupAction( | ||
String actionName, | ||
TransportService transportService, | ||
ActionFilters actionFilters, | ||
ThreadPool threadPool, | ||
Persistable<QueryGroup> queryGroupPersistenceService | ||
) { | ||
super(GetQueryGroupAction.NAME, transportService, actionFilters, GetQueryGroupRequest::new); | ||
this.threadPool = threadPool; | ||
this.queryGroupPersistenceService = queryGroupPersistenceService; | ||
} | ||
|
||
@Override | ||
protected void doExecute(Task task, GetQueryGroupRequest request, ActionListener<GetQueryGroupResponse> listener) { | ||
String name = request.getName(); | ||
threadPool.executor(ThreadPool.Names.GENERIC).execute(() -> queryGroupPersistenceService.get(name, listener)); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...d-management/src/main/java/org/opensearch/plugin/wlm/action/WorkloadManagementPlugin.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,62 @@ | ||
/* | ||
* 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.plugin.wlm.action; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.opensearch.cluster.node.DiscoveryNodes; | ||
import org.opensearch.common.inject.Module; | ||
import org.opensearch.common.settings.ClusterSettings; | ||
import org.opensearch.common.settings.IndexScopedSettings; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.settings.SettingsFilter; | ||
import org.opensearch.core.action.ActionResponse; | ||
import org.opensearch.plugin.wlm.action.rest.RestGetQueryGroupAction; | ||
import org.opensearch.plugins.ActionPlugin; | ||
import org.opensearch.plugins.Plugin; | ||
import org.opensearch.rest.RestController; | ||
import org.opensearch.rest.RestHandler; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Plugin class for WorkloadManagement | ||
*/ | ||
public class WorkloadManagementPlugin extends Plugin implements ActionPlugin { | ||
|
||
/** | ||
* Default constructor | ||
*/ | ||
public WorkloadManagementPlugin() {} | ||
|
||
@Override | ||
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() { | ||
return List.of(new ActionPlugin.ActionHandler<>(GetQueryGroupAction.INSTANCE, TransportGetQueryGroupAction.class)); | ||
} | ||
|
||
@Override | ||
public List<RestHandler> getRestHandlers( | ||
Settings settings, | ||
RestController restController, | ||
ClusterSettings clusterSettings, | ||
IndexScopedSettings indexScopedSettings, | ||
SettingsFilter settingsFilter, | ||
IndexNameExpressionResolver indexNameExpressionResolver, | ||
Supplier<DiscoveryNodes> nodesInCluster | ||
) { | ||
return List.of(new RestGetQueryGroupAction()); | ||
} | ||
|
||
@Override | ||
public Collection<Module> createGuiceModules() { | ||
return List.of(new WorkloadManagementPluginModule()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...gement/src/main/java/org/opensearch/plugin/wlm/action/WorkloadManagementPluginModule.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,32 @@ | ||
/* | ||
* 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.plugin.wlm.action; | ||
|
||
import org.opensearch.cluster.metadata.QueryGroup; | ||
import org.opensearch.common.inject.AbstractModule; | ||
import org.opensearch.common.inject.TypeLiteral; | ||
import org.opensearch.plugin.wlm.action.service.Persistable; | ||
import org.opensearch.plugin.wlm.action.service.QueryGroupPersistenceService; | ||
|
||
/** | ||
* Guice Module to manage WorkloadManagement related objects | ||
*/ | ||
public class WorkloadManagementPluginModule extends AbstractModule { | ||
|
||
/** | ||
* Constructor for WorkloadManagementPluginModule | ||
*/ | ||
public WorkloadManagementPluginModule() {} | ||
|
||
@Override | ||
protected void configure() { | ||
bind(new TypeLiteral<Persistable<QueryGroup>>() { | ||
}).to(QueryGroupPersistenceService.class).asEagerSingleton(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/action/package-info.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,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Base Package of CRUD API of QueryGroup | ||
*/ | ||
package org.opensearch.plugin.wlm.action; |
Oops, something went wrong.