From b6a042d6b56938eb9dd65117be71e56c7f8e08ff Mon Sep 17 00:00:00 2001 From: Miles-Garnsey Date: Tue, 26 Sep 2023 14:44:29 +1000 Subject: [PATCH] Ensure that StatusChange isn't serialised to Strings in constructors. --- .../com/datastax/mgmtapi/NodeOpsProvider.java | 2 +- .../resources/K8OperatorResources.java | 21 +++++++++++++++++-- .../mgmtapi/resources/models/Job.java | 7 +------ .../mgmtapi/K8OperatorResourcesTest.java | 4 ++-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/management-api-agent-common/src/main/java/com/datastax/mgmtapi/NodeOpsProvider.java b/management-api-agent-common/src/main/java/com/datastax/mgmtapi/NodeOpsProvider.java index a5bb80a1..6a3df2a3 100644 --- a/management-api-agent-common/src/main/java/com/datastax/mgmtapi/NodeOpsProvider.java +++ b/management-api-agent-common/src/main/java/com/datastax/mgmtapi/NodeOpsProvider.java @@ -909,4 +909,4 @@ public Map, List> getRangeToEndpointMap( @RpcParam(name = "keyspaceName") String keyspaceName) { return ShimLoader.instance.get().getStorageService().getRangeToEndpointMap(keyspaceName); } -} \ No newline at end of file +} diff --git a/management-api-server/src/main/java/com/datastax/mgmtapi/resources/K8OperatorResources.java b/management-api-server/src/main/java/com/datastax/mgmtapi/resources/K8OperatorResources.java index e145bf14..38d90961 100644 --- a/management-api-server/src/main/java/com/datastax/mgmtapi/resources/K8OperatorResources.java +++ b/management-api-server/src/main/java/com/datastax/mgmtapi/resources/K8OperatorResources.java @@ -11,6 +11,7 @@ import com.datastax.mgmtapi.resources.models.Job; import com.datastax.oss.driver.api.core.cql.ResultSet; import com.datastax.oss.driver.api.core.cql.Row; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -195,7 +196,23 @@ public Response getJobStatus( if (jobResponse.isEmpty()) { return Response.status(Response.Status.NOT_FOUND).entity(jobResponse).build(); } - return Response.ok(jobResponse, MediaType.APPLICATION_JSON).build(); + + TypeReference listOfJobStatus = new TypeReference>() {}; + try { + Job outJob = + new Job( + jobResponse.get("id"), + jobResponse.get("type"), + jobResponse.get("status"), + Long.parseLong(jobResponse.get("submit_time")), + Long.parseLong(jobResponse.get("end_time")), + jobResponse.get("error"), + (List) + jsonMapper.readValue(jobResponse.get("status_changes"), listOfJobStatus)); + return Response.ok(outJob, MediaType.APPLICATION_JSON).build(); + } catch (Exception e) { + throw new RuntimeException(e); + } }); } -} \ No newline at end of file +} diff --git a/management-api-server/src/main/java/com/datastax/mgmtapi/resources/models/Job.java b/management-api-server/src/main/java/com/datastax/mgmtapi/resources/models/Job.java index fe89b7f9..574fd7e5 100644 --- a/management-api-server/src/main/java/com/datastax/mgmtapi/resources/models/Job.java +++ b/management-api-server/src/main/java/com/datastax/mgmtapi/resources/models/Job.java @@ -7,12 +7,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; import java.io.Serializable; -import java.util.ArrayList; import java.util.List; public class Job implements Serializable { @@ -121,4 +116,4 @@ public List getStatusChanges() { public String getError() { return error; } -} \ No newline at end of file +} diff --git a/management-api-server/src/test/java/com/datastax/mgmtapi/K8OperatorResourcesTest.java b/management-api-server/src/test/java/com/datastax/mgmtapi/K8OperatorResourcesTest.java index 90bdfbdc..d8078490 100644 --- a/management-api-server/src/test/java/com/datastax/mgmtapi/K8OperatorResourcesTest.java +++ b/management-api-server/src/test/java/com/datastax/mgmtapi/K8OperatorResourcesTest.java @@ -587,7 +587,7 @@ public void testJobStatus() throws Exception { when(mockResultSet.one()).thenReturn(mockRow); - Map jobDetailsRow = new HashMap<>(); + Map jobDetailsRow = new HashMap<>(); jobDetailsRow.put("id", "0fe65b47-98c2-47d8-9c3c-5810c9988e10"); jobDetailsRow.put("type", "CLEANUP"); jobDetailsRow.put("status", "COMPLETED"); @@ -2140,4 +2140,4 @@ public void testMoveAsync_MissingNewToken() throws Exception { verify(context.cqlService, never()) .executePreparedStatement(any(), eq("CALL NodeOps.move(?, ?)"), eq("1234"), eq(true)); } -} \ No newline at end of file +}