-
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
Open
o-shevchenko
wants to merge
26
commits into
apache:master
Choose a base branch
from
o-shevchenko:LIVY-616
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
18254ff
[LIVY-616] Livy Server discovery
o-shevchenko 6526052
scalastyle import order and line lengths
o-shevchenko 5f30372
reorganized imports to fit project scalastyle requirements
o-shevchenko 9731aae
Trigger, flaky tests
o-shevchenko 64dabaf
added Java/Scala API, scaladocs, small refactoring
o-shevchenko a7fd7d8
scalastyle
o-shevchenko aacfd9f
Trigger, flaky tests
o-shevchenko d693ea3
Trigger, flaky tests
o-shevchenko 729beda
Trigger, flaky tests
o-shevchenko 27a7ffc
Trigger, flaky tests
o-shevchenko 104f66b
Trigger, flaky tests
o-shevchenko 5baf435
make more configurable
o-shevchenko 5d7ea28
fix typo
o-shevchenko 728deb9
Trigger, flaky tests
o-shevchenko a71c0ef
honor livy.server.host
o-shevchenko 1d0add4
remove package access
o-shevchenko 7e57010
update scaladoc
o-shevchenko 627e455
Trigger, flaky tests
o-shevchenko df5a395
refactored, changed class ZooKeeperManager to trait to be able to add…
o-shevchenko 18c10ed
Logging already mixed to ZooKeeperManager
o-shevchenko 7d655fc
fixed problem with host resolving
o-shevchenko e8dc350
fixed test
o-shevchenko 5e88b2d
log message improved
o-shevchenko 47d8852
fix scalastyle
o-shevchenko 1250fea
fix scalastyle
o-shevchenko 5c47b09
Trigger, flaky
o-shevchenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
server/src/main/scala/org/apache/livy/server/discovery/JsonMapper.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]]) | ||
| } |
65 changes: 65 additions & 0 deletions
65
server/src/main/scala/org/apache/livy/server/discovery/LivyDiscoveryManager.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| 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) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
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.
We already have one in ZooKeeperManager
LivyDiscovery is a hight level of abstraction which is used for better understanding, single responsibility and API simplification
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.
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:
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.
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.
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.
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
livy.server.thrift.zookeeper.quoruminstead of simple commonlivy.zookeeper.urlwhich can be reused. In this PR I want to not only add LivyServer discovery but also create init structure for subsequent work with ZooKeeper.