Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • ViaLactea/vlkb-soda
1 result
Select Git revision
Loading items
Show changes
......@@ -11,10 +11,14 @@ class StreamGobbler extends Thread
InputStream is;
String type;
OutputStream os;
StringBuilder sb;
StreamGobbler(InputStream is, String type)
StreamGobbler(InputStream is, String type, StringBuilder sb)
{
this(is, type, null);
this.is = is;
this.type = type;
this.os = null;
this.sb = sb;
}
StreamGobbler(InputStream is, String type, OutputStream redirect)
......@@ -48,7 +52,9 @@ class StreamGobbler extends Thread
}
else
{
LOGGER.finest(type + ">" + new String(buffer, 0, nread, "utf-8"));
String str = new String(buffer, 0, nread, "utf-8");
LOGGER.finest(type + ">" + str);//new String(buffer, 0, nread, "utf-8"));
sb.append(str);
}
}
......@@ -69,7 +75,7 @@ class ExecCmd
public int exitValue;
public void doRun(OutputStream outputStream, String[] cmd)
public void doRun(OutputStream outputStream, String[] cmd, StringBuilder error)
throws IOException, InterruptedException
{
LOGGER.fine("trace CMD: " + Arrays.toString(cmd));
......@@ -82,7 +88,7 @@ class ExecCmd
Process proc = rt.exec(cmd);
// any error message?
StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR", error);
// any output?
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT", outputStream);
......
......@@ -115,8 +115,9 @@ public class ServletCutout extends HttpServlet
}
protected void doCutoutStream(String id, Pos pos, Band band, Time time, Pol pol, String pixels,
OutputStream respOutputStream) throws IOException, InterruptedException
protected int doCutoutStream(String id,
Pos pos, Band band, Time time, Pol pol, Pixeli[] pixeli,
String pixels, OutputStream respOutputStream) throws IOException, InterruptedException
{
LOGGER.fine("trace " + pos);
......@@ -126,9 +127,23 @@ public class ServletCutout extends HttpServlet
final Soda soda = new SodaImpl(settings.fitsPaths);
// if only ID given return header
boolean headerReq = (id!=null)
&& (pos==null) && (band==null) && (time==null) && (pol==null)
&& (pixeli==null)
&& (pixels==null);
resolver.resolve(id);
soda.doStream(resolver.relPathname(), resolver.hdunum(), pos, band, time, pol, pixels, respOutputStream);
if(headerReq)
return soda.doStreamHeader(resolver.relPathname(), resolver.hdunum(),
respOutputStream);
else if(pixels != null)
return soda.doStream(resolver.relPathname(), resolver.hdunum(),
pixels, respOutputStream);
else
return soda.doStream(resolver.relPathname(), resolver.hdunum(),
pos, band, time, pol, pixeli, respOutputStream);
}
......@@ -162,8 +177,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
......@@ -261,6 +278,7 @@ public class ServletCutout extends HttpServlet
Band band = Band.parseBand(params);
Time time = Time.parseTime(params);
Pol pol = Pol.parsePol(params);
Pixeli[] pixeli = parseMultiplePixeliParam(params, "PIXEL_");
String pixels = SingleStringParam.parseSingleStringParam(params, "PIXELS");
String respFormat = sodaReq_getResponseFormat(request, DEFAULT_RESPONSEFORMAT);
......@@ -270,7 +288,8 @@ public class ServletCutout extends HttpServlet
if(respFormat.startsWith("application/fits"))
{
response.setContentType(respFormat);
doCutoutStream(id, pos, band, time, pol, pixels, respOutputStream);
int rc = doCutoutStream(id,pos,band,time,pol,pixeli, pixels, respOutputStream);
if(rc == 1) response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
else if(respFormat.startsWith("application/x-vlkb+xml"))
{
......@@ -418,6 +437,67 @@ public class ServletCutout extends HttpServlet
return (null != soda_getSingleValue(request, "nullvals"));
}
private Pixeli[] parseMultiplePixeliParam(Map<String, String[]> params, String keyRoot)
{
LOGGER.fine("trace");
final int maxAxes = 5;
Pixeli[] pixiArr = new Pixeli[maxAxes];
boolean atLeastOneFound = false;
for(int i=0; i <maxAxes; i++)
{
Pixeli pixi = new Pixeli(0,0,' ');
String[] valArr = params.get(keyRoot + String.valueOf(i+1));
if((valArr != null) && valArr.length != 0)
{
if(valArr.length > 1)
throw new IllegalArgumentException(
"MultiValuedParamNotSupported: "
+ valArr[0] + " was found " + valArr.length + " times");
else
{
// PIXEL_i=m n
String value = valArr[0];
String[] parts = value.split(" ");
if(parts.length != 2)
{
throw new IllegalArgumentException(
"PIXLE_i is interval with two space separated values but "
+ parts.length + " values found: " + value);
}
else
{
try
{
int pix1 = Integer.parseInt(parts[0]);
int pix2 = Integer.parseInt(parts[1]);
if( pix1 < 0 || pix2 < 0)
{
throw new IllegalArgumentException(
"PIXLE_i interval must be positive integers but: "
+ String.valueOf(pix1) + " " + String.valueOf(pix2));
}
pixi = new Pixeli(pix1,pix2,'x');
atLeastOneFound = true;
}
catch(NumberFormatException e)
{
throw new IllegalArgumentException(
"PIXLE_i is interval of integers but : "
+ e.getMessage());
}
}
}
}
pixiArr[i] = pixi;
LOGGER.fine("pixiArr["+ i +"]: " + pixiArr[i].pix1 +" "+ pixiArr[i].pix2
+" " + pixiArr[i].type);
}
// dont return empty (0,0,' ') array
return atLeastOneFound ? pixiArr : null;
}
}
......
......@@ -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,34 +101,32 @@ 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 );
Pixeli[] pixeli = null;
try(OutputStream fileOutputStream = new FileOutputStream(new File(cutAbsPathname)))
{
soda.doStream(relPathname, hdunum, pos, band, time, pol, pixels, fileOutputStream);
soda.doStream(relPathname, hdunum, pos, band, time, pol, pixeli, fileOutputStream);
}
}
/*
CutResult cutResult = new CutResult();
cutResult.fileName = cutAbsPathname;
cutResult.fileSize = Files.size(Paths.get(cutAbsPathname));
if(countNullValues)
public void doFile(String relPathname, int hdunum,
String pixels, String cutAbsPathname)
throws IOException, InterruptedException
{
cutResult.nullValueCount = doCountNullValues(cutAbsPathname, 1);
}
if(extraCards == null || (extraCards.length < 1))
LOGGER.fine("trace: " + cutAbsPathname );
try(OutputStream fileOutputStream = new FileOutputStream(new File(cutAbsPathname)))
{
LOGGER.finer("Adding extraCards to cut-file implemented only in VlkbAmql");
soda.doStream(relPathname, hdunum, pixels, fileOutputStream);
}
}
cutResult.pixels = null;
return cutResult;
*/ }
public MCutResult doMCutout(String jdlJson, String workDir)
......@@ -205,7 +203,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;
......@@ -347,8 +348,9 @@ class VlkbCli implements Vlkb
cmdBounds[1] = "nullvals";
cmdBounds[2] = absPathname;
StringBuilder errorStrBuilder = new StringBuilder();
ExecCmd exec = new ExecCmd();
exec.doRun(bos, cmdBounds);
exec.doRun(bos, cmdBounds, errorStrBuilder);
LOGGER.finest("exec NullVals exitValue: " + exec.exitValue);
bos.close();
......@@ -378,7 +380,8 @@ class VlkbCli implements Vlkb
}
else
{
throw new AssertionError("'vlkb nullvals' exited without results for: " + absPathname);
throw new AssertionError("'vlkb nullvals' exited with error: "
+ errorStrBuilder.toString() + " for: " + absPathname);
}
}
......
......@@ -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;
......
......@@ -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);
......