@@ -19,6 +19,7 @@ import (
19
19
"fmt"
20
20
21
21
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/cmd/piped/service"
22
+ "github.com/pipe-cd/pipecd/pkg/app/server/service/pipedservice"
22
23
"github.com/pipe-cd/pipecd/pkg/config"
23
24
"github.com/pipe-cd/pipecd/pkg/crypto"
24
25
"github.com/pipe-cd/pipecd/pkg/model"
@@ -30,19 +31,27 @@ import (
30
31
type PluginAPI struct {
31
32
service.PluginServiceServer
32
33
33
- cfg * config.PipedSpec
34
+ cfg * config.PipedSpec
35
+ apiClient apiClient
36
+
34
37
Logger * zap.Logger
35
38
}
36
39
40
+ type apiClient interface {
41
+ ReportStageLogs (ctx context.Context , req * pipedservice.ReportStageLogsRequest , opts ... grpc.CallOption ) (* pipedservice.ReportStageLogsResponse , error )
42
+ ReportStageLogsFromLastCheckpoint (ctx context.Context , in * pipedservice.ReportStageLogsFromLastCheckpointRequest , opts ... grpc.CallOption ) (* pipedservice.ReportStageLogsFromLastCheckpointResponse , error )
43
+ }
44
+
37
45
// Register registers all handling of this service into the specified gRPC server.
38
46
func (a * PluginAPI ) Register (server * grpc.Server ) {
39
47
service .RegisterPluginServiceServer (server , a )
40
48
}
41
49
42
- func NewPluginAPI (cfg * config.PipedSpec , logger * zap.Logger ) * PluginAPI {
50
+ func NewPluginAPI (cfg * config.PipedSpec , apiClient apiClient , logger * zap.Logger ) * PluginAPI {
43
51
return & PluginAPI {
44
- cfg : cfg ,
45
- Logger : logger .Named ("plugin-api" ),
52
+ cfg : cfg ,
53
+ apiClient : apiClient ,
54
+ Logger : logger .Named ("plugin-api" ),
46
55
}
47
56
}
48
57
@@ -71,6 +80,43 @@ func (a *PluginAPI) DecryptSecret(ctx context.Context, req *service.DecryptSecre
71
80
}, nil
72
81
}
73
82
83
+ func (a * PluginAPI ) ReportStageLogs (ctx context.Context , req * service.ReportStageLogsRequest ) (* service.ReportStageLogsResponse , error ) {
84
+ _ , err := a .apiClient .ReportStageLogs (ctx , & pipedservice.ReportStageLogsRequest {
85
+ DeploymentId : req .DeploymentId ,
86
+ StageId : req .StageId ,
87
+ RetriedCount : req .RetriedCount ,
88
+ Blocks : req .Blocks ,
89
+ })
90
+ if err != nil {
91
+ a .Logger .Error ("failed to report stage logs" ,
92
+ zap .String ("deploymentID" , req .DeploymentId ),
93
+ zap .String ("stageID" , req .StageId ),
94
+ zap .Error (err ))
95
+ return nil , err
96
+ }
97
+
98
+ return & service.ReportStageLogsResponse {}, nil
99
+ }
100
+
101
+ func (a * PluginAPI ) ReportStageLogsFromLastCheckpoint (ctx context.Context , req * service.ReportStageLogsFromLastCheckpointRequest ) (* service.ReportStageLogsFromLastCheckpointResponse , error ) {
102
+ _ , err := a .apiClient .ReportStageLogsFromLastCheckpoint (ctx , & pipedservice.ReportStageLogsFromLastCheckpointRequest {
103
+ DeploymentId : req .DeploymentId ,
104
+ StageId : req .StageId ,
105
+ RetriedCount : req .RetriedCount ,
106
+ Blocks : req .Blocks ,
107
+ Completed : req .Completed ,
108
+ })
109
+ if err != nil {
110
+ a .Logger .Error ("failed to report stage logs from last checkpoint" ,
111
+ zap .String ("deploymentID" , req .DeploymentId ),
112
+ zap .String ("stageID" , req .StageId ),
113
+ zap .Error (err ))
114
+ return nil , err
115
+ }
116
+
117
+ return & service.ReportStageLogsFromLastCheckpointResponse {}, nil
118
+ }
119
+
74
120
func initializeSecretDecrypter (sm * config.SecretManagement ) (crypto.Decrypter , error ) {
75
121
if sm == nil {
76
122
return nil , nil
0 commit comments