Skip to content

Commit d7717bf

Browse files
authored
Merge pull request #226 from austb/java-time-migration
Migrate from clj-time/Joda-Time to java.time
2 parents c84aa85 + 17fa912 commit d7717bf

41 files changed

Lines changed: 422 additions & 503 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ext/bin/config-openvox-test-ref

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ esac
5050

5151
# Install and update Ruby dependencies from top-level Gemfile
5252
bundle config set --local path vendor/bundle
53-
bundle config set --local without acceptance
53+
bundle config set --local without 'acceptance release'
5454
bundle install --retry=10
5555
bundle update
5656
# Print out info on Puppet dependency

project.clj

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@
141141
[clj-http "3.13.1"]
142142
[clj-kondo "2026.01.19"]
143143
[clj-stacktrace "0.2.8"]
144-
[clj-time "0.15.2"]
145144
[com.fasterxml.jackson.core/jackson-core ~jackson-version]
146145
[com.fasterxml.jackson.core/jackson-databind ~jackson-version]
147146
[com.fasterxml.jackson.dataformat/jackson-dataformat-cbor ~jackson-version]
@@ -162,7 +161,6 @@
162161
[digest "1.4.10"]
163162
[fast-zip "0.4.0"]
164163
[instaparse "1.5.0"]
165-
[joda-time "2.14.1"]
166164
[metrics-clojure "2.10.0"]
167165
[murphy "0.5.3"]
168166
[net.logstash.logback/logstash-logback-encoder "7.4"]
@@ -177,13 +175,13 @@
177175
[org.slf4j/log4j-over-slf4j ~slf4j-version]
178176
[org.openvoxproject/comidi "1.1.2"]
179177
[org.openvoxproject/i18n ~i18n-version]
180-
[org.openvoxproject/kitchensink "3.5.5"]
181-
[org.openvoxproject/kitchensink "3.5.5" :classifier "test"]
178+
[org.openvoxproject/kitchensink "3.5.6"]
179+
[org.openvoxproject/kitchensink "3.5.6" :classifier "test"]
182180
[org.openvoxproject/ssl-utils "3.6.2"]
183181
[org.openvoxproject/stockpile "1.0.1"]
184182
[org.openvoxproject/structured-logging "1.0.1"]
185-
[org.openvoxproject/trapperkeeper "4.3.2"]
186-
[org.openvoxproject/trapperkeeper "4.3.2" :classifier "test"]
183+
[org.openvoxproject/trapperkeeper "4.3.4"]
184+
[org.openvoxproject/trapperkeeper "4.3.4" :classifier "test"]
187185
[org.openvoxproject/trapperkeeper-authorization "2.1.6"]
188186
[org.openvoxproject/trapperkeeper-authorization "2.1.6" :exclusions [io.dropwizard.metrics/metrics-core]]
189187
[org.openvoxproject/trapperkeeper-filesystem-watcher "1.5.1"]
@@ -220,7 +218,6 @@
220218
[clj-commons/fs]
221219
[clj-http]
222220
[clj-stacktrace]
223-
[clj-time]
224221
[com.fasterxml.jackson.core/jackson-databind]
225222
[com.github.seancorfield/honeysql]
226223
[com.github.seancorfield/next.jdbc]
@@ -242,7 +239,6 @@
242239
[org.openvoxproject/comidi]
243240
[org.openvoxproject/i18n]
244241
[org.openvoxproject/kitchensink]
245-
[org.openvoxproject/ssl-utils]
246242
[org.openvoxproject/stockpile]
247243
[org.openvoxproject/structured-logging]
248244
[org.openvoxproject/trapperkeeper]

src/puppetlabs/puppetdb/cheshire.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
(encode-fn obj jsonGenerator))
5353
(.writeRawValue jsonGenerator (.getValue data)))))
5454
(add-encoder
55-
org.joda.time.DateTime
55+
java.time.Instant
5656
(fn [data ^JsonGenerator jsonGenerator]
5757
(.writeString jsonGenerator (to-string data))))
5858
(add-encoder
@@ -70,7 +70,7 @@
7070
7171
Encoders currently include:
7272
73-
* org.joda.time.DateTime - handled with to-string"}
73+
* java.time.Instant - handled with to-string"}
7474
add-common-json-encoders! (memoize add-common-json-encoders!*))
7575

7676
(add-common-json-encoders!)

