暂停、启动应用接口实现

Signed-off-by: devad <cossjie@foxmail.com>
This commit is contained in:
devad 2024-01-03 16:01:34 +08:00
parent a1cfa43774
commit d409682046
11 changed files with 246 additions and 26 deletions

View File

@ -561,9 +561,9 @@ service pcm {
@doc "暂停应用"
@handler PauseAppByAppName
put /apps/pauseApp (DeleteAppReq) returns (AppTaskResp)
put /apps/pauseApp (DeleteAppReq) returns (AppResp)
@doc "启动应用"
@handler StartAppByAppName
put /apps/startApp (DeleteAppReq) returns (AppTaskResp)
put /apps/startApp (DeleteAppReq) returns (AppResp)
}

View File

@ -2,6 +2,8 @@ package apps
import (
"context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/constants"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
@ -23,8 +25,17 @@ func NewPauseAppByAppNameLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
}
func (l *PauseAppByAppNameLogic) PauseAppByAppName(req *types.DeleteAppReq) (resp *types.AppTaskResp, err error) {
// todo: add your logic here and delete this line
func (l *PauseAppByAppNameLogic) PauseAppByAppName(req *types.DeleteAppReq) (resp *types.AppResp, err error) {
resp = &types.AppResp{}
var task = &Task{}
//查询应用的yamlString
l.svcCtx.DbEngin.Raw(`select * from task where ns_id= ? and name= ? AND deleted_at IS NULL`, req.NsID, req.Name).Scan(&task)
if task.Id == 0 {
resp.Code = 500
resp.Msg = "App not fount"
return resp, err
}
// 将子任务状态修改为待暂停
l.svcCtx.DbEngin.Model(&models.Cloud{}).Where("task_id", task.Id).Update("status", constants.WaitPause)
return
}

View File

@ -2,6 +2,8 @@ package apps
import (
"context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/constants"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
@ -23,8 +25,17 @@ func NewStartAppByAppNameLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
}
func (l *StartAppByAppNameLogic) StartAppByAppName(req *types.DeleteAppReq) (resp *types.AppTaskResp, err error) {
// todo: add your logic here and delete this line
func (l *StartAppByAppNameLogic) StartAppByAppName(req *types.DeleteAppReq) (resp *types.AppResp, err error) {
resp = &types.AppResp{}
var task = &Task{}
//查询应用的yamlString
l.svcCtx.DbEngin.Raw(`select * from task where ns_id= ? and name= ? AND deleted_at IS NULL`, req.NsID, req.Name).Scan(&task)
if task.Id == 0 {
resp.Code = 500
resp.Msg = "App not fount"
return resp, err
}
// 将子任务状态修改为待启动
l.svcCtx.DbEngin.Model(&models.Cloud{}).Where("task_id", task.Id).Update("status", constants.WaitStart)
return
}

View File

@ -24,4 +24,6 @@ const (
Succeeded = "Succeeded"
Failed = "Failed"
WaitRestart = "WaitRestart"
WaitPause = "WaitPause"
WaitStart = "WaitStart"
)

View File

@ -66,6 +66,10 @@ type (
DeleteList(ctx context.Context, in *ApplyListReq, opts ...grpc.CallOption) (*ApplyListResp, error)
// RestartList 重启任务列表
RestartList(ctx context.Context, in *ApplyListReq, opts ...grpc.CallOption) (*ApplyListResp, error)
// PauseList 暂停任务列表
PauseList(ctx context.Context, in *ApplyListReq, opts ...grpc.CallOption) (*ApplyListResp, error)
// StartList 暂停任务列表
StartList(ctx context.Context, in *ApplyListReq, opts ...grpc.CallOption) (*ApplyListResp, error)
}
defaultParticipantService struct {
@ -144,3 +148,15 @@ func (m *defaultParticipantService) RestartList(ctx context.Context, in *ApplyLi
client := pcmCore.NewParticipantServiceClient(m.cli.Conn())
return client.RestartList(ctx, in, opts...)
}
// PauseList 暂停任务列表
func (m *defaultParticipantService) PauseList(ctx context.Context, in *ApplyListReq, opts ...grpc.CallOption) (*ApplyListResp, error) {
client := pcmCore.NewParticipantServiceClient(m.cli.Conn())
return client.PauseList(ctx, in, opts...)
}
// StartList 暂停任务列表
func (m *defaultParticipantService) StartList(ctx context.Context, in *ApplyListReq, opts ...grpc.CallOption) (*ApplyListResp, error) {
client := pcmCore.NewParticipantServiceClient(m.cli.Conn())
return client.StartList(ctx, in, opts...)
}

View File

@ -0,0 +1,36 @@
package participantservicelogic
import (
"context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/pcmCore"
"github.com/zeromicro/go-zero/core/logx"
)
type PauseListLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewPauseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PauseListLogic {
return &PauseListLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// PauseList 暂停任务列表
func (l *PauseListLogic) PauseList(in *pcmCore.ApplyListReq) (*pcmCore.ApplyListResp, error) {
result := pcmCore.ApplyListResp{
InfoList: make([]*pcmCore.ApplyInfo, 0),
}
l.svcCtx.DbEngin.Raw("SELECT sppi.`name` as ParticipantName, c.ns_id as namespace,c.name as name , c.kind as kind FROM cloud c,sc_participant_phy_info sppi where c.`status` = 'WaitPause' and sppi.id = c.participant_id").Scan(&result.InfoList)
if len(result.InfoList) != 0 {
l.svcCtx.DbEngin.Exec("update cloud set status = ? where status = ?", "Paused", "WaitPause")
}
return &result, nil
}

View File

@ -0,0 +1,36 @@
package participantservicelogic
import (
"context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/rpc/pcmCore"
"github.com/zeromicro/go-zero/core/logx"
)
type StartListLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewStartListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StartListLogic {
return &StartListLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// StartList 启动任务列表
func (l *StartListLogic) StartList(in *pcmCore.ApplyListReq) (*pcmCore.ApplyListResp, error) {
result := pcmCore.ApplyListResp{
InfoList: make([]*pcmCore.ApplyInfo, 0),
}
l.svcCtx.DbEngin.Raw("SELECT sppi.`name` as ParticipantName, c.ns_id as namespace,c.name as name , c.kind as kind FROM cloud c,sc_participant_phy_info sppi where c.`status` = 'Paused' and sppi.id = c.participant_id").Scan(&result.InfoList)
if len(result.InfoList) != 0 {
l.svcCtx.DbEngin.Exec("update cloud set status = ? where status = ?", "Issued", "Paused")
}
return &result, nil
}

View File

@ -87,3 +87,15 @@ func (s *ParticipantServiceServer) RestartList(ctx context.Context, in *pcmCore.
l := participantservicelogic.NewRestartListLogic(ctx, s.svcCtx)
return l.RestartList(in)
}
// PauseList 暂停任务列表
func (s *ParticipantServiceServer) PauseList(ctx context.Context, in *pcmCore.ApplyListReq) (*pcmCore.ApplyListResp, error) {
l := participantservicelogic.NewPauseListLogic(ctx, s.svcCtx)
return l.PauseList(in)
}
// StartList 暂停任务列表
func (s *ParticipantServiceServer) StartList(ctx context.Context, in *pcmCore.ApplyListReq) (*pcmCore.ApplyListResp, error) {
l := participantservicelogic.NewStartListLogic(ctx, s.svcCtx)
return l.StartList(in)
}

View File

@ -335,4 +335,10 @@ service participantService {
// RestartList
rpc restartList(ApplyListReq) returns (ApplyListResp) {};
// PauseList
rpc pauseList(ApplyListReq) returns (ApplyListResp) {};
// StartList
rpc startList(ApplyListReq) returns (ApplyListResp) {};
}

View File

@ -3073,7 +3073,7 @@ var file_pb_pcmCore_proto_rawDesc = []byte{
0x52, 0x65, 0x73, 0x70, 0x12, 0x37, 0x0a, 0x08, 0x49, 0x6e, 0x66, 0x6f, 0x4c, 0x69, 0x73, 0x74,
0x12, 0x14, 0x2e, 0x70, 0x63, 0x6d, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x4c,
0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x70, 0x63, 0x6d, 0x43, 0x6f, 0x72, 0x65,
0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x32, 0xb9, 0x06,
0x2e, 0x49, 0x6e, 0x66, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x32, 0xb5, 0x07,
0x0a, 0x12, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x53, 0x65, 0x72,
0x76, 0x69, 0x63, 0x65, 0x12, 0x50, 0x0a, 0x13, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72,
0x50, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x12, 0x1a, 0x2e, 0x70, 0x63,
@ -3125,8 +3125,16 @@ var file_pb_pcmCore_proto_rawDesc = []byte{
0x74, 0x61, 0x72, 0x74, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x15, 0x2e, 0x70, 0x63, 0x6d, 0x43, 0x6f,
0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x1a,
0x16, 0x2e, 0x70, 0x63, 0x6d, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x4c,
0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x0a, 0x5a, 0x08, 0x2f, 0x70, 0x63,
0x6d, 0x43, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x3c, 0x0a, 0x09, 0x70, 0x61, 0x75,
0x73, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x15, 0x2e, 0x70, 0x63, 0x6d, 0x43, 0x6f, 0x72, 0x65,
0x2e, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e,
0x70, 0x63, 0x6d, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x4c, 0x69, 0x73,
0x74, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x3c, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74,
0x4c, 0x69, 0x73, 0x74, 0x12, 0x15, 0x2e, 0x70, 0x63, 0x6d, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41,
0x70, 0x70, 0x6c, 0x79, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x70, 0x63,
0x6d, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x4c, 0x69, 0x73, 0x74, 0x52,
0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x0a, 0x5a, 0x08, 0x2f, 0x70, 0x63, 0x6d, 0x43, 0x6f, 0x72,
0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -3206,21 +3214,25 @@ var file_pb_pcmCore_proto_depIdxs = []int32{
27, // 27: pcmCore.participantService.applyList:input_type -> pcmCore.ApplyListReq
27, // 28: pcmCore.participantService.deleteList:input_type -> pcmCore.ApplyListReq
27, // 29: pcmCore.participantService.restartList:input_type -> pcmCore.ApplyListReq
6, // 30: pcmCore.pcmCore.SyncInfo:output_type -> pcmCore.SyncInfoResp
8, // 31: pcmCore.pcmCore.InfoList:output_type -> pcmCore.InfoListResp
12, // 32: pcmCore.participantService.registerParticipant:output_type -> pcmCore.ParticipantPhyResp
11, // 33: pcmCore.participantService.reportHeartbeat:output_type -> pcmCore.HealthCheckResp
21, // 34: pcmCore.participantService.reportAvailable:output_type -> pcmCore.ParticipantResp
22, // 35: pcmCore.participantService.listParticipant:output_type -> pcmCore.ParticipantServiceResp
20, // 36: pcmCore.participantService.listPhyAvailable:output_type -> pcmCore.ListParticipantAvailResp
13, // 37: pcmCore.participantService.listPhyInformation:output_type -> pcmCore.ListParticipantPhyResp
25, // 38: pcmCore.participantService.registerTenant:output_type -> pcmCore.TenantResp
26, // 39: pcmCore.participantService.listTenant:output_type -> pcmCore.ListTenantResp
28, // 40: pcmCore.participantService.applyList:output_type -> pcmCore.ApplyListResp
28, // 41: pcmCore.participantService.deleteList:output_type -> pcmCore.ApplyListResp
28, // 42: pcmCore.participantService.restartList:output_type -> pcmCore.ApplyListResp
30, // [30:43] is the sub-list for method output_type
17, // [17:30] is the sub-list for method input_type
27, // 30: pcmCore.participantService.pauseList:input_type -> pcmCore.ApplyListReq
27, // 31: pcmCore.participantService.startList:input_type -> pcmCore.ApplyListReq
6, // 32: pcmCore.pcmCore.SyncInfo:output_type -> pcmCore.SyncInfoResp
8, // 33: pcmCore.pcmCore.InfoList:output_type -> pcmCore.InfoListResp
12, // 34: pcmCore.participantService.registerParticipant:output_type -> pcmCore.ParticipantPhyResp
11, // 35: pcmCore.participantService.reportHeartbeat:output_type -> pcmCore.HealthCheckResp
21, // 36: pcmCore.participantService.reportAvailable:output_type -> pcmCore.ParticipantResp
22, // 37: pcmCore.participantService.listParticipant:output_type -> pcmCore.ParticipantServiceResp
20, // 38: pcmCore.participantService.listPhyAvailable:output_type -> pcmCore.ListParticipantAvailResp
13, // 39: pcmCore.participantService.listPhyInformation:output_type -> pcmCore.ListParticipantPhyResp
25, // 40: pcmCore.participantService.registerTenant:output_type -> pcmCore.TenantResp
26, // 41: pcmCore.participantService.listTenant:output_type -> pcmCore.ListTenantResp
28, // 42: pcmCore.participantService.applyList:output_type -> pcmCore.ApplyListResp
28, // 43: pcmCore.participantService.deleteList:output_type -> pcmCore.ApplyListResp
28, // 44: pcmCore.participantService.restartList:output_type -> pcmCore.ApplyListResp
28, // 45: pcmCore.participantService.pauseList:output_type -> pcmCore.ApplyListResp
28, // 46: pcmCore.participantService.startList:output_type -> pcmCore.ApplyListResp
32, // [32:47] is the sub-list for method output_type
17, // [17:32] is the sub-list for method input_type
17, // [17:17] is the sub-list for extension type_name
17, // [17:17] is the sub-list for extension extendee
0, // [0:17] is the sub-list for field type_name

View File

@ -161,6 +161,8 @@ const (
ParticipantService_ApplyList_FullMethodName = "/pcmCore.participantService/applyList"
ParticipantService_DeleteList_FullMethodName = "/pcmCore.participantService/deleteList"
ParticipantService_RestartList_FullMethodName = "/pcmCore.participantService/restartList"
ParticipantService_PauseList_FullMethodName = "/pcmCore.participantService/pauseList"
ParticipantService_StartList_FullMethodName = "/pcmCore.participantService/startList"
)
// ParticipantServiceClient is the client API for ParticipantService service.
@ -189,6 +191,10 @@ type ParticipantServiceClient interface {
DeleteList(ctx context.Context, in *ApplyListReq, opts ...grpc.CallOption) (*ApplyListResp, error)
// RestartList 重启任务列表
RestartList(ctx context.Context, in *ApplyListReq, opts ...grpc.CallOption) (*ApplyListResp, error)
// PauseList 暂停任务列表
PauseList(ctx context.Context, in *ApplyListReq, opts ...grpc.CallOption) (*ApplyListResp, error)
// StartList 暂停任务列表
StartList(ctx context.Context, in *ApplyListReq, opts ...grpc.CallOption) (*ApplyListResp, error)
}
type participantServiceClient struct {
@ -298,6 +304,24 @@ func (c *participantServiceClient) RestartList(ctx context.Context, in *ApplyLis
return out, nil
}
func (c *participantServiceClient) PauseList(ctx context.Context, in *ApplyListReq, opts ...grpc.CallOption) (*ApplyListResp, error) {
out := new(ApplyListResp)
err := c.cc.Invoke(ctx, ParticipantService_PauseList_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *participantServiceClient) StartList(ctx context.Context, in *ApplyListReq, opts ...grpc.CallOption) (*ApplyListResp, error) {
out := new(ApplyListResp)
err := c.cc.Invoke(ctx, ParticipantService_StartList_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// ParticipantServiceServer is the server API for ParticipantService service.
// All implementations must embed UnimplementedParticipantServiceServer
// for forward compatibility
@ -324,6 +348,10 @@ type ParticipantServiceServer interface {
DeleteList(context.Context, *ApplyListReq) (*ApplyListResp, error)
// RestartList 重启任务列表
RestartList(context.Context, *ApplyListReq) (*ApplyListResp, error)
// PauseList 暂停任务列表
PauseList(context.Context, *ApplyListReq) (*ApplyListResp, error)
// StartList 暂停任务列表
StartList(context.Context, *ApplyListReq) (*ApplyListResp, error)
mustEmbedUnimplementedParticipantServiceServer()
}
@ -364,6 +392,12 @@ func (UnimplementedParticipantServiceServer) DeleteList(context.Context, *ApplyL
func (UnimplementedParticipantServiceServer) RestartList(context.Context, *ApplyListReq) (*ApplyListResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method RestartList not implemented")
}
func (UnimplementedParticipantServiceServer) PauseList(context.Context, *ApplyListReq) (*ApplyListResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method PauseList not implemented")
}
func (UnimplementedParticipantServiceServer) StartList(context.Context, *ApplyListReq) (*ApplyListResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method StartList not implemented")
}
func (UnimplementedParticipantServiceServer) mustEmbedUnimplementedParticipantServiceServer() {}
// UnsafeParticipantServiceServer may be embedded to opt out of forward compatibility for this service.
@ -575,6 +609,42 @@ func _ParticipantService_RestartList_Handler(srv interface{}, ctx context.Contex
return interceptor(ctx, in, info, handler)
}
func _ParticipantService_PauseList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ApplyListReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ParticipantServiceServer).PauseList(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: ParticipantService_PauseList_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ParticipantServiceServer).PauseList(ctx, req.(*ApplyListReq))
}
return interceptor(ctx, in, info, handler)
}
func _ParticipantService_StartList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ApplyListReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ParticipantServiceServer).StartList(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: ParticipantService_StartList_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ParticipantServiceServer).StartList(ctx, req.(*ApplyListReq))
}
return interceptor(ctx, in, info, handler)
}
// ParticipantService_ServiceDesc is the grpc.ServiceDesc for ParticipantService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@ -626,6 +696,14 @@ var ParticipantService_ServiceDesc = grpc.ServiceDesc{
MethodName: "restartList",
Handler: _ParticipantService_RestartList_Handler,
},
{
MethodName: "pauseList",
Handler: _ParticipantService_PauseList_Handler,
},
{
MethodName: "startList",
Handler: _ParticipantService_StartList_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "pb/pcmCore.proto",