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

Dev/event #65

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
35 changes: 23 additions & 12 deletions internal/cacctmgr/CmdArgParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,15 @@ var (
},
}

/* ---------------------------------------------------- find ---------------------------------------------------- */
findCmd = &cobra.Command{
/* ---------------------------------------------------- show/find ---------------------------------------------------- */
showCmd = &cobra.Command{
Use: "show",
Aliases: []string{"search", "query", "find"},
SilenceErrors: true,
Short: "Find a specific entity",
Short: "Show or find information of entities",
Long: "",
}
findAccountCmd = &cobra.Command{
showAccountCmd = &cobra.Command{
Use: "account",
Aliases: []string{"accounts"},
Short: "Find and display information of account",
Expand All @@ -325,7 +325,7 @@ var (
}
},
}
findUserCmd = &cobra.Command{
showUserCmd = &cobra.Command{
Use: "user",
Aliases: []string{"users"},
Short: "Find and display information of user",
Expand All @@ -341,9 +341,10 @@ var (
os.Exit(err)
}
}
ShowUser("", FlagAccountName)
},
}
findQosCmd = &cobra.Command{
showQosCmd = &cobra.Command{
Use: "qos [flags] name",
Short: "Find and display information of a specific QoS",
Long: "",
Expand All @@ -360,6 +361,15 @@ var (
}
},
}
showEventCmd = &cobra.Command{
Use: "event",
Short: "Display event table",
Long: "",
Run: func(cmd *cobra.Command, args []string) {
ShowEvents()
},
}

/* --------------------------------------------------- block ---------------------------------------------------- */
blockCmd = &cobra.Command{
Use: "block",
Expand Down Expand Up @@ -568,14 +578,15 @@ func init() {
}
}

/* ---------------------------------------------------- find ---------------------------------------------------- */
RootCmd.AddCommand(findCmd)
/* ---------------------------------------------------- show/find ---------------------------------------------------- */
RootCmd.AddCommand(showCmd)
{
findCmd.AddCommand(findAccountCmd)
findCmd.AddCommand(findQosCmd)
findCmd.AddCommand(findUserCmd)
showCmd.AddCommand(showAccountCmd)
showCmd.AddCommand(showQosCmd)
showCmd.AddCommand(showEventCmd)
showCmd.AddCommand(showUserCmd)
{
findUserCmd.Flags().StringVarP(&FlagAccountName, "account", "A", "", "Display the user under the specified account")
showUserCmd.Flags().StringVarP(&FlagAccountName, "account", "A", "", "Display the user under the specified account")
}
}

Expand Down
52 changes: 52 additions & 0 deletions internal/cacctmgr/cacctmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"strconv"
"strings"

"time"

"github.com/olekukonko/tablewriter"
log "github.com/sirupsen/logrus"
"github.com/xlab/treeprint"
Expand Down Expand Up @@ -292,6 +294,39 @@ func PraseAccountTree(parentTreeRoot treeprint.Tree, account string, accountMap
}
}

func PrintAllEvents(eventList []*protos.EventInfo) {
sort.Slice(eventList, func(i, j int) bool {
return eventList[i].StartTime.AsTime().After(eventList[j].StartTime.AsTime())
})
if len(eventList) > 100 {
eventList = eventList[:100]
}

table := tablewriter.NewWriter(os.Stdout)
util.SetBorderTable(table)
header := []string{"Node", "StartTime", "EndTime", "State", "Reason", "Uid"}
tableData := make([][]string, 0, len(eventList))
for _, eventInfo := range eventList {
var endTime string
if eventInfo.EndTime.AsTime().Year() == 1970 {
endTime = "Unknown"
} else {
endTime = eventInfo.EndTime.AsTime().In(time.Local).Format("2006-01-02 15:04:05")
}
tableData = append(tableData, []string{
eventInfo.NodeName,
eventInfo.StartTime.AsTime().In(time.Local).Format("2006-01-02 15:04:05"),
endTime,
eventInfo.State.String(),
eventInfo.Reason,
strconv.FormatUint(uint64(eventInfo.Uid), 10),
})
}
table.SetHeader(header)
table.AppendBulk(tableData)
table.Render()
}

func AddAccount(account *protos.AccountInfo) util.CraneCmdError {
// FIXME: Move name validation to the backend?
// FIXME: Seperate this to Args of cobra package?
Expand Down Expand Up @@ -571,6 +606,23 @@ func ShowAccounts() util.CraneCmdError {
}
}

