65 lines
2.0 KiB
Go
65 lines
2.0 KiB
Go
package managed_job
|
|
|
|
import (
|
|
"flink-kube-operator/internal/crd/v1alpha1"
|
|
"strings"
|
|
"time"
|
|
|
|
"gitea.com/logicamp/lc"
|
|
api "github.com/logi-camp/go-flink-client"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func (job ManagedJob) createSavepoint() error {
|
|
if job.def.Status.JobId == nil {
|
|
lc.Logger.Debug("[managed-job] [savepoint] no job id")
|
|
return v1alpha1.ErrNoJobId
|
|
}
|
|
lc.Logger.Info("[managed-job] [savepoint] creating savepoint", zap.String("interval", job.def.Spec.SavepointInterval.String()))
|
|
resp, err := job.client.SavePoints(*job.def.Status.JobId, "/flink-data/savepoints-2/", false)
|
|
if err != nil {
|
|
lc.Logger.Error("[managed-job] [savepoint] error in creating savepoint", zap.Error(err))
|
|
return err
|
|
}
|
|
lc.Logger.Debug("[managed-job] [savepoint]", zap.Any("savepoint-resp", resp))
|
|
|
|
job.crd.Patch(job.def.UID, map[string]interface{}{
|
|
"status": map[string]interface{}{
|
|
"savepointTriggerId": resp.RequestID,
|
|
},
|
|
})
|
|
return nil
|
|
}
|
|
|
|
func (job ManagedJob) trackSavepoint() error {
|
|
if job.def.Status.JobId == nil {
|
|
lc.Logger.Debug("[managed-job] [savepoint] no job id")
|
|
return v1alpha1.ErrNoJobId
|
|
}
|
|
if job.def.Status.SavepointTriggerId == nil {
|
|
lc.Logger.Debug("[managed-job] [savepoint] no job id")
|
|
return v1alpha1.ErrNoSavepointTriggerId
|
|
}
|
|
resp, err := job.client.TrackSavepoint(*job.def.Status.JobId, *job.def.Status.SavepointTriggerId)
|
|
lc.Logger.Debug("[managed-job] [savepoint] track savepoint", zap.Any("status.Id", resp.Status.Id), zap.Any("failureCause.stacktrace", resp.Operation.FailureCause.StackTrace), zap.Error(err))
|
|
if err != nil {
|
|
if strings.IndexAny(err.Error(), "http status not 2xx: 404") == 0 {
|
|
job.crd.Patch(job.def.UID, map[string]interface{}{
|
|
"status": map[string]interface{}{
|
|
"savepointTriggerId": nil,
|
|
},
|
|
})
|
|
}
|
|
}
|
|
if resp.Status.Id == api.SavepointStatusInCompleted {
|
|
job.crd.Patch(job.def.UID, map[string]interface{}{
|
|
"status": map[string]interface{}{
|
|
"lastSavepointPath": resp.Operation.Location,
|
|
"lastSavepointDate": time.Now().Format(time.RFC3339),
|
|
},
|
|
})
|
|
}
|
|
|
|
return nil
|
|
}
|