Skip to content

Commit

Permalink
structure resourceLimits into an object
Browse files Browse the repository at this point in the history
Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com>
  • Loading branch information
kaushalmahi12 committed Jun 25, 2024
1 parent 4508c9d commit 1e45475
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
* Class to define the QueryGroup schema
* {
* "_id": "fafjafjkaf9ag8a9ga9g7ag0aagaga",
* "jvm": 0.4,
* "resourceLimits": {
* "jvm": 0.4
* },
* "resiliency_mode": "enforced",
* "name": "analytics",
* "updatedAt": 4513232415
Expand Down Expand Up @@ -137,9 +139,13 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
builder.field("name", name);
builder.field("resiliency_mode", resiliencyMode.getName());
builder.field("updatedAt", updatedAtInMillis);
// write resource limits
builder.startObject("resourceLimits");
for (Map.Entry<ResourceType, Object> resourceLimit : resourceLimits.entrySet()) {
builder.field(resourceLimit.getKey().getName(), resourceLimit.getValue());
}
builder.endObject();

builder.endObject();
return builder;
}
Expand Down Expand Up @@ -173,8 +179,22 @@ public static QueryGroup fromXContent(final XContentParser parser) throws IOExce
} else if (fieldName.equals("updatedAt")) {
builder.updatedAt(parser.longValue());
} else {
resourceLimits.put(ResourceType.fromName(fieldName), parser.doubleValue());
throw new IllegalArgumentException(fieldName + " is not a valid field in QueryGroup");
}
} else if (token == XContentParser.Token.START_OBJECT ) {

if (!fieldName.equals("resourceLimits")) {
throw new IllegalArgumentException("was expecting the { " + " but found " + token);
}

while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
fieldName = parser.currentName();
} else {
resourceLimits.put(ResourceType.fromName(fieldName), parser.doubleValue());
}
}

}
}
builder.resourceLimits(resourceLimits);
Expand Down

0 comments on commit 1e45475

Please sign in to comment.