Skip to content

Commit

Permalink
fix set zos version
Browse files Browse the repository at this point in the history
  • Loading branch information
sameh-farouk committed Feb 10, 2025
1 parent 54484cd commit cf8922b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions node-registrar/pkg/db/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"gorm.io/gorm"
)

const ZOS4VersionKey = "zos_4"

// ListNodes retrieves all nodes from the database with applied filters and pagination
func (db *Database) ListNodes(filter NodeFilter, limit Limit) (nodes []Node, err error) {
query := db.gormDB.Model(&Node{})
Expand Down Expand Up @@ -81,16 +83,21 @@ func (db *Database) CreateUptimeReport(report *UptimeReport) error {

func (db *Database) SetZOSVersion(version string) error {
var current ZosVersion
err := db.gormDB.FirstOrCreate(&current, ZosVersion{Key: "zos_4"}).Error
if err != nil {
return err
}
result := db.gormDB.Where(ZosVersion{Key: ZOS4VersionKey}).Attrs(ZosVersion{Version: version}).FirstOrCreate(&current)

if current.Version == version {
return errors.New("version already set")
if result.Error != nil {
return result.Error
}

return db.gormDB.Model(&current).Update("version", version).Error
if result.RowsAffected == 0 {
if current.Version == version {
return errors.New("version already set")
}
return db.gormDB.Model(&current).
Select("version").
Update("version", version).Error
}
return nil
}

func (db *Database) GetZOSVersion() (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion node-registrar/pkg/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ type ZOSVersionRequest struct {
// @Failure 401 {object} map[string]any "Unauthorized"
// @Failure 409 {object} map[string]any "Conflict"
// @Failure 500 {object} map[string]any "Internal Server Error"
// @Router /zos/version [post]
// @Router /zos/version [put]
func (s *Server) setZOSVersionHandler(c *gin.Context) {
ensureOwner(c, s.adminTwinID)
if c.IsAborted() {
Expand Down

0 comments on commit cf8922b

Please sign in to comment.