diff --git a/graffiti/etcd/client/client.go b/graffiti/etcd/client/client.go new file mode 100644 index 0000000000000000000000000000000000000000..9cb6574071c3ad78d6795aacbc7f361b3004f4d1 --- /dev/null +++ b/graffiti/etcd/client/client.go @@ -0,0 +1,54 @@ +package client + +import ( + "time" + + etcd "go.etcd.io/etcd/client/v2" + + "github.com/skydive-project/skydive/graffiti/logging" +) + +// Client defaults +const ( + DefaultTimeout = 5 * time.Second + DefaultPort = 12379 + DefaultServer = "127.0.0.1" +) + +// MasterElectionListener describes the multi election mechanism +type MasterElectionListener interface { + OnStartAsMaster() + OnStartAsSlave() + OnSwitchToMaster() + OnSwitchToSlave() +} + +// MasterElection describes the master election mechanism +type MasterElection interface { + Start() + StartAndWait() + Stop() + IsMaster() bool + AddEventListener(listener MasterElectionListener) + TTL() time.Duration +} + +// MasterElectionService describes the election service mechanism +type MasterElectionService interface { + NewElection(key string) MasterElection +} + +// Client describes a ETCD configuration client +type Client struct { + id string + client *etcd.Client + KeysAPI etcd.KeysAPI + logger logging.Logger +} + +// Opts describes the options of an etcd client +type Opts struct { + Servers []string + Timeout time.Duration + Logger logging.Logger +} diff --git a/graffiti/http/client.go b/graffiti/http/client.go index c3dc24ce025776334141d621f5ade67dd698d124..8826f1a8ea74ecfe8eae7b9fc0418f7b01e32297 100644 --- a/graffiti/http/client.go +++ b/graffiti/http/client.go @@ -1,8 +1,10 @@ package http import ( + "bytes" "compress/gzip" "crypto/tls" + "encoding/json" "fmt" "io" "io/ioutil"