diff --git a/.dockerignore b/.dockerignore index 22fb0bc..58d8271 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,5 @@ pom.xml *jar -!opentelemetry-javaagent.jar lib classes *~ diff --git a/.gitignore b/.gitignore index 099bf07..d420222 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ pom.xml *jar -!opentelemetry-javaagent.jar lib classes *~ @@ -21,3 +20,5 @@ build/ build.xml test2junit resources/ +.clj-kondo/ +.lsp/ diff --git a/Dockerfile b/Dockerfile index 2b188a7..e7c2be5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,14 @@ -FROM clojure:openjdk-17-lein +FROM clojure:temurin-22-lein-jammy WORKDIR /usr/src/app -#RUN apk add --no-cache --update git nodejs-lts npm && \ -# rm -rf /var/cache/apk -RUN apt update && apt install -y nodejs npm +RUN apt-get update && \ + apt-get install -y git nodejs npm && \ + rm -rf /var/lib/apt/lists/* RUN npm install -g grunt-cli -RUN ln -s "/usr/local/openjdk-17/bin/java" "/bin/kifshare" - -ENV OTEL_TRACES_EXPORTER none +RUN ln -s "/opt/java/openjdk/bin/java" "/bin/kifshare" COPY project.clj /usr/src/app/ RUN lein deps @@ -26,7 +24,7 @@ COPY ui/ui.xml resources/ RUN lein uberjar RUN cp target/kifshare-standalone.jar . -ENTRYPOINT ["kifshare", "-Dlogback.configurationFile=/etc/iplant/de/logging/kifshare-logging.xml", "-javaagent:/usr/src/app/opentelemetry-javaagent.jar", "-Dotel.resource.attributes=service.name=kifshare", "-cp", ".:resources:kifshare-standalone.jar", "kifshare.core"] +ENTRYPOINT ["kifshare", "-Dlogback.configurationFile=/etc/iplant/de/logging/kifshare-logging.xml", "-cp", ".:resources:kifshare-standalone.jar", "kifshare.core"] CMD ["--help"] ARG git_commit=unknown diff --git a/kifshare.properties.tmpl b/kifshare.properties.tmpl deleted file mode 100644 index bc86ab6..0000000 --- a/kifshare.properties.tmpl +++ /dev/null @@ -1,32 +0,0 @@ -{{- with $base := (printf "configs/%s" (env "DE_ENV")) -}} -{{ with $v := (key (printf "%s/irods/host" $base)) }}kifshare.irods.host = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/irods/port" $base)) }}kifshare.irods.port = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/irods/user" $base)) }}kifshare.irods.user = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/irods/pass" $base)) }}kifshare.irods.password = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/irods/home" $base)) }}kifshare.irods.home = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/irods/zone" $base)) }}kifshare.irods.zone = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/irods/resc" $base)) }}kifshare.irods.defaultResource = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/services/port" $base)) }}kifshare.app.port = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/mode" $base)) }}kifshare.app.mode = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/download-buffer-size" $base)) }}kifshare.app.download-buffer-size = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/footer-text" $base)) }}kifshare.app.footer-text = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/resources-root" $base)) }}kifshare.app.resources-root = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/images-dir" $base)) }}kifshare.app.images-dir = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/js-dir" $base)) }}kifshare.app.js-dir = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/css-dir" $base)) }}kifshare.app.css-dir = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/flash-dir" $base)) }}kifshare.app.flash-dir = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/favicon-path" $base)) }}kifshare.app.favicon-path = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/client-cache/scope" $base)) }}kifshare.app.client-cache-scope = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/client-cache/max-age" $base)) }}kifshare.app.client-cache-max-age = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/de-url" $base)) }}kifshare.app.de-url = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/irods-url" $base)) }}kifshare.app.irods-url = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/flags/de-import" $base)) }}kifshare.app.de-import-flags = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/flags/curl" $base)) }}kifshare.app.curl-flags = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/flags/wget" $base)) }}kifshare.app.wget-flags = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/flags/iget" $base)) }}kifshare.app.iget-flags = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/flags/iget" $base)) }}kifshare.app.iget-flags = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/css-files" $base)) }}kifshare.app.css-files = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/javascript-files" $base)) }}kifshare.app.javascript-files = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/amqp/uri" $base)) }}kifshare.amqp.uri = {{ $v }}{{ end }} -{{ with $v := (key (printf "%s/kifshare/de/base" $base)) }}kifshare.app.de-url = {{ $v }}{{ end }} -{{- end -}} diff --git a/opentelemetry-javaagent.jar b/opentelemetry-javaagent.jar deleted file mode 100644 index a152125..0000000 Binary files a/opentelemetry-javaagent.jar and /dev/null differ diff --git a/project.clj b/project.clj index 254f27f..e60090a 100644 --- a/project.clj +++ b/project.clj @@ -7,7 +7,7 @@ (string/trim (:out (sh "git" "rev-parse" "HEAD"))) "")) -(defproject org.cyverse/kifshare "2.12.0-SNAPSHOT" +(defproject org.cyverse/kifshare "3.0.1-SNAPSHOT" :description "CyVerse Quickshare for iRODS" :url "https://github.com/cyverse-de/kifshare" @@ -17,32 +17,30 @@ :manifest {"Git-Ref" ~(git-ref)} :uberjar-name "kifshare-standalone.jar" - :dependencies [[org.clojure/clojure "1.11.1"] + :dependencies [[org.clojure/clojure "1.11.4"] [org.clojure/tools.logging "1.3.0"] - [ch.qos.logback/logback-classic "1.5.3"] - [net.logstash.logback/logstash-logback-encoder "7.4"] + [ch.qos.logback/logback-classic "1.5.6"] + [net.logstash.logback/logstash-logback-encoder "8.0"] [hawk "0.2.11"] + [hiccup "1.0.2"] [medley "1.4.0"] - [org.cyverse/clj-jargon "3.1.0" + [org.cyverse/clj-jargon "3.1.1" :exclusions [[org.slf4j/slf4j-log4j12] [log4j]]] - [org.cyverse/debug-utils "2.8.1"] - [org.cyverse/clojure-commons "2.8.0"] - [org.cyverse/common-cli "2.8.1"] - [org.cyverse/event-messages "0.0.1"] - [com.novemberain/langohr "3.5.1"] + [org.cyverse/debug-utils "2.9.0"] + [org.cyverse/clojure-commons "3.0.9"] + [org.cyverse/common-cli "2.8.2"] [me.raynes/fs "1.4.6"] - [cheshire "5.12.0" + [cheshire "5.13.0" :exclusions [[com.fasterxml.jackson.dataformat/jackson-dataformat-cbor] [com.fasterxml.jackson.dataformat/jackson-dataformat-smile] [com.fasterxml.jackson.core/jackson-annotations] [com.fasterxml.jackson.core/jackson-databind] [com.fasterxml.jackson.core/jackson-core]]] [slingshot "0.12.2"] - [compojure "1.5.0"] - [de.ubercode.clostache/clostache "1.4.0"] + [compojure "1.7.1"] [com.cemerick/url "0.1.1" :exclusions [com.cemerick/clojurescript.test]] - [ring-logger "1.1.1"]] + [ring/ring-core "1.12.2"]] :eastwood {:exclude-namespaces [:test-paths] :linters [:wrong-arity :wrong-ns-form :wrong-pre-post :wrong-tag :misplaced-docstrings]} @@ -50,16 +48,13 @@ :ring {:init kifshare.config/init :handler kifshare.core/app} - :profiles {:dev {:resource-paths ["build" "conf" "dev-resources"] - :jvm-opts ["-Dotel.javaagent.enabled=false"]} + :profiles {:dev {:resource-paths ["build" "conf" "dev-resources"]} :uberjar {:aot :all}} - :plugins [[jonase/eastwood "1.4.2"] + :plugins [[jonase/eastwood "1.4.3"] [lein-ancient "0.7.0"] - [lein-ring "0.7.5"] - [test2junit "1.2.2"]] + [lein-ring "0.12.6"] + [test2junit "1.4.4"]] :main ^:skip-aot kifshare.core - :jvm-opts ["-Dlogback.configurationFile=/etc/iplant/de/logging/kifshare-logging.xml" - "-javaagent:./opentelemetry-javaagent.jar" - "-Dotel.resource.attributes=service.name=kifshare"]) + :jvm-opts ["-Dlogback.configurationFile=/etc/iplant/de/logging/kifshare-logging.xml"]) diff --git a/src/kifshare/amqp.clj b/src/kifshare/amqp.clj deleted file mode 100644 index b62f759..0000000 --- a/src/kifshare/amqp.clj +++ /dev/null @@ -1,33 +0,0 @@ -(ns kifshare.amqp - (:require [clojure.tools.logging :as log] - [kifshare.config :as config] - [langohr.core :as rmq] - [langohr.channel :as lch] - [langohr.queue :as lq] - [langohr.consumers :as lc] - [langohr.exchange :as le])) - -(defn- declare-queue - [channel {exchange-name :name} queue-cfg topics] - (lq/declare channel (:name queue-cfg) (assoc queue-cfg :exclusive false)) - (doseq [key topics] - (lq/bind channel (:name queue-cfg) exchange-name {:routing-key key}))) - -(defn- declare-exchange - [channel {exchange-name :name :as exchange-cfg}] - (le/topic channel exchange-name exchange-cfg)) - -(defn- message-router - [handlers channel {:keys [delivery-tag routing-key] :as metadata} msg] - (let [handler (get handlers routing-key)] - (if-not (nil? handler) - (handler channel metadata msg) - (log/error (format "[amqp/message-router] [%s] [%s] unroutable" routing-key (String. msg)))))) - -(defn connect - [exchange-cfg queue-cfg handlers] - (let [channel (lch/open (rmq/connect {:uri (config/amqp-uri)}))] - (log/info (format "[amqp/connect] [%s]" (config/amqp-uri))) - (declare-exchange channel exchange-cfg) - (declare-queue channel exchange-cfg queue-cfg (keys handlers)) - (lc/blocking-subscribe channel (:name queue-cfg) (partial message-router handlers)))) diff --git a/src/kifshare/config.clj b/src/kifshare/config.clj index fa599ff..b88f22a 100644 --- a/src/kifshare/config.clj +++ b/src/kifshare/config.clj @@ -145,42 +145,6 @@ [] (or (get @props "kifshare.irods.anon-user") "anonymous")) -(defn amqp-uri - [] - (or (get @props "kifshare.amqp.uri") "amqp://guest:guest@rabbit:5672/")) - -(defn exchange-name - [] - (or (get @props "kifshare.amqp.exchange.name") "de")) - -(defn exchange-durable? - [] - (if-let [val (get @props "kifshare.amqp.exchange.durable")] - (boolean (Boolean/valueOf val)) - true)) - -(defn exchange-auto-delete? - [] - (if-let [val (get @props "kifshare.amqp.exchange.auto-delete")] - (boolean (Boolean/valueOf val)) - false)) - -(defn queue-name - [] - (or (get @props "kifshare.amqp.queue.name") "events.kifshare.queue")) - -(defn queue-durable? - [] - (if-let [val (get @props "kifshare.amqp.queue.durable")] - (boolean (Boolean/valueOf val)) - true)) - -(defn queue-auto-delete? - [] - (if-let [val (get @props "kifshare.amqp.queue.auto-delete")] - (boolean (Boolean/valueOf val)) - false)) - (def jgcfg (atom nil)) (defn jargon-config [] @jgcfg) diff --git a/src/kifshare/core.clj b/src/kifshare/core.clj index e691bbf..c5b78c8 100644 --- a/src/kifshare/core.clj +++ b/src/kifshare/core.clj @@ -5,19 +5,15 @@ params keyword-params nested-params - multipart-params - stacktrace]) + multipart-params]) (:require [clojure-commons.file-utils :as ft] [clojure.tools.logging :as log] [compojure.route :as route] - [ring.logger :as logger] [ring.util.response :as resp] [ring.util.http-response :as http-resp] [kifshare.config :as cfg] [kifshare.tickets-controllers :as t-c] [kifshare.anon-controllers :as a-c] - [kifshare.amqp :as amqp] - [kifshare.events :as events] [kifshare.ui-template :as ui] [clojure.string :as string] [common-cli.core :as ccli] @@ -153,8 +149,7 @@ wrap-multipart-params wrap-keyword-params wrap-nested-params - wrap-params - wrap-stacktrace)) + wrap-params)) (def app (site-handler kifshare-routes)) @@ -171,32 +166,25 @@ (or (:buffer-size opts) (* 1024 (Integer/parseInt (get @cfg/props "kifshare.app.download-buffer-size"))))) -(defn listen-for-events - [] - (let [exchange-cfg (events/exchange-config) - queue-cfg (events/queue-config)] - (amqp/connect exchange-cfg queue-cfg {"events.kifshare.ping" events/ping-handler}))) - (defn -main [& args] - - (let [{:keys [options]} (ccli/handle-args svc-info args cli-options)] - (when-not (fs/exists? (:config options)) - (ccli/exit 1 (str "The config file does not exist."))) - (when-not (fs/readable? (:config options)) - (ccli/exit 1 "The config file is not readable.")) - (cfg/local-init (:config options)) - (cfg/jargon-init) - (cfg/log-config) - (.start (Thread. listen-for-events)) - (with-redefs [clojure.java.io/buffer-size override-buffer-size] - (let [port (Integer/parseInt (string/trim (get @cfg/props "kifshare.app.port")))] - (ui/read-template) - (hawk/watch! {:watcher :polling} - [{:paths ["resources/ui.xml"] - :handler (fn [ctx e] - (when (= (:kind e) :modify) - (ui/read-template)))}]) - (log/warn "Configured listen port is: " port) - (require 'ring.adapter.jetty) - ((eval 'ring.adapter.jetty/run-jetty) (logger/wrap-with-logger app) {:port port}))))) + + (let [{:keys [options]} (ccli/handle-args svc-info args cli-options)] + (when-not (fs/exists? (:config options)) + (ccli/exit 1 (str "The config file does not exist."))) + (when-not (fs/readable? (:config options)) + (ccli/exit 1 "The config file is not readable.")) + (cfg/local-init (:config options)) + (cfg/jargon-init) + (cfg/log-config) + (with-redefs [clojure.java.io/buffer-size override-buffer-size] + (let [port (Integer/parseInt (string/trim (get @cfg/props "kifshare.app.port")))] + (ui/read-template) + (hawk/watch! {:watcher :polling} + [{:paths ["resources/ui.xml"] + :handler (fn [ctx e] + (when (= (:kind e) :modify) + (ui/read-template)))}]) + (log/warn "Configured listen port is: " port) + (require 'ring.adapter.jetty) + ((eval 'ring.adapter.jetty/run-jetty) app {:port port}))))) diff --git a/src/kifshare/events.clj b/src/kifshare/events.clj deleted file mode 100644 index ddf957c..0000000 --- a/src/kifshare/events.clj +++ /dev/null @@ -1,29 +0,0 @@ -(ns kifshare.events - (:require [clojure.tools.logging :as log] - [kifshare.config :as config] - [kifshare.amqp :as amqp] - [langohr.basic :as lb]) - (:import [org.cyverse.events.ping PingMessages$Pong] - [com.google.protobuf.util JsonFormat])) - -(defn exchange-config - [] - {:name (config/exchange-name) - :durable (config/exchange-durable?) - :auto-delete (config/exchange-auto-delete?)}) - -(defn queue-config - [] - {:name (config/queue-name) - :durable (config/queue-durable?) - :auto-delete (config/queue-auto-delete?)}) - -(defn ping-handler - [channel {:keys [delivery-tag routing-key]} msg] - (lb/ack channel delivery-tag) - (log/info (format "[events/ping-handler] [%s] [%s]" routing-key (String. msg))) - (lb/publish channel (config/exchange-name) "events.kifshare.pong" - (.print (JsonFormat/printer) - (.. (PingMessages$Pong/newBuilder) - (setPongFrom "kifshare") - (build))))) diff --git a/src/kifshare/ui_template.clj b/src/kifshare/ui_template.clj index 02f69d4..d0d68a9 100644 --- a/src/kifshare/ui_template.clj +++ b/src/kifshare/ui_template.clj @@ -1,7 +1,7 @@ (ns kifshare.ui-template (:require [kifshare.config :as cfg] - [clostache.parser :as prs] [clojure.tools.logging :as log] + [clojure-commons.template :refer [render]] [cheshire.core :as json]) (:import [org.apache.commons.io FileUtils])) @@ -23,12 +23,12 @@ (defn landing-page [ticket-id metadata-promise ticket-info] (log/debug "entered kifshare.ui-template/landing-page") - (prs/render @tmpl - (assoc ticket-info - :metadata @metadata-promise - :filesize (FileUtils/byteCountToDisplaySize - (Long/parseLong (:filesize ticket-info))) - :irods-url (cfg/irods-url) - :de-url (cfg/de-url) - :ticket-info-json (json/generate-string - (ui-ticket-info ticket-info))))) + (render @tmpl + (assoc ticket-info + :metadata @metadata-promise + :filesize (FileUtils/byteCountToDisplaySize + (Long/parseLong (:filesize ticket-info))) + :irods-url (cfg/irods-url) + :de-url (cfg/de-url) + :ticket-info-json (json/generate-string + (ui-ticket-info ticket-info))))) diff --git a/test/kifshare/test/configs.clj b/test/kifshare/test/configs.clj index e4d3e6f..7cbc734 100644 --- a/test/kifshare/test/configs.clj +++ b/test/kifshare/test/configs.clj @@ -34,11 +34,4 @@ (is (= (config/css-files) (string/split config/default-css-files #"\s*,\s*"))) (is (= (config/javascript-files) - (string/split config/default-javascript-files #"\s*,\s*"))) - (is (= (config/amqp-uri) "amqp://guest:guest@rabbit:5672/")) - (is (= (config/exchange-name) "de")) - (is (config/exchange-durable?)) - (is (not (config/exchange-auto-delete?))) - (is (= (config/queue-name) "events.kifshare.queue")) - (is (config/queue-durable?)) - (is (not (config/queue-auto-delete?))))) + (string/split config/default-javascript-files #"\s*,\s*")))))