diff --git a/data-access/servlet/src/main/java/ops/SodaImpl.java b/data-access/servlet/src/main/java/ops/SodaImpl.java index 3eeba263ce7dc4bddaa3ec8689c1877fa7e25375..637c28324bee70b7d4627a1a97e22086d5dd4d28 100644 --- a/data-access/servlet/src/main/java/ops/SodaImpl.java +++ b/data-access/servlet/src/main/java/ops/SodaImpl.java @@ -30,32 +30,16 @@ import vo.parameter.*; class SodaImpl implements Soda { - static final Logger LOGGER = Logger.getLogger("SodaImpl"); + private static final Logger LOGGER = Logger.getLogger("SodaImpl"); + private static Settings.FITSPaths fitsPaths = null; - private Settings settings = null; - private Subsurvey[] subsurveys = null; + private SodaImpl() {} - public SodaImpl() + public SodaImpl(Settings.FITSPaths fitsPaths) { - LOGGER.info("trace SodaImpl()"); - this.settings = Settings.getInstance(); - this.subsurveys = null; - } - - - public SodaImpl(Settings settings) - { - LOGGER.info("trace SodaImpl(settings)"); - this.settings = settings; - this.subsurveys = null; - } - - public SodaImpl(Settings settings, Subsurvey[] subsurveys) - { - LOGGER.info("trace SodaImpl(settings)"); - this.settings = settings; - this.subsurveys = subsurveys; + LOGGER.info("trace"); + this.fitsPaths = fitsPaths; } @@ -69,7 +53,7 @@ class SodaImpl implements Soda boolean pixels_valid = (pixels != null); String boundsString = ""; - String absPathname = settings.fitsPaths.surveys() + "/" + relPathname; + String absPathname = fitsPaths.surveys() + "/" + relPathname; if( !pixels_valid ) { @@ -132,7 +116,7 @@ class SodaImpl implements Soda cmdCut[2] = absPathname; cmdCut[3] = String.valueOf(hdunum-1); cmdCut[4] = pixFilterString; - cmdCut[5] = settings.fitsPaths.cutouts(); + cmdCut[5] = fitsPaths.cutouts(); if(outputStream == null) LOGGER.info("supplied outputStream for cut-file is null"); diff --git a/data-access/servlet/src/main/java/ops/VlkbCli.java b/data-access/servlet/src/main/java/ops/VlkbCli.java index 4e15e3bb201e9252633741ae73c5190b70fbb975..9b01482ee2fe26eefc7e3fdad9c658dac448f940 100644 --- a/data-access/servlet/src/main/java/ops/VlkbCli.java +++ b/data-access/servlet/src/main/java/ops/VlkbCli.java @@ -43,14 +43,15 @@ class VlkbCli implements Vlkb private Settings settings = null; private Subsurvey[] subsurveys = null; - private Soda soda = null; private Resolver resolver = null; + private Soda soda = null; + public VlkbCli() { LOGGER.info("trace VlkbCli()"); this.settings = Settings.getInstance(); - this.soda = new SodaImpl(settings, subsurveys); + this.soda = new SodaImpl(settings.fitsPaths); this.resolver = (settings.dbConn.isDbUriEmpty() ? new ResolverFromId(subsurveys) : new ResolverByObsCore(settings.dbConn, subsurveys)); } @@ -60,7 +61,7 @@ class VlkbCli implements Vlkb { LOGGER.info("trace VlkbCli(settings)"); this.settings = settings; - this.soda = new SodaImpl(settings, subsurveys); + this.soda = new SodaImpl(settings.fitsPaths); this.resolver = (settings.dbConn.isDbUriEmpty() ? new ResolverFromId(subsurveys) : new ResolverByObsCore(settings.dbConn, subsurveys)); } @@ -71,15 +72,13 @@ class VlkbCli implements Vlkb LOGGER.info("trace VlkbCli(settings, subsurveys)"); this.settings = settings; this.subsurveys = subsurveys; - this.soda = new SodaImpl(settings, subsurveys); + this.soda = new SodaImpl(settings.fitsPaths); this.resolver = (settings.dbConn.isDbUriEmpty() ? new ResolverFromId(subsurveys) : new ResolverByObsCore(settings.dbConn, subsurveys)); } - - public CutResult doMerge(String[] idArr, Coord coord, boolean countNullValues) throws FileNotFoundException, IOException { @@ -90,7 +89,44 @@ class VlkbCli implements Vlkb - /////////////////////////////////////////////////////////////////////////////////////// + public CutResult doFile(String relPathname, int hdunum, + Pos pos, Band band, Time time, Pol pol, String pixels, + boolean countNullValues, FitsCard[] extraCards) + throws IOException, InterruptedException + { + LOGGER.info("trace: " + pos.toString() ); + + CutResult cutResult = new CutResult(); + + LOGGER.info("Using doStream() to local file"); + + String absSubimgPathname = settings.fitsPaths.cutouts() + + "/" + generateSubimgPathname(relPathname, hdunum); + + LOGGER.info("Uses local filename : " + absSubimgPathname); + + OutputStream fileOutputStream = new FileOutputStream( new File(absSubimgPathname) ); + + soda.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)); + + if(countNullValues) + { + cutResult.nullValueCount = doCountNullValues(absSubimgPathname, 1); + } + + if(extraCards == null || (extraCards.length < 1)) + { + LOGGER.info("Adding extraCards to cut-file implemented only in VlkbAmql"); + } + + cutResult.pixels = null; + return cutResult; + } + private NullValueCount doCountNullValues(String absPathname, int hdunum) @@ -125,7 +161,8 @@ class VlkbCli implements Vlkb // parse result: '<fill-ratio> <nullvals-count> <tot-count>' String[] splitStr = nullValsString.trim().split("\\s+"); - if(splitStr.length != 3) throw new AssertionError("'vlkb nullvals' did not return 3 numbers but: " + nullValsString); + if(splitStr.length != 3) + throw new AssertionError("'vlkb nullvals' did not return 3 numbers but: " + nullValsString); NullValueCount nvc = new NullValueCount(); nvc.percent = Double.parseDouble(splitStr[0]); @@ -140,43 +177,6 @@ class VlkbCli implements Vlkb } - public CutResult doFile(String relPathname, int hdunum, - Pos pos, Band band, Time time, Pol pol, String pixels, - boolean countNullValues, FitsCard[] extraCards) - throws IOException, InterruptedException - { - LOGGER.info("trace: " + pos.toString() ); - - CutResult cutResult = new CutResult(); - - LOGGER.info("Using doStream() to local file"); - - String absSubimgPathname = settings.fitsPaths.cutouts() - + "/" + generateSubimgPathname(relPathname, hdunum); - - LOGGER.info("Uses local filename : " + absSubimgPathname); - - OutputStream fileOutputStream = new FileOutputStream( new File(absSubimgPathname) ); - - soda.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)); - - if(countNullValues) - { - cutResult.nullValueCount = doCountNullValues(absSubimgPathname, 1); - } - - if(extraCards == null || (extraCards.length < 1)) - { - LOGGER.info("Adding extraCards to cut-file not implemented when using 'vlkb' exec (implemented in engine vlkbd/AMQP)"); - } - - cutResult.pixels = null; - return cutResult; - } private CutResult doFileById(String id, Pos pos, Band band, Time time, Pol pol, String pixels, @@ -209,6 +209,7 @@ class VlkbCli implements Vlkb return cutResult; } + private String generateSubimgPathname(String relPathname, int hdunum) { String cutfitsname = "vlkb-cutout"; @@ -231,9 +232,6 @@ class VlkbCli implements Vlkb } - /////////////////////////////////////////////////////////////////////////////////////// - - public MCutResult doMCutout(String jdlJson) @@ -377,7 +375,7 @@ class VlkbCli implements Vlkb - /* + /* <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-compress</artifactId> @@ -387,7 +385,7 @@ class VlkbCli implements Vlkb import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; - */ + */ private static void createTarGzipFiles(List<Path> paths, Path output) throws IOException { diff --git a/data-access/servlet/src/main/java/webapi/ServletCutout.java b/data-access/servlet/src/main/java/webapi/ServletCutout.java index 0eefaf109e567d292db03995dc7261e0e1249448..7dc4964e077141affaacc2013b8df45d88005f43 100644 --- a/data-access/servlet/src/main/java/webapi/ServletCutout.java +++ b/data-access/servlet/src/main/java/webapi/ServletCutout.java @@ -4,6 +4,7 @@ import java.util.logging.Logger; import java.security.Principal; import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletOutputStream; @@ -43,38 +44,32 @@ import java.nio.file.Paths; import vo.parameter.*; -public class ServletCutout extends javax.servlet.http.HttpServlet +public class ServletCutout extends HttpServlet { - protected static final Logger LOGGER = Logger.getLogger(ServletCutout.class.getName()); - protected static final Settings settings = Settings.getInstance(); + protected static final Logger LOGGER = Logger.getLogger("ServletCutout"); + protected static final Settings settings = Settings.getInstance(); + protected static final Subsurvey[] subsurveys = Subsurvey.loadSubsurveys(settings.fitsPaths.surveysMetadataAbsPathname()); - final String RESPONSE_ENCODING = "utf-8"; + protected boolean resolveFromId = settings.dbConn.isDbUriEmpty(); + protected boolean useEngineOverCli = settings.amqpConn.isHostnameEmpty(); + + final String RESPONSE_ENCODING = "utf-8"; final String DEFAULT_RESPONSEFORMAT = settings.defaults.responseFormat; final String DEFAULT_SKY_SYSTEM = settings.defaults.skySystem; final String DEFAULT_SPEC_SYSTEM = settings.defaults.specSystem; - final String DEFAULT_TIME_SYSTEM = "MJD_UTC"; // FIXME take from confif file - - boolean showDuration = settings.defaults.showDuration; - long startTime_msec; - - private Subsurvey[] subsurveys = null; - - protected Soda soda = new SodaImpl(settings, subsurveys); - protected Vlkb vlkb = ( settings.amqpConn.isHostnameEmpty() ? new VlkbCli(settings): new VlkbAmqp(settings) ); - protected Resolver resolver = null; + final String DEFAULT_TIME_SYSTEM = "MJD_UTC"; // FIXME take from confif file public void init() throws ServletException { - super.init(); - - LOGGER.info("AMQP : " + settings.amqpConn.toString()); - LOGGER.info("FITS : " + settings.fitsPaths.toString()); - String surveysAbsPathname = settings.fitsPaths.surveysMetadataAbsPathname(); - if( (surveysAbsPathname != null) && (surveysAbsPathname.length() > 1) ) - subsurveys = Subsurvey.loadSubsurveys(surveysAbsPathname); - - resolver = (settings.dbConn.isDbUriEmpty() ? new ResolverFromId(subsurveys) - : new ResolverByObsCore(settings.dbConn, subsurveys)); + LOGGER.info("FITS : " + settings.fitsPaths.toString()); + if(subsurveys != null) + LOGGER.info("Subsurveys loaded : " + String.valueOf(subsurveys.length)); + LOGGER.info("DEFAULT SKY/SPEC/TIME SYSTEM : " + DEFAULT_SKY_SYSTEM + " / " + DEFAULT_SPEC_SYSTEM + " / " + DEFAULT_TIME_SYSTEM); + LOGGER.info("DEFAULT_RESPONSEFORMAT : " + DEFAULT_RESPONSEFORMAT); + LOGGER.info("Resolver : " + (resolveFromId ? "IVOID" : "DB")); + LOGGER.info("Engine : " + (useEngineOverCli ? "CLI" : "AMQP")); + if(!useEngineOverCli) + LOGGER.info("AMQP : " + settings.amqpConn.toString()); } @@ -127,6 +122,12 @@ public class ServletCutout extends javax.servlet.http.HttpServlet { LOGGER.info("trace" + pos); + final Resolver resolver = (resolveFromId ? + new ResolverFromId(subsurveys) : + new ResolverByObsCore(settings.dbConn, subsurveys)); + + final Soda soda = new SodaImpl(settings.fitsPaths); + resolver.resolve(id); soda.doStream(resolver.relPathname(), resolver.hdunum(), pos, band, time, pol, pixels, respOutputStream); @@ -141,6 +142,11 @@ public class ServletCutout extends javax.servlet.http.HttpServlet FitsCard[] extraCards = null; + final Resolver resolver = (resolveFromId ? new ResolverFromId(subsurveys): new ResolverByObsCore(settings.dbConn, subsurveys)); + final Vlkb vlkb = (useEngineOverCli ? new VlkbCli(settings) : new VlkbAmqp(settings)); + + resolver.resolve(id); + String subsurveyId = resolver.obsCollection(); if(subsurveyId != null) { @@ -181,7 +187,6 @@ public class ServletCutout extends javax.servlet.http.HttpServlet protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, UnsupportedEncodingException { - startTime_msec = System.currentTimeMillis(); final boolean NO_QUERY_STRING = (request.getQueryString() == null); @@ -193,7 +198,7 @@ public class ServletCutout extends javax.servlet.http.HttpServlet } else { - convertHttpToSoda(request, response); + execRequest(request, response); LOGGER.info("normal exit"); } } @@ -201,8 +206,6 @@ public class ServletCutout extends javax.servlet.http.HttpServlet protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, UnsupportedEncodingException { - startTime_msec = System.currentTimeMillis(); - final boolean NO_QUERY_STRING = (request.getQueryString() == null); if(NO_QUERY_STRING) @@ -213,7 +216,7 @@ public class ServletCutout extends javax.servlet.http.HttpServlet } else { - convertHttpToSoda(request, response); + execRequest(request, response); LOGGER.info("normal exit"); } } @@ -231,10 +234,13 @@ public class ServletCutout extends javax.servlet.http.HttpServlet - protected void convertHttpToSoda(HttpServletRequest request, HttpServletResponse response) + protected void execRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, UnsupportedEncodingException { + boolean showDuration = settings.defaults.showDuration; + long startTime_msec = System.currentTimeMillis(); + ServletOutputStream respOutputStream = response.getOutputStream(); try diff --git a/data-access/servlet/src/main/java/webapi/Settings.java b/data-access/servlet/src/main/java/webapi/Settings.java index 5ae1bb527e687bb9aad4edc840735f6bd14c6b88..c69075e3d1fa8d3bed7caa1605d1136588277b9e 100644 --- a/data-access/servlet/src/main/java/webapi/Settings.java +++ b/data-access/servlet/src/main/java/webapi/Settings.java @@ -97,6 +97,7 @@ class Settings // no reasonable code-defaults can be invented public static Settings getInstance() { + LOGGER.info("Settings loading from: " + CUTOUT_PROPERTIES); try { InputStream ins =