Skip to content

Commit a7f957d

Browse files
committed
rebase from main after the schema merged
Signed-off-by: Ruirui Zhang <[email protected]>
1 parent 9493f61 commit a7f957d

File tree

12 files changed

+171
-176
lines changed

12 files changed

+171
-176
lines changed

plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/querygroup/rest/RestDeleteQueryGroupAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
package org.opensearch.plugin.wlm.querygroup.rest;
1010

11-
import org.opensearch.plugin.wlm.action.DeleteQueryGroupAction;
12-
import org.opensearch.plugin.wlm.action.DeleteQueryGroupRequest;
11+
import org.opensearch.plugin.wlm.querygroup.action.DeleteQueryGroupAction;
12+
import org.opensearch.plugin.wlm.querygroup.action.DeleteQueryGroupRequest;
1313
import org.opensearch.rest.BaseRestHandler;
1414
import org.opensearch.rest.RestRequest;
1515
import org.opensearch.rest.action.RestToXContentListener;

plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/rule/QueryGroupAttribute.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
package org.opensearch.plugin.wlm.rule;
1010

1111
import org.opensearch.autotagging.Attribute;
12-
import org.opensearch.autotagging.AutoTaggingRegistry;
12+
13+
import java.util.HashMap;
14+
import java.util.Map;
1315

