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

(removes commented code from previous) implements response-*.json to add into tar.gz

parent de78264d
No related branches found
No related tags found
No related merge requests found
import org.json.simple.JSONObject;
class MCutResult
{
......@@ -10,6 +11,15 @@ class MCutResult
public int index;
public ContentType contentType;
public String content;
JSONObject toJsonObject()
{
JSONObject jo = new JSONObject();
//jo.put("input", inputs.toJsonObject());
jo.put("type", contentType.toString());
jo.put("content", content);
return jo;
}
}
......
......@@ -32,6 +32,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
import java.io.BufferedOutputStream;
import java.util.Date;
import java.text.SimpleDateFormat;
import org.json.simple.JSONArray;
import vo.parameter.*;
......@@ -89,7 +90,8 @@ class DatasetsCli implements Datasets
CutArgs[] cutArgsArr = CutArgs.parseCutArgsArr(jdlJson);
MCutResult.Cut[] cutResultArr = doCutouts( cutArgsArr );
mCutResult = doCompressCutFiles( cutResultArr );
String respJsonString = genResponseJson( cutResultArr );
mCutResult = doCompressCutFiles( cutResultArr, respJsonString );
return mCutResult;
}
......@@ -121,46 +123,25 @@ class DatasetsCli implements Datasets
// FIXME implement similar for Merge: MCutResult = call-Montage-demosaic-sequence(cutResultArr)
private MCutResult doCompressCutFiles(MCutResult.Cut[] cutArr)
private MCutResult doCompressCutFiles(MCutResult.Cut[] cutArr, String respJsonString)
throws IOException, InterruptedException
{
String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
Instant instant = Instant.now();
String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + "_" + instant.getNano();
final String tgzFileName = settings.fitsPaths.cutouts() + "/mcutout_" + timestamp + ".tar.gz";
/*
StringBuilder sb = new StringBuilder();
for(MCutResult.Cut cut : cutArr)
{
LOGGER.info("cut-id"+ String.valueOf(cut.index) + " -> " + cut.content);
if(cut.contentType == MCutResult.Cut.ContentType.FILENAME)
// generate response-*.json with timestamp
String respJsonPathname = settings.fitsPaths.cutouts() + "/response_" + timestamp + ".json";
try (PrintWriter out = new PrintWriter(respJsonPathname))
{
Path p = Paths.get(cut.content);
sb.append(" " + p.getFileName().toString());
}
out.print(respJsonString);
}
String[] cmd = new String[6];
cmd[0] = "/bin/tar";
cmd[1] = "cfz";
cmd[2] = tgzFileName;
cmd[3] = "-C";
cmd[4] = settings.fitsPaths.cutouts();
cmd[5] = sb.toString();
LOGGER.info("CMD: " + String.join(" ",cmd));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
if(bos == null)
throw new AssertionError("byte output stream for bounds was not created, is null");
ExecCmd exec = new ExecCmd();
exec.doRun(bos, cmd);
LOGGER.info("exec tar.gz exitValue: " + exec.exitValue);
boolean has_result = (exec.exitValue == 0);
*/
List<Path> paths = new ArrayList<Path>();
paths.add(Paths.get(respJsonPathname));
for(MCutResult.Cut cut : cutArr)
{
LOGGER.info("cut-id"+ String.valueOf(cut.index) + " -> " + cut.content);
......@@ -179,12 +160,26 @@ class DatasetsCli implements Datasets
mCutResult.fileName = tgzFileName;
mCutResult.fileSize = Files.size(output);
// FIXME add response.json to tar.gz, add nanosecs to timestamp
return mCutResult;
}
private String genResponseJson(MCutResult.Cut[] cutArr)
{
List<Path> paths = new ArrayList<Path>();
JSONArray jArr = new JSONArray();
for(MCutResult.Cut cut : cutArr)
{
jArr.add(cut.toJsonObject());
}
return jArr.toString();
}
private MCutResult.Cut doFileByIdWithErr(String id, Pos pos, Band band, Time time, Pol pol, String pixels,
boolean countNullValues, Subsurvey[] subsurveys)
{
......@@ -237,11 +232,8 @@ class DatasetsCli implements Datasets
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
*/
public static void createTarGzipFiles(List<Path> paths, Path output)
private static void createTarGzipFiles(List<Path> paths, Path output)
throws IOException
{
try (OutputStream fOut = Files.newOutputStream(output);
......@@ -270,7 +262,6 @@ class DatasetsCli implements Datasets
tOut.finish();
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment