-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
Copyright 2018 Banco Bilbao Vizcaya Argentaria, n.A. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package member | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/hashicorp/memberlist" | ||
) | ||
|
||
type Type int | ||
|
||
func (t Type) String() string { | ||
switch t { | ||
case Auditor: | ||
return "auditor" | ||
case Monitor: | ||
return "monitor" | ||
case Publisher: | ||
return "publisher" | ||
case Server: | ||
return "server" | ||
default: | ||
return "unknown" | ||
} | ||
} | ||
|
||
func ParseType(value string) Type { | ||
switch value { | ||
case "auditor": | ||
return Auditor | ||
case "monitor": | ||
return Monitor | ||
case "publisher": | ||
return Publisher | ||
default: | ||
return Server | ||
} | ||
} | ||
|
||
const ( | ||
Auditor Type = iota | ||
Monitor | ||
Publisher | ||
Server | ||
MaxType | ||
) | ||
|
||
// Member is a single member of the gossip cluster. | ||
type Peer struct { | ||
Name string | ||
Addr net.IP | ||
Port uint16 | ||
Meta *Meta | ||
Status Status | ||
} | ||
|
||
func (p Peer) Node() *memberlist.Node { | ||
return &memberlist.Node{ | ||
Name: p.Name, | ||
Addr: p.Addr, | ||
Port: p.Port, | ||
} | ||
} | ||
|
||
func NewPeer(name, addr string, port uint16, role Type) *Peer { | ||
meta := &Meta{ | ||
Role: role, | ||
} | ||
|
||
return &Peer{ | ||
Name: name, | ||
Addr: net.IP(addr), | ||
Port: port, | ||
Meta: meta, | ||
} | ||
} | ||
|
||
func ParsePeer(node *memberlist.Node) *Peer { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright 2018 Banco Bilbao Vizcaya Argentaria, n.A. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package member | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/bbva/qed/log" | ||
"github.com/hashicorp/go-msgpack/codec" | ||
) | ||
|
||
type Meta struct { | ||
Role Type | ||
} | ||
|
||
func (a *Meta) Encode() ([]byte, error) { | ||
var buf bytes.Buffer | ||
encoder := codec.NewEncoder(&buf, &codec.MsgpackHandle{}) | ||
if err := encoder.Encode(a); err != nil { | ||
log.Errorf("Failed to encode agent metadata: %v", err) | ||
return nil, err | ||
} | ||
return buf.Bytes(), nil | ||
} | ||
|
||
func (a *Meta) Decode(buf []byte) error { | ||
reader := bytes.NewReader(buf) | ||
decoder := codec.NewDecoder(reader, &codec.MsgpackHandle{}) | ||
if err := decoder.Decode(a); err != nil { | ||
log.Errorf("Failed to decode agent metadata: %v", err) | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Copyright 2018 Banco Bilbao Vizcaya Argentaria, n.A. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package member | ||
|
||
// Status is the state of the Agent instance. | ||
type Status int32 | ||
|
||
const ( | ||
Alive Status = iota | ||
Leaving | ||
Left | ||
Shutdown | ||
Failed | ||
) | ||
|
||
func (s Status) String() string { | ||
switch s { | ||
case Alive: | ||
return "alive" | ||
case Leaving: | ||
return "leaving" | ||
case Left: | ||
return "left" | ||
case Shutdown: | ||
return "shutdown" | ||
default: | ||
return "failed" | ||
} | ||
} |