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

mcutout: fixes too long filename (tar limit is 100bytes), fixes some files not...

mcutout: fixes too long filename (tar limit is 100bytes), fixes some files not deleted in /srv/cutouts
parent 58bd23d9
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,8 @@ import java.util.logging.Level; ...@@ -4,6 +4,8 @@ import java.util.logging.Level;
import java.security.Principal; import java.security.Principal;
import java.time.Instant;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -159,8 +161,11 @@ public class ServletCutout extends HttpServlet ...@@ -159,8 +161,11 @@ public class ServletCutout extends HttpServlet
LOGGER.fine("Resolver returns subsurveyId null: no extraCards loaded."); LOGGER.fine("Resolver returns subsurveyId null: no extraCards loaded.");
} }
String cutAbsPathname = settings.fitsPaths.cutouts() + "/"
+ generateSubimgPathname(resolver.relPathname(), resolver.hdunum());
return vlkb.doFile(resolver.relPathname(), resolver.hdunum(), return vlkb.doFile(resolver.relPathname(), resolver.hdunum(),
pos, band, time, pol, pixels, countNullValues, extraCards); pos, band, time, pol, pixels, countNullValues, extraCards, cutAbsPathname);
} }
...@@ -337,6 +342,26 @@ public class ServletCutout extends HttpServlet ...@@ -337,6 +342,26 @@ public class ServletCutout extends HttpServlet
} }
private String generateSubimgPathname(String relPathname, int hdunum)
{
String cutfitsname = "vlkb-cutout";
Instant instant = Instant.now() ;
String timestamp = instant.toString().replace(":","-").replace(".","_");
String tempPathname1 = relPathname.replaceAll("/","-");
String tempPathname2 = tempPathname1.replaceAll(" ","_");
if(hdunum == 1)
{
return cutfitsname + "_" + timestamp + "_" + tempPathname2;
}
else
{
String extnum = "EXT" + String.valueOf(hdunum-1);
return cutfitsname + "_" + timestamp + "_" + extnum + "_" + tempPathname2;
}
}
......
This diff is collapsed.
...@@ -10,6 +10,8 @@ import java.io.OutputStreamWriter; ...@@ -10,6 +10,8 @@ import java.io.OutputStreamWriter;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import org.apache.commons.io.FileUtils;
import uws.UWSException; import uws.UWSException;
import uws.job.ErrorType; import uws.job.ErrorType;
import uws.job.JobThread; import uws.job.JobThread;
...@@ -78,7 +80,10 @@ public class UWSMCutoutWork extends JobThread ...@@ -78,7 +80,10 @@ public class UWSMCutoutWork extends JobThread
} }
String reqJsonString = jsonStringBuffer.toString(); String reqJsonString = jsonStringBuffer.toString();
MCutResult mresult = vlkb.doMCutout(reqJsonString); String workDir = settings.fitsPaths.cutouts() + "/" + job.getJobId();
FileUtils.forceMkdir(new File(workDir));
MCutResult mresult = vlkb.doMCutout(reqJsonString, workDir);
logger.logThread(LogLevel.INFO, this, "Prepare Result", logger.logThread(LogLevel.INFO, this, "Prepare Result",
" job:requestUrl: " + job.getUrl().getRequestURL(), null); " job:requestUrl: " + job.getUrl().getRequestURL(), null);
...@@ -88,9 +93,11 @@ public class UWSMCutoutWork extends JobThread ...@@ -88,9 +93,11 @@ public class UWSMCutoutWork extends JobThread
// delete cut-files (were published/copied to uws-file store) // delete cut-files (were published/copied to uws-file store)
mresult.deleteResJson(); //mresult.deleteResJson();
mresult.deleteCutFiles(); //mresult.deleteCutFiles();
FileUtils.deleteDirectory(new File(workDir));
//FileUtils.deleteQuietly(new File(workDir));// FIXME Never throws except. leaves the dir there if error
/* FIXME here was uws-check is-job-Interrupted */ /* FIXME here was uws-check is-job-Interrupted */
} }
...@@ -104,19 +111,18 @@ public class UWSMCutoutWork extends JobThread ...@@ -104,19 +111,18 @@ public class UWSMCutoutWork extends JobThread
private void publishOnEndpoint(String epName, String mimeType, String absPathname) private void publishOnEndpoint(String epName, String mimeType, String absPathname)
throws FileNotFoundException, IOException, UWSException throws FileNotFoundException, IOException, UWSException
{ {
Result result = new Result(epName, "none", null, false); Result result = new Result(epName, "none", null, false);
result.setMimeType(mimeType); result.setMimeType(mimeType);
File downloadFile = new File(absPathname); File downloadFile = new File(absPathname);
FileInputStream fileInput = new FileInputStream(downloadFile); try(FileInputStream fileInput = new FileInputStream(downloadFile);
OutputStream resOutputStream = getResultOutput(result))
OutputStream resOutputStream = getResultOutput(result); {
fileInput.transferTo(resOutputStream); fileInput.transferTo(resOutputStream);
publishResult(result);
publishResult(result); }
downloadFile.delete();
downloadFile.delete(); }
}
} }
...@@ -15,12 +15,13 @@ public interface Vlkb ...@@ -15,12 +15,13 @@ public interface Vlkb
{ {
public CutResult doFile(String relPathname, int hdunum, public CutResult doFile(String relPathname, int hdunum,
Pos pos, Band band, Time time, Pol pol, String pixels, Pos pos, Band band, Time time, Pol pol, String pixels,
boolean countNullValues, FitsCard[] extraCards) boolean countNullValues, FitsCard[] extraCards,
String cutAbsPathname)
throws IOException, InterruptedException; throws IOException, InterruptedException;
public MCutResult doMCutout(String jdlJson) public MCutResult doMCutout(String jdlJson, String workDir)
throws IOException, InterruptedException; throws IOException, InterruptedException;
......
...@@ -79,7 +79,7 @@ class VlkbAmqp implements Vlkb ...@@ -79,7 +79,7 @@ class VlkbAmqp implements Vlkb
public CutResult doFile(String relPathname, int hdunum, public CutResult doFile(String relPathname, int hdunum,
Pos pos, Band band, Time time, Pol pol, String pixels, Pos pos, Band band, Time time, Pol pol, String pixels,
boolean countNullValues, FitsCard[] extraCards) boolean countNullValues, FitsCard[] extraCards, String dummyCutAbsPathname)
throws IOException, InterruptedException throws IOException, InterruptedException
{ {
LOGGER.fine("trace: " + pos.toString() ); LOGGER.fine("trace: " + pos.toString() );
...@@ -134,7 +134,7 @@ class VlkbAmqp implements Vlkb ...@@ -134,7 +134,7 @@ class VlkbAmqp implements Vlkb
final String DEFAULT_TIME_SYSTEM = "MJD_UTC"; // FIXME take from confif file final String DEFAULT_TIME_SYSTEM = "MJD_UTC"; // FIXME take from confif file
CutResult cutResult = doFile(relPathname, hdunum, pos, band, time, pol, pixels, CutResult cutResult = doFile(relPathname, hdunum, pos, band, time, pol, pixels,
countNullValues, extraCards); countNullValues, extraCards, null);
return cutResult; return cutResult;
} }
...@@ -145,7 +145,7 @@ class VlkbAmqp implements Vlkb ...@@ -145,7 +145,7 @@ class VlkbAmqp implements Vlkb
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
public MCutResult doMCutout(String jdlJson) public MCutResult doMCutout(String jdlJson, String workDir)
throws IOException throws IOException
{ {
LOGGER.fine("trace"); LOGGER.fine("trace");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment