add missing error handling
This commit is contained in:
+11
-4
@@ -35,9 +35,12 @@ func Run() {
|
|||||||
cluster := Cluster{}
|
cluster := Cluster{}
|
||||||
cluster.Init(client)
|
cluster.Init(client)
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Printf("[INFO] starting cluster sync\n")
|
err := cluster.Sync()
|
||||||
cluster.Sync()
|
if err != nil {
|
||||||
|
log.Printf("[Error] error encountered while syncing cluster: %s", err)
|
||||||
|
} else {
|
||||||
log.Printf("[INFO] synced cluster in %fs\n", time.Since(start).Seconds())
|
log.Printf("[INFO] synced cluster in %fs\n", time.Since(start).Seconds())
|
||||||
|
}
|
||||||
|
|
||||||
// set repeating update for full rebuilds
|
// set repeating update for full rebuilds
|
||||||
ticker := time.NewTicker(time.Duration(config.ReloadInterval) * time.Second)
|
ticker := time.NewTicker(time.Duration(config.ReloadInterval) * time.Second)
|
||||||
@@ -51,10 +54,14 @@ func Run() {
|
|||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Printf("[INFO] starting cluster sync\n")
|
log.Printf("[INFO] starting cluster sync\n")
|
||||||
cluster.Sync()
|
err := cluster.Sync()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("[Error] error encountered while syncing cluster: %s", err)
|
||||||
|
} else {
|
||||||
log.Printf("[INFO] synced cluster in %fs\n", time.Since(start).Seconds())
|
log.Printf("[INFO] synced cluster in %fs\n", time.Since(start).Seconds())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
router.GET("/version", func(c *gin.Context) {
|
router.GET("/version", func(c *gin.Context) {
|
||||||
@@ -188,7 +195,7 @@ func Run() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
log.Printf("[INFO] starting API listening on 0.0.0.0:%d", config.ListenPort)
|
log.Printf("[INFO] starting API listening on 0.0.0.0:%d", config.ListenPort)
|
||||||
err := router.Run("0.0.0.0:" + strconv.Itoa(config.ListenPort))
|
err = router.Run("0.0.0.0:" + strconv.Itoa(config.ListenPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("[Err] Error starting router: %s", err.Error())
|
log.Fatalf("[Err] Error starting router: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-9
@@ -249,23 +249,39 @@ func (host *Node) RebuildInstance(instancetype InstanceType, vmid uint) error {
|
|||||||
host.Instances[instanceID] = instance
|
host.Instances[instanceID] = instance
|
||||||
|
|
||||||
for volid := range instance.configDisks {
|
for volid := range instance.configDisks {
|
||||||
instance.RebuildVolume(host, volid)
|
err = instance.RebuildVolume(host, volid)
|
||||||
|
if err != nil {
|
||||||
|
err_ch <- err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for netid := range instance.configNets {
|
for netid := range instance.configNets {
|
||||||
instance.RebuildNet(host, netid)
|
err = instance.RebuildNet(host, netid)
|
||||||
|
if err != nil {
|
||||||
|
err_ch <- err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for deviceid := range instance.configHostPCIs {
|
for deviceid := range instance.configHostPCIs {
|
||||||
instance.RebuildDevice(host, deviceid)
|
err = instance.RebuildDevice(host, deviceid)
|
||||||
|
if err != nil {
|
||||||
|
err_ch <- err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if instance.Type == VM {
|
if instance.Type == VM {
|
||||||
instance.RebuildBoot(host)
|
err = instance.RebuildBoot(host)
|
||||||
|
if err != nil {
|
||||||
|
err_ch <- err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// after synchronizing an instance, resync pool membership
|
// after synchronizing an instance, resync pool membership
|
||||||
host.cluster.ResolvePoolMembership()
|
err = host.cluster.ResolvePoolMembership()
|
||||||
|
if err != nil {
|
||||||
|
err_ch <- err
|
||||||
|
}
|
||||||
|
|
||||||
err_ch <- nil
|
err_ch <- nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -302,11 +318,11 @@ func (instance *Instance) RebuildNet(host *Node, netid string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) RebuildDevice(host *Node, deviceid string) {
|
func (instance *Instance) RebuildDevice(host *Node, deviceid string) error {
|
||||||
instanceDevice, ok := instance.configHostPCIs[deviceid]
|
instanceDevice, ok := instance.configHostPCIs[deviceid]
|
||||||
if !ok { // if device does not exist
|
if !ok { // if device does not exist
|
||||||
log.Printf("[WARN] %s not found in devices", deviceid)
|
log.Printf("[WARN] %s not found in devices on node %s", deviceid, host.Name)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
hostDeviceBusID := DeviceID(strings.Split(instanceDevice, ",")[0])
|
hostDeviceBusID := DeviceID(strings.Split(instanceDevice, ",")[0])
|
||||||
@@ -322,9 +338,11 @@ func (instance *Instance) RebuildDevice(host *Node, deviceid string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
instance.Devices[DeviceID(instanceDeviceBusID)].Device_ID = DeviceID(deviceid)
|
instance.Devices[DeviceID(instanceDeviceBusID)].Device_ID = DeviceID(deviceid)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (instance *Instance) RebuildBoot(host *Node) {
|
func (instance *Instance) RebuildBoot(host *Node) error {
|
||||||
instance.Boot = BootOrder{}
|
instance.Boot = BootOrder{}
|
||||||
|
|
||||||
eligibleBoot := map[string]bool{}
|
eligibleBoot := map[string]bool{}
|
||||||
@@ -365,4 +383,6 @@ func (instance *Instance) RebuildBoot(host *Node) {
|
|||||||
log.Printf("[WARN] encountered disabled and non-eligible boot target %s in instance %s\n", bootTarget, instance.Name)
|
log.Printf("[WARN] encountered disabled and non-eligible boot target %s in instance %s\n", bootTarget, instance.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user