Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ff1b849

Browse files
author
Sarah Brown
committed
domainToPath and domainToPathPfx rewrite namers
1 parent 129395e commit ff1b849

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

linkerd/admin/src/main/scala/io/buoyant/linkerd/admin/AdminInitializer.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.twitter.util.Monitor
1010
import io.buoyant.linkerd.Admin
1111
import io.buoyant.linkerd.Admin.AdminPort
1212
import java.net.InetSocketAddress
13+
import scala.util.Properties
1314

1415
class AdminInitializer(admin: Admin, svc: Service[Request, Response]) {
1516

@@ -22,6 +23,7 @@ class AdminInitializer(admin: Admin, svc: Service[Request, Response]) {
2223
val loggingMonitor = new Monitor {
2324
def handle(exc: Throwable): Boolean = {
2425
log.log(Level.ERROR, s"Caught exception in AdminInitializer: $exc", exc)
26+
log.log(Level.ERROR, exc.getStackTrace().mkString("", Properties.lineSeparator, Properties.lineSeparator))
2527
false
2628
}
2729
}

router/http/src/main/scala/io/buoyant/http/namer.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,40 @@ class subdomainOfPfx extends RewritingNamer {
135135
}
136136
}
137137

138+
/**
139+
* A rewriting namer that accepts names in the form:
140+
*
141+
* /foo.buoyant.io/resource/name
142+
*
143+
* and rewrites to:
144+
*
145+
* /io/buoyant/foo/resource/name
146+
*/
147+
class domainToPath extends RewritingNamer {
148+
protected[this] def rewrite(path: Path) = path.take(1) match {
149+
case Path.Utf8(host@Match.host()) =>
150+
Some(Path.Utf8(host.split("\\.").reverse: _*) ++ path.drop(1))
151+
case _ => None
152+
}
153+
}
154+
155+
/**
156+
* A rewriting namer that accepts names in the form:
157+
*
158+
* /pfx/foo.buoyant.io/resource/name
159+
*
160+
* and rewrites to:
161+
*
162+
* /pfx/io/buoyant/foo/resource/name
163+
*/
164+
class domainToPathPfx extends RewritingNamer {
165+
protected[this] def rewrite(path: Path) = path.take(2) match {
166+
case Path.Utf8(pfx, host@Match.host()) =>
167+
Some(Path.Utf8(pfx +: host.split("\\.").reverse: _*) ++ path.drop(2))
168+
case _ => None
169+
}
170+
}
171+
138172
/**
139173
* A service namer that accepts names in the form:
140174
*

router/http/src/test/scala/io/buoyant/http/NamerTest.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ class NamerTest extends FunSuite with Awaits {
6161
assert(lookup(path) == NameTree.Leaf(Name.Path(Path.Utf8("foo", "bar", "bah"))))
6262
}
6363

64+
test("domainToPath") {
65+
val path = Path.read("/$/io.buoyant.http.domainToPath/foo.buoyant.io")
66+
assert(lookup(path) == NameTree.Leaf(Name.Path(Path.Utf8("io", "buoyant", "foo"))))
67+
}
68+
69+
test("domainToPathPfx") {
70+
val path = Path.read("/$/io.buoyant.http.domainToPathPfx/pfx/foo.buoyant.io")
71+
assert(lookup(path) == NameTree.Leaf(Name.Path(Path.Utf8("pfx", "io", "buoyant", "foo"))))
72+
}
73+
6474
test("status") {
6575
val client = Http.newService("/$/io.buoyant.http.status/401/foo/bar.a.b/bah")
6676
val rsp = await(client(Request()))

0 commit comments

Comments
 (0)