Commit 69b91ce4 authored by Robert Butora's avatar Robert Butora
Browse files

adjust ServletCutout static/instance variable init and Soda/Vlkb constructors

parent 86d69371
Loading
Loading
Loading
Loading
+8 −24
Original line number Diff line number Diff line
@@ -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");
+48 −50
Original line number Diff line number Diff line
@@ -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)
+36 −30
Original line number Diff line number Diff line
@@ -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,10 +44,14 @@ 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 Logger      LOGGER     = Logger.getLogger("ServletCutout");
   protected static final Settings    settings   = Settings.getInstance();
   protected static final Subsurvey[] subsurveys = Subsurvey.loadSubsurveys(settings.fitsPaths.surveysMetadataAbsPathname());

   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;
@@ -54,27 +59,17 @@ public class ServletCutout extends javax.servlet.http.HttpServlet
   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;

   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));
      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
+1 −0
Original line number Diff line number Diff line
@@ -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 =