-
Notifications
You must be signed in to change notification settings - Fork 66
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
Igor sync #1169
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ecba23e
igor: Adding in the sync API. This initial version will attempt to di…
csymonds d1c9830
igor: sync - sync will now automatically try to purge orphan IDs from…
csymonds 8c486f2
igor: sync - changing the flag options to something that makes a bit …
csymonds 06ca8f9
igor: sync - change the underscore to a hyphen
csymonds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ var commands = []*Command{ | |
cmdPower, | ||
cmdExtend, | ||
cmdNotify, | ||
cmdSync, | ||
} | ||
|
||
var exitStatus = 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
`, | ||
} | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead you could |
||
} | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?