From e9a3ea07df311e8513a865a2247851e18d505922 Mon Sep 17 00:00:00 2001
From: Robert Butora <robert.butora@gmail.com>
Date: Tue, 2 Apr 2024 10:44:28 -0400
Subject: [PATCH] cutout with doStream to file minors: adds better logging,
 moves db-hostname-configed check to Settings and sets servlet-config to
 legacy-vlkb

---
 data-access/engine/Makefile                        |  4 ++++
 data-access/servlet/config/Makefile                |  7 ++++---
 data-access/servlet/config/cutout.properties.in    | 14 +++++++-------
 data-access/servlet/config/dbms.conf-              |  1 +
 .../servlet/src/main/java/datasets/CutoutImpl.java |  6 ++++++
 .../src/main/java/webapi/ServletCutout.java        |  2 +-
 .../servlet/src/main/java/webapi/Settings.java     |  7 ++++++-
 .../servlet/src/main/resources/cutout.properties   |  2 +-
 8 files changed, 30 insertions(+), 13 deletions(-)
 create mode 100644 data-access/servlet/config/dbms.conf-

diff --git a/data-access/engine/Makefile b/data-access/engine/Makefile
index bb728de..d44feed 100644
--- a/data-access/engine/Makefile
+++ b/data-access/engine/Makefile
@@ -45,6 +45,10 @@ uninstall:
 
 
 # vlkb-devel site local
+.PHONY: vlkb-devel
+vlkb-devel: stop uninstall clean build install config start
+
+
 
 .PHONY: config
 config:
diff --git a/data-access/servlet/config/Makefile b/data-access/servlet/config/Makefile
index 93856fc..6e549a0 100644
--- a/data-access/servlet/config/Makefile
+++ b/data-access/servlet/config/Makefile
@@ -1,9 +1,11 @@
 ################################################################
 # args
 AMQP_QUEUE ?= vlkbdevel
+# if amqp_host_name empty -> uses ExecCmd vlkb for cutout (not AMQP+vlkbd)
 
-# localhost pasquale pasqule-devel
-DBMS ?= localhost
+# Resolver DB: <none> localhost pasquale pasqule-devel
+# DBMS ?= localhost
+# if <none> uses ResolverById
 
 # test prod
 #FITSDB ?= test
@@ -12,7 +14,6 @@ CONTEXT_ROOT ?= vlkb/datasets
 
 # <empty> ia2token garrtoken basic
 AUTH ?=
-#NAUTHZ ?= anonymous
 
 ################################################################
 
diff --git a/data-access/servlet/config/cutout.properties.in b/data-access/servlet/config/cutout.properties.in
index 96e9782..af59304 100644
--- a/data-access/servlet/config/cutout.properties.in
+++ b/data-access/servlet/config/cutout.properties.in
@@ -9,21 +9,21 @@ default_spec_system=VELO_LSRK
 # MIME-type of the response (only one of [1][2][3])
 
 # [1]:
-default_response_format=application/x-vlkb+xml
+# default_response_format=application/fits
 
 # [2]:
 # default_response_format=application/fits;createfile=yes
 # fits_path_cutouts=/srv/vlkb/cutouts
-# amqp_host_name=localhost
+# amqp_host_name=
 # amqp_port=5672
 # amqp_routing_key=AMQP_QUEUE
 
 # [3]:
-# default_response_format=application/x-vlkb+xml
-# surveys_metadata_abs_pathname=/srv/vlkb/surveys/survey_populate.csv
-# fits_path_cutouts=/srv/vlkb/cutouts
-# fits_url_cutouts=http://localhost:8080/CONTEXT_ROOT/cutouts
-# amqp_host_name=localhost
+default_response_format=application/x-vlkb+xml
+surveys_metadata_abs_pathname=/srv/vlkb/surveys/survey_populate.csv
+fits_path_cutouts=/srv/vlkb/cutouts
+fits_url_cutouts=http://vlkb-devel.ia2.inaf.it:8080/CONTEXT_ROOT/cutouts
+# amqp_host_name=
 # amqp_port=5672
 # amqp_routing_key=AMQP_QUEUE
 
diff --git a/data-access/servlet/config/dbms.conf- b/data-access/servlet/config/dbms.conf-
new file mode 100644
index 0000000..ae63d7c
--- /dev/null
+++ b/data-access/servlet/config/dbms.conf-
@@ -0,0 +1 @@
+# DBMS=<empty> -> Resolver will attempt ResolverById
diff --git a/data-access/servlet/src/main/java/datasets/CutoutImpl.java b/data-access/servlet/src/main/java/datasets/CutoutImpl.java
index a253c4c..cd2a6e9 100644
--- a/data-access/servlet/src/main/java/datasets/CutoutImpl.java
+++ b/data-access/servlet/src/main/java/datasets/CutoutImpl.java
@@ -193,9 +193,13 @@ class CutoutImpl implements Cutout
 
          if(settings.amqpConn.isHostnameEmpty())
          {
+            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) );
 
             doStream(relPathname, hdunum, pos, band, time, pol, fileOutputStream);
@@ -211,6 +215,8 @@ class CutoutImpl implements Cutout
          }
          else
          {
+            LOGGER.info("Using AMQP");
+
             JsonEncoder jReq = new JsonEncoder();
             jReq.add(relPathname, hdunum);
             jReq.add(pos);
diff --git a/data-access/servlet/src/main/java/webapi/ServletCutout.java b/data-access/servlet/src/main/java/webapi/ServletCutout.java
index 8b77375..bfad952 100644
--- a/data-access/servlet/src/main/java/webapi/ServletCutout.java
+++ b/data-access/servlet/src/main/java/webapi/ServletCutout.java
@@ -146,7 +146,7 @@ public class ServletCutout extends javax.servlet.http.HttpServlet
 
       String dbUri = settings.dbConn.uri();
 
-      if((dbUri == null) || dbUri.trim().isEmpty())
+      if(settings.dbConn.isDbUriEmpty())
       {
          Resolver rsl = new ResolverFromId();
          rsl.resolve(id);
diff --git a/data-access/servlet/src/main/java/webapi/Settings.java b/data-access/servlet/src/main/java/webapi/Settings.java
index c56f91a..30be9a7 100644
--- a/data-access/servlet/src/main/java/webapi/Settings.java
+++ b/data-access/servlet/src/main/java/webapi/Settings.java
@@ -45,6 +45,11 @@ class Settings
          return uri() + " [" + schema + "] " + user_name + " / " + password  + " ";
       }
 
+      public boolean isDbUriEmpty()
+      {
+         return ((uri == null) || uri.trim().isEmpty());
+      }
+
       public String uri() { return uri; }
       public String schema() { return schema; }
       public String userName() { return user_name; }
@@ -167,7 +172,7 @@ class Settings
    private static AMQPConn loadAMQPConn(Properties properties)
    {
       AMQPConn amqpconn = new AMQPConn();
-      amqpconn.hostName   = properties.getProperty("amqp_host_name", "localhost").strip();
+      amqpconn.hostName   = properties.getProperty("amqp_host_name", "").strip();
       String strPortNum   = properties.getProperty("amqp_port", "5672").strip();
       amqpconn.portNum    = Integer.parseInt(strPortNum);
       amqpconn.routingKey = properties.getProperty("amqp_routing_key", "").strip();
diff --git a/data-access/servlet/src/main/resources/cutout.properties b/data-access/servlet/src/main/resources/cutout.properties
index ad6722d..5d4a790 100644
--- a/data-access/servlet/src/main/resources/cutout.properties
+++ b/data-access/servlet/src/main/resources/cutout.properties
@@ -26,7 +26,7 @@
 # surveys_metadata_abs_pathname=/srv/surveys/survey_populate.csv
 # fits_path_cutouts=/srv/cutouts
 # fits_url_cutouts=
-# amqp_host_name=localhost
+# amqp_host_name=
 # amqp_port=5672
 # amqp_routing_key=
 
-- 
GitLab