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

fix: open correct file in BDV

parent 1808bf57
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,9 @@ package cz.it4i.fiji.haas_spim_benchmark.core;
import static cz.it4i.fiji.haas_spim_benchmark.core.Constants.BENCHMARK_RESULT_FILE;
import static cz.it4i.fiji.haas_spim_benchmark.core.Constants.BENCHMARK_TASK_NAME_MAP;
import static cz.it4i.fiji.haas_spim_benchmark.core.Constants.FUSION_SWITCH;
import static cz.it4i.fiji.haas_spim_benchmark.core.Constants.HAAS_UPDATE_TIMEOUT;
import static cz.it4i.fiji.haas_spim_benchmark.core.Constants.HDF5_XML_FILENAME;
import static cz.it4i.fiji.haas_spim_benchmark.core.Constants.SPIM_OUTPUT_FILENAME_PATTERN;
import static cz.it4i.fiji.haas_spim_benchmark.core.Constants.UI_TO_HAAS_FREQUENCY_UPDATE_RATIO;
......@@ -11,7 +13,6 @@ import java.io.Closeable;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
......@@ -24,8 +25,6 @@ import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Scanner;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
......@@ -36,7 +35,6 @@ import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
import cz.it4i.fiji.haas.HaaSOutputHolder;
import cz.it4i.fiji.haas.HaaSOutputHolderImpl;
......@@ -89,13 +87,14 @@ public class BenchmarkJobManager implements Closeable {
public synchronized void startJob(Progress progress) throws IOException {
job.uploadFile(Constants.CONFIG_YAML, new P_ProgressNotifierAdapter(progress));
String outputName = getOutputName(job.openLocalFile(Constants.CONFIG_YAML));
LoadedYAML yaml = new LoadedYAML(job.openLocalFile(Constants.CONFIG_YAML));
verifiedState = null;
verifiedStateProcessed = false;
running = null;
job.submit();
job.setProperty(SPIM_OUTPUT_FILENAME_PATTERN, outputName);
job.setProperty(SPIM_OUTPUT_FILENAME_PATTERN,
yaml.getCommonProperty(FUSION_SWITCH) + "_" + yaml.getCommonProperty(HDF5_XML_FILENAME));
}
public JobState getState() {
......@@ -270,6 +269,10 @@ public class BenchmarkJobManager implements Closeable {
public Path getOutputDirectory() {
return job.getOutputDirectory();
}
public Path getResultXML() {
return Paths.get(job.getProperty(SPIM_OUTPUT_FILENAME_PATTERN) + ".xml");
}
private ProgressNotifier convertTo(Progress progress) {
return progress == null ? null : new P_ProgressNotifierAdapter(progress);
......@@ -596,26 +599,7 @@ public class BenchmarkJobManager implements Closeable {
return new BenchmarkJob(job);
}
private String getOutputName(InputStream openLocalFile) throws IOException {
try (InputStream is = openLocalFile) {
Yaml yaml = new Yaml();
Map<String, Map<String, String>> map = yaml.load(is);
String result = Optional.ofNullable(map).map(m -> m.get("common")).map(m -> m.get("hdf5_xml_filename"))
.orElse(null);
if (result == null) {
throw new IllegalArgumentException("hdf5_xml_filename not found");
}
if (result.charAt(0) == '"' || result.charAt(0) == '\'') {
if (result.charAt(result.length() - 1) != result.charAt(0)) {
throw new IllegalArgumentException(result);
}
result = result.substring(1, result.length() - 1);
}
return result;
}
}
private static Predicate<String> downloadFinishedData(String filePattern) {
return name -> {
......
......@@ -20,6 +20,9 @@ public interface Constants {
String SPIM_OUTPUT_FILENAME_PATTERN = "spim.outputFilenamePattern";
String CONFIG_YAML = "config.yaml";
String BENCHMARK_RESULT_FILE = "benchmark_result.csv";
String HDF5_XML_FILENAME = "hdf5_xml_filename";
String FUSION_SWITCH = "fusion_switch";
// This map is considered as ground truth for chronologic task sorting
Map<String, String> BENCHMARK_TASK_NAME_MAP = new LinkedHashMap<String, String>() {
......
package cz.it4i.fiji.haas_spim_benchmark.core;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Optional;
import org.yaml.snakeyaml.Yaml;
public class LoadedYAML {
private Map<String, Map<String, String>> map;
public LoadedYAML(InputStream openFile) throws IOException {
try (InputStream is = openFile) {
Yaml yaml = new Yaml();
map = yaml.load(is);
}
}
public String getCommonProperty(String name) {
String result = Optional.ofNullable(map).map(m -> m.get("common")).map(m -> m.get(name))
.orElse(null);
if (result == null) {
throw new IllegalArgumentException("hdf5_xml_filename not found");
}
if (result.charAt(0) == '"' || result.charAt(0) == '\'') {
if (result.charAt(result.length() - 1) != result.charAt(0)) {
throw new IllegalArgumentException(result);
}
result = result.substring(1, result.length() - 1);
}
return result;
}
}
package cz.it4i.fiji.haas_spim_benchmark.ui;
import static cz.it4i.fiji.haas_spim_benchmark.core.Constants.CONFIG_YAML;
......@@ -363,13 +364,26 @@ public class BenchmarkSPIMControl extends BorderPane implements CloseableControl
}
private void openBigDataViewer(BenchmarkJob job) {
Path resultXML = job.getResultXML();
Path localPathToResultXML = job.getOutputDirectory().resolve(resultXML);
String openFile;
if(Files.exists(localPathToResultXML)) {
openFile = localPathToResultXML.toString();
} else {
openFile = startBDSForData(job, resultXML);
}
try {
BigDataViewer.open( "http://localhost:8080/Data/", "Result of job " + job.getId(), new ProgressWriterConsole() , ViewerOptions.options() );
BigDataViewer.open( openFile, "Result of job " + job.getId(), new ProgressWriterConsole() , ViewerOptions.options() );
} catch (SpimDataException e) {
log.error(e.getMessage(), e);
}
}
private String startBDSForData(BenchmarkJob job, Path resultXML) {
throw new UnsupportedOperationException("File " + resultXML + " was not found in " + job.getOutputDirectory()
+ " and remote BigDataServer is not implemented yet.");
}
private interface P_JobAction {
public void doAction(Progress p) throws IOException;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment