Github user knusbaum commented on a diff in the pull request: https://github.com/apache/storm/pull/838#discussion_r45515660 --- Diff: storm-core/src/clj/org/apache/storm/pacemaker/pacemaker_state_factory.clj --- @@ -0,0 +1,124 @@ +;; Licensed to the Apache Software Foundation (ASF) under one +;; or more contributor license agreements. See the NOTICE file +;; distributed with this work for additional information +;; regarding copyright ownership. The ASF licenses this file +;; to you under the Apache License, Version 2.0 (the +;; "License"); you may not use this file except in compliance +;; with the License. You may obtain a copy of the License at +;; +;; http://www.apache.org/licenses/LICENSE-2.0 +;; +;; Unless required by applicable law or agreed to in writing, software +;; distributed under the License is distributed on an "AS IS" BASIS, +;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +;; See the License for the specific language governing permissions and +;; limitations under the License. + +(ns org.apache.storm.pacemaker.pacemaker-state-factory + (:require [org.apache.storm.pacemaker pacemaker] + [backtype.storm.cluster-state [zookeeper-state-factory :as zk-factory]] + [backtype.storm + [config :refer :all] + [cluster :refer :all] + [log :refer :all] + [util :as util]]) + (:import [backtype.storm.generated + HBExecutionException HBNodes HBRecords + HBServerMessageType HBMessage HBMessageData HBPulse] + [backtype.storm.cluster_state zookeeper_state_factory] + [backtype.storm.cluster ClusterState] + [org.apache.storm.pacemaker PacemakerClient]) + (:gen-class + :implements [backtype.storm.cluster.ClusterStateFactory])) + +;; So we can mock the client for testing +(defn makeClient [conf] + (PacemakerClient. conf)) + +(defn makeZKState [conf auth-conf acls context] + (.mkState (zookeeper_state_factory.) conf auth-conf acls context)) + +(def max-retries 10) + +(defn -mkState [this conf auth-conf acls context] + (let [zk-state (makeZKState conf auth-conf acls context) + pacemaker-client (makeClient conf)] + + (reify + ClusterState + ;; Let these pass through to the zk-state. We only want to handle heartbeats. + (register [this callback] (.register zk-state callback)) + (unregister [this callback] (.unregister zk-state callback)) + (set_ephemeral_node [this path data acls] (.set_ephemeral_node zk-state path data acls)) + (create_sequential [this path data acls] (.create_sequential zk-state path data acls)) + (set_data [this path data acls] (.set_data zk-state path data acls)) + (delete_node [this path] (.delete_node zk-state path)) + (get_data [this path watch?] (.get_data zk-state path watch?)) + (get_data_with_version [this path watch?] (.get_data_with_version zk-state path watch?)) + (get_version [this path watch?] (.get_version zk-state path watch?)) + (get_children [this path watch?] (.get_children zk-state path watch?)) + (mkdirs [this path acls] (.mkdirs zk-state path acls)) + (node_exists [this path watch?] (.node_exists zk-state path watch?)) + (add_listener [this listener] (.add_listener zk-state listener)) + (sync_path [this path] (.sync_path zk-state path)) + + (set_worker_hb [this path data acls] + (util/retry-on-exception + max-retries + "set_worker_hb" + #(let [response + (.send pacemaker-client + (HBMessage. HBServerMessageType/SEND_PULSE + (HBMessageData/pulse + (doto (HBPulse.) + (.set_id path) + (.set_details data)))))] + (if (= (.get_type response) HBServerMessageType/SEND_PULSE_RESPONSE) + :ok + (throw (HBExecutionException. "Invalid Response Type")))))) --- End diff -- It's part of the ClusterState interface spec.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---