events are in cluster.E
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
9608bb680f
commit
18053caca8
4
add.go
4
add.go
|
@ -125,6 +125,6 @@ func (c *Cluster) BlankFields() {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *Cluster) AppendEvent(e *Event) {
|
||||
c.Events = append(c.Events, e)
|
||||
func (epb *Events) AppendEvent(e *Event) {
|
||||
epb.Events = append(epb.Events, e)
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ func (c *Cluster) ChangeDropletState(d *Droplet, newState DropletState) error {
|
|||
now := time.Now()
|
||||
e.Start = timestamppb.New(now)
|
||||
|
||||
c.Events = append(c.Events, e)
|
||||
c.E.Events = append(c.E.Events, e)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ func (c *Cluster) DropletMoved(d *Droplet, newh *Hypervisor) error {
|
|||
now := time.Now()
|
||||
e.Start = timestamppb.New(now)
|
||||
|
||||
c.Events = append(c.Events, e)
|
||||
c.E.Events = append(c.E.Events, e)
|
||||
|
||||
// update the droplet record
|
||||
d.CurrentHypervisor = newh.Hostname
|
||||
|
|
|
@ -8,7 +8,12 @@ import "event.proto";
|
|||
message Cluster {
|
||||
int64 id = 1;
|
||||
repeated string dirs = 2;
|
||||
|
||||
repeated Droplet droplets = 3;
|
||||
repeated Hypervisor hypervisors = 4;
|
||||
repeated Event events = 5;
|
||||
// repeated Event events = 5;
|
||||
|
||||
Droplets d = 6;
|
||||
Hypervisors h = 7;
|
||||
Events e = 8;
|
||||
}
|
||||
|
|
97
config.go
97
config.go
|
@ -47,14 +47,11 @@ func (c *Cluster) ConfigSave() error {
|
|||
return err
|
||||
}
|
||||
|
||||
var e *Events
|
||||
e = new(Events)
|
||||
e.Events = c.Events
|
||||
if err := ConfigWriteJSON(e, "events.json"); err != nil {
|
||||
if err := ConfigWriteJSON(c.E, "events.json"); err != nil {
|
||||
fmt.Println("events.json write failed")
|
||||
return err
|
||||
}
|
||||
if err := ConfigWriteTEXT(e, "events.text"); err != nil {
|
||||
if err := ConfigWriteTEXT(c.E, "events.text"); err != nil {
|
||||
fmt.Println("events.json write failed")
|
||||
return err
|
||||
}
|
||||
|
@ -68,7 +65,7 @@ func (c *Cluster) ConfigSave() error {
|
|||
newc.Dirs = c.Dirs
|
||||
newc.Droplets = nil
|
||||
newc.Hypervisors = nil
|
||||
newc.Events = nil
|
||||
newc.E = nil
|
||||
if err := ConfigWriteTEXT(&newc, "cluster.text"); err != nil {
|
||||
fmt.Println("cluster.json write failed")
|
||||
return err
|
||||
|
@ -88,45 +85,6 @@ func backupConfigFiles() error {
|
|||
return backupFiles(srcDir, destDir)
|
||||
}
|
||||
|
||||
/*
|
||||
func (c *Cluster) ConfigLoadOld2() error {
|
||||
if c == nil {
|
||||
return errors.New("It's not safe to run ConfigLoad() on a nil cluster")
|
||||
}
|
||||
|
||||
// erase or zero fields that shouldn't ever be written to the config file
|
||||
c.BlankFields()
|
||||
|
||||
// load the cluster config file
|
||||
if data, err := loadFile("virtigo.json"); err == nil {
|
||||
if err = protojson.Unmarshal(data, c); err != nil {
|
||||
fmt.Println("broken cluster.json config file")
|
||||
fmt.Println(err)
|
||||
return errors.New("cluster.json file is broken")
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
|
||||
var e *Events
|
||||
e = new(Events)
|
||||
// load the events config file
|
||||
if data, err := loadFile("events.json"); err == nil {
|
||||
if err = protojson.Unmarshal(data, e); err != nil {
|
||||
fmt.Println("broken events.json config file")
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
// copy them over. is this needed? does the memory free otherwise?
|
||||
for _, a := range e.Events {
|
||||
c.Events = append(c.Events, a)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
|
||||
func (c *Cluster) ConfigLoad() error {
|
||||
if c == nil {
|
||||
return errors.New("It's not safe to run ConfigLoad() on a nil cluster")
|
||||
|
@ -177,20 +135,51 @@ func (c *Cluster) ConfigLoad() error {
|
|||
c.Hypervisors = append(c.Hypervisors, a)
|
||||
}
|
||||
|
||||
var e *Events
|
||||
e = new(Events)
|
||||
if err := c.loadEvents(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cluster) loadEvents() error {
|
||||
var data []byte
|
||||
var err error
|
||||
|
||||
if c == nil {
|
||||
fmt.Println("cluster == nil")
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
if c.E == nil {
|
||||
fmt.Println("cluster.E == nil")
|
||||
c.E = new(Events)
|
||||
}
|
||||
|
||||
if c.E == nil {
|
||||
fmt.Println("cluster.E == nil")
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
// load the events config file
|
||||
if data, err := loadFile("events.json"); err == nil {
|
||||
if err = protojson.Unmarshal(data, e); err != nil {
|
||||
if data, err = loadFile("events.json"); err != nil {
|
||||
fmt.Println("broken events.json config file")
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
|
||||
err = protojson.Unmarshal(data, c.E)
|
||||
if err != nil {
|
||||
fmt.Println("broken events.json config file")
|
||||
// json load failed. try loading prototext
|
||||
if data, err = loadFile("events.text"); err != nil {
|
||||
fmt.Println("broken events.text config file")
|
||||
fmt.Println(err)
|
||||
return errors.New("events.text file is broken")
|
||||
}
|
||||
if err = prototext.Unmarshal(data, c.E); err != nil {
|
||||
fmt.Println("broken events.text config file")
|
||||
fmt.Println(err)
|
||||
return errors.New("events.text file is broken")
|
||||
}
|
||||
// copy them over. is this needed? does the memory free otherwise?
|
||||
for _, a := range e.Events {
|
||||
c.Events = append(c.Events, a)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ package virtbuf
|
|||
import (
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/encoding/prototext"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// human readable JSON
|
||||
|
@ -77,3 +78,7 @@ func (d *Droplet) UnmarshalJSON(data []byte) error {
|
|||
func (e *Events) UnmarshalJSON(data []byte) error {
|
||||
return protojson.Unmarshal(data, e)
|
||||
}
|
||||
|
||||
func (d *Droplet) Unmarshal(data []byte) error {
|
||||
return proto.Unmarshal(data, d)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
syntax = "proto3";
|
||||
package virtbuf;
|
||||
|
||||
message Cluster {
|
||||
int64 id = 1;
|
||||
repeated string s = 2;
|
||||
repeated int i = 3;
|
||||
}
|
Loading…
Reference in New Issue