Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jsonify customized metadata on management API #3059

Merged
merged 8 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
import java.util.Date;
import java.util.List;

import org.pytorch.serve.ModelServer;
import org.pytorch.serve.util.JsonUtils;
import com.google.gson.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DescribeModelResponse {
private Logger logger = LoggerFactory.getLogger(ModelServer.class);

private String modelName;
private String modelVersion;
Expand All @@ -22,7 +29,7 @@ public class DescribeModelResponse {
private List<Worker> workers;
private Metrics metrics;
private JobQueueStatus jobQueueStatus;
private String customizedMetadata;
private JsonObject customizedMetadata;

public DescribeModelResponse() {
workers = new ArrayList<>();
Expand Down Expand Up @@ -160,10 +167,16 @@ public void setJobQueueStatus(JobQueueStatus jobQueueStatus) {
}

public void setCustomizedMetadata(byte[] customizedMetadata) {
this.customizedMetadata = new String(customizedMetadata, Charset.forName("UTF-8"));
String stringMetadata = new String(customizedMetadata, Charset.forName("UTF-8"));
try {
this.customizedMetadata = JsonUtils.GSON.fromJson(stringMetadata, JsonObject.class);
} catch(com.google.gson.JsonSyntaxException ex) {
logger.warn("Customized metadata should be a dictionary.");
this.customizedMetadata = new JsonObject();
}
}

public String getCustomizedMetadata() {
public JsonObject getCustomizedMetadata() {
return customizedMetadata;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ public void testNoopCustomized() throws InterruptedException {
DescribeModelResponse[] resp =
JsonUtils.GSON.fromJson(TestUtils.getResult(), DescribeModelResponse[].class);
Assert.assertEquals(
resp[0].getCustomizedMetadata(), "{\n \"data1\": \"1\",\n \"data2\": \"2\"\n}");
resp[0].getCustomizedMetadata().toString(), "{\"data1\":\"1\",\"data2\":\"2\"}");

testUnregisterModel("noop-customized", "1.0");
}
Expand Down
Loading