Skip to content

Commit 84d43f0

Browse files
committed
modify based on comments
Signed-off-by: Ruirui Zhang <[email protected]>
1 parent 805cefc commit 84d43f0

File tree

50 files changed

+354
-388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+354
-388
lines changed

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/RulePersistenceService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
import org.opensearch.action.support.clustermanager.AcknowledgedResponse;
1212
import org.opensearch.core.action.ActionListener;
13+
import org.opensearch.rule.action.CreateRuleRequest;
14+
import org.opensearch.rule.action.CreateRuleResponse;
15+
import org.opensearch.rule.action.DeleteRuleRequest;
16+
import org.opensearch.rule.action.GetRuleRequest;
17+
import org.opensearch.rule.action.GetRuleResponse;
18+
import org.opensearch.rule.action.UpdateRuleRequest;
19+
import org.opensearch.rule.action.UpdateRuleResponse;
1320

1421
/**
1522
* Interface for a service that handles rule persistence CRUD operations.

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/RuleQueryMapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package org.opensearch.rule;
1010

1111
import org.opensearch.common.annotation.ExperimentalApi;
12+
import org.opensearch.rule.action.GetRuleRequest;
1213

1314
/**
1415
* This interface is responsible for creating query objects which storage layer can use

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/RuleRoutingService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
package org.opensearch.rule;
1010

1111
import org.opensearch.core.action.ActionListener;
12+
import org.opensearch.rule.action.CreateRuleRequest;
13+
import org.opensearch.rule.action.CreateRuleResponse;
14+
import org.opensearch.rule.action.UpdateRuleRequest;
15+
import org.opensearch.rule.action.UpdateRuleResponse;
1216

1317
/**
1418
* Interface that handles rule routing logic

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/RuleUtils.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
package org.opensearch.rule;
1010

1111
import org.opensearch.common.annotation.ExperimentalApi;
12+
import org.opensearch.rule.action.UpdateRuleRequest;
1213
import org.opensearch.rule.autotagging.Attribute;
1314
import org.opensearch.rule.autotagging.FeatureType;
1415
import org.opensearch.rule.autotagging.Rule;
1516

1617
import java.nio.charset.StandardCharsets;
1718
import java.time.Instant;
1819
import java.util.Collections;
20+
import java.util.List;
1921
import java.util.Map;
2022
import java.util.Optional;
2123
import java.util.Set;
@@ -60,12 +62,11 @@ public static String computeRuleHash(
6062
* between the current rule and the one being checked.
6163
*
6264
* @param rule The rule to be validated against ruleMap.
63-
* @param ruleMap This map contains existing rules to be checked
65+
* @param ruleList This list contains existing rules to be checked
6466
*/
65-
public static Optional<String> getDuplicateRuleId(Rule rule, Map<String, Rule> ruleMap) {
67+
public static Optional<String> getDuplicateRuleId(Rule rule, List<Rule> ruleList) {
6668
Map<Attribute, Set<String>> targetAttributeMap = rule.getAttributeMap();
67-
for (Map.Entry<String, Rule> entry : ruleMap.entrySet()) {
68-
Rule currRule = entry.getValue();
69+
for (Rule currRule : ruleList) {
6970
Map<Attribute, Set<String>> existingAttributeMap = currRule.getAttributeMap();
7071

7172
if (rule.getFeatureType() != currRule.getFeatureType() || targetAttributeMap.size() != existingAttributeMap.size()) {
@@ -81,7 +82,7 @@ public static Optional<String> getDuplicateRuleId(Rule rule, Map<String, Rule> r
8182
}
8283
}
8384
if (allAttributesIntersect) {
84-
return Optional.of(entry.getKey());
85+
return Optional.of(currRule.getId());
8586
}
8687
}
8788
return Optional.empty();

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/UpdatedRuleBuilder.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/CreateRuleRequest.java renamed to modules/autotagging-commons/common/src/main/java/org/opensearch/rule/action/CreateRuleRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.rule;
9+
package org.opensearch.rule.action;
1010

1111
import org.opensearch.action.ActionRequest;
1212
import org.opensearch.action.ActionRequestValidationException;

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/CreateRuleResponse.java renamed to modules/autotagging-commons/common/src/main/java/org/opensearch/rule/action/CreateRuleResponse.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.rule;
9+
package org.opensearch.rule.action;
1010

1111
import org.opensearch.core.action.ActionResponse;
1212
import org.opensearch.core.common.io.stream.StreamInput;
@@ -22,7 +22,7 @@
2222
* Response for the create API for Rule
2323
* Example response:
2424
* {
25-
* "_id":"wi6VApYBoX5wstmtU_8l",
25+
* "id":"wi6VApYBoX5wstmtU_8l",
2626
* "description":"description1",
2727
* "index_pattern":["log*", "uvent*"],
2828
* "workload_group":"poOiU851RwyLYvV5lbvv5w",
@@ -31,16 +31,13 @@
3131
* @opensearch.experimental
3232
*/
3333
public class CreateRuleResponse extends ActionResponse implements ToXContent, ToXContentObject {
34-
private final String _id;
3534
private final Rule rule;
3635

3736
/**
3837
* contructor for CreateRuleResponse
39-
* @param id - the id for the rule created
4038
* @param rule - the rule created
4139
*/
42-
public CreateRuleResponse(String id, final Rule rule) {
43-
this._id = id;
40+
public CreateRuleResponse(final Rule rule) {
4441
this.rule = rule;
4542
}
4643

@@ -49,13 +46,11 @@ public CreateRuleResponse(String id, final Rule rule) {
4946
* @param in - The {@link StreamInput} instance to read from.
5047
*/
5148
public CreateRuleResponse(StreamInput in) throws IOException {
52-
_id = in.readString();
5349
rule = new Rule(in);
5450
}
5551

5652
@Override
5753
public void writeTo(StreamOutput out) throws IOException {
58-
out.writeString(_id);
5954
rule.writeTo(out);
6055
}
6156

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/DeleteRuleRequest.java renamed to modules/autotagging-commons/common/src/main/java/org/opensearch/rule/action/DeleteRuleRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.rule;
9+
package org.opensearch.rule.action;
1010

1111
import org.opensearch.action.ActionRequest;
1212
import org.opensearch.action.ActionRequestValidationException;
@@ -80,7 +80,7 @@ public String getRuleId() {
8080
*
8181
* @return The feature type.
8282
*/
83-
public FeatureType getFeatureType() {
83+
FeatureType getFeatureType() {
8484
return featureType;
8585
}
8686
}

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/GetRuleRequest.java renamed to modules/autotagging-commons/common/src/main/java/org/opensearch/rule/action/GetRuleRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.rule;
9+
package org.opensearch.rule.action;
1010

1111
import org.opensearch.action.ActionRequest;
1212
import org.opensearch.action.ActionRequestValidationException;
@@ -67,7 +67,7 @@ public GetRuleRequest(StreamInput in) throws IOException {
6767
@Override
6868
public ActionRequestValidationException validate() {
6969
if (RuleValidator.isEmpty(id)) {
70-
throw new IllegalArgumentException(Rule._ID_STRING + " cannot be empty.");
70+
throw new IllegalArgumentException(Rule.ID_STRING + " cannot be empty.");
7171
}
7272
if (RuleValidator.isEmpty(searchAfter)) {
7373
throw new IllegalArgumentException("search_after cannot be empty.");

modules/autotagging-commons/common/src/main/java/org/opensearch/rule/GetRuleResponse.java renamed to modules/autotagging-commons/common/src/main/java/org/opensearch/rule/action/GetRuleResponse.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.rule;
9+
package org.opensearch.rule.action;
1010

1111
import org.opensearch.common.annotation.ExperimentalApi;
1212
import org.opensearch.core.action.ActionResponse;
@@ -18,15 +18,15 @@
1818
import org.opensearch.rule.autotagging.Rule;
1919

2020
import java.io.IOException;
21-
import java.util.Map;
21+
import java.util.List;
2222

2323
/**
2424
* Response for the get API for Rule.
2525
* Example response:
2626
* {
2727
* "rules": [
2828
* {
29-
* "_id": "z1MJApUB0zgMcDmz-UQq",
29+
* "id": "z1MJApUB0zgMcDmz-UQq",
3030
* "description": "Rule for tagging workload_group_id to index123"
3131
* "index_pattern": ["index123"],
3232
* "workload_group": "workload_group_id",
@@ -40,15 +40,15 @@
4040
*/
4141
@ExperimentalApi
4242
public class GetRuleResponse extends ActionResponse implements ToXContent, ToXContentObject {
43-
private final Map<String, Rule> rules;
43+
private final List<Rule> rules;
4444
private final String searchAfter;
4545

4646
/**
4747
* Constructor for GetRuleResponse
4848
* @param rules - Rules get from the request
4949
* @param searchAfter - The sort value used for pagination.
5050
*/
51-
public GetRuleResponse(final Map<String, Rule> rules, String searchAfter) {
51+
public GetRuleResponse(final List<Rule> rules, String searchAfter) {
5252
this.rules = rules;
5353
this.searchAfter = searchAfter;
5454
}
@@ -58,21 +58,21 @@ public GetRuleResponse(final Map<String, Rule> rules, String searchAfter) {
5858
* @param in - The {@link StreamInput} instance to read from.
5959
*/
6060
public GetRuleResponse(StreamInput in) throws IOException {
61-
this(in.readMap(StreamInput::readString, Rule::new), in.readOptionalString());
61+
this(in.readList(Rule::new), in.readOptionalString());
6262
}
6363

6464
@Override
6565
public void writeTo(StreamOutput out) throws IOException {
66-
out.writeMap(rules, StreamOutput::writeString, (outStream, rule) -> rule.writeTo(outStream));
66+
out.writeList(rules);
6767
out.writeOptionalString(searchAfter);
6868
}
6969

7070
@Override
7171
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
7272
builder.startObject();
7373
builder.startArray("rules");
74-
for (Map.Entry<String, Rule> entry : rules.entrySet()) {
75-
entry.getValue().toXContent(builder, params);
74+
for (Rule rule : rules) {
75+
rule.toXContent(builder, params);
7676
}
7777
builder.endArray();
7878
if (searchAfter != null && !searchAfter.isEmpty()) {
@@ -85,7 +85,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
8585
/**
8686
* rules getter
8787
*/
88-
public Map<String, Rule> getRules() {
88+
public List<Rule> getRules() {
8989
return rules;
9090
}
9191
}

0 commit comments

Comments
 (0)