Skip to content

Commit

Permalink
Ensure that StatusChange isn't serialised to Strings in constructors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Miles-Garnsey committed Sep 26, 2023
1 parent 47d90f2 commit b6a042d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -909,4 +909,4 @@ public Map<List<String>, List<String>> getRangeToEndpointMap(
@RpcParam(name = "keyspaceName") String keyspaceName) {
return ShimLoader.instance.get().getStorageService().getRangeToEndpointMap(keyspaceName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<List<Job.StatusChange>>() {};
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<Job.StatusChange>)
jsonMapper.readValue(jobResponse.get("status_changes"), listOfJobStatus));
return Response.ok(outJob, MediaType.APPLICATION_JSON).build();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -121,4 +116,4 @@ public List<StatusChange> getStatusChanges() {
public String getError() {
return error;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ public void testJobStatus() throws Exception {

when(mockResultSet.one()).thenReturn(mockRow);

Map<String, Object> jobDetailsRow = new HashMap<>();
Map<String, String> jobDetailsRow = new HashMap<>();
jobDetailsRow.put("id", "0fe65b47-98c2-47d8-9c3c-5810c9988e10");
jobDetailsRow.put("type", "CLEANUP");
jobDetailsRow.put("status", "COMPLETED");
Expand Down Expand Up @@ -2140,4 +2140,4 @@ public void testMoveAsync_MissingNewToken() throws Exception {
verify(context.cqlService, never())
.executePreparedStatement(any(), eq("CALL NodeOps.move(?, ?)"), eq("1234"), eq(true));
}
}
}

0 comments on commit b6a042d

Please sign in to comment.