feat: add rest routes to take the control of flink jobs
This commit is contained in:
81
internal/rest/controller/crd.go
Normal file
81
internal/rest/controller/crd.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flink-kube-operator/internal/crd"
|
||||
"flink-kube-operator/internal/crd/v1alpha1"
|
||||
"flink-kube-operator/internal/manager"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
|
||||
type GetJobsReq struct {
|
||||
}
|
||||
|
||||
type GetJobsResp struct {
|
||||
Body []v1alpha1.FlinkJob
|
||||
}
|
||||
|
||||
func GetJobs(ctx context.Context, req *GetJobsReq) (*GetJobsResp, error) {
|
||||
jobs := []v1alpha1.FlinkJob{}
|
||||
for _, key := range crd.GetAllJobKeys() {
|
||||
job := crd.GetJob(key)
|
||||
job.ManagedFields = nil
|
||||
jobs = append(jobs, job)
|
||||
}
|
||||
return &GetJobsResp{Body: jobs}, nil
|
||||
}
|
||||
|
||||
type StopJobReq struct {
|
||||
JobUId string `path:"uid"`
|
||||
}
|
||||
|
||||
type StopJobRespBody struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type StopJobResp struct {
|
||||
Body StopJobRespBody
|
||||
}
|
||||
|
||||
func StopJob(ctx context.Context, req *StopJobReq) (*StopJobResp, error) {
|
||||
mgr := manager.GetManager()
|
||||
job := mgr.GetJob(types.UID(req.JobUId))
|
||||
err := job.Stop()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &StopJobResp{Body: StopJobRespBody{
|
||||
Success: true,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func StartJob(ctx context.Context, req *StopJobReq) (*StopJobResp, error) {
|
||||
mgr := manager.GetManager()
|
||||
job := mgr.GetJob(types.UID(req.JobUId))
|
||||
err := job.Run(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &StopJobResp{Body: StopJobRespBody{
|
||||
Success: true,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func RemoveJobJar(ctx context.Context, req *StopJobReq) (*StopJobResp, error) {
|
||||
mgr := manager.GetManager()
|
||||
job := mgr.GetJob(types.UID(req.JobUId))
|
||||
job.RemoveJar()
|
||||
return &StopJobResp{Body: StopJobRespBody{
|
||||
Success: true,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func PauseJob(ctx context.Context, req *StopJobReq) (*StopJobResp, error) {
|
||||
mgr := manager.GetManager()
|
||||
job := mgr.GetJob(types.UID(req.JobUId))
|
||||
job.Pause()
|
||||
return &StopJobResp{Body: StopJobRespBody{
|
||||
Success: true,
|
||||
}}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user