/
cluster.go
47 lines (40 loc) · 956 Bytes
/
cluster.go
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
package types
import (
"errors"
"fmt"
"strconv"
"github.com/opensds/multi-cloud/s3/pkg/helper"
)
type Cluster struct {
Fsid string
Pool string
Weight int
}
func (c *Cluster) Serialize() (map[string]interface{}, error) {
fields := make(map[string]interface{})
bytes, err := helper.MsgPackMarshal(c)
if err != nil {
return nil, err
}
fields[FIELD_NAME_BODY] = string(bytes)
return fields, nil
}
func (c *Cluster) Deserialize(fields map[string]string) (interface{}, error) {
body, ok := fields[FIELD_NAME_BODY]
if !ok {
return nil, errors.New(fmt.Sprintf("no field %s found", FIELD_NAME_BODY))
}
err := helper.MsgPackUnMarshal([]byte(body), c)
if err != nil {
return nil, err
}
return c, nil
}
func (c *Cluster) GetValues() (values map[string]map[string][]byte, err error) {
values = map[string]map[string][]byte{
CLUSTER_COLUMN_FAMILY: map[string][]byte{
"weight": []byte(strconv.Itoa(c.Weight)),
},
}
return
}