src/puppetlabs/puppetdb/cli/benchmark.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@
12451245
prints it to the console every 5 seconds. Uses run-interval to compute the
12461246
number of nodes that would produce that load."
12471247
[rate-monitor-ch run-interval commands-per-puppet-run _state]
1248-
(let [run-interval-seconds (time/in-seconds run-interval)
1248+
(let [run-interval-seconds (time/to-seconds run-interval)
12491249
expected-node-message-rate (/ commands-per-puppet-run run-interval-seconds)]
12501250
(println-err
12511251
(str "q/s - queries per second\n"
@@ -1276,7 +1276,7 @@
12761276
(trs "{0} cmd/s (~{1} nodes @ {2}m) | {3} q/s {4} s/q | {5} err"
12771277
cmd-per-sec
12781278
(int (/ cmd-per-sec expected-node-message-rate))
1279-
(time/in-minutes run-interval)
1279+
(time/to-minutes run-interval)
12801280
(format "%.2f" query-per-sec)
12811281
(format "%.2f" (-> @metrics :query-duration timers/mean (/ 1000000000)))
12821282
errors))
@@ -1387,7 +1387,7 @@
13871387
[numhosts run-interval num-msgs end-commands-in rand-catalogs rand-facts
13881388
simulation-threads sim-ch host-info-ch read-ch
13891389
& {:keys [facts catalogs reports include-edges? storage-dir]}]
1390-
(let [run-interval-minutes (time/in-minutes run-interval)
1390+
(let [run-interval-minutes (time/to-minutes run-interval)
13911391
hosts-per-second (/ numhosts (* run-interval-minutes 60))
13921392
ms-per-message (/ 1000 hosts-per-second)
13931393
ms-per-thread (* ms-per-message simulation-threads)

src/puppetlabs/puppetdb/cli/generate.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
(defmethod weigh Number [_] 4)
268268
(defmethod weigh Boolean [_] 1)
269269
(defmethod weigh nil [_] 0)
270-
(defmethod weigh org.joda.time.DateTime [_] 8)
270+
(defmethod weigh java.time.Instant [_] 8)
271271
(defmethod weigh :default
272272
[what] (throw (Exception. (format "Don't know how to weigh a %s of type %s" what (type what)))))
273273

src/puppetlabs/puppetdb/cli/services.clj

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@
7474
[puppetlabs.puppetdb.time
7575
:refer [ago
7676
ephemeral-now-ns
77-
to-seconds
78-
to-millis
7977
format-period
80-
period?]]
78+
period?
79+
to-millis
80+
to-seconds
81+
truncate-to-day]]
8182
[puppetlabs.puppetdb.utils :as utils
8283
:refer [await-scheduler-shutdown
8384
call-unless-shutting-down
@@ -101,7 +102,7 @@
101102
(java.io Closeable)
102103
(java.sql SQLException)
103104
[java.util.concurrent.locks ReentrantLock]
104-
[org.joda.time Period]))
105+
))
105106

106107
(def env-monitor-queries?
107108
;; Note: theres'a also a :conf/test switch
@@ -211,9 +212,6 @@
211212
(defn update-db-lock-status [state what f]
212213
(swap! state update what f))
213214

214-
(defn rounded-date [d]
215-
(-> (ago d) .dayOfYear .roundFloorCopy))
216-
217215
(defn sweep-reports!
218216
"Deletes reports older than than report-ttl. When resource-events-ttl
219217
is also provided, deletes events that are older than that
@@ -224,8 +222,8 @@
224222
[db {:keys [incremental? report-ttl resource-events-ttl db-lock-status]}]
225223
{:pre [(map? db)
226224
(period? report-ttl)]}
227-
(let [rounded-events-ttl (some-> resource-events-ttl rounded-date)
228-
rounded-report-ttl (rounded-date report-ttl)
225+
(let [rounded-events-ttl (some-> resource-events-ttl ago truncate-to-day)
226+
rounded-report-ttl (truncate-to-day (ago report-ttl))
229227
update-lock-status (partial update-db-lock-status db-lock-status)
230228
del-opts (merge {:report-ttl rounded-report-ttl
231229
:incremental? incremental?
@@ -268,7 +266,7 @@
268266
{:pre [(map? db)
269267
(period? resource-events-ttl)]}
270268
;; apply a day floor on this - we can't be more granular than a day here.
271-
(let [rounded-ttl (rounded-date resource-events-ttl)
269+
(let [rounded-ttl (truncate-to-day (ago resource-events-ttl))
272270
update-lock-status (partial update-db-lock-status db-lock-status)]
273271
(try
274272
(kitchensink/demarcate
@@ -369,10 +367,10 @@
369367
[db
370368
lock :- ReentrantLock
371369
{:keys [node-ttl node-purge-ttl
372-
report-ttl resource-events-ttl]} :- {:node-ttl Period
373-
:node-purge-ttl Period
374-
:report-ttl Period
375-
:resource-events-ttl Period
370+
report-ttl resource-events-ttl]} :- {:node-ttl java.time.Duration
371+
:node-purge-ttl java.time.Duration
372+
:report-ttl java.time.Duration
373+
:resource-events-ttl java.time.Duration
376374
s/Keyword s/Any}
377375
db-lock-status :- clojure.lang.Atom
378376
;; Later, the values might be maps, i.e. {:limit 1000}

src/puppetlabs/puppetdb/cli/time_shift_export.clj

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
[puppetlabs.kitchensink.core :as kitchensink]
2525
[clojure.java.io :as io]
2626
[puppetlabs.puppetdb.archive :as archive]
27-
[puppetlabs.puppetdb.time :refer [parse-wire-datetime after? now interval plus]]
28-
[clj-time.coerce :as time-coerce]
27+
[puppetlabs.puppetdb.time :as time :refer [wire-datetime->instant after? now interval plus to-long]]
2928
[puppetlabs.puppetdb.cheshire :as json]
3029
[clojure.string :as str]))
3130

@@ -37,7 +36,7 @@
3736
(defn time-shift-timestamp
3837
[timestamp-string shift-period]
3938
(-> timestamp-string
40-
parse-wire-datetime
39+
wire-datetime->instant
4140
(plus shift-period)))
4241

4342
(defn time-shift-resources
@@ -96,7 +95,7 @@
9695
command-type (if (= command-type "facts") command-type (str/join "" (drop-last command-type)))
9796
filename (clojure.core/format "%s-%s_%s_%s_%s.json"
9897
(next-command-index)
99-
(time-coerce/to-long (:producer_timestamp shifted-data))
98+
(to-long (:producer_timestamp shifted-data))
10099
command-type
101100
(str (get command-type-versions command-type))
102101
(:certname shifted-data))]
@@ -152,12 +151,12 @@
152151
(json-data :end_time)]
153152
(map #(:time %) (json-data :logs))
154153
(get-resources-timestamps (json-data :resources)))
155-
(map parse-wire-datetime)
154+
(map wire-datetime->instant)
156155
(reduce get-newest-timestamp)))
157156

158157
(defn entry-producer-timestamp
159158
[json-data]
160-
(parse-wire-datetime (:producer_timestamp json-data)))
159+
(wire-datetime->instant (:producer_timestamp json-data)))
161160

162161
(defn compare-command-versions
163162
[command-type actual-version]
@@ -190,7 +189,7 @@
190189

191190
(defn newest-timestamp-from-archive
192191
[archive-path]
193-
(let [newest-timestamp (atom (parse-wire-datetime "1000-01-01T11:11:11.111Z"))]
192+
(let [newest-timestamp (atom (wire-datetime->instant "1000-01-01T11:11:11.111Z"))]
194193

195194
(with-open [tar-reader (archive/tarball-reader archive-path)]
196195
(doseq [tar-entry (archive/all-entries tar-reader)]
@@ -203,12 +202,12 @@
203202
(defn time-shift-export
204203
[args]
205204
(let [newest-timestamp (newest-timestamp-from-archive (:input args))
206-
shift-period (.toPeriod (interval newest-timestamp (:shift-to-time args)))]
205+
shift-period (interval newest-timestamp (:shift-to-time args))]
207206
(time-shift-input-archive (assoc args :shift-to-time shift-period))))
208207

209208
(defn parse-time-shift-parameter
210209
[time-string]
211-
(let [parsed-time (parse-wire-datetime time-string)]
210+
(let [parsed-time (wire-datetime->instant time-string)]
212211
(when-not parsed-time
213212
(utils/throw-sink-cli-error (str "\nError: time shift date: " time-string ", must be in UTC format!\n")))
214213
parsed-time))

src/puppetlabs/puppetdb/command.clj

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
[puppetlabs.puppetdb.jdbc :as jdbc]
6565
[puppetlabs.puppetdb.schema :refer [defn-validated]]
6666
[puppetlabs.puppetdb.time :as time
67-
:refer [now in-millis interval]]
67+
:refer [now to-millis interval]]
6868
[puppetlabs.puppetdb.utils :as utils
6969
:refer [await-scheduler-shutdown
7070
call-unless-shutting-down
@@ -298,7 +298,7 @@
298298
;; manually stringify these to avoid locale-specific formatting
299299
(let [id (str id)
300300
received-time (str (time/to-long received-time))
301-
duration (str (in-millis (interval start-time (now))))
301+
duration (str (to-millis (interval start-time (now))))
302302
command-name (command-names command-kw)
303303
producer-utc-s (or (some-> producer-ts time/to-timestamp .getTime)
304304
"nil")
@@ -825,16 +825,14 @@
825825
(log/info (trs "Revival of delayed message interrupted")))))))
826826
command-delay-ms)))
827827

828-
(def ^:private iso-formatter (time/formatters :date-time))
829-
830828
(defn process-message
831829
[{:keys [certname command version received delete? id] :as cmdref}
832830
q command-chan dlo delay-pool broadcast-pool write-dbs response-chan stats
833831
options-config maybe-send-cmd-event! shutdown-for-ex]
834832
(when received
835-
(let [q-time (-> (time/parse iso-formatter received)
833+
(let [q-time (-> (time/to-date-time received)
836834
(time/interval (now))
837-
time/in-seconds)]
835+
time/to-seconds)]
838836
(create-metrics-for-command! command version)
839837
(update! (global-metric :queue-time) q-time)
840838
(update! (cmd-metric command version :queue-time) q-time)))

src/puppetlabs/puppetdb/config.clj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
[puppetlabs.trapperkeeper.services :refer [service-context]])
2222
(:import
2323
(clojure.lang ExceptionInfo)
24-
(java.util.regex PatternSyntaxException)
25-
(org.joda.time Minutes Period)))
24+
(java.time Duration)
25+
(java.util.regex PatternSyntaxException)))
2626

2727
(defn throw-cli-error [msg]
2828
(throw (ex-info msg {:type ::cli-error :message msg})))
@@ -119,7 +119,7 @@
119119
:classname (pls/defaulted-maybe String "org.postgresql.Driver")
120120
:subprotocol (pls/defaulted-maybe String "postgresql")
121121
:subname String
122-
:conn-max-age Minutes
122+
:conn-max-age Duration
123123
:read-only? Boolean
124124
:partition-conn-min s/Int
125125
:partition-conn-max s/Int
@@ -128,7 +128,7 @@
128128
:log-statements Boolean
129129
:connection-timeout s/Int
130130
:maximum-pool-size s/Int
131-
(s/optional-key :conn-lifetime) (s/maybe Minutes)
131+
(s/optional-key :conn-lifetime) (s/maybe Duration)
132132
(s/optional-key :connection-migrator-username) String
133133
(s/optional-key :connection-username) String
134134
(s/optional-key :user) String
@@ -141,7 +141,7 @@
141141
:facts-blocklist-type String
142142

143143
:schema-check-interval s/Int
144-
:node-purge-ttl Period})
144+
:node-purge-ttl Duration})
145145

146146
(def per-write-database-config-out
147147
"Schema for parsed/processed database config that includes write database params"
@@ -153,10 +153,10 @@
153153
(s/optional-key :gc-interval-packages) (s/cond-pre String s/Int)
154154
(s/optional-key :gc-interval-fact-paths) (s/cond-pre String s/Int)
155155
(s/optional-key :gc-interval-catalogs) (s/cond-pre String s/Int)
156-
:report-ttl Period
156+
:report-ttl Duration
157157
:node-purge-gc-batch-limit (s/constrained s/Int (complement neg?))
158-
:node-ttl Period
159-
(s/optional-key :resource-events-ttl) Period
158+
:node-ttl Duration
159+
(s/optional-key :resource-events-ttl) Duration
160160
:migrate Boolean}))
161161

162162
(defn half-the-cores*
@@ -393,7 +393,7 @@
393393

394394
(defn gc-intervals->periods
395395
[{:keys [gc-interval] :as config}]
396-
(let [one-day (-> 24 t/hours .toPeriod)
396+
(let [one-day (t/hours 24)
397397
gc-interval-period (interval->period gc-interval)
398398
get-period (fn [custom] (interval->period (or custom gc-interval)))
399399
get-paths-period (fn [custom]

src/puppetlabs/puppetdb/export.clj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
[puppetlabs.puppetdb.catalogs :as catalogs]
1111
[puppetlabs.puppetdb.factsets :as factsets]
1212
[puppetlabs.puppetdb.reports :as reports]
13-
[puppetlabs.puppetdb.time :refer [now]]
13+
[puppetlabs.puppetdb.time :as time :refer [now]]
1414
[puppetlabs.puppetdb.nodes :as nodes]
1515
[puppetlabs.puppetdb.command.constants :as command-constants]
1616
[puppetlabs.puppetdb.utils :as utils]
17-
[clj-time.coerce :as time-coerce]
1817
[puppetlabs.puppetdb.schema :as pls]
1918
[puppetlabs.i18n.core :refer [trs]]))
2019

@@ -33,7 +32,7 @@
3332
(format "%s-%s%s"
3433
certname
3534
(-> producer_timestamp
36-
time-coerce/to-date-time
35+
time/to-date-time
3736
hash/generic-identity-hash)
3837
export-file-ext))
3938

0 commit comments

Comments
 (0)