// ResetNms resets the runners nms
ResetNms resets the runners nms
// ResetNms resets the runners nms
func (s RunnerService) ResetNms(runner api.Runner) error {
	var nms api.Nms
	if err := s.DB.Preload("Licences").First(&nms, "address = ?", runner.Nms).Error; err != nil {
		s.logger.Error("Cannot get NMS from DB",
			zap.String("runner", runner.Name),
			zap.String("nms", runner.Nms),
			zap.String("exception", err.Error()),
		)
		return err
	}
	nms.InUse = nms.InUse - runner.Workers
	for _, lic := range nms.Licences {
		if lic.Type == runner.Licence {
			lic.InUse = lic.InUse - 1
			if err := s.DB.Save(&lic).Error; err != nil {
				s.logger.Error("Cannot update licence-information to DB",
					zap.String("runner", runner.Name),
					zap.String("nms", runner.Nms),
					zap.String("licence", lic.Type),
					zap.String("exception", err.Error()),
				)
				return err
			}
		}
	}
	if err := s.DB.Save(&nms).Error; err != nil {
		s.logger.Error("Cannot update nms-information to DB",
			zap.String("runner", runner.Name),
			zap.String("nms", runner.Nms),
			zap.String("licence", runner.Licence),
			zap.String("exception", err.Error()),
		)
		return err
	}
	return nil
}
func ( s RunnerService ) ResetNms ( runner api . Runner ) error { var nms api . Nms if err := s . DB . Preload ( " " ) . First ( & nms , " " , runner . Nms ) . Error ; err != nil { s . logger . Error ( " " , zap . String ( " " , runner . Name ) , zap . String ( " " , runner . Nms ) , zap . String ( " " , err . Error ( ) ) , ) return err } nms . InUse = nms . InUse - runner . Workers for _ , lic := range nms . Licences { if lic . Type == runner . Licence { lic . InUse = lic . InUse - 1 if err := s . DB . Save ( & lic ) . Error ; err != nil { s . logger . Error ( " " , zap . String ( " " , runner . Name ) , zap . String ( " " , runner . Nms ) , zap . String ( " " , lic . Type ) , zap . String ( " " , err . Error ( ) ) , ) return err } } } if err := s . DB . Save ( & nms ) . Error ; err != nil { s . logger . Error ( " " , zap . String ( " " , runner . Name ) , zap . String ( " " , runner . Nms ) , zap . String ( " " , runner . Licence ) , zap . String ( " " , err . Error ( ) ) , ) return err } return nil }
ResetNms resets the runners nms
ResetNms resets the runners nms
// Get the latest data for the nms-server // Reset the licences for the nms // update the nms to the db