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

fix of getJobs method

parent babc2b22
No related branches found
No related tags found
No related merge requests found
...@@ -40,8 +40,8 @@ public class BenchmarkJobManager { ...@@ -40,8 +40,8 @@ public class BenchmarkJobManager {
return new UploadingFileFromResource("", CONFIG_YAML); return new UploadingFileFromResource("", CONFIG_YAML);
} }
public Collection<JobInfo> getJobs() { public Collection<JobInfo> getJobs() throws IOException {
return jobManager.getJobs(); return jobManager.getJobs(progress);
} }
} }
...@@ -53,7 +53,7 @@ public class CheckStatusOfHaaS implements Command { ...@@ -53,7 +53,7 @@ public class CheckStatusOfHaaS implements Command {
window = ModalDialogs.doModal(new CheckStatusOfHaaSWindow(getFrame(), context)); window = ModalDialogs.doModal(new CheckStatusOfHaaSWindow(getFrame(), context));
ProgressDialog dialog = ModalDialogs.doModal(new ProgressDialog(window)); ProgressDialog dialog = ModalDialogs.doModal(new ProgressDialog(window));
dialog.setTitle("Downloading info about jobs"); dialog.setTitle("Downloading info about jobs");
Collection<JobInfo> jobs = jobManager.getJobs(); Collection<JobInfo> jobs = jobManager.getJobs(dialog);
int count = 0; int count = 0;
for (JobInfo ji : jobs) { for (JobInfo ji : jobs) {
String item; String item;
......
...@@ -78,18 +78,17 @@ public class Job { ...@@ -78,18 +78,17 @@ public class Job {
private String name; private String name;
public Job(String name, Path basePath, Supplier<HaaSClient> haasClientSupplier, Progress progress) throws IOException { public Job(String name, Path basePath, Supplier<HaaSClient> haasClientSupplier, Progress progress) throws IOException {
this(haasClientSupplier); this(haasClientSupplier, progress);
HaaSClient client = this.haasClientSupplier.get(); HaaSClient client = this.haasClientSupplier.get();
long id = client.createJob(name, Collections.emptyList(), long id = client.createJob(name, Collections.emptyList(),notifier);
notifier = new P_ProgressNotifierAdapter(progress));
jobDir = basePath.resolve("" + id); jobDir = basePath.resolve("" + id);
this.name = name; this.name = name;
Files.createDirectory(jobDir); Files.createDirectory(jobDir);
updateState(); updateState();
} }
public Job(Path p, Supplier<HaaSClient> haasClientSupplier) throws IOException { public Job(Path p, Supplier<HaaSClient> haasClientSupplier, Progress progress) throws IOException {
this(haasClientSupplier); this(haasClientSupplier, progress);
jobDir = p; jobDir = p;
loadJobInfo(); loadJobInfo();
} }
...@@ -108,7 +107,8 @@ public class Job { ...@@ -108,7 +107,8 @@ public class Job {
client.submitJob(jobId, notifier); client.submitJob(jobId, notifier);
} }
private Job(Supplier<HaaSClient> haasClientSupplier) { private Job(Supplier<HaaSClient> haasClientSupplier, Progress progress) {
notifier = new P_ProgressNotifierAdapter(progress);
this.haasClientSupplier = haasClientSupplier; this.haasClientSupplier = haasClientSupplier;
} }
......
...@@ -27,23 +27,15 @@ public class JobManager { ...@@ -27,23 +27,15 @@ public class JobManager {
private Path workDirectory; private Path workDirectory;
private Collection<Job> jobs = new LinkedList<>(); private Collection<Job> jobs;
private HaaSClient haasClient; private HaaSClient haasClient;
private Settings settings; private Settings settings;
public JobManager(Path workDirectory, Settings settings) throws IOException { public JobManager(Path workDirectory, Settings settings){
this.workDirectory = workDirectory; this.workDirectory = workDirectory;
this.settings = settings; this.settings = settings;
Files.list(this.workDirectory).filter(p -> Files.isDirectory(p) && Job.isJobPath(p)).forEach(p -> {
try {
jobs.add(new Job(p, this::getHaasClient));
} catch (IOException e) {
e.printStackTrace();
}
});
} }
public JobInfo createJob(Progress progress) throws IOException { public JobInfo createJob(Progress progress) throws IOException {
...@@ -73,7 +65,17 @@ public class JobManager { ...@@ -73,7 +65,17 @@ public class JobManager {
return () -> jobs.stream().filter(j -> j.needsDownload()).map(j -> new JobInfo(j)).iterator(); return () -> jobs.stream().filter(j -> j.needsDownload()).map(j -> new JobInfo(j)).iterator();
} }
public Collection<JobInfo> getJobs() { public Collection<JobInfo> getJobs(Progress progress) throws IOException {
if(jobs == null) {
jobs = new LinkedList<>();
Files.list(this.workDirectory).filter(p -> Files.isDirectory(p) && Job.isJobPath(p)).forEach(p -> {
try {
jobs.add(new Job(p, this::getHaasClient, progress));
} catch (IOException e) {
e.printStackTrace();
}
});
}
return jobs.stream().map(j -> new JobInfo(j)).collect(Collectors.toList()); return jobs.stream().map(j -> new JobInfo(j)).collect(Collectors.toList());
} }
......
...@@ -38,7 +38,7 @@ public class RunBenchmark { ...@@ -38,7 +38,7 @@ public class RunBenchmark {
log.info("job: " + ji.getId() + " hasStatus " + ji.getState()); log.info("job: " + ji.getId() + " hasStatus " + ji.getState());
if (ji.getState() == JobState.Configuring) { if (ji.getState() == JobState.Configuring) {
benchmarkJobManager.startJob(ji); benchmarkJobManager.startJob(ji);
} else if (ji.getState() != JobState.Running) { } else if (ji.getState() != JobState.Running && ji.getState() != JobState.Queued) {
ji.downloadData(new P_Progress()); ji.downloadData(new P_Progress());
} }
} }
......
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