Skip to content
Snippets Groups Projects
Commit 294ce7ed authored by Robert Butora's avatar Robert Butora
Browse files

removes DataLink from ServletCutout response-serialization (uses CutResult instead)

parent 3a8d8608
No related branches found
No related tags found
No related merge requests found
Showing with 203 additions and 105 deletions
...@@ -13,17 +13,31 @@ class Coord ...@@ -13,17 +13,31 @@ class Coord
Band band; Band band;
Time time; Time time;
Pol pol; 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.pos = pos;
this.band = band; this.band = band;
this.time = time; this.time = time;
this.pol = pol; this.pol = pol;
this.pixels = pixels;
this.skySystem = skySystem; this.skySystem = skySystem;
this.specSystem = specSystem; 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);
}
} }
...@@ -3,9 +3,10 @@ ...@@ -3,9 +3,10 @@
class CutResult class CutResult
{ {
String filename; String fileName;
long filesize; long fileSize;
NullValueCount nullValueCount; NullValueCount nullValueCount;
String pixels;
CutResult() CutResult()
......
...@@ -339,8 +339,8 @@ class CutoutImpl implements Cutout ...@@ -339,8 +339,8 @@ class CutoutImpl implements Cutout
doStream(relPathname, hdunum, pos, band, time, pol, pixels, fileOutputStream); doStream(relPathname, hdunum, pos, band, time, pol, pixels, fileOutputStream);
// engine returns absPathname see common/cutout.cpp::do_cutout_file() // engine returns absPathname see common/cutout.cpp::do_cutout_file()
cutResult.filename = absSubimgPathname; cutResult.fileName = absSubimgPathname;
cutResult.filesize = Files.size(Paths.get(absSubimgPathname)); cutResult.fileSize = Files.size(Paths.get(absSubimgPathname));
if(countNullValues) if(countNullValues)
{ {
...@@ -351,6 +351,8 @@ class CutoutImpl implements Cutout ...@@ -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)"); LOGGER.info("Adding extraCards to cut-file not implemented when using 'vlkb' exec (implemented in engine vlkbd/AMQP)");
} }
cutResult.pixels = null;
} }
else else
{ {
......
...@@ -213,8 +213,8 @@ class DatasetsImpl implements Datasets ...@@ -213,8 +213,8 @@ class DatasetsImpl implements Datasets
// 3. Merge cut-files // 3. Merge cut-files
//String[] strar_results = mergefiles_parallel(id, logFileName, // logfilename //String[] strar_results = mergefiles_parallel(id, logFileName, // logfileName
//String[] strar_results = mergefiles_split_execution(id, logFileName, // logfilename //String[] strar_results = mergefiles_split_execution(id, logFileName, // logfileName
CutResult strar_results = mergefiles( CutResult strar_results = mergefiles(
String.valueOf(dim), // prefix: "2D" or "3D" String.valueOf(dim), // prefix: "2D" or "3D"
allCutPathnames); // files to merge allCutPathnames); // files to merge
...@@ -455,7 +455,7 @@ class DatasetsImpl implements Datasets ...@@ -455,7 +455,7 @@ class DatasetsImpl implements Datasets
default: default:
LOGGER.severe("Assert(Results.toXML): results msg has unhandled msgtype code : " + res); 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()]); return data.toArray(new String[data.size()]);
......
...@@ -68,8 +68,8 @@ public class JsonDecoder ...@@ -68,8 +68,8 @@ public class JsonDecoder
long null_count = (long) jnvc.get("nullcount"); long null_count = (long) jnvc.get("nullcount");
long total_count = (long) jnvc.get("totalcount"); long total_count = (long) jnvc.get("totalcount");
cut.filesize = fileSize; cut.fileSize = fileSize;
cut.filename = fileName; cut.fileName = fileName;
cut.nullValueCount.percent = fillRatio; cut.nullValueCount.percent = fillRatio;
cut.nullValueCount.nullCount = null_count; cut.nullValueCount.nullCount = null_count;
cut.nullValueCount.totalCount = total_count; cut.nullValueCount.totalCount = total_count;
......
...@@ -128,7 +128,8 @@ public class ServletCutout extends javax.servlet.http.HttpServlet ...@@ -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) boolean countNullValues, String respFormat)
throws IOException, InterruptedException throws IOException, InterruptedException
{ {
...@@ -173,9 +174,9 @@ public class ServletCutout extends javax.servlet.http.HttpServlet ...@@ -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); 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,16 +286,28 @@ public class ServletCutout extends javax.servlet.http.HttpServlet ...@@ -285,16 +286,28 @@ public class ServletCutout extends javax.servlet.http.HttpServlet
boolean countNullValues = vlkbReq_getNullValues(request); boolean countNullValues = vlkbReq_getNullValues(request);
response.setContentType(respFormat); 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); respFormat);
/* FIXME errors from engine not checked - cut-file might not have been created */ /* 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)); PrintWriter writer =new PrintWriter(new OutputStreamWriter(respOutputStream, RESPONSE_ENCODING));
XmlSerializer.serializeToLegacyCutResults(writer,
respEncoding, respDataLink, showDuration, startTime_msec); // 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 */ writer.close(); /* must close to force flush to complete the xml */
} }
else else
...@@ -347,6 +360,17 @@ public class ServletCutout extends javax.servlet.http.HttpServlet ...@@ -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;
}
......
...@@ -105,9 +105,9 @@ public class UWSSodaWork extends JobThread ...@@ -105,9 +105,9 @@ public class UWSSodaWork extends JobThread
CutResult cutResult = datasets.doCutoutFile(rsl.relPathname, rsl.hdunum, pos, band, time, pol, false, null); 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 */ /* send Results */
...@@ -118,12 +118,25 @@ public class UWSSodaWork extends JobThread ...@@ -118,12 +118,25 @@ public class UWSSodaWork extends JobThread
if(respContentType.equals("text/xml") || respContentType.equals("application/xml")) if(respContentType.equals("text/xml") || respContentType.equals("application/xml"))
{ {
PrintWriter writer = new PrintWriter(new OutputStreamWriter(respOutputStream, RESPONSE_ENCODING)); PrintWriter writer = new PrintWriter(new OutputStreamWriter(respOutputStream, RESPONSE_ENCODING));
XmlSerializer.serializeToLegacyCutResults(writer, RESPONSE_ENCODING, respDataLink, showDuration, startTime_msec);
// 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(); writer.close();
} }
else if(respContentType.equals("application/fits")) 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); FileInputStream input = new FileInputStream(downloadFile);
input.transferTo(respOutputStream); input.transferTo(respOutputStream);
......
...@@ -45,7 +45,7 @@ class DataLink ...@@ -45,7 +45,7 @@ class DataLink
String id, Pos pos, Band band, Time time, Pol pol, boolean countNullValues) String id, Pos pos, Band band, Time time, Pol pol, boolean countNullValues)
{ {
this.id = id; this.id = id;
this.accessUrl = convertLocalPathnameToRemoteUrl(cutResult.filename, this.accessUrl = convertLocalPathnameToRemoteUrl(cutResult.fileName,
settings.fitsPaths.cutouts(), settings.fitsPaths.cutoutsUrl()); settings.fitsPaths.cutouts(), settings.fitsPaths.cutoutsUrl());
this.serviceDef = null; this.serviceDef = null;
this.errorMessage = null; this.errorMessage = null;
...@@ -54,16 +54,16 @@ class DataLink ...@@ -54,16 +54,16 @@ class DataLink
// + pos.toString() + " " + band.toString() + " " + time.toString() + " " + pol.toString(); // + pos.toString() + " " + band.toString() + " " + time.toString() + " " + pol.toString();
this.semantics = "http://www.ivoa.net/rdf/datalink/core#proc#cutout"; this.semantics = "http://www.ivoa.net/rdf/datalink/core#proc#cutout";
this.contentType = "application/fits"; this.contentType = "application/fits";
this.contentLength = cutResult.filesize; this.contentLength = cutResult.fileSize;
// VLKB-extension to DataLink: // 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()); LOGGER.info(coord.toString());
this.inputs = new Inputs(id, coord, countNullValues); this.inputs = new Inputs(id, coord, countNullValues);
this.versionString = Version.asString; this.versionString = Version.asString;
this.cut = null; this.cut = null;
this.absCutPathname = cutResult.filename; this.absCutPathname = cutResult.fileName;
this.datacubeCount = 1; this.datacubeCount = 1;
this.nullVals = ((cutResult.nullValueCount.percent < 0) || (cutResult.nullValueCount.totalCount < 1)) ? this.nullVals = ((cutResult.nullValueCount.percent < 0) || (cutResult.nullValueCount.totalCount < 1)) ?
null : cutResult.nullValueCount; null : cutResult.nullValueCount;
...@@ -76,19 +76,19 @@ class DataLink ...@@ -76,19 +76,19 @@ class DataLink
this.nullVals = new NullValueCount(); this.nullVals = new NullValueCount();
this.id = "_PIXEL_BOUNDS"; this.id = "_PIXEL_BOUNDS";
this.accessUrl = cutResult.filename; // FIXME filename ->> remoteUrl this.accessUrl = cutResult.fileName; // FIXME fileName ->> remoteUrl
this.serviceDef = null; this.serviceDef = null;
this.errorMessage = null; this.errorMessage = null;
this.description = "cutout_from ID"; this.description = "cutout_from ID";
this.semantics = "FIXME find in IVOA docs..."; this.semantics = "FIXME find in IVOA docs...";
this.contentType = "application/fits"; this.contentType = "application/fits";
this.contentLength = cutResult.filesize; this.contentLength = cutResult.fileSize;
// VLKB-extension to DataLink: // VLKB-extension to DataLink:
this.inputs = null; this.inputs = null;
this.versionString = Version.asString; this.versionString = Version.asString;
this.cut = null; this.cut = null;
this.absCutPathname = cutResult.filename; this.absCutPathname = cutResult.fileName;
this.datacubeCount = 1; this.datacubeCount = 1;
this.nullVals = cutResult.nullValueCount; this.nullVals = cutResult.nullValueCount;
this.mcutResultArr = null; this.mcutResultArr = null;
...@@ -101,7 +101,7 @@ class DataLink ...@@ -101,7 +101,7 @@ class DataLink
this.nullVals = new NullValueCount(); this.nullVals = new NullValueCount();
this.id = "_PIXEL_BOUNDS"; this.id = "_PIXEL_BOUNDS";
this.accessUrl = cutResult.fileName; // FIXME filename ->> remoteUrl this.accessUrl = cutResult.fileName; // FIXME fileName ->> remoteUrl
this.serviceDef = null; this.serviceDef = null;
this.errorMessage = null; this.errorMessage = null;
this.description = "cutout_from ID"; this.description = "cutout_from ID";
...@@ -122,9 +122,9 @@ class DataLink ...@@ -122,9 +122,9 @@ class DataLink
public String convertLocalPathnameToRemoteUrl(String localPathname, String FITScutpath, String FITSRemoteUrlCutouts) public String convertLocalPathnameToRemoteUrl(String localPathname, String FITScutpath, String FITSRemoteUrlCutouts)
{ {
String filename = localPathname.replaceAll(FITScutpath + "/", ""); String fileName = localPathname.replaceAll(FITScutpath + "/", "");
LOGGER.info("local filename: " + filename); LOGGER.info("local filename: " + fileName);
String remotefname = FITSRemoteUrlCutouts + "/" + filename; String remotefname = FITSRemoteUrlCutouts + "/" + fileName;
LOGGER.info("remote url : " + remotefname); LOGGER.info("remote url : " + remotefname);
return remotefname; return remotefname;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import java.util.logging.Logger; import java.util.logging.Logger;
import java.io.PrintWriter; import java.io.PrintWriter;
import vo.parameter.*;
public final class XmlSerializer public final class XmlSerializer
{ {
...@@ -37,10 +37,53 @@ public final class XmlSerializer ...@@ -37,10 +37,53 @@ public final class XmlSerializer
if(showDuration) 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 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));
writer.println("<?xml version=\"1.0\" encoding=\"" + charEncoding + "\" standalone=\"yes\"?>");
writer.println("<results>");
writer.println("<description> SODA cutout from: " + (id==null?"null":id) + " </description>");
Coord coord = new Coord(pos, band, time, pol, pixels);// pixels-input
Inputs inputs = new Inputs(id, coord, countNullValues);
serialize(writer, inputs);
// pixels-output
if(cutResult.pixels != null)
writer.println("<CUT> " + cutResult.pixels + " </CUT>");
if(accessUrl != null)
{
writer.println("<URL> " + accessUrl + " </URL>");
writer.println("<cutoutSize> " + cutResult.fileSize + " </cutoutSize>");
}
if(cutResult.nullValueCount != null)
writer.println(serialize(cutResult.nullValueCount ));
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>"); writer.println("</results>");
} }
public static String serialize(NullValueCount nullVals) public static String serialize(NullValueCount nullVals)
{ {
StringBuilder xml = new StringBuilder(); StringBuilder xml = new StringBuilder();
......
...@@ -30,7 +30,8 @@ services: ...@@ -30,7 +30,8 @@ services:
#- SECURITY=ia2token #- SECURITY=ia2token
#- VLKBOBSCORE_PG_URI=postgresql://vialactea:ia2vlkb@pasquale.ia2.inaf.it:5432/vialactea #- VLKBOBSCORE_PG_URI=postgresql://vialactea:ia2vlkb@pasquale.ia2.inaf.it:5432/vialactea
- ACCESS_CONTEXT_ROOT=vlkb#datasets - 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/x-vlkb+xml
#- RESPONSE_FORMAT=application/fits #- RESPONSE_FORMAT=application/fits
#- RESPONSE_FORMAT=application/fits;createfile=yes #- RESPONSE_FORMAT=application/fits;createfile=yes
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment