Skip to content

Commit 7ee4519

Browse files
committed
[coconut] Implement list workflow templates
1 parent 5b3569e commit 7ee4519

File tree

3 files changed

+131
-10
lines changed

3 files changed

+131
-10
lines changed

coconut/cmd/template.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* === This file is part of ALICE O² ===
3+
*
4+
* Copyright 2018 CERN and copyright holders of ALICE O².
5+
* Author: Teo Mrnjavac <teo.mrnjavac@cern.ch>
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
* In applying this license CERN does not waive the privileges and
21+
* immunities granted to it by virtue of its status as an
22+
* Intergovernmental Organization or submit itself to any jurisdiction.
23+
*/
24+
25+
package cmd
26+
27+
import (
28+
"fmt"
29+
30+
"github.com/AliceO2Group/Control/common/product"
31+
"github.com/spf13/cobra"
32+
)
33+
34+
// templateCmd represents the template command
35+
var templateCmd = &cobra.Command{
36+
Use: "template",
37+
Aliases: []string{"templ"},
38+
Short: "query available workflow templates in O² configuration",
39+
Long: fmt.Sprintf(`The template command interacts with the loaded %s configuration to
40+
display information on available O² templates.`, product.PRETTY_SHORTNAME),
41+
}
42+
43+
func init() {
44+
rootCmd.AddCommand(templateCmd)
45+
}

coconut/cmd/template_list.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* === This file is part of ALICE O² ===
3+
*
4+
* Copyright 2018 CERN and copyright holders of ALICE O².
5+
* Author: Teo Mrnjavac <teo.mrnjavac@cern.ch>
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
* In applying this license CERN does not waive the privileges and
21+
* immunities granted to it by virtue of its status as an
22+
* Intergovernmental Organization or submit itself to any jurisdiction.
23+
*/
24+
25+
package cmd
26+
27+
import (
28+
"github.com/spf13/cobra"
29+
"github.com/AliceO2Group/Control/coconut/control"
30+
)
31+
32+
// templateListCmd represents the template list command
33+
var templateListCmd = &cobra.Command{
34+
Use: "list",
35+
Aliases: []string{"list", "ls", "l"},
36+
Short: "list available workflow templates",
37+
Long: `The template list command shows a list of available workflow templates.
38+
These workflow templates can then be loaded to create an environment.`,
39+
Run: control.WrapCall(control.ListWorkflowTemplates),
40+
}
41+
42+
func init() {
43+
templateCmd.AddCommand(templateListCmd)
44+
}

coconut/control/control.go

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ func WrapCall(call ControlCall) RunFunc {
100100

101101

102102
func GetInfo(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.Command, args []string, o io.Writer) (err error) {
103-
response, err := rpc.GetFrameworkInfo(cxt, &pb.GetFrameworkInfoRequest{}, grpc.EmptyCallOption{})
103+
var response *pb.GetFrameworkInfoReply
104+
response, err = rpc.GetFrameworkInfo(cxt, &pb.GetFrameworkInfoRequest{}, grpc.EmptyCallOption{})
104105
if err != nil {
105106
return
106107
}
@@ -123,7 +124,8 @@ func Teardown(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.Command, a
123124

124125

125126
func GetEnvironments(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.Command, args []string, o io.Writer) (err error) {
126-
response, err := rpc.GetEnvironments(cxt, &pb.GetEnvironmentsRequest{}, grpc.EmptyCallOption{})
127+
var response *pb.GetEnvironmentsReply
128+
response, err = rpc.GetEnvironments(cxt, &pb.GetEnvironmentsRequest{}, grpc.EmptyCallOption{})
127129
if err != nil {
128130
return
129131
}
@@ -193,7 +195,8 @@ func ShowEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.Com
193195
return
194196
}
195197

196-
response, err := rpc.GetEnvironment(cxt, &pb.GetEnvironmentRequest{Id: args[0]}, grpc.EmptyCallOption{})
198+
var response *pb.GetEnvironmentReply
199+
response, err = rpc.GetEnvironment(cxt, &pb.GetEnvironmentRequest{Id: args[0]}, grpc.EmptyCallOption{})
197200
if err != nil {
198201
return
199202
}
@@ -237,10 +240,10 @@ func ControlEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.
237240
return
238241
}
239242

240-
response, err := rpc.ControlEnvironment(cxt, &pb.ControlEnvironmentRequest{Id: args[0], Type: pb.ControlEnvironmentRequest_Optype(pb.ControlEnvironmentRequest_Optype_value[event])}, grpc.EmptyCallOption{})
243+
var response *pb.ControlEnvironmentReply
244+
response, err = rpc.ControlEnvironment(cxt, &pb.ControlEnvironmentRequest{Id: args[0], Type: pb.ControlEnvironmentRequest_Optype(pb.ControlEnvironmentRequest_Optype_value[event])}, grpc.EmptyCallOption{})
241245
if err != nil {
242246
return
243-
244247
}
245248

246249
fmt.Fprintln(o, "transition complete")
@@ -295,7 +298,8 @@ func ModifyEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.C
295298
}
296299

297300
// Check current state first
298-
envResponse, err := rpc.GetEnvironment(cxt, &pb.GetEnvironmentRequest{Id: envId}, grpc.EmptyCallOption{})
301+
var envResponse *pb.GetEnvironmentReply
302+
envResponse, err = rpc.GetEnvironment(cxt, &pb.GetEnvironmentRequest{Id: envId}, grpc.EmptyCallOption{})
299303
if err != nil {
300304
return
301305
}
@@ -308,7 +312,8 @@ func ModifyEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.C
308312
}
309313

310314
// Do the request
311-
response, err := rpc.ModifyEnvironment(cxt, &pb.ModifyEnvironmentRequest{
315+
var response *pb.ModifyEnvironmentReply
316+
response, err = rpc.ModifyEnvironment(cxt, &pb.ModifyEnvironmentRequest{
312317
Id: envId,
313318
Operations: ops,
314319
ReconfigureAll: reconfigure,
@@ -341,7 +346,8 @@ func DestroyEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.
341346
envId := args[0]
342347

343348
// Check current state first
344-
envResponse, err := rpc.GetEnvironment(cxt, &pb.GetEnvironmentRequest{Id: envId}, grpc.EmptyCallOption{})
349+
var envResponse *pb.GetEnvironmentReply
350+
envResponse, err = rpc.GetEnvironment(cxt, &pb.GetEnvironmentRequest{Id: envId}, grpc.EmptyCallOption{})
345351
if err != nil {
346352
return
347353
}
@@ -365,7 +371,8 @@ func DestroyEnvironment(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.
365371

366372

367373
func GetTasks(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.Command, args []string, o io.Writer) (err error) {
368-
response, err := rpc.GetTasks(cxt, &pb.GetTasksRequest{}, grpc.EmptyCallOption{})
374+
var response *pb.GetTasksReply
375+
response, err = rpc.GetTasks(cxt, &pb.GetTasksRequest{}, grpc.EmptyCallOption{})
369376
if err != nil {
370377
return
371378
}
@@ -400,7 +407,8 @@ func QueryRoles(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.Command,
400407
envId := args[0]
401408
queryPath := args[1]
402409

403-
response, err := rpc.GetRoles(cxt, &pb.GetRolesRequest{EnvId: envId, PathSpec: queryPath}, grpc.EmptyCallOption{})
410+
var response *pb.GetRolesReply
411+
response, err = rpc.GetRoles(cxt, &pb.GetRolesRequest{EnvId: envId, PathSpec: queryPath}, grpc.EmptyCallOption{})
404412
if err != nil {
405413
return
406414
}
@@ -421,5 +429,29 @@ func QueryRoles(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.Command,
421429
}
422430
}
423431

432+
return nil
433+
}
434+
435+
func ListWorkflowTemplates(cxt context.Context, rpc *coconut.RpcClient, cmd *cobra.Command, args []string, o io.Writer) (err error) {
436+
if len(args) != 0 {
437+
err = errors.New(fmt.Sprintf("accepts no arg(s), received %d", len(args)))
438+
return
439+
}
440+
441+
var response *pb.GetWorkflowTemplatesReply
442+
response, err = rpc.GetWorkflowTemplates(cxt, &pb.GetWorkflowTemplatesRequest{}, grpc.EmptyCallOption{})
443+
if err != nil {
444+
return
445+
}
446+
447+
templates := response.GetWorkflowTemplates()
448+
if len(templates) == 0 {
449+
fmt.Fprintln(o, "no templates found")
450+
} else {
451+
fmt.Fprintln(o, "available templates in loaded configuration:")
452+
for _, tmpl := range templates {
453+
fmt.Fprintln(o, "\t" + tmpl)
454+
}
455+
}
424456
return nil
425457
}

0 commit comments

Comments
 (0)