-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
22 changed files
with
1,221 additions
and
7 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
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
...oad-management/src/main/java/org/opensearch/plugin/wlm/action/DeleteQueryGroupAction.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 for delete QueryGroup | ||
* | ||
* @opensearch.api | ||
*/ | ||
public class DeleteQueryGroupAction extends ActionType<DeleteQueryGroupResponse> { | ||
|
||
/** | ||
/** | ||
* An instance of DeleteQueryGroupAction | ||
*/ | ||
public static final DeleteQueryGroupAction INSTANCE = new DeleteQueryGroupAction(); | ||
|
||
/** | ||
* Name for DeleteQueryGroupAction | ||
*/ | ||
public static final String NAME = "cluster:admin/opensearch/wlm/query_group/_delete"; | ||
|
||
/** | ||
* Default constructor | ||
*/ | ||
private DeleteQueryGroupAction() { | ||
super(NAME, DeleteQueryGroupResponse::new); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...ad-management/src/main/java/org/opensearch/plugin/wlm/action/DeleteQueryGroupRequest.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,74 @@ | ||
/* | ||
* 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 delete QueryGroup | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class DeleteQueryGroupRequest extends ActionRequest implements Writeable.Reader<DeleteQueryGroupRequest> { | ||
String name; | ||
|
||
/** | ||
* Default constructor for DeleteQueryGroupRequest | ||
* @param name - name for the QueryGroup to get | ||
*/ | ||
public DeleteQueryGroupRequest(String name) { | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Constructor for DeleteQueryGroupRequest | ||
* @param in - A {@link StreamInput} object | ||
*/ | ||
public DeleteQueryGroupRequest(StreamInput in) throws IOException { | ||
super(in); | ||
name = in.readOptionalString(); | ||
} | ||
|
||
@Override | ||
public DeleteQueryGroupRequest read(StreamInput in) throws IOException { | ||
return new DeleteQueryGroupRequest(in); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
/** | ||
* Name getter | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* Name setter | ||
* @param name - name to be set | ||
*/ | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeOptionalString(name); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...d-management/src/main/java/org/opensearch/plugin/wlm/action/DeleteQueryGroupResponse.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 delete API for QueryGroup | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class DeleteQueryGroupResponse extends ActionResponse implements ToXContent, ToXContentObject { | ||
private final List<QueryGroup> queryGroups; | ||
private RestStatus restStatus; | ||
|
||
/** | ||
* Constructor for DeleteQueryGroupResponse | ||
* @param queryGroups - The QueryGroup list to be fetched | ||
* @param restStatus - The rest status for this response | ||
*/ | ||
public DeleteQueryGroupResponse(final List<QueryGroup> queryGroups, RestStatus restStatus) { | ||
this.queryGroups = queryGroups; | ||
this.restStatus = restStatus; | ||
} | ||
|
||
/** | ||
* Constructor for DeleteQueryGroupResponse | ||
* @param in - A {@link StreamInput} object | ||
*/ | ||
public DeleteQueryGroupResponse(StreamInput in) throws IOException { | ||
this.queryGroups = in.readList(QueryGroup::new); | ||
this.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("deleted"); | ||
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
...ement/src/main/java/org/opensearch/plugin/wlm/action/TransportDeleteQueryGroupAction.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 delete QueryGroup | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class TransportDeleteQueryGroupAction extends HandledTransportAction<DeleteQueryGroupRequest, DeleteQueryGroupResponse> { | ||
|
||
private final ThreadPool threadPool; | ||
private final Persistable<QueryGroup> queryGroupPersistenceService; | ||
|
||
/** | ||
* Constructor for TransportDeleteQueryGroupAction | ||
* | ||
* @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 TransportDeleteQueryGroupAction( | ||
String actionName, | ||
TransportService transportService, | ||
ActionFilters actionFilters, | ||
ThreadPool threadPool, | ||
Persistable<QueryGroup> queryGroupPersistenceService | ||
) { | ||
super(DeleteQueryGroupAction.NAME, transportService, actionFilters, DeleteQueryGroupRequest::new); | ||
this.threadPool = threadPool; | ||
this.queryGroupPersistenceService = queryGroupPersistenceService; | ||
} | ||
|
||
@Override | ||
protected void doExecute(Task task, DeleteQueryGroupRequest request, ActionListener<DeleteQueryGroupResponse> listener) { | ||
String name = request.getName(); | ||
threadPool.executor(ThreadPool.Names.GENERIC).execute(() -> queryGroupPersistenceService.delete(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.RestDeleteQueryGroupAction; | ||
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<>(DeleteQueryGroupAction.INSTANCE, TransportDeleteQueryGroupAction.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 RestDeleteQueryGroupAction()); | ||
} | ||
|
||
@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.