Skip to content

Commit

Permalink
add _id as the resourceLimitGroup key
Browse files Browse the repository at this point in the history
Signed-off-by: Kaushal Kumar <[email protected]>
  • Loading branch information
kaushalmahi12 committed May 15, 2024
1 parent c7e56f4 commit bd1f864
Showing 1 changed file with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
/**
* Class to define the ResourceLimitGroup schema
* {
* "analytics":{
* "analytics" : {
* "jvm": 0.4,
* "mpde": "enforced",
* "mode": "enforced",
* "_id": "fafjafjkaf9ag8a9ga9g7ag0aagaga"
* }
* }
Expand Down Expand Up @@ -112,8 +112,8 @@ private void validateResourceLimits(Map<String, Object> 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();
Expand All @@ -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();

Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
}

}
Expand Down

0 comments on commit bd1f864

Please sign in to comment.