forked from hazelcast/hazelcast-commandline-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLC-19]:
\di
Command to List Indexes (hazelcast#292)
- Loading branch information
1 parent
1acb688
commit a4a16f6
Showing
16 changed files
with
488 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
$----------------------------------$ | ||
$ Map Name | Name | Attributes $ | ||
$----------------------------------$ | ||
$ default | my-index | [A] $ | ||
$----------------------------------$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
$Shortcut Commands:$ | ||
$\di List Indexes$ | ||
$\di MAPPING List Indexes for a specific mapping$ | ||
$\dm List mappings$ | ||
$\dm MAPPING Display information about a mapping$ | ||
$\dm+ MAPPING Describe a mapping$ | ||
$\exit Exit the shell$ | ||
$\help Display help for CLC commands$ | ||
$\help Display help for CLC commands$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package maps | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hazelcast/hazelcast-commandline-client/base/commands/object" | ||
"github.com/hazelcast/hazelcast-commandline-client/base/objects" | ||
"github.com/hazelcast/hazelcast-commandline-client/clc" | ||
"github.com/hazelcast/hazelcast-commandline-client/internal/output" | ||
"github.com/hazelcast/hazelcast-commandline-client/internal/plug" | ||
"github.com/hazelcast/hazelcast-commandline-client/internal/proto/codec" | ||
"github.com/hazelcast/hazelcast-commandline-client/internal/serialization" | ||
"github.com/hazelcast/hazelcast-go-client/types" | ||
) | ||
|
||
func Indexes(ctx context.Context, ec plug.ExecContext, mapName string) error { | ||
var mapNames []string | ||
if mapName != "" { | ||
mapNames = append(mapNames, mapName) | ||
} else { | ||
maps, err := objects.GetAll(ctx, ec, object.Map, false) | ||
if err != nil { | ||
return err | ||
} | ||
for _, mm := range maps { | ||
mapNames = append(mapNames, mm.Name) | ||
} | ||
} | ||
ci, err := ec.ClientInternal(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
resp, stop, err := ec.ExecuteBlocking(ctx, func(ctx context.Context, sp clc.Spinner) (any, error) { | ||
allIndexes := make(map[string][]types.IndexConfig) | ||
for _, mn := range mapNames { | ||
sp.SetText(fmt.Sprintf("Getting indexes of map %s", mn)) | ||
req := codec.EncodeMCGetMapConfigRequest(mn) | ||
// If member configurations are different, this may not work well, however it is nothing to do with CLC | ||
resp, err := ci.InvokeOnRandomTarget(ctx, req, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
_, _, _, _, _, _, _, _, _, _, globalIndexes := codec.DecodeMCGetMapConfigResponse(resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
allIndexes[mn] = globalIndexes | ||
} | ||
return allIndexes, nil | ||
}) | ||
stop() | ||
var rows []output.Row | ||
for mn, indexes := range resp.(map[string][]types.IndexConfig) { | ||
for _, index := range indexes { | ||
rows = append(rows, | ||
output.Row{ | ||
output.Column{ | ||
Name: "Map Name", | ||
Type: serialization.TypeString, | ||
Value: mn, | ||
}, output.Column{ | ||
Name: "Name", | ||
Type: serialization.TypeString, | ||
Value: index.Name, | ||
}, output.Column{ | ||
Name: "Attributes", | ||
Type: serialization.TypeStringArray, | ||
Value: index.Attributes, | ||
}}) | ||
} | ||
} | ||
return ec.AddOutputRows(ctx, rows...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package objects | ||
|
||
import ( | ||
"context" | ||
"sort" | ||
"strings" | ||
|
||
"github.com/hazelcast/hazelcast-commandline-client/clc" | ||
"github.com/hazelcast/hazelcast-commandline-client/internal/plug" | ||
"github.com/hazelcast/hazelcast-go-client/types" | ||
) | ||
|
||
func GetAll(ctx context.Context, ec plug.ExecContext, typeFilter string, showHidden bool) ([]types.DistributedObjectInfo, error) { | ||
ci, err := ec.ClientInternal(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
objs, stop, err := ec.ExecuteBlocking(ctx, func(ctx context.Context, sp clc.Spinner) (any, error) { | ||
sp.SetText("Getting distributed objects") | ||
return ci.Client().GetDistributedObjectsInfo(ctx) | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
stop() | ||
var r []types.DistributedObjectInfo | ||
typeFilter = strings.ToLower(typeFilter) | ||
for _, o := range objs.([]types.DistributedObjectInfo) { | ||
if !showHidden && (o.Name == "" || strings.HasPrefix(o.Name, "__")) { | ||
continue | ||
} | ||
if o.Name == "" { | ||
o.Name = "(no name)" | ||
} | ||
if typeFilter == "" { | ||
r = append(r, o) | ||
continue | ||
} | ||
if typeFilter == ShortType(o.ServiceName) { | ||
r = append(r, o) | ||
} | ||
} | ||
sort.Slice(r, func(i, j int) bool { | ||
// first sort by type, then name | ||
ri := r[i] | ||
rj := r[j] | ||
if ri.ServiceName < rj.ServiceName { | ||
return true | ||
} | ||
if ri.ServiceName > rj.ServiceName { | ||
return false | ||
} | ||
return ri.Name < rj.Name | ||
}) | ||
return r, nil | ||
} | ||
|
||
func ShortType(svcName string) string { | ||
s := strings.TrimSuffix(strings.TrimPrefix(svcName, "hz:impl:"), "Service") | ||
return strings.ToLower(s) | ||
} |
Oops, something went wrong.