Skip to content

Commit

Permalink
Try using a JobDTO which doesn't have an enum to avoid serialisation …
Browse files Browse the repository at this point in the history
…issues in RPC framework.
  • Loading branch information
Miles-Garnsey committed Sep 21, 2023
1 parent 1f42dbc commit 059d4b5
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.datastax.mgmtapi.rpc.RpcParam;
import com.datastax.mgmtapi.rpc.RpcRegistry;
import com.datastax.mgmtapi.util.Job;
import com.datastax.mgmtapi.util.JobDto;
import com.datastax.mgmtapi.util.JobExecutor;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder;
Expand Down Expand Up @@ -79,22 +80,29 @@ public synchronized void unregister() {
}

@Rpc(name = "jobStatus")
public Map<String, String> getJobStatus(@RpcParam(name = "job_id") String jobId) {
Map<String, String> resultMap = new HashMap<>();
public JobDto getJobStatus(@RpcParam(name = "job_id") String jobId) {
Job jobWithId = service.getJobWithId(jobId);
if (jobWithId == null) {
return resultMap;
}
resultMap.put("id", jobWithId.getJobId());
resultMap.put("type", jobWithId.getJobType());
resultMap.put("status", jobWithId.getStatus().name());
resultMap.put("submit_time", String.valueOf(jobWithId.getSubmitTime()));
resultMap.put("end_time", String.valueOf(jobWithId.getFinishedTime()));
return new JobDto(null, null);
}
JobDto jobStatus = new JobDto(jobWithId.getJobType(), jobWithId.getJobId());
jobStatus.setStatus(jobWithId.getStatus().name());
jobWithId.statusChanges.stream()
.forEach(
statusChange -> {
JobDto.StatusChange changeToAdd =
jobStatus.new StatusChange(statusChange.getStatus(), statusChange.message);
changeToAdd.changeTime = statusChange.getChangeTime();
jobStatus.statusChanges.add(changeToAdd);
});
jobStatus.submitTime = jobWithId.getSubmitTime();
jobStatus.finishedTime = jobWithId.getFinishedTime();
jobStatus.startTime = jobWithId.startTime;
if (jobWithId.getStatus() == Job.JobStatus.ERROR) {
resultMap.put("error", jobWithId.getError().getLocalizedMessage());
jobStatus.setError(jobWithId.getError());
}

return resultMap;
return jobStatus;
}

@Rpc(name = "setFullQuerylog")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ public enum JobStatus {
WAITING;
}

private String jobId;
private String jobType;
private JobStatus status;
private long submitTime;
private long startTime;
private long finishedTime;
private Throwable error;
public String jobId;
public String jobType;
public JobStatus status;
public long submitTime;
public long startTime;
public long finishedTime;
public Throwable error;

public class StatusChange {
ProgressEventType status;
long changeTime;
public ProgressEventType status;
public long changeTime;

String message;
public String message;

public StatusChange(ProgressEventType type, String message) {
changeTime = System.currentTimeMillis();
Expand All @@ -50,7 +50,7 @@ public String getMessage() {
}
}

private List<StatusChange> statusChanges;
public List<StatusChange> statusChanges;

public Job(String jobType, String jobId) {
this.jobType = jobType;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright DataStax, Inc.
*
* Please see the included license file for details.
*/
package com.datastax.mgmtapi.util;

import com.google.common.annotations.VisibleForTesting;
import java.util.ArrayList;
import java.util.List;
import org.apache.cassandra.utils.progress.ProgressEventType;

public class JobDto {

public String jobId;
public String jobType;
public String status;
public long submitTime;
public long startTime;
public long finishedTime;
public Throwable error;

public class StatusChange {
public ProgressEventType status;
public long changeTime;

public String message;

public StatusChange(ProgressEventType type, String message) {
changeTime = System.currentTimeMillis();
status = type;
this.message = message;
}

public ProgressEventType getStatus() {
return status;
}

public long getChangeTime() {
return changeTime;
}

public String getMessage() {
return message;
}
}

public List<StatusChange> statusChanges;

public JobDto(String jobType, String jobId) {
this.jobType = jobType;
this.jobId = jobId;
submitTime = System.currentTimeMillis();
status = "WAITING";
statusChanges = new ArrayList<>();
}

@VisibleForTesting
// This method is only for testing purposes
public void setJobId(String jobId) {
this.jobId = jobId;
}

public String getJobId() {
return jobId;
}

public String getJobType() {
return jobType;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public void setStatusChange(ProgressEventType type, String message) {
statusChanges.add(new StatusChange(type, message));
}

public List<StatusChange> getStatusChanges() {
return statusChanges;
}

public long getSubmitTime() {
return submitTime;
}

public long getFinishedTime() {
return finishedTime;
}

public void setFinishedTime(long finishedTime) {
this.finishedTime = finishedTime;
}

public Throwable getError() {
return error;
}

public void setError(Throwable error) {
this.error = error;
}

public void setStartTime(long startTime) {
this.startTime = startTime;
}
}

0 comments on commit 059d4b5

Please sign in to comment.