-
Notifications
You must be signed in to change notification settings - Fork 624
[LIVY-616] Livy Server discovery #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 20 commits
18254ff
6526052
5f30372
9731aae
64dabaf
a7fd7d8
aacfd9f
d693ea3
729beda
27a7ffc
104f66b
5baf435
5d7ea28
728deb9
a71c0ef
1d0add4
7e57010
627e455
df5a395
18c10ed
7d655fc
e8dc350
5e88b2d
47d8852
1250fea
5c47b09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * 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.server.discovery | ||
|
|
||
| import scala.reflect.{classTag, ClassTag} | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper | ||
| import com.fasterxml.jackson.module.scala.DefaultScalaModule | ||
|
|
||
| import org.apache.livy.sessions.SessionKindModule | ||
|
|
||
| protected[server] trait JsonMapper { | ||
| protected val mapper = new ObjectMapper() | ||
| .registerModule(DefaultScalaModule) | ||
| .registerModule(new SessionKindModule()) | ||
|
|
||
| def serializeToBytes(value: Object): Array[Byte] = mapper.writeValueAsBytes(value) | ||
|
|
||
| def deserialize[T: ClassTag](json: Array[Byte]): T = | ||
| mapper.readValue(json, classTag[T].runtimeClass.asInstanceOf[Class[T]]) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * 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.server.discovery | ||
|
|
||
| import java.net.URI | ||
|
|
||
| import org.apache.curator.framework.CuratorFramework | ||
|
|
||
| import org.apache.livy.LivyConf | ||
|
|
||
| /** | ||
| * Livy Server Discovery manager. | ||
| * Stores information about Livy Server location in ZooKeeper. | ||
| * The address will be stored in | ||
| * "/{@code LIVY_ZOOKEEPER_NAMESPACE}/{@code LIVY_SERVER_ZOOKEEPER_NAMESPACE}" znode | ||
| * By default, the full path to znode is /livy/server.uri. | ||
| * Need to set {@code livy.zookeeper.url} to be able to get information from ZooKeeper. | ||
| * | ||
| * @param livyConf - Livy configurations | ||
| * @param mockCuratorClient - used for testing | ||
| */ | ||
| class LivyDiscoveryManager(val livyConf: LivyConf, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we consider providing a generic method to publishing configuration key/value to zookeeper? In some other scenario, e.g. this PR #193 , a bunch of hive related configurations need to be published. If we have a generic method publish configuration key/value, it may be easier to let other components to leverage the code.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have one in ZooKeeperManager
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just refactored StateStore to move functionality for communication with ZK from ZooKeeperStateStore.scala to separated trait ZooKeeperManager.scala. In ZooKeeperStateStore we will use ZooKeeperManager to store data in ZK. ZooKeeperManager code was not changed except couple small improvements for configurations to make it more flexible. We can use this trait everywhere when we need to store something to ZooKeeper since it's generic:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ZooKeeperManager should be used every time by design when we need to store something to ZK. I think we need to have one logic for ZK interaction for LivyServer discovery, ZK state store, Livy HA, Livy Thrift Server HA. That's why I moved this functionality to the separated trait, to make it reuseable for someone else.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I have tried to make all configurations more generic and configurable on the top level to use it everywhere. As far as I see, for now, we have a couple of PRs with different ZK logic which can't be reused a lot and I see too specific confs like |
||
| val mockCuratorClient: Option[CuratorFramework] = None) | ||
| extends ZooKeeperManager { | ||
|
|
||
| private val LIVY_SERVER_URI_KEY = livyConf.get(LivyConf.LIVY_SERVER_ZOOKEEPER_NAMESPACE) | ||
|
|
||
| /** | ||
| * Save Livy Server URI to ZooKeeper. | ||
| * @param address - URI address of Livy Server | ||
| */ | ||
| def setServerUri(address: URI): Unit = { | ||
| setData(LIVY_SERVER_URI_KEY, address) | ||
| } | ||
|
|
||
| /** | ||
| * Get Livy Server URI from ZooKeeper. | ||
| * @return Livy Server URI | ||
| */ | ||
| def getServerUri(): URI = { | ||
| getData[URI](LIVY_SERVER_URI_KEY).getOrElse(URI.create("")) | ||
| } | ||
| } | ||
|
|
||
| object LivyDiscoveryManager { | ||
|
|
||
| def apply(livyConf: LivyConf, | ||
| mockCuratorClient: Option[CuratorFramework] = None): LivyDiscoveryManager = { | ||
| new LivyDiscoveryManager(livyConf, mockCuratorClient) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not quite understand the if condition here. Could you please explain it a bit? Thanks.
And another question is why we return the hostname instead of IP here? IMHO, IP should be more convenient, as hostname user needs to update their hosts file or set up the name service.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can find more detailed info in the specification which attached to the Jira ticket
So, basically it's needed to resolve Livy Server address by replacing
0.0.0.0default value with the correct IP address if user didn't specify any Livy Server address in the conf file. In this case, we can useInetAddress.getLocalHost.getHostNameto get the address from the node where LivyServer was started.See your point,
InetAddress.getLocalHost.getHostAddressmight be the better choice here.Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From your description, should it be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I see
it's my mistake.
good catch!
livyConf.get(LivyConf.SERVER_HOST.dflt.toString)not make a sense in this case, looks like it's typical copy problemThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR was updated