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

Add namespace to search attributes operations requests #346

Merged
merged 1 commit into from
Feb 7, 2023
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
4 changes: 2 additions & 2 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func EnvProperty(c *cli.Context) error {

env, key := envKey(fullKey)

val := tctlConfig.EnvProperty(env, key)
val, _ := tctlConfig.EnvProperty(env, key)
fmt.Println(val)

return nil
Expand Down Expand Up @@ -148,7 +148,7 @@ func populateFlagsFunc(command *cli.Command, globalFlags []cli.Flag) func(ctx *c

for _, c := range ctx.Lineage() {
if !c.IsSet(name) {
value := tctlConfig.EnvProperty(tctlConfig.CurrentEnv, name)
value, _ := tctlConfig.EnvProperty(tctlConfig.CurrentEnv, name)
Copy link
Contributor

Choose a reason for hiding this comment

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

oh i wouldn't really upgrade tctl-kit since in the latest versions it has breaking changes (focusing on Temporal single binary). Though again i also wanted to completely remove tctl-next code from here so tctl-kit is not even imported. Just pushed the deprecation message #342

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@feedmeapples
What's the status of deprecating? I need to add this to next release of tctl to work with Server v1.20.
Can I merge this first?

Copy link
Contributor

Choose a reason for hiding this comment

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

currently there is a notice in --help text output. tctl next code is unlikely to be removed asap so approving the PR

if value != "" {
c.Set(name, value)
}
Expand Down
10 changes: 9 additions & 1 deletion cli/search_attribute_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ const (

// ListSearchAttributes lists search attributes
func ListSearchAttributes(c *cli.Context) error {
namespace := c.String(FlagNamespace)
client := cFactory.OperatorClient(c)
ctx, cancel := newContext(c)
defer cancel()

resp, err := client.ListSearchAttributes(ctx, &operatorservice.ListSearchAttributesRequest{})
resp, err := client.ListSearchAttributes(
ctx,
&operatorservice.ListSearchAttributesRequest{Namespace: namespace},
)
if err != nil {
return fmt.Errorf("unable to list search attributes: %w", err)
}
Expand Down Expand Up @@ -75,6 +79,7 @@ func ListSearchAttributes(c *cli.Context) error {

// AddSearchAttributes to add search attributes
func AddSearchAttributes(c *cli.Context) error {
namespace := c.String(FlagNamespace)
names := c.StringSlice(FlagName)
typeStrs := c.StringSlice(FlagType)

Expand Down Expand Up @@ -125,6 +130,7 @@ func AddSearchAttributes(c *cli.Context) error {

request := &operatorservice.AddSearchAttributesRequest{
SearchAttributes: searchAttributes,
Namespace: namespace,
}

ctx, cancel = newContextWithTimeout(c, addSearchAttributesTimeout)
Expand All @@ -139,6 +145,7 @@ func AddSearchAttributes(c *cli.Context) error {

// RemoveSearchAttributes to add search attributes
func RemoveSearchAttributes(c *cli.Context) error {
namespace := c.String(FlagNamespace)
names := c.StringSlice(FlagName)

promptMsg := fmt.Sprintf(
Expand All @@ -154,6 +161,7 @@ func RemoveSearchAttributes(c *cli.Context) error {
defer cancel()
request := &operatorservice.RemoveSearchAttributesRequest{
SearchAttributes: names,
Namespace: namespace,
}

_, err := client.RemoveSearchAttributes(ctx, request)
Expand Down
2 changes: 1 addition & 1 deletion cli_curr/adminCommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ func AdminListGossipMembers(c *cli.Context) {
}

members := response.MembershipInfo.Rings
if roleFlag != primitives.AllServices {
if roleFlag != string(primitives.AllServices) {
all := members

members = members[:0]
Expand Down
26 changes: 13 additions & 13 deletions cli_curr/admin_cluster_search_attributes_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (

// AdminAddSearchAttributes to add search attributes
func AdminAddSearchAttributes(c *cli.Context) {
namespace := getRequiredGlobalOption(c, FlagNamespace)
names := getRequiredStringSliceOption(c, FlagName)
typeStrs := getRequiredStringSliceOption(c, FlagType)

Expand All @@ -54,7 +55,7 @@ func AdminAddSearchAttributes(c *cli.Context) {
}

adminClient := cFactory.AdminClient(c)
existingSearchAttributes, err := getSearchAttributes(c, adminClient)
existingSearchAttributes, err := getSearchAttributes(c, adminClient, namespace)
if err != nil {
ErrorAndExit("Unable to get existing search attributes.", err)
}
Expand Down Expand Up @@ -105,6 +106,7 @@ func AdminAddSearchAttributes(c *cli.Context) {
SearchAttributes: searchAttributes,
IndexName: c.String(FlagElasticsearchIndex),
SkipSchemaUpdate: c.Bool(FlagSkipSchemaUpdate),
Namespace: namespace,
}

ctx, cancel := newContextWithTimeout(c, addSearchAttributesTimeout)
Expand All @@ -114,16 +116,12 @@ func AdminAddSearchAttributes(c *cli.Context) {
ErrorAndExit("Unable to add search attributes.", err)
}

resp, err := getSearchAttributes(c, adminClient)
if err != nil {
ErrorAndExit("Search attributes have been added successfully but there was an error while reading them back.", err)
}
printSearchAttributesResponse(resp, c.String(FlagElasticsearchIndex))
color.HiGreen("Search attributes have been added successfully.")
}

// AdminRemoveSearchAttributes to add search attributes
func AdminRemoveSearchAttributes(c *cli.Context) {
namespace := getRequiredGlobalOption(c, FlagNamespace)
names := getRequiredStringSliceOption(c, FlagName)

// ask user for confirmation
Expand All @@ -139,25 +137,22 @@ func AdminRemoveSearchAttributes(c *cli.Context) {
request := &adminservice.RemoveSearchAttributesRequest{
SearchAttributes: names,
IndexName: c.String(FlagElasticsearchIndex),
Namespace: namespace,
}

_, err := adminClient.RemoveSearchAttributes(ctx, request)
if err != nil {
ErrorAndExit("Unable to remove search attributes.", err)
}

resp, err := getSearchAttributes(c, adminClient)
if err != nil {
ErrorAndExit("Search attributes have been removed successfully but there was an error while reading them back.", err)
}
printSearchAttributesResponse(resp, c.String(FlagElasticsearchIndex))
color.HiGreen("Search attributes have been removed successfully.")
}

// AdminGetSearchAttributes to print search attributes
func AdminGetSearchAttributes(c *cli.Context) {
namespace := getRequiredGlobalOption(c, FlagNamespace)
adminClient := cFactory.AdminClient(c)
resp, err := getSearchAttributes(c, adminClient)
resp, err := getSearchAttributes(c, adminClient, namespace)
if err != nil {
ErrorAndExit("Unable to get search attributes.", err)
}
Expand All @@ -168,11 +163,16 @@ func AdminGetSearchAttributes(c *cli.Context) {
printSearchAttributesResponse(resp, c.String(FlagElasticsearchIndex))
}

func getSearchAttributes(c *cli.Context, adminClient adminservice.AdminServiceClient) (*adminservice.GetSearchAttributesResponse, error) {
func getSearchAttributes(
c *cli.Context,
adminClient adminservice.AdminServiceClient,
namespace string,
) (*adminservice.GetSearchAttributesResponse, error) {
ctx, cancel := newContext(c)
defer cancel()
request := &adminservice.GetSearchAttributesRequest{
IndexName: c.String(FlagElasticsearchIndex),
Namespace: namespace,
}
return adminClient.GetSearchAttributes(ctx, request)
}
Expand Down
15 changes: 9 additions & 6 deletions cli_curr/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,15 @@ func (s *cliAppSuite) TestAdminAddSearchAttributes() {
SearchAttributes: map[string]enumspb.IndexedValueType{
"testKey": enumspb.INDEXED_VALUE_TYPE_KEYWORD,
},
Namespace: cliTestNamespace,
}
s.serverAdminClient.EXPECT().AddSearchAttributes(gomock.Any(), request)

getRequest := &adminservice.GetSearchAttributesRequest{}
getRequest := &adminservice.GetSearchAttributesRequest{
Namespace: cliTestNamespace,
}
getResponse := &adminservice.GetSearchAttributesResponse{}
s.serverAdminClient.EXPECT().GetSearchAttributes(gomock.Any(), getRequest).Return(getResponse, nil).Times(2)
s.serverAdminClient.EXPECT().GetSearchAttributes(gomock.Any(), getRequest).Return(getResponse, nil)

err := s.app.Run([]string{"", "--auto_confirm", "--ns", cliTestNamespace, "admin", "cl", "asa", "--name", "testKey", "--type", "keyword"})
s.Nil(err)
Expand All @@ -589,18 +592,18 @@ func (s *cliAppSuite) TestAdminAddSearchAttributes() {
func (s *cliAppSuite) TestAdminRemoveSearchAttributes() {
request := &adminservice.RemoveSearchAttributesRequest{
SearchAttributes: []string{"testKey"},
Namespace: cliTestNamespace,
}
s.serverAdminClient.EXPECT().RemoveSearchAttributes(gomock.Any(), request)

getRequest := &adminservice.GetSearchAttributesRequest{}
s.serverAdminClient.EXPECT().GetSearchAttributes(gomock.Any(), getRequest)

err := s.app.Run([]string{"", "--auto_confirm", "--ns", cliTestNamespace, "admin", "cl", "rsa", "--name", "testKey"})
s.Nil(err)
}

func (s *cliAppSuite) TestAdminGetSearchAttributes() {
getRequest := &adminservice.GetSearchAttributesRequest{}
getRequest := &adminservice.GetSearchAttributesRequest{
Namespace: cliTestNamespace,
}
s.serverAdminClient.EXPECT().GetSearchAttributes(gomock.Any(), getRequest)

err := s.app.Run([]string{"", "--ns", cliTestNamespace, "admin", "cl", "gsa"})
Expand Down
27 changes: 5 additions & 22 deletions cli_curr/namespaceCommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,13 @@ import (
"go.temporal.io/api/serviceerror"
"go.temporal.io/api/workflowservice/v1"

"go.temporal.io/server/common/namespace"
"go.temporal.io/server/common/primitives/timestamp"
)

type (
namespaceCLIImpl struct {
// used when making RPC call to frontend service``
frontendClient workflowservice.WorkflowServiceClient

// act as admin to modify namespace in DB directly
namespaceHandler namespace.Handler
}
)

Expand All @@ -58,21 +54,8 @@ func newNamespaceCLI(
c *cli.Context,
isAdminMode bool,
) *namespaceCLIImpl {

var frontendClient workflowservice.WorkflowServiceClient
var namespaceHandler namespace.Handler
if !isAdminMode {
frontendClient = initializeFrontendClient(c)
} else {
var err error
namespaceHandler, err = initializeAdminNamespaceHandler(c)
if err != nil {
ErrorAndExit("Unable to initialize admin namespace handler", err)
}
}
return &namespaceCLIImpl{
frontendClient: frontendClient,
namespaceHandler: namespaceHandler,
frontendClient: initializeFrontendClient(c),
}
}

Expand Down Expand Up @@ -433,7 +416,7 @@ func (d *namespaceCLIImpl) listNamespaces(
return d.frontendClient.ListNamespaces(ctx, request)
}

return d.namespaceHandler.ListNamespaces(ctx, request)
return d.frontendClient.ListNamespaces(ctx, request)
}

func (d *namespaceCLIImpl) registerNamespace(
Expand All @@ -445,7 +428,7 @@ func (d *namespaceCLIImpl) registerNamespace(
return err
}

_, err := d.namespaceHandler.RegisterNamespace(ctx, request)
_, err := d.frontendClient.RegisterNamespace(ctx, request)
return err
}

Expand All @@ -458,7 +441,7 @@ func (d *namespaceCLIImpl) updateNamespace(
return err
}

_, err := d.namespaceHandler.UpdateNamespace(ctx, request)
_, err := d.frontendClient.UpdateNamespace(ctx, request)
return err
}

Expand All @@ -471,7 +454,7 @@ func (d *namespaceCLIImpl) describeNamespace(
return d.frontendClient.DescribeNamespace(ctx, request)
}

resp, err := d.namespaceHandler.DescribeNamespace(ctx, request)
resp, err := d.frontendClient.DescribeNamespace(ctx, request)
return resp, err
}

Expand Down
Loading