Skip to content

Commit 059d4b5

Browse files
committed
Try using a JobDTO which doesn't have an enum to avoid serialisation issues in RPC framework.
1 parent 1f42dbc commit 059d4b5

File tree

3 files changed

+141
-22
lines changed

3 files changed

+141
-22
lines changed

management-api-agent-common/src/main/java/com/datastax/mgmtapi/NodeOpsProvider.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.datastax.mgmtapi.rpc.RpcParam;
1010
import com.datastax.mgmtapi.rpc.RpcRegistry;
1111
import com.datastax.mgmtapi.util.Job;
12+
import com.datastax.mgmtapi.util.JobDto;
1213
import com.datastax.mgmtapi.util.JobExecutor;
1314
import com.datastax.oss.driver.api.core.CqlIdentifier;
1415
import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder;
@@ -79,22 +80,29 @@ public synchronized void unregister() {
7980
}
8081

8182
@Rpc(name = "jobStatus")
82-
public Map<String, String> getJobStatus(@RpcParam(name = "job_id") String jobId) {
83-
Map<String, String> resultMap = new HashMap<>();
83+
public JobDto getJobStatus(@RpcParam(name = "job_id") String jobId) {
8484
Job jobWithId = service.getJobWithId(jobId);
8585
if (jobWithId == null) {
86-
return resultMap;
87-
}
88-
resultMap.put("id", jobWithId.getJobId());
89-
resultMap.put("type", jobWithId.getJobType());
90-
resultMap.put("status", jobWithId.getStatus().name());
91-
resultMap.put("submit_time", String.valueOf(jobWithId.getSubmitTime()));
92-
resultMap.put("end_time", String.valueOf(jobWithId.getFinishedTime()));
86+
return new JobDto(null, null);
87+
}
88+
JobDto jobStatus = new JobDto(jobWithId.getJobType(), jobWithId.getJobId());
89+
jobStatus.setStatus(jobWithId.getStatus().name());
90+
jobWithId.statusChanges.stream()
91+
.forEach(
92+
statusChange -> {
93+
JobDto.StatusChange changeToAdd =
94+
jobStatus.new StatusChange(statusChange.getStatus(), statusChange.message);
95+
changeToAdd.changeTime = statusChange.getChangeTime();
96+
jobStatus.statusChanges.add(changeToAdd);
97+
});
98+
jobStatus.submitTime = jobWithId.getSubmitTime();
99+
jobStatus.finishedTime = jobWithId.getFinishedTime();
100+
jobStatus.startTime = jobWithId.startTime;
93101
if (jobWithId.getStatus() == Job.JobStatus.ERROR) {
94-
resultMap.put("error", jobWithId.getError().getLocalizedMessage());
102+
jobStatus.setError(jobWithId.getError());
95103
}
96104

97-
return resultMap;
105+
return jobStatus;
98106
}
99107

100108
@Rpc(name = "setFullQuerylog")

management-api-agent-common/src/main/java/com/datastax/mgmtapi/util/Job.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ public enum JobStatus {
1717
WAITING;
1818
}
1919

20-
private String jobId;
21-
private String jobType;
22-
private JobStatus status;
23-
private long submitTime;
24-
private long startTime;
25-
private long finishedTime;
26-
private Throwable error;
20+
public String jobId;
21+
public String jobType;
22+
public JobStatus status;
23+
public long submitTime;
24+
public long startTime;
25+
public long finishedTime;
26+
public Throwable error;
2727

2828
public class StatusChange {
29-
ProgressEventType status;
30-
long changeTime;
29+
public ProgressEventType status;
30+
public long changeTime;
3131

32-
String message;
32+
public String message;
3333

3434
public StatusChange(ProgressEventType type, String message) {
3535
changeTime = System.currentTimeMillis();
@@ -50,7 +50,7 @@ public String getMessage() {
5050
}
5151
}
5252

53-
private List<StatusChange> statusChanges;
53+
public List<StatusChange> statusChanges;
5454

5555
public Job(String jobType, String jobId) {
5656
this.jobType = jobType;
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright DataStax, Inc.
3+
*
4+
* Please see the included license file for details.
5+
*/
6+
package com.datastax.mgmtapi.util;
7+
8+
import com.google.common.annotations.VisibleForTesting;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import org.apache.cassandra.utils.progress.ProgressEventType;
12+
13+
public class JobDto {
14+
15+
public String jobId;
16+
public String jobType;
17+
public String status;
18+
public long submitTime;
19+
public long startTime;
20+
public long finishedTime;
21+
public Throwable error;
22+
23+
public class StatusChange {
24+
public ProgressEventType status;
25+
public long changeTime;
26+
27+
public String message;
28+
29+
public StatusChange(ProgressEventType type, String message) {
30+
changeTime = System.currentTimeMillis();
31+
status = type;
32+
this.message = message;
33+
}
34+
35+
public ProgressEventType getStatus() {
36+
return status;
37+
}
38+
39+
public long getChangeTime() {
40+
return changeTime;
41+
}
42+
43+
public String getMessage() {
44+
return message;
45+
}
46+
}
47+
48+
public List<StatusChange> statusChanges;
49+
50+
public JobDto(String jobType, String jobId) {
51+
this.jobType = jobType;
52+
this.jobId = jobId;
53+
submitTime = System.currentTimeMillis();
54+
status = "WAITING";
55+
statusChanges = new ArrayList<>();
56+
}
57+
58+
@VisibleForTesting
59+
// This method is only for testing purposes
60+
public void setJobId(String jobId) {
61+
this.jobId = jobId;
62+
}
63+
64+
public String getJobId() {
65+
return jobId;
66+
}
67+
68+
public String getJobType() {
69+
return jobType;
70+
}
71+
72+
public String getStatus() {
73+
return status;
74+
}
75+
76+
public void setStatus(String status) {
77+
this.status = status;
78+
}
79+
80+
public void setStatusChange(ProgressEventType type, String message) {
81+
statusChanges.add(new StatusChange(type, message));
82+
}
83+
84+
public List<StatusChange> getStatusChanges() {
85+
return statusChanges;
86+
}
87+
88+
public long getSubmitTime() {
89+
return submitTime;
90+
}
91+
92+
public long getFinishedTime() {
93+
return finishedTime;
94+
}
95+
96+
public void setFinishedTime(long finishedTime) {
97+
this.finishedTime = finishedTime;
98+
}
99+
100+
public Throwable getError() {
101+
return error;
102+
}
103+
104+
public void setError(Throwable error) {
105+
this.error = error;
106+
}
107+
108+
public void setStartTime(long startTime) {
109+
this.startTime = startTime;
110+
}
111+
}

0 commit comments

Comments
 (0)