From reviews-return-3550-archive-asf-public=cust-asf.ponee.io@livy.incubator.apache.org Thu Mar 12 10:21:18 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 5CB6618064F for ; Thu, 12 Mar 2020 11:21:18 +0100 (CET) Received: (qmail 43488 invoked by uid 500); 12 Mar 2020 10:21:17 -0000 Mailing-List: contact reviews-help@livy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: reviews@livy.incubator.apache.org Delivered-To: mailing list reviews@livy.incubator.apache.org Received: (qmail 43476 invoked by uid 99); 12 Mar 2020 10:21:17 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Mar 2020 10:21:17 +0000 From: GitBox To: reviews@livy.apache.org Subject: [GitHub] [incubator-livy] yiheng commented on a change in pull request #276: [LIVY-723] Server Registration Message-ID: <158400847755.4501.11250119839070848205.gitbox@gitbox.apache.org> References: In-Reply-To: Date: Thu, 12 Mar 2020 10:21:17 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit yiheng commented on a change in pull request #276: [LIVY-723] Server Registration URL: https://github.com/apache/incubator-livy/pull/276#discussion_r391523456 ########## File path: server/src/main/scala/org/apache/livy/cluster/ZKClusterManager.scala ########## @@ -0,0 +1,79 @@ +/* + * 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. + */ +package org.apache.livy.cluster + +import java.util.UUID + +import scala.collection.mutable +import scala.collection.mutable.{ArrayBuffer, Set} + +import org.apache.livy.rsc.RSCConf.Entry.LAUNCHER_ADDRESS +import org.apache.livy.LivyConf.{SERVER_PORT, ZK_SERVICE_DIR} +import org.apache.livy.LivyConf +import org.apache.livy.Logging +import org.apache.livy.server.recovery.ZooKeeperManager + +class ZKClusterManager(livyConf: LivyConf, zkManager: ZooKeeperManager) + extends ClusterManager with Logging { + private val serverIP = livyConf.get(LAUNCHER_ADDRESS) + require(serverIP != null, "Please config the livy.rsc.launcher.address") + + private val port = livyConf.getInt(SERVER_PORT) + private val serviceDir = livyConf.get(ZK_SERVICE_DIR) + + private val nodes = new mutable.HashSet[ServiceNode]() + private val nodeJoinListeners = new ArrayBuffer[ServiceNode => Unit]() + private val nodeLeaveListeners = new ArrayBuffer[ServiceNode => Unit]() + + zkManager.getChildren(serviceDir).foreach(node => { + val serviceNode = zkManager.get[ServiceNode](serviceDir + "/" + node).get + nodes.add(serviceNode) + }) + + // Start listening + zkManager.watchAddNode(serviceDir, nodeAddHandler) + zkManager.watchRemoveNode(serviceDir, nodeRemoveHandler) + + override def register(): Unit = { + val node = ServiceNode(serverIP, port, UUID.randomUUID().toString) + zkManager.createEphemeralNode(serviceDir + "/" + serverIP + ":" + port, node) + } + + override def getNodes(): Set[ServiceNode] = { + nodes + } + + override def registerNodeJoinListener(listener: ServiceNode => Unit): Unit = { + nodeJoinListeners.append(listener) + } + + override def registerNodeLeaveListener(listener : ServiceNode => Unit): Unit = { + nodeLeaveListeners.append(listener) + } + + private def nodeAddHandler(path: String, node: ServiceNode): Unit = { + logger.info("Detect new node join: " + node) + nodes.add(node) + nodeJoinListeners.foreach(_(node)) + } + + private def nodeRemoveHandler(path: String, node: ServiceNode): Unit = { + logger.info("Detect node leave: " + node) + nodes.remove(node) + nodeLeaveListeners.foreach(_(node)) Review comment: Here we notify all registered listeners on the server. The listenser may take action based on the node join/leave event. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services