Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Igor sync #1169

Merged
merged 4 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/igor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var commands = []*Command{
cmdPower,
cmdExtend,
cmdNotify,
cmdSync,
}

var exitStatus = 0
Expand Down
111 changes: 111 additions & 0 deletions src/igor/sync.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright (2018) Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.

package main

import (
"fmt"
log "minilog"
)

var cmdSync = &Command{
UsageLine: "sync",
Short: "synchronize igor data",
Long: `
Does an internal check to verify the integrity of the data file.

OPTIONAL FLAGS:

-v Verbose - Prints additioanl information
`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add line for what -l does?

}

var subL bool // -l
var subV bool // -v

func init() {
// break init cycle
cmdSync.Run = runSync

cmdSync.Flag.BoolVar(&subL, "l", false, "")
cmdSync.Flag.BoolVar(&subV, "v", false, "")
}

// Gather data integrity information, report, and fix
func runSync(cmd *Command, args []string) {
user, err := getUser()
if err != nil {
log.Fatalln("Cannot determine current user", err)
}
if user.Username != "root" {
log.Fatalln("Sync access restricted. Please use as admin.")
}

log.Debug("Sync called - finding orphan IDs")
IDs := getOrphanIDs()
if len(IDs) > 0 {
fmt.Printf("%v orphan Reservation IDs found\n", len(IDs))
if subV {
for _, id := range IDs {
fmt.Println(id)
}
}
}
// we are only listing
if subL {
return
}

// purge the orphan IDs from the shedule
if len(IDs) > 0 {
if !subV {
fmt.Println("Purging Orphan IDs from Schedule...")
}
for _, oid := range IDs {
purgeFromSchedule(oid)
}
fmt.Println("Done.")
dirty = true
}

}

func getOrphanIDs() []uint64 {
resIDs := make(map[uint64]bool)
// make a list of all reseration IDs that appear in the schedule
for _, s := range Schedule {
for _, n := range s.Nodes {
resIDs[n] = true
}
}
// Go through the reservations and turn off IDs we know about
for _, r := range Reservations {
resIDs[r.ID] = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead you could delete(resIDs, r.ID) so that below you don't need to check the value of resIDs for the given k -- it should only be false.

}
resIDs[0] = false //we don't care about 0
// Compile a list of the remaining IDs, if any
var orphanIDs []uint64
for k, v := range resIDs {
if v {
orphanIDs = append(orphanIDs, k)
}
}
log.Debug("Sync:getOrphanIDs concluded with: %v", resIDs)
return orphanIDs
}

func purgeFromSchedule(id uint64) {
if subV {
fmt.Printf("Purging orphan ID %v from schedule...\n", id)
}
newSched := Schedule
for i := 0; i < len(newSched); i++ {
for j := 0; j < len(newSched[i].Nodes); j++ {
if newSched[i].Nodes[j] == id {
newSched[i].Nodes[j] = 0
}
}
}
Schedule = newSched
}
2 changes: 1 addition & 1 deletion src/igor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,5 @@ func emitReservationLog(action string, res Reservation) {
format := "2006-Jan-2-15:04"
rnge, _ := ranges.NewRange(igorConfig.Prefix, igorConfig.Start, igorConfig.End)
unsplit, _ := rnge.UnsplitRange(res.Hosts)
log.Info("%s user=%v resname=%v nodes=%v start=%v end=%v duration=%v\n", action, res.Owner, res.ResName, unsplit, time.Unix(res.StartTime, 0).Format(format), time.Unix(res.EndTime, 0).Format(format), res.Duration)
log.Info("%s user=%v resname=%v id=%v nodes=%v start=%v end=%v duration=%v\n", action, res.Owner, res.ResName, res.ID, unsplit, time.Unix(res.StartTime, 0).Format(format), time.Unix(res.EndTime, 0).Format(format), res.Duration)
}