Skip to content

Commit

Permalink
add etcd client
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiibou-chan committed Nov 11, 2024
1 parent 37977ff commit 0b69989
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import channels.{Abort, NioTCP, TCP, UDP}
import com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec
import com.github.plokhotnyuk.jsoniter_scala.macros.{CodecMakerConfig, JsonCodecMaker}
import de.rmgk.options.*
import probench.clients.{ClientCLI, ProBenchClient}
import probench.clients.{ClientCLI, EtcdClient, ProBenchClient}
import probench.data.{ClientNodeState, KVOperation, Request}
import rdts.base.Uid
import rdts.datatypes.experiments.protocols.Membership
Expand Down Expand Up @@ -67,6 +67,7 @@ object cli {
inline def initialClusterIds = named[List[Uid]]("--initial-cluster-ids", "")
inline def clientNode = named[(String, Int)]("--node", "<ip:port>")
inline def name = named[Uid]("--name", "", Uid.gen())
inline def endpoints = named[List[String]]("--endpoints", "")

subcommand("node", "starts a cluster node") {
val node = Node(name.value, initialClusterIds.value.toSet)
Expand Down Expand Up @@ -148,7 +149,11 @@ object cli {
ClientCLI(name.value, client).startCLI()
}.value

subcommand("benchmark", "") {}.value
subcommand("etcd-client", "starts a client to interact with an etcd cluster") {
val client = EtcdClient(name.value, endpoints.value)

ClientCLI(name.value, client).startCLI()
}
}

argparse.parse(args.toList).printHelp()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package probench.clients

import io.etcd.jetcd
import io.etcd.jetcd.ByteSequence
import probench.data
import probench.data.KVOperation
import rdts.base.Uid

class EtcdClient(val name: Uid, val endpoints: List[String]) extends Client(name) {

private val etcdClient = jetcd.Client.builder().endpoints(endpoints*).build()
private val kvClient = etcdClient.getKVClient

override def handleOpImpl(op: KVOperation[String, String]): Unit = {
op match
case data.KVOperation.Read(opKey) =>
val key = ByteSequence.from(opKey.getBytes)
val res = kvClient.get(key).get().getKvs.get(0)
println(s"${res.getKey}=${res.getValue}")
case data.KVOperation.Write(opKey, opValue) =>
val key = ByteSequence.from(opKey.getBytes)
val value = ByteSequence.from(opValue.getBytes)
kvClient.put(key, value).get()
println(s"$opKey=$opValue; OK")
}

}
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ lazy val proBench = project.in(file("Modules/Examples/Protocol Benchmarks"))
Dependencies.munitCheck,
Dependencies.munit,
Dependencies.slips.options,
Dependencies.jetcd,
)

lazy val rdts = crossProject(JVMPlatform, JSPlatform, NativePlatform).crossType(CrossType.Pure)
Expand Down
1 change: 1 addition & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object Dependencies {
def scalaJavaTime = libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % "2.3.0"
def scalajsDom = libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "2.8.0"
def sqliteJdbc = libraryDependencies += "org.xerial" % "sqlite-jdbc" % "3.47.0.0"
def jetcd = libraryDependencies += "io.etcd" % "jetcd-core" % "0.8.3"

def scalatags(conf: Configuration = Compile) = libraryDependencies += "com.lihaoyi" %%% "scalatags" % "0.13.1" % conf

Expand Down

0 comments on commit 0b69989

Please sign in to comment.