func ShowEvents() util.CraneCmdError {
req := &protos.QueryEntityInfoRequest{Uid: userUid, EntityType: protos.EntityType_Event}
reply, err := stub.QueryEntityInfo(context.Background(), req)
if err != nil {
util.GrpcErrorPrintf(err, "Fail to show events")
return util.ErrorNetwork
}

if reply.GetOk() {
PrintAllEvents(reply.EventList)
return util.ErrorSuccess
} else {
fmt.Println(reply.Reason)
return util.ErrorBackend
}
}

func ShowUser(name string, account string) util.CraneCmdError {
req := protos.QueryEntityInfoRequest{Uid: userUid, EntityType: protos.EntityType_User, Name: name, Account: account}
reply, err := stub.QueryEntityInfo(context.Background(), &req)
Expand Down
5 changes: 4 additions & 1 deletion internal/ccontrol/ccontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ func ChangeTaskPriority(taskId uint32, priority float64) util.CraneCmdError {
}

func ChangeNodeState(nodeName string, state string, reason string) util.CraneCmdError {
var req = &protos.ModifyCranedStateRequest{}
req := &protos.ModifyCranedStateRequest{
Uid: uint32(os.Getuid()),
}

if nodeName == "" {
log.Errorln("No valid node name in update node command. Specify node names by -n or --name.")
return util.ErrorCmdArg
Expand Down
10 changes: 8 additions & 2 deletions internal/cinfo/cinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,23 @@ func cinfoFunc() util.CraneCmdError {
table := tablewriter.NewWriter(os.Stdout)
util.SetBorderlessTable(table)
var tableData [][]string
table.SetHeader([]string{"PARTITION", "AVAIL", "TIMELIMIT", "NODES", "STATE", "NODELIST"})
table.SetHeader([]string{"PARTITION", "AVAIL", "TIMELIMIT", "NODES", "STATE", "NODELIST(REASON)"})
for _, partitionCraned := range reply.Partitions {
for _, commonCranedStateList := range partitionCraned.CranedLists {
nodeListReason := ""
if commonCranedStateList.Reason != "" {
nodeListReason = fmt.Sprintf("%s(%s)", commonCranedStateList.CranedListRegex, commonCranedStateList.Reason)
} else {
nodeListReason = commonCranedStateList.CranedListRegex
}
if commonCranedStateList.Count > 0 {
tableData = append(tableData, []string{
partitionCraned.Name,
strings.ToLower(partitionCraned.State.String()[10:]),
"infinite",
strconv.FormatUint(uint64(commonCranedStateList.Count), 10),
strings.ToLower(commonCranedStateList.State.String()[6:]),
commonCranedStateList.CranedListRegex,
nodeListReason,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions protos/Crane.proto
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ message ModifyCranedStateRequest{
string craned_id = 1;
CranedState new_state = 2;
string reason = 3;
uint32 uid = 4;
}

message ModifyCranedStateReply{
Expand Down Expand Up @@ -370,6 +371,7 @@ message QueryEntityInfoReply {
repeated UserInfo user_list = 3;
repeated AccountInfo account_list = 4;
repeated QosInfo qos_list = 5;
repeated EventInfo event_list = 6;
}

message BlockAccountOrUserRequest {
Expand Down
12 changes: 12 additions & 0 deletions protos/PublicDefs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ message TrimmedPartitionInfo {
CranedState state = 1;
uint32 count = 2;
string craned_list_regex = 3;
string reason = 4;
}

string name = 1;
Expand All @@ -252,6 +253,7 @@ enum EntityType {
Account = 0;
User = 1;
Qos = 2;
Event = 3;
}

message AccountInfo {
Expand Down Expand Up @@ -307,6 +309,16 @@ message QosInfo {
uint64 max_time_limit_per_task = 6;
}

message EventInfo {
google.protobuf.Timestamp start_time = 1;
google.protobuf.Timestamp end_time = 2;
string node_name = 3;
string cluster_name =4;
string reason = 5;
CranedState state = 6;
uint32 uid = 7;
}

message TimeInterval {
google.protobuf.Timestamp lower_bound = 1;
google.protobuf.Timestamp upper_bound = 2;
Expand Down