diff --git a/data-access/servlet/src/main/java/common/Coord.java b/data-access/servlet/src/main/java/common/Coord.java index 91983b1b52cc58130d41fbb9bf5a7941a50a71eb..7f364e2f72d10134485e1a96f64c660b630ed837 100644 --- a/data-access/servlet/src/main/java/common/Coord.java +++ b/data-access/servlet/src/main/java/common/Coord.java @@ -13,17 +13,31 @@ class Coord Band band; Time time; Pol pol; + String pixels; - Coord(String skySystem, Pos pos, String specSystem, Band band, Time time, Pol pol) + Coord(String skySystem, Pos pos, String specSystem, Band band, Time time, Pol pol, String pixels) { this.pos = pos; this.band = band; this.time = time; this.pol = pol; + this.pixels = pixels; this.skySystem = skySystem; this.specSystem = specSystem; } + Coord(String skySystem, Pos pos, String specSystem, Band band, Time time, Pol pol) + { + this(skySystem, pos, specSystem, band, time, pol, null); + } + + Coord(Pos pos, Band band, Time time, Pol pol, String pixels) + { + this( (pos ==null)? null : pos.system.toString(), pos, + (band==null)? null : band.system.toString(), band, + time, pol, pixels); + } + } diff --git a/data-access/servlet/src/main/java/common/output/CutResult.java b/data-access/servlet/src/main/java/common/output/CutResult.java index 7d1e0bb0e48fafc334b0a49068953103a7a00d5f..ccfe721acdcd8ce0865a2ac0131ce34b664851f6 100644 --- a/data-access/servlet/src/main/java/common/output/CutResult.java +++ b/data-access/servlet/src/main/java/common/output/CutResult.java @@ -3,9 +3,10 @@ class CutResult { - String filename; - long filesize; + String fileName; + long fileSize; NullValueCount nullValueCount; + String pixels; CutResult() diff --git a/data-access/servlet/src/main/java/cutout/CutoutImpl.java b/data-access/servlet/src/main/java/cutout/CutoutImpl.java index dbcb5e3bbb5e13b32c7870b149b7497c7ddebff2..ccc8090b0735b6c862e5f7f95d56db15ab72c663 100644 --- a/data-access/servlet/src/main/java/cutout/CutoutImpl.java +++ b/data-access/servlet/src/main/java/cutout/CutoutImpl.java @@ -339,8 +339,8 @@ class CutoutImpl implements Cutout doStream(relPathname, hdunum, pos, band, time, pol, pixels, fileOutputStream); // engine returns absPathname see common/cutout.cpp::do_cutout_file() - cutResult.filename = absSubimgPathname; - cutResult.filesize = Files.size(Paths.get(absSubimgPathname)); + cutResult.fileName = absSubimgPathname; + cutResult.fileSize = Files.size(Paths.get(absSubimgPathname)); if(countNullValues) { @@ -351,6 +351,8 @@ class CutoutImpl implements Cutout { LOGGER.info("Adding extraCards to cut-file not implemented when using 'vlkb' exec (implemented in engine vlkbd/AMQP)"); } + + cutResult.pixels = null; } else { diff --git a/data-access/servlet/src/main/java/cutout/DatasetsImpl.java b/data-access/servlet/src/main/java/cutout/DatasetsImpl.java index b64e361fce77a38d08c61a150dddbaefb3139b66..c00c675362c3356a7d1b98fd232963eb9f7873ef 100644 --- a/data-access/servlet/src/main/java/cutout/DatasetsImpl.java +++ b/data-access/servlet/src/main/java/cutout/DatasetsImpl.java @@ -213,8 +213,8 @@ class DatasetsImpl implements Datasets // 3. Merge cut-files - //String[] strar_results = mergefiles_parallel(id, logFileName, // logfilename - //String[] strar_results = mergefiles_split_execution(id, logFileName, // logfilename + //String[] strar_results = mergefiles_parallel(id, logFileName, // logfileName + //String[] strar_results = mergefiles_split_execution(id, logFileName, // logfileName CutResult strar_results = mergefiles( String.valueOf(dim), // prefix: "2D" or "3D" allCutPathnames); // files to merge @@ -455,7 +455,7 @@ class DatasetsImpl implements Datasets default: LOGGER.severe("Assert(Results.toXML): results msg has unhandled msgtype code : " + res); }*/ - data.add(res.filename); + data.add(res.fileName); } return data.toArray(new String[data.size()]); diff --git a/data-access/servlet/src/main/java/cutout/json/JsonDecoder.java b/data-access/servlet/src/main/java/cutout/json/JsonDecoder.java index 3ac4b2b37a8d2e96ceb424aa8e311705762bec98..ccf791391317021808706e1cbb82941afb39a28b 100644 --- a/data-access/servlet/src/main/java/cutout/json/JsonDecoder.java +++ b/data-access/servlet/src/main/java/cutout/json/JsonDecoder.java @@ -68,8 +68,8 @@ public class JsonDecoder long null_count = (long) jnvc.get("nullcount"); long total_count = (long) jnvc.get("totalcount"); - cut.filesize = fileSize; - cut.filename = fileName; + cut.fileSize = fileSize; + cut.fileName = fileName; cut.nullValueCount.percent = fillRatio; cut.nullValueCount.nullCount = null_count; cut.nullValueCount.totalCount = total_count; diff --git a/data-access/servlet/src/main/java/webapi/ServletCutout.java b/data-access/servlet/src/main/java/webapi/ServletCutout.java index 53389d39d5e377650246eadcaf9cb2b149c9e9be..74fff0971bae99c916bbd3b125ff4abaf4e78570 100644 --- a/data-access/servlet/src/main/java/webapi/ServletCutout.java +++ b/data-access/servlet/src/main/java/webapi/ServletCutout.java @@ -128,7 +128,8 @@ public class ServletCutout extends javax.servlet.http.HttpServlet - protected DataLink doCutoutFile(String id, Pos pos, Band band, Time time, Pol pol, String pixels, + //protected DataLink doCutoutFile(String id, Pos pos, Band band, Time time, Pol pol, String pixels, + protected CutResult doCutoutFile(String id, Pos pos, Band band, Time time, Pol pol, String pixels, boolean countNullValues, String respFormat) throws IOException, InterruptedException { @@ -173,9 +174,9 @@ public class ServletCutout extends javax.servlet.http.HttpServlet CutResult cutResult = cutout.doFile(relPathname, hdunum, pos, band, time, pol, pixels, false, null); - DataLink dlk = new DataLink(settings, cutResult, id, pos, band, time, pol, countNullValues); + //DataLink dlk = new DataLink(settings, cutResult, id, pos, band, time, pol, countNullValues); - return dlk; + return cutResult; } @@ -285,17 +286,29 @@ public class ServletCutout extends javax.servlet.http.HttpServlet boolean countNullValues = vlkbReq_getNullValues(request); response.setContentType(respFormat); - DataLink respDataLink = doCutoutFile(id, pos, band, time, pol, pixels, countNullValues, +// DataLink respDataLink = doCutoutFile(id, pos, band, time, pol, pixels, countNullValues, +// respFormat); + CutResult cutResult = doCutoutFile(id, pos, band, time, pol, pixels, countNullValues, respFormat); + /* FIXME errors from engine not checked - cut-file might not have been created */ - LOGGER.info("DataLink - id:" + respDataLink.id + " url: " + respDataLink.accessUrl ); - final String respEncoding = "utf-8"; PrintWriter writer =new PrintWriter(new OutputStreamWriter(respOutputStream, RESPONSE_ENCODING)); - XmlSerializer.serializeToLegacyCutResults(writer, - respEncoding, respDataLink, showDuration, startTime_msec); - writer.close(); /* must close to force flush to complete the xml */ + +// XmlSerializer.serializeToLegacyCutResults(writer, +// respEncoding, respDataLink, showDuration, startTime_msec); + + String accessUrl = convertLocalPathnameToRemoteUrl(cutResult.fileName, + settings.fitsPaths.cutouts(), + settings.fitsPaths.cutoutsUrl()); + + XmlSerializer.serializeToLegacyCutResult(writer, RESPONSE_ENCODING, + cutResult, accessUrl, + id, pos, band, time, pol, pixels, countNullValues, + showDuration, startTime_msec); + + writer.close(); /* must close to force flush to complete the xml */ } else { @@ -347,6 +360,17 @@ public class ServletCutout extends javax.servlet.http.HttpServlet } + private String convertLocalPathnameToRemoteUrl(String localPathname, + String FITScutpath, String FITSRemoteUrlCutouts) + { + LOGGER.info("trace " + localPathname); + String fileName = localPathname.replaceAll(FITScutpath + "/", ""); + LOGGER.info("local filename: " + fileName); + String remotefname = FITSRemoteUrlCutouts + "/" + fileName; + LOGGER.info("remote url : " + remotefname); + return remotefname; + } + diff --git a/data-access/servlet/src/main/java/webapi/UWSSodaWork.java b/data-access/servlet/src/main/java/webapi/UWSSodaWork.java index d15bf7fa9d810a1fb4334124b4bb6ede3877a5c2..5ac6b0ad784240ce1d294f2dddbb8b070c0d9617 100644 --- a/data-access/servlet/src/main/java/webapi/UWSSodaWork.java +++ b/data-access/servlet/src/main/java/webapi/UWSSodaWork.java @@ -105,9 +105,9 @@ public class UWSSodaWork extends JobThread CutResult cutResult = datasets.doCutoutFile(rsl.relPathname, rsl.hdunum, pos, band, time, pol, false, null); - DataLink respDataLink = new DataLink(cutResult); +// DataLink respDataLink = new DataLink(cutResult); - respDataLink.inputs = new Inputs(id, coord, false);//countNullValues); +// respDataLink.inputs = new Inputs(id, coord, false);//countNullValues); /* send Results */ @@ -118,12 +118,25 @@ public class UWSSodaWork extends JobThread if(respContentType.equals("text/xml") || respContentType.equals("application/xml")) { PrintWriter writer = new PrintWriter(new OutputStreamWriter(respOutputStream, RESPONSE_ENCODING)); - XmlSerializer.serializeToLegacyCutResults(writer, RESPONSE_ENCODING, respDataLink, showDuration, startTime_msec); - writer.close(); + + // XmlSerializer.serializeToLegacyCutResults(writer, RESPONSE_ENCODING, respDataLink, showDuration, startTime_msec); + + String accessUrl = convertLocalPathnameToRemoteUrl(cutResult.fileName, + settings.fitsPaths.cutouts(), + settings.fitsPaths.cutoutsUrl()); + + XmlSerializer.serializeToLegacyCutResult(writer, RESPONSE_ENCODING, + cutResult, accessUrl, + id, pos, band, time, pol, null, false, + showDuration, startTime_msec); + + + writer.close(); } else if(respContentType.equals("application/fits")) { - File downloadFile = new File(respDataLink.absCutPathname); + String absCutPathname = cutResult.fileName; + File downloadFile = new File(/*respDataLink.*/absCutPathname); FileInputStream input = new FileInputStream(downloadFile); input.transferTo(respOutputStream); diff --git a/data-access/servlet/src/main/java/webapi/output/DataLink.java b/data-access/servlet/src/main/java/webapi/output/DataLink.java index 82a89fb4a9a53f90ace077c7b3002f6155439d61..a1bbd2f9341937dcac8e07b00be1f6a9439703ae 100644 --- a/data-access/servlet/src/main/java/webapi/output/DataLink.java +++ b/data-access/servlet/src/main/java/webapi/output/DataLink.java @@ -45,7 +45,7 @@ class DataLink String id, Pos pos, Band band, Time time, Pol pol, boolean countNullValues) { this.id = id; - this.accessUrl = convertLocalPathnameToRemoteUrl(cutResult.filename, + this.accessUrl = convertLocalPathnameToRemoteUrl(cutResult.fileName, settings.fitsPaths.cutouts(), settings.fitsPaths.cutoutsUrl()); this.serviceDef = null; this.errorMessage = null; @@ -54,16 +54,16 @@ class DataLink // + pos.toString() + " " + band.toString() + " " + time.toString() + " " + pol.toString(); this.semantics = "http://www.ivoa.net/rdf/datalink/core#proc#cutout"; this.contentType = "application/fits"; - this.contentLength = cutResult.filesize; + this.contentLength = cutResult.fileSize; // VLKB-extension to DataLink: - Coord coord = new Coord(pos.system.toString(), pos, band.system.toString(), band, time, pol); + Coord coord = new Coord(pos, band, time, pol, null); LOGGER.info(coord.toString()); this.inputs = new Inputs(id, coord, countNullValues); this.versionString = Version.asString; this.cut = null; - this.absCutPathname = cutResult.filename; + this.absCutPathname = cutResult.fileName; this.datacubeCount = 1; this.nullVals = ((cutResult.nullValueCount.percent < 0) || (cutResult.nullValueCount.totalCount < 1)) ? null : cutResult.nullValueCount; @@ -76,19 +76,19 @@ class DataLink this.nullVals = new NullValueCount(); this.id = "_PIXEL_BOUNDS"; - this.accessUrl = cutResult.filename; // FIXME filename ->> remoteUrl + this.accessUrl = cutResult.fileName; // FIXME fileName ->> remoteUrl this.serviceDef = null; this.errorMessage = null; this.description = "cutout_from ID"; this.semantics = "FIXME find in IVOA docs..."; this.contentType = "application/fits"; - this.contentLength = cutResult.filesize; + this.contentLength = cutResult.fileSize; // VLKB-extension to DataLink: this.inputs = null; this.versionString = Version.asString; this.cut = null; - this.absCutPathname = cutResult.filename; + this.absCutPathname = cutResult.fileName; this.datacubeCount = 1; this.nullVals = cutResult.nullValueCount; this.mcutResultArr = null; @@ -101,7 +101,7 @@ class DataLink this.nullVals = new NullValueCount(); this.id = "_PIXEL_BOUNDS"; - this.accessUrl = cutResult.fileName; // FIXME filename ->> remoteUrl + this.accessUrl = cutResult.fileName; // FIXME fileName ->> remoteUrl this.serviceDef = null; this.errorMessage = null; this.description = "cutout_from ID"; @@ -122,9 +122,9 @@ class DataLink public String convertLocalPathnameToRemoteUrl(String localPathname, String FITScutpath, String FITSRemoteUrlCutouts) { - String filename = localPathname.replaceAll(FITScutpath + "/", ""); - LOGGER.info("local filename: " + filename); - String remotefname = FITSRemoteUrlCutouts + "/" + filename; + String fileName = localPathname.replaceAll(FITScutpath + "/", ""); + LOGGER.info("local filename: " + fileName); + String remotefname = FITSRemoteUrlCutouts + "/" + fileName; LOGGER.info("remote url : " + remotefname); return remotefname; } diff --git a/data-access/servlet/src/main/java/webapi/output/XmlSerializer.java b/data-access/servlet/src/main/java/webapi/output/XmlSerializer.java index 1da707c98f36333c3ed1fa778a922adb22d18a04..f76d3081261554576fa53fc8cc03145979bdefcc 100644 --- a/data-access/servlet/src/main/java/webapi/output/XmlSerializer.java +++ b/data-access/servlet/src/main/java/webapi/output/XmlSerializer.java @@ -2,7 +2,7 @@ import java.util.logging.Logger; import java.io.PrintWriter; - +import vo.parameter.*; public final class XmlSerializer { @@ -36,84 +36,127 @@ public final class XmlSerializer writer.println("<DatacubeCount> " + dataLink.datacubeCount + " </DatacubeCount>"); if(showDuration) - writer.println("<duration unit=\"msec\">" + (System.currentTimeMillis() - startTime_msec) + "</duration>"); + writer.println("<duration unit=\"msec\">"+(System.currentTimeMillis() - startTime_msec)+"</duration>"); + writer.println("</results>"); } - public static String serialize(NullValueCount nullVals) - { - StringBuilder xml = new StringBuilder(); - xml.append("<nullValues>"); - xml.append("<description> Undefined pixel count </description>"); - xml.append("<percent>" + nullVals.percent + "</percent>"); - xml.append("<pixels>"); - xml.append("<nullcount>" + nullVals.nullCount + "</nullcount>"); - xml.append("<totalcount>" + nullVals.totalCount + "</totalcount>"); - xml.append("</pixels>"); - xml.append("</nullValues>"); - return xml.toString(); - } - - public static String serialize(Coord coord) - { - StringBuilder xml = new StringBuilder(); - xml.append("<SkySystem>"+coord.skySystem+"</SkySystem>"); + public static void serializeToLegacyCutResult(PrintWriter writer, String charEncoding, + CutResult cutResult, String accessUrl, + String id, Pos pos, Band band, Time time, Pol pol, String pixels, boolean countNullValues, + boolean showDuration, long startTime_msec) + { + LOGGER.info("trace serialize for accessUrl: " + ((accessUrl==null)? "null":accessUrl)); - /* reconstruct VLKB-legacy param values from SODA-params */ + writer.println("<?xml version=\"1.0\" encoding=\"" + charEncoding + "\" standalone=\"yes\"?>"); + writer.println("<results>"); + writer.println("<description> SODA cutout from: " + (id==null?"null":id) + " </description>"); - if(coord.shape != null) - { - switch(coord.shape) - { - case "CIRCLE" : - xml.append("<l>"+coord.pos.circle.lon+"</l>"); - xml.append("<b>"+coord.pos.circle.lat+"</b>"); - xml.append("<r>"+coord.pos.circle.radius+"</r>"); - break; - case "RECT" : - xml.append("<l>" + String.valueOf((coord.pos.range.lon1 + coord.pos.range.lon2)/2.0) + "</l>"); - xml.append("<b>" + String.valueOf((coord.pos.range.lat1 + coord.pos.range.lat2)/2.0) + "</b>"); - xml.append("<dl>" + String.valueOf(coord.pos.range.lon2 - coord.pos.range.lon1) + "</dl>"); - xml.append("<db>" + String.valueOf(coord.pos.range.lat2 - coord.pos.range.lat1) + "</db>"); - break; - default: - xml.append("<shape> unknown shape: "+ coord.shape +" </shape>"); - } - } + Coord coord = new Coord(pos, band, time, pol, pixels);// pixels-input + Inputs inputs = new Inputs(id, coord, countNullValues); - if(coord.band != null) - { - xml.append("<vl>" + String.valueOf(coord.band.getMin()) +"</vl>"); - xml.append("<vu>" + String.valueOf(coord.band.getMax()) +"</vu>"); - xml.append("<vtype>" + coord.specSystem + "</vtype>"); - } + serialize(writer, inputs); - return xml.toString(); - } + // pixels-output + if(cutResult.pixels != null) + writer.println("<CUT> " + cutResult.pixels + " </CUT>"); - public static String serialize(AuthPolicy auth) - { - StringBuilder xml = new StringBuilder(); - xml.append("<AccessPolicy>" + auth.getAccessPolicy() + "</AccessPolicy>"); - String ug = auth.getUserGroupsAsString(" "); - if(auth.getUserName() != null) xml.append("<UserName>" + auth.getUserName() + "</UserName>"); - if(ug != null) xml.append("<GroupNames>" + ug + "</GroupNames>"); - return xml.toString(); - } + if(accessUrl != null) + { + writer.println("<URL> " + accessUrl + " </URL>"); + writer.println("<cutoutSize> " + cutResult.fileSize + " </cutoutSize>"); + } + if(cutResult.nullValueCount != null) + writer.println(serialize(cutResult.nullValueCount )); - public static void serialize(PrintWriter writer, Inputs inputs) - { - if(inputs != null) - { - writer.println("<input>"); - if(inputs.pubdid != null) writer.println("<pubdid>"+inputs.pubdid+"</pubdid>"); - if(inputs.coord != null) writer.println(serialize(inputs.coord)); - if(inputs.countNullValues) writer.println("<nullvals> set </nullvals>"); - if(inputs.auth != null) writer.println(serialize(inputs.auth)); - writer.println("</input>"); - } - } + writer.println("<msg> " + Version.asString + " </msg>"); + + writer.println("<DatacubeCount> 1 </DatacubeCount>"); + + if(showDuration) + writer.println("<duration unit=\"msec\">"+(System.currentTimeMillis() - startTime_msec)+"</duration>"); + + writer.println("</results>"); + } + + + + + public static String serialize(NullValueCount nullVals) + { + StringBuilder xml = new StringBuilder(); + xml.append("<nullValues>"); + xml.append("<description> Undefined pixel count </description>"); + xml.append("<percent>" + nullVals.percent + "</percent>"); + xml.append("<pixels>"); + xml.append("<nullcount>" + nullVals.nullCount + "</nullcount>"); + xml.append("<totalcount>" + nullVals.totalCount + "</totalcount>"); + xml.append("</pixels>"); + xml.append("</nullValues>"); + return xml.toString(); + } + + public static String serialize(Coord coord) + { + StringBuilder xml = new StringBuilder(); + xml.append("<SkySystem>"+coord.skySystem+"</SkySystem>"); + + /* reconstruct VLKB-legacy param values from SODA-params */ + + if(coord.shape != null) + { + switch(coord.shape) + { + case "CIRCLE" : + xml.append("<l>"+coord.pos.circle.lon+"</l>"); + xml.append("<b>"+coord.pos.circle.lat+"</b>"); + xml.append("<r>"+coord.pos.circle.radius+"</r>"); + break; + case "RECT" : + xml.append("<l>" + String.valueOf((coord.pos.range.lon1 + coord.pos.range.lon2)/2.0) + "</l>"); + xml.append("<b>" + String.valueOf((coord.pos.range.lat1 + coord.pos.range.lat2)/2.0) + "</b>"); + xml.append("<dl>" + String.valueOf(coord.pos.range.lon2 - coord.pos.range.lon1) + "</dl>"); + xml.append("<db>" + String.valueOf(coord.pos.range.lat2 - coord.pos.range.lat1) + "</db>"); + break; + default: + xml.append("<shape> unknown shape: "+ coord.shape +" </shape>"); + } + } + + if(coord.band != null) + { + xml.append("<vl>" + String.valueOf(coord.band.getMin()) +"</vl>"); + xml.append("<vu>" + String.valueOf(coord.band.getMax()) +"</vu>"); + xml.append("<vtype>" + coord.specSystem + "</vtype>"); + } + + return xml.toString(); + } + + public static String serialize(AuthPolicy auth) + { + StringBuilder xml = new StringBuilder(); + xml.append("<AccessPolicy>" + auth.getAccessPolicy() + "</AccessPolicy>"); + String ug = auth.getUserGroupsAsString(" "); + if(auth.getUserName() != null) xml.append("<UserName>" + auth.getUserName() + "</UserName>"); + if(ug != null) xml.append("<GroupNames>" + ug + "</GroupNames>"); + return xml.toString(); + } + + + public static void serialize(PrintWriter writer, Inputs inputs) + { + if(inputs != null) + { + writer.println("<input>"); + if(inputs.pubdid != null) writer.println("<pubdid>"+inputs.pubdid+"</pubdid>"); + if(inputs.coord != null) writer.println(serialize(inputs.coord)); + if(inputs.countNullValues) writer.println("<nullvals> set </nullvals>"); + if(inputs.auth != null) writer.println(serialize(inputs.auth)); + writer.println("</input>"); + } + } } diff --git a/docker/example-compose-vlkb.yaml b/docker/example-compose-vlkb.yaml index 88b66b5d61a69037b37436567c56bc7826307cdd..5e979843c7ffffb545d0d57bce77922d2b686d7e 100644 --- a/docker/example-compose-vlkb.yaml +++ b/docker/example-compose-vlkb.yaml @@ -30,7 +30,8 @@ services: #- SECURITY=ia2token #- VLKBOBSCORE_PG_URI=postgresql://vialactea:ia2vlkb@pasquale.ia2.inaf.it:5432/vialactea - ACCESS_CONTEXT_ROOT=vlkb#datasets - - URL_CUTOUTS=vlkb-devel.ia2.inaf.it:8004/cutouts + #- URL_CUTOUTS=vlkb-devel.ia2.inaf.it:8004/cutouts + - URL_CUTOUTS=http://localhost:8080/vlkb/datasets/cutouts - RESPONSE_FORMAT=application/x-vlkb+xml #- RESPONSE_FORMAT=application/fits #- RESPONSE_FORMAT=application/fits;createfile=yes