This repository was archived by the owner on Feb 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathEtcdClient.scala
82 lines (62 loc) · 2.64 KB
/
EtcdClient.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package me.maciejb.etcd.client
import akka.actor.{ActorSystem, Cancellable}
import akka.http.scaladsl.model.HttpHeader
import akka.http.scaladsl.settings.ClientConnectionSettings
import akka.stream.Materializer
import akka.stream.scaladsl.Source
import me.maciejb.etcd.client.impl.EtcdClientImpl
import scala.collection.immutable
import scala.concurrent.{ExecutionContext, Future}
/**
* `etcd` client API
*
* @see [[https://coreos.com/etcd/docs/latest/api.html etcd API documentation]]
*/
trait EtcdClient {
def get(key: String, recursive: Boolean = false, sorted: Boolean = false): Future[EtcdResponse]
def wait(key: String,
waitIndex: Option[Int] = None,
recursive: Boolean = false,
sorted: Boolean = false,
quorum: Boolean = false): Future[EtcdResponse]
def set(key: String, value: String, ttl: Option[Int] = None): Future[EtcdResponse]
def compareAndSet(key: String, value: String,
ttl: Option[Int] = None,
prevValue: Option[String] = None,
prevIndex: Option[Int] = None,
prevExist: Option[Boolean] = None): Future[EtcdResponse]
def refreshTtl(key: String, ttl: Int): Future[EtcdResponse]
def clearTtl(key: String): Future[EtcdResponse]
def create(parentKey: String, value: String): Future[EtcdResponse]
def createDir(key: String, ttl: Option[Int] = None): Future[EtcdResponse]
def refreshDirTtl(key: String, ttl: Int): Future[EtcdResponse]
def delete(key: String, recursive: Boolean = false): Future[EtcdResponse]
def compareAndDelete(key: String,
prevValue: Option[String] = None,
prevIndex: Option[Int] = None): Future[EtcdResponse]
def watch(key: String,
waitIndex: Option[Int] = None,
recursive: Boolean = false,
quorum: Boolean = false): Source[EtcdResponse, Cancellable]
}
/**
* `etcd` client factory.
*/
object EtcdClient {
val DefaultPort = 2379
/**
* Creates a new instance of `etcd` client.
*
* @param host host to connect to.
* @param port port to connect to, 2379 by default.
* @param httpClientSettings optional client options for Akka HTTP.
*/
def apply(host: String, port: Int = DefaultPort,
httpClientSettings: Option[ClientConnectionSettings] = None,
httpHeaders: immutable.Seq[HttpHeader] = Nil,
sslEnabled: Boolean = false)
(implicit ec: ExecutionContext,
system: ActorSystem,
mat: Materializer): EtcdClient =
new EtcdClientImpl(host, port, httpClientSettings, httpHeaders, sslEnabled)
}