From bd1f864d71bd80ed75cb3db15a46463ee5b07008 Mon Sep 17 00:00:00 2001 From: Kaushal Kumar Date: Wed, 15 May 2024 14:56:43 -0700 Subject: [PATCH] add _id as the resourceLimitGroup key Signed-off-by: Kaushal Kumar --- .../cluster/metadata/ResourceLimitGroup.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/server/src/main/java/org/opensearch/cluster/metadata/ResourceLimitGroup.java b/server/src/main/java/org/opensearch/cluster/metadata/ResourceLimitGroup.java index 7feee416b8b67..46183faa705fb 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/ResourceLimitGroup.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/ResourceLimitGroup.java @@ -27,9 +27,9 @@ /** * Class to define the ResourceLimitGroup schema * { - * "analytics":{ + * "analytics" : { * "jvm": 0.4, - * "mpde": "enforced", + * "mode": "enforced", * "_id": "fafjafjkaf9ag8a9ga9g7ag0aagaga" * } * } @@ -112,8 +112,8 @@ private void validateResourceLimits(Map resourceLimits) { @Override public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { builder.startObject(); - builder.startObject(this.name); - builder.field("_id", _id); + builder.startObject(this._id); + builder.field("name", name); builder.field("mode", mode.getName()); builder.mapContents(resourceLimits); builder.endObject(); @@ -132,7 +132,7 @@ public static ResourceLimitGroup fromXContent(final XContentParser parser) throw throw new IllegalArgumentException("Expected FIELD_NAME token but found [" + parser.currentName() + "]"); } - Builder builder = builder().name(parser.currentName()); + Builder builder = builder()._id(parser.currentName()); XContentParser.Token token = parser.nextToken(); @@ -147,8 +147,8 @@ public static ResourceLimitGroup fromXContent(final XContentParser parser) throw if (token == XContentParser.Token.FIELD_NAME) { fieldName = parser.currentName(); } else if (token.isValue()) { - if (fieldName.equals("_id")) { - builder._id(parser.text()); + if (fieldName.equals("name")) { + builder.name(parser.text()); } else if (fieldName.equals("mode")) { builder.mode(parser.text()); } else if (ALLOWED_RESOURCES.contains(fieldName)) { @@ -219,16 +219,12 @@ public String getName() { } public static ResourceLimitGroupMode fromName(String s) { - switch (s) { - case "soft": - return SOFT; - case "enforced": - return ENFORCED; - case "monitor": - return MONITOR; - default: - throw new IllegalArgumentException("Invalid value for ResourceLimitGroupMode: " + s); + for (ResourceLimitGroupMode mode: values()) { + if (mode.getName().equalsIgnoreCase(s)) + return mode; + } + throw new IllegalArgumentException("Invalid value for ResourceLimitGroupMode: " + s); } }