Commit b5edf8ad authored by vicotor's avatar vicotor

update for worker info

parent 177c8467
...@@ -19,6 +19,7 @@ import ( ...@@ -19,6 +19,7 @@ import (
func (wm *WorkerManager) updateWorkerInfo(worker *Worker, winfo *operator.WorkerInfo) error { func (wm *WorkerManager) updateWorkerInfo(worker *Worker, winfo *operator.WorkerInfo) error {
// 2. update worker running info. // 2. update worker running info.
wm.workerRunningOperator.DeleteByWorkerId(context.Background(), worker.WorkerAccount().String()) wm.workerRunningOperator.DeleteByWorkerId(context.Background(), worker.WorkerAccount().String())
runningList := make([]*operator.WorkerRunningInfo, 0)
for _, running := range worker.info.Models.RunningModels { for _, running := range worker.info.Models.RunningModels {
id, _ := strconv.Atoi(running.ModelId) id, _ := strconv.Atoi(running.ModelId)
iInfo := &operator.WorkerRunningInfo{ iInfo := &operator.WorkerRunningInfo{
...@@ -26,17 +27,24 @@ func (wm *WorkerManager) updateWorkerInfo(worker *Worker, winfo *operator.Worker ...@@ -26,17 +27,24 @@ func (wm *WorkerManager) updateWorkerInfo(worker *Worker, winfo *operator.Worker
ModelId: id, ModelId: id,
ExecTime: int(running.ExecTime), ExecTime: int(running.ExecTime),
} }
_, err := wm.workerRunningOperator.Insert(context.Background(), iInfo) runningList = append(runningList, iInfo)
if err != nil {
log.WithFields(log.Fields{ }
"worker": worker.WorkerAccount().String(), res, err := wm.workerRunningOperator.InsertMany(context.Background(), runningList)
"model": id, if err != nil {
}).WithError(err).Error("insert worker running model info failed") log.WithFields(log.Fields{
continue "worker": worker.WorkerAccount().String(),
} }).WithError(err).Error("insert worker running model info failed")
} else {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
"count": len(res.InsertedIDs),
}).Debug("insert worker running model info success")
} }
// 3. update worker installed info. // 3. update worker installed info.
wm.workerInstalledOperator.DeleteByWorkerId(context.Background(), worker.WorkerAccount().String()) wm.workerInstalledOperator.DeleteByWorkerId(context.Background(), worker.WorkerAccount().String())
installList := make([]*operator.WorkerInstalledInfo, 0)
for _, installed := range worker.info.Models.InstalledModels { for _, installed := range worker.info.Models.InstalledModels {
id, _ := strconv.Atoi(installed.ModelId) id, _ := strconv.Atoi(installed.ModelId)
iInfo := &operator.WorkerInstalledInfo{ iInfo := &operator.WorkerInstalledInfo{
...@@ -46,22 +54,29 @@ func (wm *WorkerManager) updateWorkerInfo(worker *Worker, winfo *operator.Worker ...@@ -46,22 +54,29 @@ func (wm *WorkerManager) updateWorkerInfo(worker *Worker, winfo *operator.Worker
if len(worker.info.Hardware.GPU) > 0 { if len(worker.info.Hardware.GPU) > 0 {
iInfo.GpuFree = worker.info.Hardware.GPU[0].MemFree iInfo.GpuFree = worker.info.Hardware.GPU[0].MemFree
} }
_, err := wm.workerInstalledOperator.Insert(context.Background(), iInfo) installList = append(installList, iInfo)
if err != nil { }
log.WithFields(log.Fields{ res, err = wm.workerInstalledOperator.InsertMany(context.Background(), installList)
"worker": worker.WorkerAccount().String(), if err != nil {
"model": id, log.WithFields(log.Fields{
}).WithError(err).Error("insert worker installed model info failed") "worker": worker.WorkerAccount().String(),
continue }).WithError(err).Error("insert worker installed model info failed")
} } else {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
"count": len(res.InsertedIDs),
}).Debug("insert worker installed model info success")
} }
// 1. update worker info. // 1. update worker info.
winfo.Hardware = types.PbToHardwareInfo(worker.info.Hardware) winfo.Hardware = types.PbToHardwareInfo(worker.info.Hardware)
winfo.Models = types.PbToModelInfo(worker.info.Models) winfo.Models = types.PbToModelInfo(worker.info.Models)
winfo.NodeInfo = types.PbToNodeInfo(worker.info.Info) winfo.NodeInfo = types.PbToNodeInfo(worker.info.Info)
err := wm.workerInfoOperator.UpdateWorker(context.Background(), winfo) err = wm.workerInfoOperator.UpdateWorker(context.Background(), winfo)
if err != nil { if err != nil {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
}).WithError(err).Error("update worker info failed")
return err return err
} }
...@@ -81,7 +96,7 @@ func (wm *WorkerManager) addWorkerInfo(worker *Worker) error { ...@@ -81,7 +96,7 @@ func (wm *WorkerManager) addWorkerInfo(worker *Worker) error {
} }
// 2. add worker running info. // 2. add worker running info.
runningList := make([]*operator.WorkerRunningInfo, 0)
for _, running := range worker.info.Models.RunningModels { for _, running := range worker.info.Models.RunningModels {
id, _ := strconv.Atoi(running.ModelId) id, _ := strconv.Atoi(running.ModelId)
iInfo := &operator.WorkerRunningInfo{ iInfo := &operator.WorkerRunningInfo{
...@@ -89,17 +104,23 @@ func (wm *WorkerManager) addWorkerInfo(worker *Worker) error { ...@@ -89,17 +104,23 @@ func (wm *WorkerManager) addWorkerInfo(worker *Worker) error {
ModelId: id, ModelId: id,
ExecTime: int(running.ExecTime), ExecTime: int(running.ExecTime),
} }
_, err := wm.workerRunningOperator.Insert(context.Background(), iInfo) runningList = append(runningList, iInfo)
if err != nil {
log.WithFields(log.Fields{ }
"worker": worker.WorkerAccount().String(), res, err := wm.workerRunningOperator.InsertMany(context.Background(), runningList)
"model": id, if err != nil {
}).WithError(err).Error("insert worker running model info failed") log.WithFields(log.Fields{
continue "worker": worker.WorkerAccount().String(),
} }).WithError(err).Error("insert worker running model info failed")
} else {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
"count": len(res.InsertedIDs),
}).Debug("insert worker running model info success")
} }
// 3. add worker installed info. // 3. add worker installed info.
installList := make([]*operator.WorkerInstalledInfo, 0)
for _, installed := range worker.info.Models.InstalledModels { for _, installed := range worker.info.Models.InstalledModels {
id, _ := strconv.Atoi(installed.ModelId) id, _ := strconv.Atoi(installed.ModelId)
iInfo := &operator.WorkerInstalledInfo{ iInfo := &operator.WorkerInstalledInfo{
...@@ -109,14 +130,19 @@ func (wm *WorkerManager) addWorkerInfo(worker *Worker) error { ...@@ -109,14 +130,19 @@ func (wm *WorkerManager) addWorkerInfo(worker *Worker) error {
if len(worker.info.Hardware.GPU) > 0 { if len(worker.info.Hardware.GPU) > 0 {
iInfo.GpuFree = worker.info.Hardware.GPU[0].MemFree iInfo.GpuFree = worker.info.Hardware.GPU[0].MemFree
} }
_, err := wm.workerInstalledOperator.Insert(context.Background(), iInfo) installList = append(installList, iInfo)
if err != nil {
log.WithFields(log.Fields{ }
"worker": worker.WorkerAccount().String(), res, err = wm.workerInstalledOperator.InsertMany(context.Background(), installList)
"model": id, if err != nil {
}).WithError(err).Error("insert worker installed model info failed") log.WithFields(log.Fields{
continue "worker": worker.WorkerAccount().String(),
} }).WithError(err).Error("insert worker installed model info failed")
} else {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
"count": len(res.InsertedIDs),
}).Debug("insert worker installed model info success")
} }
return nil return nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment