@@ -30,6 +30,7 @@ import (
3030 "runtime"
3131 "time"
3232
33+ "github.com/AliceO2Group/Control/core/task/channel"
3334 "golang.org/x/net/context"
3435 "google.golang.org/grpc"
3536
@@ -90,11 +91,13 @@ func (m *RpcServer) GetFrameworkInfo(context.Context, *pb.GetFrameworkInfoReques
9091 m .logMethod ()
9192 m .state .RLock ()
9293 defer m .state .RUnlock ()
94+
9395 r := & pb.GetFrameworkInfoReply {
9496 FrameworkId : store .GetIgnoreErrors (m .fidStore )(),
9597 EnvironmentsCount : int32 (len (m .state .environments .Ids ())),
9698 TasksCount : int32 (m .state .taskman .TaskCount ()),
9799 State : m .state .sm .Current (),
100+ HostsCount : int32 (m .state .taskman .AgentCache .Count ()),
98101 }
99102 return r , nil
100103}
@@ -124,16 +127,14 @@ func (m *RpcServer) GetEnvironments(context.Context, *pb.GetEnvironmentsRequest)
124127 continue
125128 }
126129 tasks := env .Workflow ().GetTasks ()
127- taskNames := make ([]string , len (tasks ))
128- for i , task := range tasks {
129- taskNames [i ] = task .GetName ()
130- }
131130 e := & pb.EnvironmentInfo {
132131 Id : env .Id ().String (),
133132 CreatedWhen : env .CreatedWhen ().Format (time .RFC3339 ),
134133 State : env .CurrentState (),
135- Tasks : taskNames ,
134+ Tasks : tasksToShortTaskInfos (tasks ),
135+ RootRole : env .Workflow ().GetName (),
136136 }
137+
137138 r .Environments = append (r .Environments , e )
138139 }
139140 return r , nil
@@ -164,7 +165,7 @@ func (m *RpcServer) NewEnvironment(cxt context.Context, request *pb.NewEnvironme
164165 }
165166
166167 // Create new Environment instance with some roles, we get back a UUID
167- id , err := m .state .environments .CreateEnvironment (request .GetWorkflow ())
168+ id , err := m .state .environments .CreateEnvironment (request .GetWorkflowTemplate ())
168169 if err != nil {
169170 return nil , status .Newf (codes .Internal , "cannot create new environment: %s" , err .Error ()).Err ()
170171 }
@@ -174,9 +175,15 @@ func (m *RpcServer) NewEnvironment(cxt context.Context, request *pb.NewEnvironme
174175 return nil , status .Newf (codes .Internal , "cannot get newly created environment: %s" , err .Error ()).Err ()
175176 }
176177
178+ tasks := newEnv .Workflow ().GetTasks ()
177179 r := & pb.NewEnvironmentReply {
178- Id : id .String (),
179- State : newEnv .Sm .Current (),
180+ Environment : & pb.EnvironmentInfo {
181+ Id : newEnv .Id ().String (),
182+ CreatedWhen : newEnv .CreatedWhen ().Format (time .RFC3339 ),
183+ State : newEnv .CurrentState (),
184+ Tasks : tasksToShortTaskInfos (tasks ),
185+ RootRole : newEnv .Workflow ().GetName (),
186+ },
180187 }
181188
182189 return r , nil
@@ -197,17 +204,15 @@ func (m *RpcServer) GetEnvironment(cxt context.Context, req *pb.GetEnvironmentRe
197204 }
198205
199206 tasks := env .Workflow ().GetTasks ()
200- taskNames := make ([]string , len (tasks ))
201- for i , task := range tasks {
202- taskNames [i ] = task .GetName ()
203- }
204207 r := & pb.GetEnvironmentReply {
205208 Environment : & pb.EnvironmentInfo {
206209 Id : env .Id ().String (),
207210 CreatedWhen : env .CreatedWhen ().Format (time .RFC3339 ),
208211 State : env .CurrentState (),
209- Tasks : taskNames ,
212+ Tasks : tasksToShortTaskInfos (tasks ),
213+ RootRole : env .Workflow ().GetName (),
210214 },
215+ Workflow : workflowToRoleTree (env .Workflow ()),
211216 }
212217 return r , nil
213218}
@@ -291,17 +296,87 @@ func (m *RpcServer) GetTasks(context.Context, *pb.GetTasksRequest) (*pb.GetTasks
291296 m .state .RLock ()
292297 defer m .state .RUnlock ()
293298
299+ tasks := m .state .taskman .GetTasks ()
294300 r := & pb.GetTasksReply {
295- Tasks : make ([] * pb. TaskInfo , 0 , 0 ),
301+ Tasks : tasksToShortTaskInfos ( tasks ),
296302 }
297303
298- for _ , task := range m .state .taskman .GetTasks () {
299- ri := & pb.TaskInfo {
300- Locked : task .IsLocked (),
301- Hostname : task .GetHostname (),
302- Name : task .GetName (),
304+ return r , nil
305+ }
306+
307+ func (m * RpcServer ) GetTask (cxt context.Context , req * pb.GetTaskRequest ) (* pb.GetTaskReply , error ) {
308+ m .logMethod ()
309+ m .state .RLock ()
310+ defer m .state .RUnlock ()
311+
312+ task := m .state .taskman .GetTask (req .TaskId )
313+ if task == nil {
314+ return & pb.GetTaskReply {}, status .New (codes .NotFound , "task not found" ).Err ()
315+ }
316+ taskClass := task .GetTaskClass ()
317+ commandInfo := task .BuildTaskCommand ()
318+ var outbound []channel.Outbound
319+ taskPath := ""
320+ // TODO: probably not the nicest way to do this... the outbound assignments should be cached
321+ // in the Task
322+ if task .IsLocked () {
323+ type parentRole interface {
324+ CollectOutboundChannels () []channel.Outbound
325+ GetPath () string
326+ }
327+ parent , ok := task .GetParentRole ().(parentRole )
328+ if ok {
329+ outbound = parent .CollectOutboundChannels ()
330+ taskPath = parent .GetPath ()
303331 }
304- r .Tasks = append (r .Tasks , ri )
305332 }
306- return r , nil
333+
334+ rep := & pb.GetTaskReply {
335+ Task : & pb.TaskInfo {
336+ ShortInfo : taskToShortTaskInfo (task ),
337+ ClassInfo : & pb.TaskClassInfo {
338+ Name : task .GetClassName (),
339+ ControlMode : taskClass .Control .Mode .String (),
340+ },
341+ InboundChannels : inboundChannelsToPbChannels (taskClass .Bind ),
342+ OutboundChannels : outboundChannelsToPbChannels (outbound ),
343+ CommandInfo : commandInfoToPbCommandInfo (commandInfo ),
344+ TaskPath : taskPath ,
345+ EnvId : task .GetEnvironmentId ().String (),
346+ },
347+ }
348+ return rep , nil
307349}
350+
351+ func (m * RpcServer ) CleanupTasks (context.Context , * pb.CleanupTasksRequest ) (* pb.CleanupTasksReply , error ) {
352+ log .WithPrefix ("rpcserver" ).
353+ WithField ("method" , "CleanupTasks" ).
354+ Debug ("implement me" )
355+
356+ return & pb.CleanupTasksReply {}, status .New (codes .Unimplemented , "not implemented" ).Err ()
357+ }
358+
359+
360+ func (m * RpcServer ) GetRoles (cxt context.Context , req * pb.GetRolesRequest ) (* pb.GetRolesReply , error ) {
361+ m .logMethod ()
362+ m .state .RLock ()
363+ defer m .state .RUnlock ()
364+
365+ if req == nil || len (req .EnvId ) == 0 {
366+ return nil , status .New (codes .InvalidArgument , "received nil request" ).Err ()
367+ }
368+
369+ env , err := m .state .environments .Environment (uuid .Parse (req .EnvId ))
370+ if err != nil {
371+ return nil , status .Newf (codes .NotFound , "environment not found: %s" , err .Error ()).Err ()
372+ }
373+
374+ resultRoles := env .QueryRoles (req .PathSpec )
375+
376+ roleInfos := make ([]* pb.RoleInfo , len (resultRoles ))
377+ for i , rr := range resultRoles {
378+ roleInfos [i ] = workflowToRoleTree (rr )
379+ }
380+ return & pb.GetRolesReply {Roles : roleInfos }, nil
381+ }
382+
0 commit comments