-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finagle-core, twitter-server: Add
c.t.finagle.DtabFlags
Problem There is currently no defined way for users of the `c.t.finagle.Dtab` API to append to the `Dtab.base` delegation table with a supplemental value that is passed at runtime. Solution Add the `c.t.finagle.DtabFlags` trait which defines a `c.t.app.Flag`, "dtab.add" that can provide a supplemental delegation table (`Dtab`) to append to the current server `Dtab.base`. The trait exposes a `addDtabs()` function which applies the parsed Flag value and appends it to the current `Dtab.base`. Result Users are able to augment the base delegation table (`Dtab.base`) of the server with a value passed at runtime via the command line. JIRA Issues: CSL-7766 Differential Revision: https://phabricator.twitter.biz/D297596
- Loading branch information
Showing
5 changed files
with
44 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
36 changes: 29 additions & 7 deletions
36
server/src/main/scala/com/twitter/server/handler/DtabHandler.scala
This file contains 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 |
---|---|---|
@@ -1,18 +1,40 @@ | ||
package com.twitter.server.handler | ||
|
||
import com.twitter.finagle.http.{MediaType, Request, Response} | ||
import com.twitter.finagle.{Dtab, Service} | ||
import com.twitter.finagle.http.{Request, Response} | ||
import com.twitter.server.util.HttpUtils.newOk | ||
import com.twitter.io.Buf | ||
import com.twitter.server.util.{HttpUtils, JsonConverter} | ||
import com.twitter.util.Future | ||
|
||
/** | ||
* Dumps a simple string representation of the current Dtab. | ||
* Dumps a simple JSON string representation of the current [[com.twitter.finagle.Dtab.base]]. | ||
* | ||
* From the Dtab docs: A Dtab--short for delegation table--comprises a sequence | ||
* of delegation rules. Together, these describe how to bind a | ||
* path to an Addr. | ||
* of delegation rules. Together, these describe how to bind a path to an Addr. | ||
* | ||
* {{{ | ||
* { | ||
* "dtab": [ | ||
* "/srv => /srv#/production", | ||
* "/srv => /srv#/prod", | ||
* "/s => /srv/local", | ||
* "/$/inet => /$/nil", | ||
* "/zk => /$/nil" | ||
* ] | ||
* } | ||
* }}} | ||
* | ||
* @see [[com.twitter.finagle.Dtab]] | ||
*/ | ||
class DtabHandler extends Service[Request, Response] { | ||
final class DtabHandler extends Service[Request, Response] { | ||
def apply(req: Request): Future[Response] = | ||
newOk(Dtab.base.toString) | ||
HttpUtils.newResponse(contentType = MediaType.Json, content = Buf.Utf8(jsonResponse)) | ||
|
||
private[this] def jsonResponse: String = { | ||
JsonConverter.writeToString(Map("dtab" -> formattedDtabEntries)) | ||
} | ||
|
||
private[this] def formattedDtabEntries: Seq[String] = { | ||
for (dentry <- Dtab.base) yield { s"${dentry.prefix.show} => ${dentry.dst.show}" } | ||
} | ||
} |