Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
MCKZX-llx committed Jun 24, 2024
1 parent 7d1dea3 commit 78740d7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
45 changes: 31 additions & 14 deletions internal/ccontrol/CmdArgParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
FlagPartitions []string
FlagNodeStr string
FlagJobPriority float64
FlagPartitionPriority uint32
FlagPartitionPriority int64
FlagAllowAccounts []string
FlagDenyAccounts []string
FlagState string
Expand Down Expand Up @@ -139,6 +139,12 @@ var (
Long: "",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("priority") && FlagPartitionPriority < 0 {
return &util.CraneError{
Code: util.ErrorCmdArg,
Message: "--priority must be greater than or equal to 0",
}
}
return AddPartition(FlagName, FlagNodeStr, FlagPartitionPriority, FlagAllowAccounts, FlagDenyAccounts)
},
}
Expand Down Expand Up @@ -214,12 +220,12 @@ var (

if flagStateSet && flagReasonSet && !flagMemorySet && !flagCpuSet {
return ChangeNodeState(FlagName, FlagState, FlagReason)
} else if !flagStateSet && !flagReasonSet && flagMemorySet && flagCpuSet {
} else if !flagStateSet && !flagReasonSet && (flagMemorySet || flagCpuSet) {
return UpdateNode(FlagName, FlagCpus, FlagMem)
} else {
return &util.CraneError{
Code: util.ErrorCmdArg,
Message: "Either --state&&--reason or --cpu&&--mem should be set",
Message: "Either --state&&--reason or --cpu or --mem should be set",
}
}
},
Expand All @@ -230,6 +236,12 @@ var (
Long: "",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("priority") && FlagPartitionPriority < 0 {
return &util.CraneError{
Code: util.ErrorCmdArg,
Message: "--priority must be greater than or equal to 0",
}
}
return UpdatePartition(FlagName, FlagNodeStr, FlagPartitionPriority, FlagAllowAccounts, FlagDenyAccounts)
},
}
Expand Down Expand Up @@ -268,8 +280,8 @@ func init() {
addCmd.AddCommand(addNodeCmd)
{
addNodeCmd.Flags().StringVarP(&FlagName, "name", "N", "", "Host name")
addNodeCmd.Flags().Float64Var(&FlagCpus, "cpu", 0.0, "Number of CPU cores")
addNodeCmd.Flags().StringVarP(&FlagMem, "memory", "M", "", "Memory size, in units of G/M/K/B")
addNodeCmd.Flags().Float64VarP(&FlagCpus, "cpu", "c", 0.0, "Number of CPU cores")
addNodeCmd.Flags().StringVarP(&FlagMem, "memory", "M", "", "Memory size, in units of G/M/K/B, default MB")
addNodeCmd.Flags().StringSliceVarP(&FlagPartitions, "partition", "P", nil, "The partition name to which the node belongs")
err := addNodeCmd.MarkFlagRequired("name")
if err != nil {
Expand All @@ -289,20 +301,25 @@ func init() {
{
addPartitionCmd.Flags().StringVarP(&FlagName, "name", "N", "", "Partition name")
addPartitionCmd.Flags().StringVar(&FlagNodeStr, "nodes", "", "The included nodes can be written individually, abbreviated or mixed, please write them in a string")
addPartitionCmd.Flags().Float64Var(&FlagJobPriority, "priority", 0.0, "Partition priority")
addPartitionCmd.Flags().StringSliceVar(&FlagAllowAccounts, "allowlist", nil, "List of accounts allowed to use this partition")
addPartitionCmd.Flags().StringSliceVar(&FlagDenyAccounts, "denylist", nil, "Prohibit the use of the account list in this partition. The --denylist and the --allowlist parameter can only be selected as either")
addPartitionCmd.Flags().Int64VarP(&FlagPartitionPriority, "priority", "P", -1, "Partition priority")
addPartitionCmd.Flags().StringSliceVarP(&FlagAllowAccounts, "allowlist", "A", nil, "List of accounts allowed to use this partition")
addPartitionCmd.Flags().StringSliceVarP(&FlagDenyAccounts, "denylist", "D", nil, "Prohibit the use of the account list in this partition. The --denylist and the --allowlist parameter can only be selected as either")
addPartitionCmd.MarkFlagsMutuallyExclusive("allowlist", "denylist")
err := addPartitionCmd.MarkFlagRequired("name")
if err != nil {
return
}
err = addPartitionCmd.MarkFlagRequired("nodes")
if err != nil {
return
}
}
}

RootCmd.AddCommand(deleteCmd)
{
deleteCmd.AddCommand(deleteNodeCmd)
deleteNodeCmd.Flags().StringVarP(&FlagName, "name", "N", "", "Host name")

deleteCmd.AddCommand(deletePartitionCmd)
deletePartitionCmd.Flags().StringVarP(&FlagName, "name", "N", "", "Partition name")
}

RootCmd.AddCommand(updateCmd)
Expand Down Expand Up @@ -338,9 +355,9 @@ func init() {
{
updatePartitionCmd.Flags().StringVarP(&FlagName, "name", "N", "", "Partition name")
updatePartitionCmd.Flags().StringVar(&FlagNodeStr, "nodes", "", "The included nodes can be written individually, abbreviated or mixed, please write them in a string")
updatePartitionCmd.Flags().Float64Var(&FlagJobPriority, "priority", -1, "Partition priority")
updatePartitionCmd.Flags().StringSliceVar(&FlagAllowAccounts, "allowlist", nil, "List of accounts allowed to use this partition")
updatePartitionCmd.Flags().StringSliceVar(&FlagDenyAccounts, "denylist", nil, "Prohibit the use of the account list in this partition. The --denylist and the --allowlist parameter can only be selected as either")
updatePartitionCmd.Flags().Int64VarP(&FlagPartitionPriority, "priority", "P", -1, "Partition priority")
updatePartitionCmd.Flags().StringSliceVarP(&FlagAllowAccounts, "allowlist", "A", nil, "List of accounts allowed to use this partition")
updatePartitionCmd.Flags().StringSliceVarP(&FlagDenyAccounts, "denylist", "D", nil, "Prohibit the use of the account list in this partition. The --denylist and the --allowlist parameter can only be selected as either")
updatePartitionCmd.MarkFlagsMutuallyExclusive("allowlist", "denylist")
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/ccontrol/ccontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func ChangeNodeState(nodeName string, state string, reason string) error {
}
}

reply, err := stub.ModifyNode(context.Background(), req)
reply, err := stub.ModifyNodeState(context.Background(), req)
if err != nil {
return &util.CraneError{
Code: util.ErrorNetwork,
Expand Down Expand Up @@ -443,7 +443,7 @@ func AddNode(name string, cpu float64, mem string, partition []string) error {
}
}

func AddPartition(name string, nodes string, priority uint32, allowlist []string, denylist []string) error {
func AddPartition(name string, nodes string, priority int64, allowlist []string, denylist []string) error {
var req *protos.AddPartitionRequest
req = &protos.AddPartitionRequest{
Uid: uint32(os.Getuid()),
Expand Down Expand Up @@ -597,7 +597,7 @@ func UpdateNode(name string, cpu float64, mem string) error {
}
}

func UpdatePartition(name string, nodes string, priority uint32, allowlist []string, denylist []string) error {
func UpdatePartition(name string, nodes string, priority int64, allowlist []string, denylist []string) error {
var req *protos.UpdatePartitionRequest
req = &protos.UpdatePartitionRequest{
Uid: uint32(os.Getuid()),
Expand Down
1 change: 0 additions & 1 deletion internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package util
import (
"errors"
"github.com/spf13/cobra"
"strings"

nested "github.com/antonfisher/nested-logrus-formatter"
log "github.com/sirupsen/logrus"
Expand Down
2 changes: 1 addition & 1 deletion protos/Crane.proto
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ service CraneCtld {
rpc QueryCranedInfo(QueryCranedInfoRequest) returns (QueryCranedInfoReply);
rpc QueryPartitionInfo(QueryPartitionInfoRequest) returns (QueryPartitionInfoReply);
rpc ModifyTask(ModifyTaskRequest) returns (ModifyTaskReply);
rpc ModifyNode(ModifyCranedStateRequest) returns (ModifyCranedStateReply);
rpc ModifyNodeState(ModifyCranedStateRequest) returns (ModifyCranedStateReply);

rpc AddPartition(AddPartitionRequest) returns (AddPartitionReply);
rpc AddNode(AddNodeRequest) returns (AddNodeReply);
Expand Down
2 changes: 1 addition & 1 deletion protos/PublicDefs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ message PartitionInfo {
uint64 avail_mem = 10;
uint64 alloc_mem = 11;

uint32 priority = 12;
int64 priority = 12;
repeated string allow_list = 13;
repeated string deny_list = 14;
}
Expand Down

0 comments on commit 78740d7

Please sign in to comment.