-
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 <mariazrr@amazon.com>
- Loading branch information
Showing
18 changed files
with
517 additions
and
46 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
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
25 changes: 25 additions & 0 deletions
25
server/src/main/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsAction.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,25 @@ | ||
/* | ||
* 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.action.admin.cluster.wlm; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
/** | ||
* Transport action for obtaining QueryGroup Stats. | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class QueryGroupStatsAction extends ActionType<QueryGroupStatsResponse> { | ||
public static final QueryGroupStatsAction INSTANCE = new QueryGroupStatsAction(); | ||
public static final String NAME = "cluster:monitor/query_group_stats"; | ||
|
||
private QueryGroupStatsAction() { | ||
super(NAME, QueryGroupStatsResponse::new); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
server/src/main/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsRequest.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,45 @@ | ||
/* | ||
* 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.action.admin.cluster.wlm; | ||
|
||
import org.opensearch.action.support.nodes.BaseNodesRequest; | ||
import org.opensearch.common.annotation.ExperimentalApi; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* A request to get QueryGroupStats | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class QueryGroupStatsRequest extends BaseNodesRequest<QueryGroupStatsRequest> { | ||
|
||
protected QueryGroupStatsRequest(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
public QueryGroupStatsRequest() { | ||
super(false, (String[]) null); | ||
} | ||
|
||
/** | ||
* Get QueryGroup stats from nodes based on the nodes ids specified. If none are passed, stats | ||
* for all nodes will be returned. | ||
*/ | ||
public QueryGroupStatsRequest(String... nodesIds) { | ||
super(nodesIds); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
server/src/main/java/org/opensearch/action/admin/cluster/wlm/QueryGroupStatsResponse.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,72 @@ | ||
/* | ||
* 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.action.admin.cluster.wlm; | ||
|
||
import org.opensearch.action.FailedNodeException; | ||
import org.opensearch.action.support.nodes.BaseNodesResponse; | ||
import org.opensearch.cluster.ClusterName; | ||
import org.opensearch.common.annotation.ExperimentalApi; | ||
import org.opensearch.common.xcontent.XContentFactory; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.xcontent.ToXContentFragment; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import org.opensearch.wlm.stats.QueryGroupStats; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* A response for obtaining QueryGroupStats | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class QueryGroupStatsResponse extends BaseNodesResponse<QueryGroupStats> implements ToXContentFragment { | ||
|
||
QueryGroupStatsResponse(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
QueryGroupStatsResponse(ClusterName clusterName, List<QueryGroupStats> nodes, List<FailedNodeException> failures) { | ||
super(clusterName, nodes, failures); | ||
} | ||
|
||
@Override | ||
protected List<QueryGroupStats> readNodesFrom(StreamInput in) throws IOException { | ||
return in.readList(QueryGroupStats::new); | ||
} | ||
|
||
@Override | ||
protected void writeNodesTo(StreamOutput out, List<QueryGroupStats> nodes) throws IOException { | ||
out.writeList(nodes); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
for (QueryGroupStats queryGroupStats : getNodes()) { | ||
builder.startObject(queryGroupStats.getNode().getId()); | ||
queryGroupStats.toXContent(builder, params); | ||
builder.endObject(); | ||
} | ||
return builder; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
try { | ||
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint(); | ||
builder.startObject(); | ||
toXContent(builder, EMPTY_PARAMS); | ||
builder.endObject(); | ||
return builder.toString(); | ||
} catch (IOException e) { | ||
return "{ \"error\" : \"" + e.getMessage() + "\"}"; | ||
} | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
...src/main/java/org/opensearch/action/admin/cluster/wlm/TransportQueryGroupStatsAction.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,110 @@ | ||
/* | ||
* 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.action.admin.cluster.wlm; | ||
|
||
import org.opensearch.action.FailedNodeException; | ||
import org.opensearch.action.support.ActionFilters; | ||
import org.opensearch.action.support.nodes.TransportNodesAction; | ||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.inject.Inject; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.threadpool.ThreadPool; | ||
import org.opensearch.transport.TransportRequest; | ||
import org.opensearch.transport.TransportService; | ||
import org.opensearch.wlm.QueryGroupService; | ||
import org.opensearch.wlm.stats.QueryGroupStats; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* Transport action for obtaining QueryGroupStats | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public class TransportQueryGroupStatsAction extends TransportNodesAction< | ||
QueryGroupStatsRequest, | ||
QueryGroupStatsResponse, | ||
TransportQueryGroupStatsAction.NodeQueryGroupStatsRequest, | ||
QueryGroupStats> { | ||
|
||
QueryGroupService queryGroupService; | ||
|
||
@Inject | ||
public TransportQueryGroupStatsAction( | ||
ThreadPool threadPool, | ||
ClusterService clusterService, | ||
TransportService transportService, | ||
QueryGroupService queryGroupService, | ||
ActionFilters actionFilters | ||
) { | ||
super( | ||
QueryGroupStatsAction.NAME, | ||
threadPool, | ||
clusterService, | ||
transportService, | ||
actionFilters, | ||
QueryGroupStatsRequest::new, | ||
NodeQueryGroupStatsRequest::new, | ||
ThreadPool.Names.MANAGEMENT, | ||
QueryGroupStats.class | ||
); | ||
this.queryGroupService = queryGroupService; | ||
} | ||
|
||
@Override | ||
protected QueryGroupStatsResponse newResponse( | ||
QueryGroupStatsRequest request, | ||
List<QueryGroupStats> queryGroupStats, | ||
List<FailedNodeException> failures | ||
) { | ||
return new QueryGroupStatsResponse(clusterService.getClusterName(), queryGroupStats, failures); | ||
} | ||
|
||
@Override | ||
protected NodeQueryGroupStatsRequest newNodeRequest(QueryGroupStatsRequest request) { | ||
return new NodeQueryGroupStatsRequest(request); | ||
} | ||
|
||
@Override | ||
protected QueryGroupStats newNodeResponse(StreamInput in) throws IOException { | ||
return new QueryGroupStats(in); | ||
} | ||
|
||
@Override | ||
protected QueryGroupStats nodeOperation(NodeQueryGroupStatsRequest nodeQueryGroupStatsRequest) { | ||
return queryGroupService.nodeStats(); | ||
} | ||
|
||
/** | ||
* Inner QueryGroupStatsRequest | ||
* | ||
* @opensearch.experimental | ||
*/ | ||
public static class NodeQueryGroupStatsRequest extends TransportRequest { | ||
|
||
protected QueryGroupStatsRequest request; | ||
|
||
public NodeQueryGroupStatsRequest(StreamInput in) throws IOException { | ||
super(in); | ||
request = new QueryGroupStatsRequest(in); | ||
} | ||
|
||
NodeQueryGroupStatsRequest(QueryGroupStatsRequest request) { | ||
this.request = request; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
request.writeTo(out); | ||
} | ||
} | ||
} |
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.