1416
/**
1517
* Attributes specific to the query group feature.
16-
* @opensearch.experimental
1718
*/
1819
public enum QueryGroupAttribute implements Attribute {
1920
INDEX_PATTERN("index_pattern");
@@ -22,24 +23,14 @@ public enum QueryGroupAttribute implements Attribute {
2223

2324
QueryGroupAttribute(String name) {
2425
this.name = name;
25-
}
26-
27-
static {
28-
for (QueryGroupAttribute attr : QueryGroupAttribute.values()) {
29-
attr.registerAttribute();
30-
}
26+
validateAttribute();
3127
}
3228

3329
@Override
3430
public String getName() {
3531
return name;
3632
}
3733

38-
@Override
39-
public void registerAttribute() {
40-
AutoTaggingRegistry.registerAttribute(this);
41-
}
42-
4334
public static QueryGroupAttribute fromName(String name) {
4435
for (QueryGroupAttribute attr : QueryGroupAttribute.values()) {
4536
if (attr.getName().equals(name)) {
@@ -48,4 +39,12 @@ public static QueryGroupAttribute fromName(String name) {
4839
}
4940
throw new IllegalArgumentException("Unknown QueryGroupAttribute: " + name);
5041
}
42+
43+
public static Map<String, Attribute> toMap() {
44+
Map<String, Attribute> map = new HashMap<>();
45+
for (QueryGroupAttribute attr : QueryGroupAttribute.values()) {
46+
map.put(attr.getName(), attr);
47+
}
48+
return map;
49+
}
5150
}

plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/rule/QueryGroupFeatureType.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@
1212
import org.opensearch.autotagging.AutoTaggingRegistry;
1313
import org.opensearch.autotagging.FeatureType;
1414

15-
import java.util.Set;
15+
import java.util.Map;
1616

17-
/**
18-
* Represents the feature type for "query_group" in the OpenSearch workload management plugin.
19-
* @opensearch.experimental
20-
*/
2117
public class QueryGroupFeatureType implements FeatureType {
2218
public static final QueryGroupFeatureType INSTANCE = new QueryGroupFeatureType();
2319
public static final String NAME = "query_group";
2420
private static final int MAX_ATTRIBUTE_VALUES = 10;
2521
private static final int MAX_ATTRIBUTE_VALUE_LENGTH = 100;
26-
private static final Set<Attribute> ALLOWED_ATTRIBUTES = Set.of(QueryGroupAttribute.values());
22+
private static final Map<String, Attribute> ALLOWED_ATTRIBUTES = QueryGroupAttribute.toMap();
2723

2824
private QueryGroupFeatureType() {}
2925

@@ -47,7 +43,7 @@ public int getMaxCharLengthPerAttributeValue() {
4743
}
4844

4945
@Override
50-
public Set<Attribute> getAllowedAttributes() {
46+
public Map<String, Attribute> getAllowedAttributesRegistry() {
5147
return ALLOWED_ATTRIBUTES;
5248
}
5349

plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/rule/action/GetRuleRequest.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.opensearch.autotagging.Attribute;
1414
import org.opensearch.core.common.io.stream.StreamInput;
1515
import org.opensearch.core.common.io.stream.StreamOutput;
16+
import org.opensearch.plugin.wlm.rule.QueryGroupFeatureType;
1617

1718
import java.io.IOException;
1819
import java.util.HashSet;
@@ -28,18 +29,18 @@
2829
* @opensearch.experimental
2930
*/
3031
public class GetRuleRequest extends ActionRequest {
31-
private final String _id;
32+
private final String id;
3233
private final Map<Attribute, Set<String>> attributeFilters;
3334
private final String searchAfter;
3435

3536
/**
3637
* Constructor for GetRuleRequest
37-
* @param _id - Rule _id that we want to get
38+
* @param id - Rule id that we want to get
3839
* @param attributeFilters - Attributes that we want to filter on
3940
* @param searchAfter - The sort values from the last document of the previous page, used for pagination
4041
*/
41-
public GetRuleRequest(String _id, Map<Attribute, Set<String>> attributeFilters, String searchAfter) {
42-
this._id = _id;
42+
public GetRuleRequest(String id, Map<Attribute, Set<String>> attributeFilters, String searchAfter) {
43+
this.id = id;
4344
this.attributeFilters = attributeFilters;
4445
this.searchAfter = searchAfter;
4546
}
@@ -50,8 +51,8 @@ public GetRuleRequest(String _id, Map<Attribute, Set<String>> attributeFilters,
5051
*/
5152
public GetRuleRequest(StreamInput in) throws IOException {
5253
super(in);
53-
_id = in.readOptionalString();
54-
attributeFilters = in.readMap(Attribute::from, i -> new HashSet<>(i.readStringList()));
54+
id = in.readOptionalString();
55+
attributeFilters = in.readMap(i -> Attribute.from(i, QueryGroupFeatureType.INSTANCE), i -> new HashSet<>(i.readStringList()));
5556
searchAfter = in.readOptionalString();
5657
}
5758

@@ -63,16 +64,16 @@ public ActionRequestValidationException validate() {
6364
@Override
6465
public void writeTo(StreamOutput out) throws IOException {
6566
super.writeTo(out);
66-
out.writeOptionalString(_id);
67+
out.writeOptionalString(id);
6768
out.writeMap(attributeFilters, (output, attribute) -> attribute.writeTo(output), StreamOutput::writeStringCollection);
6869
out.writeOptionalString(searchAfter);
6970
}
7071

7172
/**
72-
* _id getter
73+
* id getter
7374
*/
74-
public String get_id() {
75-
return _id;
75+
public String getId() {
76+
return id;
7677
}
7778

7879
/**

plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/rule/action/GetRuleResponse.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.opensearch.core.xcontent.ToXContent;
1717
import org.opensearch.core.xcontent.ToXContentObject;
1818
import org.opensearch.core.xcontent.XContentBuilder;
19-
import org.opensearch.plugin.wlm.rule.QueryGroupFeatureType;
2019

2120
import java.io.IOException;
2221
import java.util.Map;
@@ -43,7 +42,7 @@
4342
* @opensearch.experimental
4443
*/
4544
public class GetRuleResponse extends ActionResponse implements ToXContent, ToXContentObject {
46-
private final Map<String, Rule<QueryGroupFeatureType>> rules;
45+
private final Map<String, Rule> rules;
4746
private final String searchAfter;
4847
private final RestStatus restStatus;
4948

@@ -53,7 +52,7 @@ public class GetRuleResponse extends ActionResponse implements ToXContent, ToXCo
5352
* @param searchAfter - The searchAfter field for the response
5453
* @param restStatus - The restStatus for the response
5554
*/
56-
public GetRuleResponse(final Map<String, Rule<QueryGroupFeatureType>> rules, String searchAfter, RestStatus restStatus) {
55+
public GetRuleResponse(final Map<String, Rule> rules, String searchAfter, RestStatus restStatus) {
5756
this.rules = rules;
5857
this.searchAfter = searchAfter;
5958
this.restStatus = restStatus;
@@ -78,7 +77,7 @@ public void writeTo(StreamOutput out) throws IOException {
7877
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
7978
builder.startObject();
8079
builder.startArray("rules");
81-
for (Map.Entry<String, Rule<QueryGroupFeatureType>> entry : rules.entrySet()) {
80+
for (Map.Entry<String, Rule> entry : rules.entrySet()) {
8281
entry.getValue().toXContent(builder, new MapParams(Map.of(_ID_STRING, entry.getKey())));
8382
}
8483
builder.endArray();
@@ -92,7 +91,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
9291
/**
9392
* rules getter
9493
*/
95-
public Map<String, Rule<QueryGroupFeatureType>> getRules() {
94+
public Map<String, Rule> getRules() {
9695
return rules;
9796
}
9897

plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/rule/action/TransportGetRuleAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public TransportGetRuleAction(
4242

4343
@Override
4444
protected void doExecute(Task task, GetRuleRequest request, ActionListener<GetRuleResponse> listener) {
45-
rulePersistenceService.getRule(request.get_id(), request.getAttributeFilters(), request.getSearchAfter(), listener);
45+
rulePersistenceService.getRule(request.getId(), request.getAttributeFilters(), request.getSearchAfter(), listener);
4646
}
4747
}

plugins/workload-management/src/main/java/org/opensearch/plugin/wlm/rule/rest/RestGetRuleAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package org.opensearch.plugin.wlm.rule.rest;
1010

1111
import org.opensearch.autotagging.Attribute;
12-
import org.opensearch.client.node.NodeClient;
1312
import org.opensearch.core.rest.RestStatus;
1413
import org.opensearch.core.xcontent.ToXContent;
1514
import org.opensearch.plugin.wlm.rule.QueryGroupAttribute;
@@ -22,6 +21,7 @@
2221
import org.opensearch.rest.RestRequest;
2322
import org.opensearch.rest.RestResponse;
2423
import org.opensearch.rest.action.RestResponseListener;
24+
import org.opensearch.transport.client.node.NodeClient;
2525

2626
import java.io.IOException;
2727
import java.util.Arrays;

0 commit comments

Comments
 (0)