Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create CLI command to list Tasks from Tasklist #433

Merged
merged 2 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 30 additions & 54 deletions tools/cli/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,36 @@ func newAdminTaskListCommands() []cli.Command {
AdminDescribeTaskList(c)
},
},
{
Name: "list_tasks",
Usage: "List tasks of a tasklist",
Flags: append(getDBFlags(),
cli.StringFlag{
Name: FlagNamespaceID,
Usage: "Namespace Id",
},
Copy link
Contributor

@shawnhathaway shawnhathaway Jun 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add field for TaskID to be able to select a singular based off Friday discussion

Copy link
Contributor Author

@feedmeapples feedmeapples Jun 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created a tracking ticket to add predicates support to all of the list commands https://app.clubhouse.io/temporal-technologies-inc/story/845/support-predicates-for-admin-list-commands

cli.StringFlag{
Name: FlagTaskListType,
Value: "activity",
Usage: "Tasklist type: activity, decision",
},
cli.StringFlag{
Name: FlagTaskList,
Usage: "Tasklist name",
},
cli.Int64Flag{
Name: FlagMinReadLevel,
Usage: "Lower bound of read level",
},
cli.Int64Flag{
Name: FlagMaxReadLevel,
Usage: "Upper bound of read level",
},
),
Action: func(c *cli.Context) {
AdminListTaskListTasks(c)
},
},
}
}

Expand Down Expand Up @@ -939,57 +969,3 @@ func newDBCommands() []cli.Command {
},
}
}

// TODO need to support other database: https://github.com/uber/cadence/issues/2777
func getDBFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: FlagDBEngine,
Value: "cassandra",
Usage: "Type of the DB engine to use (cassandra, mysql..)",
},
cli.StringFlag{
Name: FlagDBAddress,
Value: "127.0.0.1",
Usage: "persistence address (right now only cassandra is fully supported)",
},
cli.IntFlag{
Name: FlagDBPort,
Value: 9042,
Usage: "persistence port",
},
cli.StringFlag{
Name: FlagUsername,
Usage: "cassandra username",
},
cli.StringFlag{
Name: FlagPassword,
Usage: "cassandra password",
},
cli.StringFlag{
Name: FlagKeyspace,
Value: "temporal",
Usage: "cassandra keyspace",
},
cli.BoolFlag{
Name: FlagEnableTLS,
Usage: "enable TLS over cassandra connection",
},
cli.StringFlag{
Name: FlagTLSCertPath,
Usage: "cassandra tls client cert path (tls must be enabled)",
},
cli.StringFlag{
Name: FlagTLSKeyPath,
Usage: "cassandra tls client key path (tls must be enabled)",
},
cli.StringFlag{
Name: FlagTLSCaPath,
Usage: "cassandra tls client ca path (tls must be enabled)",
},
cli.BoolFlag{
Name: FlagTLSEnableHostVerification,
Usage: "cassandra tls verify hostname and server cert (tls must be enabled)",
},
}
}
25 changes: 25 additions & 0 deletions tools/cli/adminTaskListCommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"strings"

"github.com/olekukonko/tablewriter"
"github.com/temporalio/temporal/common/persistence"
"github.com/urfave/cli"
tasklistpb "go.temporal.io/temporal-proto/tasklist"
"go.temporal.io/temporal-proto/workflowservice"
Expand Down Expand Up @@ -107,3 +108,27 @@ func printPollerInfo(pollers []*tasklistpb.PollerInfo, taskListType tasklistpb.T
}
table.Render()
}

// AdminListTaskListTasks displays task information
func AdminListTaskListTasks(c *cli.Context) {
namespace := getRequiredOption(c, FlagNamespaceID)
tlName := getRequiredOption(c, FlagTaskList)
tlTypeFlag := strings.Title(c.String(FlagTaskListType))
tlTypeInt := tasklistpb.TaskListType_value[tlTypeFlag]
tlType := tasklistpb.TaskListType(tlTypeInt)
minReadLvl := getRequiredInt64Option(c, FlagMinReadLevel)
maxReadLvl := getRequiredInt64Option(c, FlagMaxReadLevel)

pFactory := CreatePersistenceFactory(c)
taskManager, err := pFactory.NewTaskManager()
if err != nil {
ErrorAndExit("Failed to initialize task manager", err)
}

req := &persistence.GetTasksRequest{NamespaceID: namespace, TaskList: tlName, TaskType: tlType, ReadLevel: minReadLvl, MaxReadLevel: &maxReadLvl}
tasks, err := taskManager.GetTasks(req)
if err != nil {
ErrorAndExit("Failed to get Tasks", err)
}
prettyPrintJSONObject(tasks)
}
55 changes: 55 additions & 0 deletions tools/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ const (
FlagSignalNameWithAlias = FlagSignalName + ", sig"
FlagTaskID = "task_id"
FlagTaskType = "task_type"
FlagMinReadLevel = "min_read_level"
FlagMaxReadLevel = "max_read_level"
FlagTaskVisibilityTimestamp = "task_timestamp"
FlagMinVisibilityTimestamp = "min_visibility_ts"
FlagMaxVisibilityTimestamp = "max_visibility_ts"
Expand Down Expand Up @@ -582,3 +584,56 @@ func getFlagsForObserveID() []cli.Flag {
},
}
}

func getDBFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: FlagDBEngine,
Value: "cassandra",
Usage: "Type of the DB engine to use (cassandra, mysql..)",
},
cli.StringFlag{
Name: FlagDBAddress,
Value: "127.0.0.1",
Usage: "persistence address (right now only cassandra is fully supported)",
},
cli.IntFlag{
Name: FlagDBPort,
Value: 9042,
Usage: "persistence port",
},
cli.StringFlag{
Name: FlagUsername,
Usage: "cassandra username",
},
cli.StringFlag{
Name: FlagPassword,
Usage: "cassandra password",
},
cli.StringFlag{
Name: FlagKeyspace,
Value: "temporal",
Usage: "cassandra keyspace",
},
cli.BoolFlag{
Name: FlagEnableTLS,
Usage: "enable TLS over cassandra connection",
},
cli.StringFlag{
Name: FlagTLSCertPath,
Usage: "cassandra tls client cert path (tls must be enabled)",
},
cli.StringFlag{
Name: FlagTLSKeyPath,
Usage: "cassandra tls client key path (tls must be enabled)",
},
cli.StringFlag{
Name: FlagTLSCaPath,
Usage: "cassandra tls client ca path (tls must be enabled)",
},
cli.BoolFlag{
Name: FlagTLSEnableHostVerification,
Usage: "cassandra tls verify hostname and server cert (tls must be enabled)",
},
}
}
4 changes: 2 additions & 2 deletions tools/cli/persistenceUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ func CreateDefaultDBConfig(c *cli.Context) (config.DataStore, error) {

if engine == cassandraDBType {
defaultConfig := &config.Cassandra{
Hosts: getRequiredOption(c, FlagDBAddress),
Hosts: c.String(FlagDBAddress),
Port: c.Int(FlagDBPort),
User: c.String(FlagUsername),
Password: c.String(FlagPassword),
Keyspace: getRequiredOption(c, FlagKeyspace),
Keyspace: c.String(FlagKeyspace),
}

if c.Bool(FlagEnableTLS) {
Expand Down