diff --git a/data-access/servlet/src/main/java/cutout/Soda.java b/data-access/servlet/src/main/java/cutout/Soda.java index 7d510f893da7870f5c7bbb40a098d0638856bf78..8410d7519fb62bd9b4869000f19dcdbce885e669 100644 --- a/data-access/servlet/src/main/java/cutout/Soda.java +++ b/data-access/servlet/src/main/java/cutout/Soda.java @@ -15,7 +15,10 @@ public interface Soda { public int doStream(String relPathname, int hdunum, - Pos pos, Band band, Time time, Pol pol, String pixels, + Pos pos, Band band, Time time, Pol pol, + OutputStream outputStream) throws IOException, InterruptedException; + + public int doStream(String relPathname, int hdunum, String pixels, OutputStream outputStream) throws IOException, InterruptedException; } diff --git a/data-access/servlet/src/main/java/cutout/SodaImpl.java b/data-access/servlet/src/main/java/cutout/SodaImpl.java index b0374bdd6bcd2f0cedcd04aa7bcaf07e007ebe81..44b460e05da1eca3b34e212f0ef113b9aa27c619 100644 --- a/data-access/servlet/src/main/java/cutout/SodaImpl.java +++ b/data-access/servlet/src/main/java/cutout/SodaImpl.java @@ -44,7 +44,7 @@ class SodaImpl implements Soda public int doStream(String relPathname, int hdunum, - Pos pos, Band band, Time time, Pol pol, String pixels, + Pos pos, Band band, Time time, Pol pol, OutputStream outputStream) throws IOException, InterruptedException { Instant start = Instant.now(); @@ -54,15 +54,6 @@ class SodaImpl implements Soda LOGGER.finest("supplied outputStream for cut-file is null"); // FIXME throw excpetion here - //boolean pixels_valid = (pixels != null); - //final boolean isDavCall = relPathname.startsWith("http://") - // || relPathname.startsWith("https://"); - //final boolean isAbsPath = relPathname.startsWith("/"); // Resolver removes schema from file:// - // file:///some_abs_path -> /soma_abs_path - // file://some_rel_path -> some_rel_path - //String absPathname = (isDavCall || isAbsPath) ? relPathname - // : (fitsPaths.surveys() +"/"+ relPathname); - boolean has_overlap = false; String boundsString = ""; JsonEncoder jReq = new JsonEncoder(); @@ -105,5 +96,55 @@ class SodaImpl implements Soda } } + + + + public int doStream(String relPathname, int hdunum, + String pixels, OutputStream outputStream) throws IOException, InterruptedException + { + Instant start = Instant.now(); + LOGGER.fine("trace"); + + if(outputStream == null) + LOGGER.finest("supplied outputStream for cut-file is null"); + + final boolean isDavCall= relPathname.startsWith("http://") || relPathname.startsWith("https://"); + final boolean isAbsPath= relPathname.startsWith("/"); + String absPathname = (isDavCall || isAbsPath) ? relPathname + : (fitsPaths.surveys() +"/"+ relPathname); + + String[] cmd = new String[5]; + cmd[0] = "/usr/local/bin/vlkb"; + cmd[1] = (isDavCall) ? "imcopydav" : "imcopy"; + cmd[2] = absPathname; + cmd[3] = String.valueOf(hdunum); + cmd[4] = pixels; + LOGGER.finest(String.join(" ", cmd)); + + StringBuilder errorStrBuilder = new StringBuilder(); + + ExecCmd exec = new ExecCmd(); + exec.doRun(outputStream, cmd, errorStrBuilder); + int rc = exec.exitValue; + LOGGER.finest("exec cutout exitValue: " + rc); + LOGGER.finer("EXECTIME cutoutDone: " + Duration.between(start, Instant.now())); + + if(rc == 0) + { + return rc; // OK + } + else if(rc == 1) + { + return rc; // OK, but no overlap + } + else + { + throw new IllegalArgumentException( + "overlap computation could not be completed with the given arguments. " + + errorStrBuilder.toString()); + } + } + + } diff --git a/data-access/servlet/src/main/java/cutout/webapi/ServletCutout.java b/data-access/servlet/src/main/java/cutout/webapi/ServletCutout.java index 846fb166a8d8b0b18ec39acf620b3e7195b8831c..4db0f6ad5b6e84da322317f3a965ac0168b0faa1 100644 --- a/data-access/servlet/src/main/java/cutout/webapi/ServletCutout.java +++ b/data-access/servlet/src/main/java/cutout/webapi/ServletCutout.java @@ -128,7 +128,11 @@ public class ServletCutout extends HttpServlet resolver.resolve(id); - return soda.doStream(resolver.relPathname(), resolver.hdunum(), pos, band, time, pol, pixels, respOutputStream); + if(pixels != null) + return soda.doStream(resolver.relPathname(), resolver.hdunum(), pixels, respOutputStream); + else + return soda.doStream(resolver.relPathname(), resolver.hdunum(), + pos, band, time, pol, respOutputStream); } @@ -162,8 +166,10 @@ public class ServletCutout extends HttpServlet String cutAbsPathname = settings.fitsPaths.cutouts() + "/" + generateSubimgPathname(resolver.relPathname(), resolver.hdunum()); - vlkb.doFile(resolver.relPathname(), resolver.hdunum(), - pos, band, time, pol, pixels, cutAbsPathname); + if(pixels != null) + vlkb.doFile(resolver.relPathname(), resolver.hdunum(), pos,band,time,pol, cutAbsPathname); + else + vlkb.doFile(resolver.relPathname(), resolver.hdunum(), pixels, cutAbsPathname); // VLKB specific: null-value-count and extra-cards diff --git a/data-access/servlet/src/main/java/mcutout/VlkbCli.java b/data-access/servlet/src/main/java/mcutout/VlkbCli.java index 5cb4af6dce00e12e6b135d6d51697a0d02418360..0c742f58f58ed89b2cd0cd117ee57bdaffb348d4 100644 --- a/data-access/servlet/src/main/java/mcutout/VlkbCli.java +++ b/data-access/servlet/src/main/java/mcutout/VlkbCli.java @@ -88,7 +88,7 @@ class VlkbCli implements Vlkb } public CutResult doFileAmqp(String relPathname, int hdunum, - Pos pos, Band band, Time time, Pol pol, String pixels, + Pos pos, Band band, Time time, Pol pol, boolean countNullValues, FitsCard[] extraCards, String cutAbsPathname) throws IOException, InterruptedException @@ -101,37 +101,33 @@ class VlkbCli implements Vlkb public void doFile(String relPathname, int hdunum, - Pos pos, Band band, Time time, Pol pol, String pixels, - /*boolean countNullValues, FitsCard[] extraCards,*/ + Pos pos, Band band, Time time, Pol pol, String cutAbsPathname) throws IOException, InterruptedException - { - LOGGER.fine("trace: " + cutAbsPathname ); - - try(OutputStream fileOutputStream = new FileOutputStream(new File(cutAbsPathname))) { - soda.doStream(relPathname, hdunum, pos, band, time, pol, pixels, fileOutputStream); - } -/* - CutResult cutResult = new CutResult(); + LOGGER.fine("trace: " + cutAbsPathname ); - cutResult.fileName = cutAbsPathname; - cutResult.fileSize = Files.size(Paths.get(cutAbsPathname)); - if(countNullValues) - { - cutResult.nullValueCount = doCountNullValues(cutAbsPathname, 1); + try(OutputStream fileOutputStream = new FileOutputStream(new File(cutAbsPathname))) + { + soda.doStream(relPathname, hdunum, pos, band, time, pol, fileOutputStream); + } } - if(extraCards == null || (extraCards.length < 1)) + + public void doFile(String relPathname, int hdunum, + String pixels, String cutAbsPathname) + throws IOException, InterruptedException { - LOGGER.finer("Adding extraCards to cut-file implemented only in VlkbAmql"); + LOGGER.fine("trace: " + cutAbsPathname ); + + try(OutputStream fileOutputStream = new FileOutputStream(new File(cutAbsPathname))) + { + soda.doStream(relPathname, hdunum, pixels, fileOutputStream); + } } - cutResult.pixels = null; - return cutResult; -*/ } - public MCutResult doMCutout(String jdlJson, String workDir) + public MCutResult doMCutout(String jdlJson, String workDir) throws IOException, InterruptedException { LOGGER.fine("trace"); @@ -205,7 +201,10 @@ class VlkbCli implements Vlkb String cutAbsPathname = workDir + "/" + generateSubimgPathname(ix, relPathname, hdunum, MAX_FILENAME_LEN); - doFile(relPathname, hdunum, pos, band, time, pol, pixels, cutAbsPathname); + if(pixels != null) + doFile(relPathname, hdunum, pixels, cutAbsPathname); + else + doFile(relPathname, hdunum, pos, band, time, pol, cutAbsPathname); cut.content = cutAbsPathname; cut.contentType = MCutResult.Cut.ContentType.FILENAME; @@ -380,7 +379,7 @@ class VlkbCli implements Vlkb else { throw new AssertionError("'vlkb nullvals' exited with error: " - + errorStrBuilder.toString() + " for: " + absPathname); + + errorStrBuilder.toString() + " for: " + absPathname); } } diff --git a/data-access/servlet/src/main/java/vlkb/Vlkb.java b/data-access/servlet/src/main/java/vlkb/Vlkb.java index 032ef41db64b764d3317fb8f4b7ad1de8b8e70a6..f81378ed0d30f935051e9397730a7de6a58bad87 100644 --- a/data-access/servlet/src/main/java/vlkb/Vlkb.java +++ b/data-access/servlet/src/main/java/vlkb/Vlkb.java @@ -14,10 +14,15 @@ import vo.parameter.*; public interface Vlkb { public void doFile(String relPathname, int hdunum, - Pos pos, Band band, Time time, Pol pol, String pixels, + Pos pos, Band band, Time time, Pol pol, String cutAbsPathname) throws IOException, InterruptedException; + public void doFile(String relPathname, int hdunum, + String pixels, String cutAbsPathname) + throws IOException, InterruptedException; + + public MCutResult doMCutout(String jdlJson, String workDir) throws IOException, InterruptedException; @@ -34,7 +39,7 @@ public interface Vlkb // deprecated - used only in VlkbAmqp public CutResult doFileAmqp(String relPathname, int hdunum, - Pos pos, Band band, Time time, Pol pol, String pixels, + Pos pos, Band band, Time time, Pol pol, boolean countNullValues, FitsCard[] extraCards, String cutAbsPathname) throws IOException, InterruptedException; diff --git a/data-access/servlet/src/main/java/vlkb/VlkbAmqp.java b/data-access/servlet/src/main/java/vlkb/VlkbAmqp.java index 4b4fe76d8d9dc2cd880a48eb133af792af767377..065c1cbd825d3e42a7f7c56e4a9e527d97d63e5a 100644 --- a/data-access/servlet/src/main/java/vlkb/VlkbAmqp.java +++ b/data-access/servlet/src/main/java/vlkb/VlkbAmqp.java @@ -83,16 +83,24 @@ class VlkbAmqp implements Vlkb /////////////////////////////////////////////////////////////////////////////////// public void doFile(String relPathname, int hdunum, - Pos pos, Band band, Time time, Pol pol, String pixels, - /*boolean countNullValues, FitsCard[] extraCards,*/ String dummyCutAbsPathname) + Pos pos, Band band, Time time, Pol pol, String dummyCutAbsPathname) throws IOException, InterruptedException { ;// only placehoder for compatibility with Vlkb.java interface, //Amqp support is deprecated } + public void doFile(String relPathname, int hdunum, + String pixels, String dummyCutAbsPathname) + throws IOException, InterruptedException + { + ;// only placehoder for compatibility with Vlkb.java interface, + //Amqp support is deprecated + } + + public CutResult doFileAmqp(String relPathname, int hdunum, - Pos pos, Band band, Time time, Pol pol, String pixels, + Pos pos, Band band, Time time, Pol pol, boolean countNullValues, FitsCard[] extraCards, String dummyCutAbsPathname) throws IOException, InterruptedException { @@ -109,8 +117,6 @@ class VlkbAmqp implements Vlkb jReq.add(time); jReq.add(pol); - // jReq.add(pixels), FIXME implement to supoort PIXLES in vlkb-legacy by AMQP - jReq.add(countNullValues); jReq.add(extraCards); @@ -123,7 +129,7 @@ class VlkbAmqp implements Vlkb - private CutResult doFileById(String id, Pos pos, Band band, Time time, Pol pol, String pixels, + private CutResult doFileById(String id, Pos pos, Band band, Time time, Pol pol, boolean countNullValues, Subsurvey[] subsurveys) throws IOException, InterruptedException { @@ -147,7 +153,7 @@ class VlkbAmqp implements Vlkb final String DEFAULT_TIME_SYSTEM = "MJD_UTC"; // FIXME take from confif file - CutResult cutResult = doFileAmqp(relPathname, hdunum, pos, band, time, pol, pixels, + CutResult cutResult = doFileAmqp(relPathname, hdunum, pos, band, time, pol, countNullValues, extraCards, null); return cutResult; @@ -224,8 +230,6 @@ class VlkbAmqp implements Vlkb jReq.add(coord.time); jReq.add(coord.pol); - // jReq.add(pixels), FIXME implement to supoort PIXLES in vlkb-legacy by AMQP - jReq.add(countNullValues); jReq.add(extraCards);