Skip to content
Snippets Groups Projects
Commit a3ac7c58 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

code, fix: delete jobs

change order in BenchmarkJobManager, JobManager
job deletion
state for disposed jobs
fix update of table with deleted job
parent 7d8104e5
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,15 @@ import cz.it4i.fiji.scpclient.TransferFileProgress;
*/
public class Job {
public static boolean isValidJobPath(Path path) {
try {
getJobId(path);
} catch (NumberFormatException e) {
return false;
}
return Files.isRegularFile(path.resolve(JOB_INFO_FILENAME));
}
private static final String JOB_NAME = "job.name";
private static final String JOB_NEEDS_UPLOAD = "job.needs_upload";
......@@ -50,15 +59,6 @@ public class Job {
private static final String JOB_IS_UPLOADED = "job.uploaded";
public static boolean isValidJobPath(Path path) {
try {
getJobId(path);
} catch (NumberFormatException e) {
return false;
}
return Files.isRegularFile(path.resolve(JOB_INFO_FILENAME));
}
private static Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas.Job.class);
private Path jobDir;
......@@ -318,9 +318,9 @@ public class Job {
return jobDir;
}
public boolean remove() {
public boolean delete() {
boolean result;
if ((result = jobManager.remove(this)) && Files.isDirectory(jobDir)) {
if ((result = jobManager.deleteJob(this)) && Files.isDirectory(jobDir)) {
List<Path> pathsToDelete;
try {
pathsToDelete = Files.walk(jobDir).sorted(Comparator.reverseOrder()).collect(Collectors.toList());
......
......@@ -18,7 +18,7 @@ import cz.it4i.fiji.haas_java_client.SynchronizableFileType;
public class JobManager implements Closeable {
interface JobManager4Job {
boolean remove(Job job);
boolean deleteJob(Job job);
}
private static Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas.JobManager.class);
......@@ -34,7 +34,8 @@ public class JobManager implements Closeable {
private final JobManager4Job remover = new JobManager4Job() {
@Override
public boolean remove(Job job) {
public boolean deleteJob(Job job) {
haasClient.deleteJob(job.getId());
return jobs.remove(job);
}
};
......
......@@ -28,7 +28,7 @@ public interface JavaFXRoutines {
void accept(TableCell<?, ?> cell, B value, boolean empty);
}
private TableCellUpdater<S, T> updater;
private final TableCellUpdater<S, T> updater;
public TableCellAdapter(TableCellUpdater<S, T> updater) {
this.updater = updater;
......@@ -36,14 +36,18 @@ public interface JavaFXRoutines {
@Override
protected void updateItem(T item, boolean empty) {
updater.accept(this, item, empty);
if(empty) {
this.setText("");
} else {
updater.accept(this, item, empty);
}
}
}
static public class FutureValueUpdater<S, T, U extends CompletableFuture<T>> implements TableCellUpdater<S, U> {
private TableCellUpdater<S, T> inner;
private Executor executor;
private final TableCellUpdater<S, T> inner;
private final Executor executor;
public FutureValueUpdater(TableCellUpdater<S, T> inner, Executor exec) {
this.inner = inner;
......
......@@ -298,6 +298,14 @@ public class HaaSClient {
}
}
public void deleteJob(long id) {
try {
getJobManagement().deleteJob(id, getSessionID());
} catch (RemoteException | ServiceException e) {
throw new HaaSClientException(e);
}
}
private HaaSFileTransferImp getFileTransferMethod(long jobId, TransferFileProgress progress)
throws RemoteException, UnsupportedEncodingException, ServiceException, JSchException {
P_FileTransferPool pool = filetransferPoolMap.computeIfAbsent(jobId, id -> new P_FileTransferPool(id));
......
......@@ -8,5 +8,6 @@ public enum JobState {
Running,
Finished,
Failed,
Canceled;
Canceled,
Disposed;
}
......@@ -205,8 +205,8 @@ public class BenchmarkJobManager implements Closeable{
return computationAccessor.getActualOutput(Arrays.asList(SynchronizableFileType.StandardErrorFile)).get(0);
}
public boolean remove() {
return job.remove();
public boolean delete() {
return job.delete();
}
public void cancelJob() {
......@@ -223,6 +223,34 @@ public class BenchmarkJobManager implements Closeable{
job.resumeUpload();
}
public void setDownloaded(Boolean val) {
job.setDownloaded(val);
}
public void setUploaded(boolean b) {
job.setUploaded(b);
}
public boolean isDownloaded() {
return job.isDownloaded();
}
public boolean isUploaded() {
return job.isUploaded();
}
public void stopDownload() {
job.stopDownloadData();
}
public boolean needsDownload() {
return job.needsDownload();
}
public boolean needsUpload() {
return job.needsUpload();
}
@Override
public String toString() {
return "" + getId();
......@@ -420,34 +448,6 @@ public class BenchmarkJobManager implements Closeable{
Stream<BenchmarkError> taskSpecificErrors = tasks.stream().flatMap(s -> s.getErrors().stream());
return Stream.concat(nonTaskSpecificErrors.stream(), taskSpecificErrors).collect(Collectors.toList());
}
public void setDownloaded(Boolean val) {
job.setDownloaded(val);
}
public void setUploaded(boolean b) {
job.setUploaded(b);
}
public boolean isDownloaded() {
return job.isDownloaded();
}
public boolean isUploaded() {
return job.isUploaded();
}
public void stopDownload() {
job.stopDownloadData();
}
public boolean needsDownload() {
return job.needsDownload();
}
public boolean needsUpload() {
return job.needsUpload();
}
}
public BenchmarkJobManager(BenchmarkSPIMParameters params) throws IOException {
......
......@@ -126,10 +126,10 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
menu.addItem("Upload data", job -> executeWSCallAsync("Uploading data", p -> job.getValue().startUpload()),
job -> executeWSCallAsync("Stop uploading data", p -> job.getValue().stopUpload()),
job -> JavaFXRoutines.notNullValue(job, j -> !EnumSet.of(JobState.Running).contains(j.getState())),
job -> JavaFXRoutines.notNullValue(job,
j -> !EnumSet.of(JobState.Running, JobState.Disposed).contains(j.getState())),
job -> job.getUploadProgress().isWorking());
menu.addItem("Download result",
job -> executeWSCallAsync("Downloading data", p -> job.getValue().startDownload()),
job -> executeWSCallAsync("Stop downloading data", p -> job.getValue().stopDownload()),
......@@ -146,6 +146,13 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
job -> JavaFXRoutines.notNullValue(job, j -> j.getState().equals(JobState.Failed)));
menu.addItem("Open working directory", j -> open(j.getValue()), x -> JavaFXRoutines.notNullValue(x, j -> true));
menu.addItem("Delete", j -> deleteJob(j.getValue()), x -> JavaFXRoutines.notNullValue(x, j -> true));
}
private void deleteJob(BenchmarkJob bj) {
bj.delete();
registry.update();
}
private void open(BenchmarkJob j) {
......@@ -242,7 +249,6 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
private void remove(BenchmarkJob bj) {
jobs.getItems().remove(registry.get(bj));
bj.remove();
}
private void setCellValueFactory(int index, Function<BenchmarkJob, String> mapper) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment