Skip to content

Commit 4ba809e

Browse files
committed
Add ccontrol create reservation
1 parent 58205a3 commit 4ba809e

File tree

4 files changed

+133
-12
lines changed

4 files changed

+133
-12
lines changed

internal/ccontrol/CmdArgParser.go

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,22 @@ import (
2828
)
2929

3030
var (
31-
FlagNodeName string
32-
FlagState string
33-
FlagReason string
34-
FlagPartitionName string
35-
FlagTaskId uint32
36-
FlagTaskIds string
37-
FlagQueryAll bool
38-
FlagTimeLimit string
39-
FlagPriority float64
40-
FlagHoldTime string
41-
FlagConfigFilePath string
42-
FlagJson bool
31+
FlagNodeName string
32+
FlagState string
33+
FlagReason string
34+
FlagPartitionName string
35+
FlagTaskId uint32
36+
FlagTaskIds string
37+
FlagQueryAll bool
38+
FlagTimeLimit string
39+
FlagPriority float64
40+
FlagHoldTime string
41+
FlagConfigFilePath string
42+
FlagJson bool
43+
FlagReservationName string
44+
FlagStartTime string
45+
FlagDuration string
46+
FlagNodes string
4347

4448
RootCmd = &cobra.Command{
4549
Use: "ccontrol",
@@ -112,6 +116,17 @@ var (
112116
}
113117
},
114118
}
119+
// showReservationsCmd = &cobra.Command{
120+
// Use: "reservation",
121+
// Short: "Display details of the reservations",
122+
// Long: "",
123+
// Args: cobra.ExactArgs(0),
124+
// Run: func(cmd *cobra.Command, args []string) {
125+
// if err := ShowReservations(); err != util.ErrorSuccess {
126+
// os.Exit(err)
127+
// }
128+
// },
129+
// }
115130
showConfigCmd = &cobra.Command{
116131
Use: "config",
117132
Short: "Display the configuration file in key-value format",
@@ -207,6 +222,22 @@ var (
207222
}
208223
},
209224
}
225+
createCmd = &cobra.Command{
226+
Use: "create",
227+
Short: "Create a new entity",
228+
Long: "",
229+
}
230+
createReservationCmd = &cobra.Command{
231+
Use: "reservation [flags]",
232+
Short: "Create a new reservation",
233+
Long: "",
234+
Args: cobra.ExactArgs(0),
235+
Run: func(cmd *cobra.Command, args []string) {
236+
if err := CreateReservation(); err != util.ErrorSuccess {
237+
os.Exit(err)
238+
}
239+
},
240+
}
210241
)
211242

212243
// ParseCmdArgs executes the root command.
@@ -228,6 +259,7 @@ func init() {
228259
showCmd.AddCommand(showPartitionCmd)
229260
showCmd.AddCommand(showJobCmd)
230261
showCmd.AddCommand(showConfigCmd)
262+
// showCmd.AddCommand(showReservationsCmd)
231263
}
232264

233265
RootCmd.AddCommand(updateCmd)
@@ -251,9 +283,22 @@ func init() {
251283
}
252284
}
253285
}
286+
254287
RootCmd.AddCommand(holdCmd)
255288
{
256289
holdCmd.Flags().StringVarP(&FlagHoldTime, "time", "t", "", "Specify the duration the job will be prevented from starting")
257290
}
291+
258292
RootCmd.AddCommand(releaseCmd)
293+
294+
RootCmd.AddCommand(createCmd)
295+
{
296+
createCmd.AddCommand(createReservationCmd)
297+
{
298+
createReservationCmd.Flags().StringVarP(&FlagReservationName, "name", "n", "", "Specify the name of the reservation")
299+
createReservationCmd.Flags().StringVarP(&FlagStartTime, "start-time", "s", "", "Specify the start time of the reservation")
300+
createReservationCmd.Flags().StringVarP(&FlagDuration, "duration", "d", "", "Specify the duration of the reservation")
301+
createReservationCmd.Flags().StringVarP(&FlagNodes, "nodes", "N", "", "Specify the nodes of the reservation")
302+
}
303+
}
259304
}

internal/ccontrol/ccontrol.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"strings"
3333
"time"
3434

35+
"google.golang.org/protobuf/types/known/timestamppb"
3536
"gopkg.in/yaml.v3"
3637

3738
log "github.com/sirupsen/logrus"
@@ -656,3 +657,39 @@ func ChangeNodeState(nodeRegex string, state string, reason string) util.CraneCm
656657

657658
return SummarizeReply(reply)
658659
}
660+
661+
func CreateReservation() util.CraneCmdError {
662+
start_time, err := util.ParseTime(FlagStartTime)
663+
if err != nil {
664+
log.Errorln(err)
665+
return util.ErrorCmdArg
666+
}
667+
668+
reservation_info := &protos.ReservationInfo{}
669+
reservation_info.ReservationName = FlagReservationName
670+
reservation_info.StartTime = timestamppb.New(start_time)
671+
ok := util.ParseDuration(FlagDuration, reservation_info.Duration)
672+
if !ok {
673+
log.Errorln("Invalid duration specified.")
674+
return util.ErrorCmdArg
675+
}
676+
reservation_info.CranedRegex = FlagNodes
677+
678+
req := &protos.CreateReservationRequest{
679+
ReservationInfo: reservation_info,
680+
}
681+
682+
reply, err := stub.CreateReservation(context.Background(), req)
683+
if err != nil {
684+
util.GrpcErrorPrintf(err, "Failed to create reservation")
685+
return util.ErrorNetwork
686+
}
687+
688+
if reply.GetOk() {
689+
fmt.Printf("Reservation %s created successfully.\n", FlagReservationName)
690+
} else {
691+
log.Errorf("Failed to create reservation: %s.\n", reply.GetReason())
692+
return util.ErrorBackend
693+
}
694+
return util.ErrorSuccess
695+
}

protos/Crane.proto

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,35 @@ message QueryTasksInfoReply{
449449
repeated TaskInfo task_info_list = 2;
450450
}
451451

452+
message CreateReservationRequest {
453+
ReservationInfo reservation_info = 1;
454+
}
455+
456+
message CreateReservationReply {
457+
bool ok = 1;
458+
string reason = 2;
459+
}
460+
461+
// message DeleteReservationRequest {
462+
// string reservation_name = 1;
463+
// }
464+
465+
// message DeleteReservationReply {
466+
// bool ok = 1;
467+
// string reason = 2;
468+
// }
469+
470+
// message QueryReservationRequest {
471+
// repeated string filter_reservation_name = 1;
472+
// uint32 num_limit = 3;
473+
// }
474+
475+
// message QueryReservationReply {
476+
// bool ok = 1;
477+
// string reason = 2;
478+
// repeated ReservationInfo reservation_info_list = 3;
479+
// }
480+
452481
message StreamCallocRequest {
453482
enum CallocRequestType {
454483
TASK_REQUEST = 0;
@@ -794,6 +823,9 @@ service CraneCtld {
794823

795824
/* common RPCs */
796825
rpc QueryTasksInfo(QueryTasksInfoRequest) returns (QueryTasksInfoReply);
826+
rpc CreateReservation(CreateReservationRequest) returns (CreateReservationReply);
827+
// rpc DeleteReservation(DeleteReservationRequest) returns (DeleteReservationReply);
828+
// rpc QueryReservation(QueryReservationRequest) returns (QueryReservationReply);
797829
}
798830

799831
service Craned {

protos/PublicDefs.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,11 @@ message CranedRemoteMeta {
478478
string craned_version = 3;
479479
google.protobuf.Timestamp craned_start_time = 4;
480480
google.protobuf.Timestamp system_boot_time = 5;
481+
}
482+
483+
message ReservationInfo {
484+
string reservation_name = 1;
485+
google.protobuf.Timestamp start_time = 2;
486+
google.protobuf.Duration duration = 3;
487+
string craned_regex = 4;
481488
}

0 commit comments

Comments
 (0)