简体   繁体   English

如何构建简单的Linkerd Namer插件?

[英]How to build simple Linkerd namer plugin?

I'm trying to run linkerd with some custom namer plug-in but failing on startup. 我正在尝试使用一些自定义命名器插件运行linkerd,但是启动失败。 I've got the source code of io.l5d.fs and cut off all the business logic to get some minimalistic example with hardcoded addresses. 我已经有了io.l5d.fs的源代码,并切断了所有业务逻辑,以获取一些带有硬编码地址的简约示例。

Initializer: 初始化器:

package com.consg
import io.buoyant.namer.NamerInitializer

class MyInitializer extends NamerInitializer {
  val configClass = classOf[MyConfig]
  override def configId = "com.consg.MyConfig"
}

object MyInitializer extends MyInitializer

Config: 配置:

package com.consg

import com.fasterxml.jackson.annotation.JsonIgnore
import com.twitter.finagle.{Path, Stack}
import io.buoyant.config.types.Directory
import io.buoyant.namer.NamerConfig

case class MyConfig(rootDir: Directory) extends NamerConfig {

  @JsonIgnore
  override def defaultPrefix: Path = Path.read("/my.namer")

  @JsonIgnore
  def newNamer(params: Stack.Params) = {
    println("params: " + params)
    new MyNamer(rootDir.path, prefix)
  }

}

Namer: 姓名:

package com.consg

import java.nio.file.{Path => NioPath}

import com.twitter.finagle._
import com.twitter.util._
import io.buoyant.namer.EnumeratingNamer

class MyNamer(rootDir: NioPath, prefix: Path) extends EnumeratingNamer {

  def lookup(path: Path): Activity[NameTree[Name]] = {
    println("lookup path: " + path)

    val address1 = Address("127.0.0.1", 7777)
    val addr = Addr.Bound(Set(address1), Addr.Metadata.empty)
    val varr = Var.apply(addr)

    Activity.value(NameTree.Leaf(Name.Bound(varr, path, path)))
  }

  override def getAllNames: Activity[Set[Path]] = {
    println("getAllNames!")
    Activity.value(Set.apply(Path.read("animal")))
  }
}

build.sbt build.sbt

name := "plug"
version := "1"
scalaVersion := "2.12.1"

libraryDependencies += "io.buoyant" % "linkerd-core_2.12" % "1.3.2" % "provided"

Also I exposed the "com.consg.MyInitializer" service under META-INF/services/io.buoyant.namer.NamerInitializer 我还公开了META-INF / services / io.buoyant.namer.NamerInitializer下的“ com.consg.MyInitializer”服务

Then I build the plugin jar & placed it under plugins (linkerd-1.3.1/plugins) 然后,我构建插件jar并将其放在插件下(linkerd-1.3.1 / plugins)

Now I'm trying to run linkerd with config: 现在,我尝试使用config运行linkerd:

namers:
- kind: com.consg.MyConfig
  rootDir: disco

routers:
- protocol: http
  dtab: /svc => /#/my.namer;
  servers:
  - port: 8080

And as a result I've got: 结果,我得到了:

com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'com.consg.MyConfig' into a subtype of [simple type, class io.buoyant.namer.NamerConfig]: known type ids = [NamerConfig, io.l5d.consul, io.l5d.curator, io.l5d.dnssrv, io.l5d.fs, io.l5d.k8s, io.l5d.k8s.external, io.l5d.k8s.ns, io.l5d.marathon, io.l5d.rewrite, io.l5d.serversets, io.l5d.zkLeader]

So it looks like the plugin not loaded at all. 因此,看起来插件根本没有加载。 Need some help. 需要一些帮助。

code on github github上的代码

Looks like my problem was undefined $L5D_HOME environment variable. 看来我的问题是未定义的$ L5D_HOME环境变量。 After I've set it the plug-in was enabled. 设置好之后,插件即被启用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM