@@ -65,7 +65,7 @@ type DeploymentPlugin[Config, DeployTargetConfig any] interface {
65
65
// DetermineStrategy determines the strategy to deploy the resources.
66
66
DetermineStrategy (context.Context , * Config , * Client , TODO ) (TODO , error )
67
67
// BuildQuickSyncStages builds the stages that will be executed during the quick sync process.
68
- BuildQuickSyncStages (context.Context , * Config , * Client , TODO ) (TODO , error )
68
+ BuildQuickSyncStages (context.Context , * Config , * BuildQuickSyncStagesInput ) (* BuildQuickSyncStagesResponse , error )
69
69
}
70
70
71
71
// StagePlugin is the interface implemented by a plugin that focuses on executing generic stages.
@@ -168,8 +168,23 @@ func (s *DeploymentPluginServiceServer[Config, DeployTargetConfig]) BuildPipelin
168
168
}
169
169
return buildPipelineSyncStages (ctx , s .base , & s .config , client , request , s .logger )
170
170
}
171
- func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) BuildQuickSyncStages (context.Context , * deployment.BuildQuickSyncStagesRequest ) (* deployment.BuildQuickSyncStagesResponse , error ) {
172
- return nil , status .Errorf (codes .Unimplemented , "method BuildQuickSyncStages not implemented" )
171
+ func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) BuildQuickSyncStages (ctx context.Context , request * deployment.BuildQuickSyncStagesRequest ) (* deployment.BuildQuickSyncStagesResponse , error ) {
172
+ input := & BuildQuickSyncStagesInput {
173
+ Request : BuildQuickSyncStagesRequest {
174
+ Rollback : request .GetRollback (),
175
+ },
176
+ Client : & Client {
177
+ base : s .client ,
178
+ pluginName : s .Name (),
179
+ },
180
+ Logger : s .logger ,
181
+ }
182
+
183
+ response , err := s .base .BuildQuickSyncStages (ctx , & s .config , input )
184
+ if err != nil {
185
+ return nil , status .Errorf (codes .Internal , "failed to build quick sync stages: %v" , err )
186
+ }
187
+ return newQuickSyncStagesResponse (s .base , time .Now (), response ), nil
173
188
}
174
189
func (s * DeploymentPluginServiceServer [Config , DeployTargetConfig ]) ExecuteStage (ctx context.Context , request * deployment.ExecuteStageRequest ) (response * deployment.ExecuteStageResponse , _ error ) {
175
190
lp := s .logPersister .StageLogPersister (request .GetInput ().GetDeployment ().GetId (), request .GetInput ().GetStage ().GetId ())
@@ -377,25 +392,26 @@ func newPipelineSyncStagesResponse(plugin Plugin, now time.Time, request *deploy
377
392
if id == "" {
378
393
id = fmt .Sprintf ("%s-stage-%d" , plugin .Name (), s .Index )
379
394
}
380
- stages = append (stages , & model.PipelineStage {
381
- Id : id ,
382
- Name : s .Name ,
383
- Desc : requestStage .GetDesc (),
384
- Index : int32 (s .Index ),
385
- Status : model .StageStatus_STAGE_NOT_STARTED_YET ,
386
- StatusReason : "" , // TODO: set the reason
387
- Metadata : s .Metadata ,
388
- Rollback : s .Rollback ,
389
- CreatedAt : now .Unix (),
390
- UpdatedAt : now .Unix (),
391
- AvailableOperation : s .AvailableOperation .toModelEnum (),
392
- })
395
+
396
+ stages = append (stages , s .toModel (id , requestStage .GetDesc (), now ))
393
397
}
394
398
return & deployment.BuildPipelineSyncStagesResponse {
395
399
Stages : stages ,
396
400
}, nil
397
401
}
398
402
403
+ // newQuickSyncStagesResponse converts the response to the external representation.
404
+ func newQuickSyncStagesResponse (plugin Plugin , now time.Time , response * BuildQuickSyncStagesResponse ) * deployment.BuildQuickSyncStagesResponse {
405
+ stages := make ([]* model.PipelineStage , 0 , len (response .Stages ))
406
+ for i , s := range response .Stages {
407
+ id := fmt .Sprintf ("%s-stage-%d" , plugin .Name (), i )
408
+ stages = append (stages , s .toModel (id , now ))
409
+ }
410
+ return & deployment.BuildQuickSyncStagesResponse {
411
+ Stages : stages ,
412
+ }
413
+ }
414
+
399
415
// BuildPipelineSyncStagesInput is the input for the BuildPipelineSyncStages method.
400
416
type BuildPipelineSyncStagesInput struct {
401
417
// Request is the request to build pipeline sync stages.
@@ -415,6 +431,23 @@ type BuildPipelineSyncStagesRequest struct {
415
431
Stages []StageConfig
416
432
}
417
433
434
+ // BuildQuickSyncStagesInput is the input for the BuildQuickSyncStages method.
435
+ type BuildQuickSyncStagesInput struct {
436
+ // Request is the request to build pipeline sync stages.
437
+ Request BuildQuickSyncStagesRequest
438
+ // Client is the client to interact with the piped.
439
+ Client * Client
440
+ // Logger is the logger to log the events.
441
+ Logger * zap.Logger
442
+ }
443
+
444
+ // BuildQuickSyncStagesRequest is the request to build quick sync stages.
445
+ // Rollback indicates whether the stages for rollback are requested.
446
+ type BuildQuickSyncStagesRequest struct {
447
+ // Rollback indicates whether the stages for rollback are requested.
448
+ Rollback bool
449
+ }
450
+
418
451
// StageConfig represents the configuration of a stage.
419
452
type StageConfig struct {
420
453
// Index is the order of the stage in the pipeline.
@@ -433,6 +466,11 @@ type BuildPipelineSyncStagesResponse struct {
433
466
Stages []PipelineStage
434
467
}
435
468
469
+ // BuildQuickSyncStagesResponse is the response of the request to build quick sync stages.
470
+ type BuildQuickSyncStagesResponse struct {
471
+ Stages []QuickSyncStage
472
+ }
473
+
436
474
// PipelineStage represents a stage in the pipeline.
437
475
type PipelineStage struct {
438
476
// Index is the order of the stage in the pipeline.
@@ -450,6 +488,53 @@ type PipelineStage struct {
450
488
AvailableOperation ManualOperation
451
489
}
452
490
491
+ func (p * PipelineStage ) toModel (id , description string , now time.Time ) * model.PipelineStage {
492
+ return & model.PipelineStage {
493
+ Id : id ,
494
+ Name : p .Name ,
495
+ Desc : description ,
496
+ Index : int32 (p .Index ),
497
+ Status : model .StageStatus_STAGE_NOT_STARTED_YET ,
498
+ StatusReason : "" , // TODO: set the reason
499
+ Metadata : p .Metadata ,
500
+ Rollback : p .Rollback ,
501
+ CreatedAt : now .Unix (),
502
+ UpdatedAt : now .Unix (),
503
+ AvailableOperation : p .AvailableOperation .toModelEnum (),
504
+ }
505
+ }
506
+
507
+ // QuickSyncStage represents a stage in the pipeline.
508
+ type QuickSyncStage struct {
509
+ // Name is the name of the stage.
510
+ // It must be one of the stages returned by FetchDefinedStages.
511
+ Name string
512
+ // Description is the description of the stage.
513
+ Description string
514
+ // Rollback indicates whether the stage is for rollback.
515
+ Rollback bool
516
+ // Metadata contains the metadata of the stage.
517
+ Metadata map [string ]string
518
+ // AvailableOperation indicates the manual operation that the user can perform.
519
+ AvailableOperation ManualOperation
520
+ }
521
+
522
+ func (p * QuickSyncStage ) toModel (id string , now time.Time ) * model.PipelineStage {
523
+ return & model.PipelineStage {
524
+ Id : id ,
525
+ Name : p .Name ,
526
+ Desc : p .Description ,
527
+ Index : 0 ,
528
+ Status : model .StageStatus_STAGE_NOT_STARTED_YET ,
529
+ StatusReason : "" , // TODO: set the reason
530
+ Metadata : p .Metadata ,
531
+ Rollback : p .Rollback ,
532
+ CreatedAt : now .Unix (),
533
+ UpdatedAt : now .Unix (),
534
+ AvailableOperation : p .AvailableOperation .toModelEnum (),
535
+ }
536
+ }
537
+
453
538
// ExecuteStageInput is the input for the ExecuteStage method.
454
539
type ExecuteStageInput struct {
455
540
// Request is the request to execute a stage.
0 commit comments