|
24 | 24 | [java.net URI]
|
25 | 25 | [org.apache.commons.io FileUtils]
|
26 | 26 | [java.io File])
|
27 |
| - (:use [backtype.storm config util log timer]) |
| 27 | + (:use [backtype.storm config util log timer local-state]) |
28 | 28 | (:use [backtype.storm.daemon common])
|
29 | 29 | (:require [backtype.storm.daemon [worker :as worker]]
|
30 | 30 | [backtype.storm [process-simulator :as psim] [cluster :as cluster] [event :as event]]
|
|
38 | 38 | (defmulti download-storm-code cluster-mode)
|
39 | 39 | (defmulti launch-worker (fn [supervisor & _] (cluster-mode (:conf supervisor))))
|
40 | 40 |
|
41 |
| -;; used as part of a map from port to this |
42 |
| -(defrecord LocalAssignment [storm-id executors]) |
43 |
| - |
44 | 41 | (defprotocol SupervisorDaemon
|
45 | 42 | (get-id [this])
|
46 | 43 | (get-conf [this])
|
|
76 | 73 | (into {} (for [[port executors] port-executors]
|
77 | 74 | ;; need to cast to int b/c it might be a long (due to how yaml parses things)
|
78 | 75 | ;; doall is to avoid serialization/deserialization problems with lazy seqs
|
79 |
| - [(Integer. port) (LocalAssignment. storm-id (doall executors))] |
| 76 | + [(Integer. port) (mk-local-assignment storm-id (doall executors))] |
80 | 77 | ))))
|
81 | 78 |
|
82 | 79 | (defn- read-assignments
|
|
104 | 101 | (defn read-worker-heartbeat [conf id]
|
105 | 102 | (let [local-state (worker-state conf id)]
|
106 | 103 | (try
|
107 |
| - (.get local-state LS-WORKER-HEARTBEAT) |
108 |
| - (catch IOException e |
| 104 | + (ls-worker-heartbeat local-state) |
| 105 | + (catch Exception e |
109 | 106 | (log-warn e "Failed to read local heartbeat for workerId : " id ",Ignoring exception.")
|
110 | 107 | nil))))
|
111 | 108 |
|
|
148 | 145 | (let [conf (:conf supervisor)
|
149 | 146 | ^LocalState local-state (:local-state supervisor)
|
150 | 147 | id->heartbeat (read-worker-heartbeats conf)
|
151 |
| - approved-ids (set (keys (.get local-state LS-APPROVED-WORKERS)))] |
| 148 | + approved-ids (set (keys (ls-approved-workers local-state)))] |
152 | 149 | (into
|
153 | 150 | {}
|
154 | 151 | (dofor [[id hb] id->heartbeat]
|
|
174 | 171 | (defn- wait-for-worker-launch [conf id start-time]
|
175 | 172 | (let [state (worker-state conf id)]
|
176 | 173 | (loop []
|
177 |
| - (let [hb (.get state LS-WORKER-HEARTBEAT)] |
| 174 | + (let [hb (ls-worker-heartbeat state)] |
178 | 175 | (when (and
|
179 | 176 | (not hb)
|
180 | 177 | (<
|
|
185 | 182 | (Time/sleep 500)
|
186 | 183 | (recur)
|
187 | 184 | )))
|
188 |
| - (when-not (.get state LS-WORKER-HEARTBEAT) |
| 185 | + (when-not (ls-worker-heartbeat state) |
189 | 186 | (log-message "Worker " id " failed to start")
|
190 | 187 | )))
|
191 | 188 |
|
|
320 | 317 | download-lock (:download-lock supervisor)
|
321 | 318 | ^LocalState local-state (:local-state supervisor)
|
322 | 319 | storm-cluster-state (:storm-cluster-state supervisor)
|
323 |
| - assigned-executors (defaulted (.get local-state LS-LOCAL-ASSIGNMENTS) {}) |
| 320 | + assigned-executors (defaulted (ls-local-assignments local-state) {}) |
324 | 321 | now (current-time-secs)
|
325 | 322 | allocated (read-allocated-workers supervisor assigned-executors now)
|
326 | 323 | keepers (filter-val
|
|
358 | 355 | (doseq [id (vals new-worker-ids)]
|
359 | 356 | (local-mkdirs (worker-pids-root conf id))
|
360 | 357 | (local-mkdirs (worker-heartbeats-root conf id)))
|
361 |
| - (.put local-state LS-APPROVED-WORKERS |
| 358 | + (ls-approved-workers! local-state |
362 | 359 | (merge
|
363 |
| - (select-keys (.get local-state LS-APPROVED-WORKERS) |
| 360 | + (select-keys (ls-approved-workers local-state) |
364 | 361 | (keys keepers))
|
365 | 362 | (zipmap (vals new-worker-ids) (keys new-worker-ids))
|
366 | 363 | ))
|
|
416 | 413 | (defn shutdown-disallowed-workers [supervisor]
|
417 | 414 | (let [conf (:conf supervisor)
|
418 | 415 | ^LocalState local-state (:local-state supervisor)
|
419 |
| - assigned-executors (defaulted (.get local-state LS-LOCAL-ASSIGNMENTS) {}) |
| 416 | + assigned-executors (defaulted (ls-local-assignments local-state) {}) |
420 | 417 | now (current-time-secs)
|
421 | 418 | allocated (read-allocated-workers supervisor assigned-executors now)
|
422 | 419 | disallowed (keys (filter-val
|
|
442 | 439 | assignment-versions)
|
443 | 440 | storm-code-map (read-storm-code-locations assignments-snapshot)
|
444 | 441 | downloaded-storm-ids (set (read-downloaded-storm-ids conf))
|
445 |
| - existing-assignment (.get local-state LS-LOCAL-ASSIGNMENTS) |
| 442 | + existing-assignment (ls-local-assignments local-state) |
446 | 443 | all-assignment (read-assignments assignments-snapshot
|
447 | 444 | (:assignment-id supervisor)
|
448 | 445 | existing-assignment
|
|
472 | 469 | (set (keys new-assignment)))]
|
473 | 470 | (.killedWorker isupervisor (int p)))
|
474 | 471 | (.assigned isupervisor (keys new-assignment))
|
475 |
| - (.put local-state |
476 |
| - LS-LOCAL-ASSIGNMENTS |
| 472 | + (ls-local-assignments! local-state |
477 | 473 | new-assignment)
|
478 | 474 | (reset! (:assignment-versions supervisor) versions)
|
479 | 475 | (reset! (:curr-assignment supervisor) new-assignment)
|
|
780 | 776 | (prepare [this conf local-dir]
|
781 | 777 | (reset! conf-atom conf)
|
782 | 778 | (let [state (LocalState. local-dir)
|
783 |
| - curr-id (if-let [id (.get state LS-ID)] |
| 779 | + curr-id (if-let [id (ls-supervisor-id state)] |
784 | 780 | id
|
785 | 781 | (generate-supervisor-id))]
|
786 |
| - (.put state LS-ID curr-id) |
| 782 | + (ls-supervisor-id! state curr-id) |
787 | 783 | (reset! id-atom curr-id))
|
788 | 784 | )
|
789 | 785 | (confirmAssigned [this port]
|
|
0 commit comments