This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch property
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit 2f115a84eab6a6185a1ed57117caf8fcc2007604
Author: Gao Hongtao <[email protected]>
AuthorDate: Sun Jul 2 07:21:00 2023 +0000

    List all properties in a group
    
    Signed-off-by: Gao Hongtao <[email protected]>
---
 CHANGES.md                                |  6 +++++
 api/proto/banyandb/common/v1/common.proto |  2 +-
 api/proto/banyandb/property/v1/rpc.proto  |  3 +++
 bydbctl/internal/cmd/property.go          |  6 ++++-
 bydbctl/internal/cmd/property_test.go     | 40 ++++++++++++++++++++++++++++++-
 bydbctl/internal/cmd/root.go              |  8 +++++++
 test/integration/other/property_test.go   |  9 ++++++-
 7 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 429c2781..4a24c8aa 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -6,6 +6,12 @@ Release Notes.
 
 ### Features
 
+- List all properties in a group.
+
+## 0.4.0
+
+### Features
+
 - Add TSDB concept document.
 - [UI] Add YAML editor for inputting query criteria.
 - Refactor TopN to support `NULL` group while keeping seriesID from the source 
measure.
diff --git a/api/proto/banyandb/common/v1/common.proto 
b/api/proto/banyandb/common/v1/common.proto
index fb8572f3..16fe8e67 100644
--- a/api/proto/banyandb/common/v1/common.proto
+++ b/api/proto/banyandb/common/v1/common.proto
@@ -36,7 +36,7 @@ message Metadata {
   // group contains a set of options, like retention policy, max
   string group = 1;
   // name of the entity
-  string name = 2 [(validate.rules).string.min_len = 1];
+  string name = 2;
   uint32 id = 3;
   // readonly. create_revision is the revision of last creation on this key.
   int64 create_revision = 4;
diff --git a/api/proto/banyandb/property/v1/rpc.proto 
b/api/proto/banyandb/property/v1/rpc.proto
index 10a09c78..8151c8bc 100644
--- a/api/proto/banyandb/property/v1/rpc.proto
+++ b/api/proto/banyandb/property/v1/rpc.proto
@@ -102,6 +102,9 @@ service PropertyService {
   rpc List(ListRequest) returns (ListResponse) {
     option (google.api.http) = {
       get: "/v1/property/lists/{container.group}/{container.name}/{ids}/{tags}"
+      additional_bindings {
+        get: "/v1/property/lists/{container.group}"
+      }
     };
   }
 }
diff --git a/bydbctl/internal/cmd/property.go b/bydbctl/internal/cmd/property.go
index 47fa68fd..27c8420d 100644
--- a/bydbctl/internal/cmd/property.go
+++ b/bydbctl/internal/cmd/property.go
@@ -35,6 +35,7 @@ var (
        propertySchemaPathWithoutTagParams  = propertySchemaPath + 
"/{group}/{name}/{id}"
        propertySchemaPathWithTagParams     = propertySchemaPath + 
"/{group}/{name}/{id}/{tag}"
        propertyListSchemaPathWithTagParams = propertySchemaPath + 
"/lists/{group}/{name}/{ids}/{tags}"
+       propertyListSchemaPath              = propertySchemaPath + 
"/lists/{group}"
 )
 
 func newPropertyCmd() *cobra.Command {
@@ -103,12 +104,15 @@ func newPropertyCmd() *cobra.Command {
                Short:   "List properties",
                RunE: func(_ *cobra.Command, _ []string) (err error) {
                        return rest(parseFromFlags, func(request request) 
(*resty.Response, error) {
+                               if len(request.name) == 0 {
+                                       return 
request.req.SetPathParam("group", 
request.group).Get(getPath(propertyListSchemaPath))
+                               }
                                return request.req.SetPathParam("name", 
request.name).SetPathParam("group", request.group).
                                        SetPathParam("ids", 
request.ids()).SetPathParam("tags", 
request.tags()).Get(getPath(propertyListSchemaPathWithTagParams))
                        }, yamlPrinter)
                },
        }
-       bindNameFlag(listCmd)
+       listCmd.Flags().StringVarP(&name, "name", "n", "", "the name of the 
resource")
        listCmd.Flags().StringArrayVarP(&ids, "ids", "", nil, "id selector")
        listCmd.Flags().StringArrayVarP(&tags, "tags", "t", nil, "tag selector")
 
diff --git a/bydbctl/internal/cmd/property_test.go 
b/bydbctl/internal/cmd/property_test.go
index 614375d1..191591c6 100644
--- a/bydbctl/internal/cmd/property_test.go
+++ b/bydbctl/internal/cmd/property_test.go
@@ -201,7 +201,44 @@ tags:
                Expect(err).To(MatchError("rpc error: code = NotFound desc = 
banyandb: resource not found"))
        })
 
-       It("list property", func() {
+       It("list all properties", func() {
+               // create another property for list operation
+               rootCmd.SetArgs([]string{"property", "apply", "-f", "-"})
+               rootCmd.SetIn(strings.NewReader(`
+metadata:
+  container:
+    group: ui-template 
+    name: service
+  id: spring
+tags:
+  - key: content
+    value:
+      str:
+        value: bar
+  - key: state
+    value:
+      int:
+        value: 1
+`))
+               out := capturer.CaptureStdout(func() {
+                       err := rootCmd.Execute()
+                       Expect(err).NotTo(HaveOccurred())
+               })
+               Expect(out).To(ContainSubstring("created: true"))
+               Expect(out).To(ContainSubstring("tagsNum: 2"))
+               // list
+               rootCmd.SetArgs([]string{"property", "list", "-g", 
"ui-template"})
+               out = capturer.CaptureStdout(func() {
+                       cmd.ResetFlags()
+                       err := rootCmd.Execute()
+                       Expect(err).NotTo(HaveOccurred())
+               })
+               resp := new(propertyv1.ListResponse)
+               helpers.UnmarshalYAML([]byte(out), resp)
+               Expect(resp.Property).To(HaveLen(2))
+       })
+
+       It("list properties in a container", func() {
                // create another property for list operation
                rootCmd.SetArgs([]string{"property", "apply", "-f", "-"})
                rootCmd.SetIn(strings.NewReader(`
@@ -229,6 +266,7 @@ tags:
                // list
                rootCmd.SetArgs([]string{"property", "list", "-g", 
"ui-template", "-n", "service"})
                out = capturer.CaptureStdout(func() {
+                       cmd.ResetFlags()
                        err := rootCmd.Execute()
                        Expect(err).NotTo(HaveOccurred())
                })
diff --git a/bydbctl/internal/cmd/root.go b/bydbctl/internal/cmd/root.go
index 7c7a16e2..c7956d8c 100644
--- a/bydbctl/internal/cmd/root.go
+++ b/bydbctl/internal/cmd/root.go
@@ -42,6 +42,14 @@ var (
        }
 )
 
+// ResetFlags resets the flags.
+func ResetFlags() {
+       filePath = ""
+       name = ""
+       start = ""
+       end = ""
+}
+
 // Execute executes the root command.
 func Execute() error {
        return rootCmd.Execute()
diff --git a/test/integration/other/property_test.go 
b/test/integration/other/property_test.go
index d7ec7c66..79f8f38b 100644
--- a/test/integration/other/property_test.go
+++ b/test/integration/other/property_test.go
@@ -140,7 +140,14 @@ var _ = Describe("Property application", func() {
                Expect(conn.Close()).To(Succeed())
                deferFn()
        })
-       It("lists properties", func() {
+       It("lists properties in a group", func() {
+               got, err := client.List(context.Background(), 
&propertyv1.ListRequest{Container: &commonv1.Metadata{
+                       Group: "g",
+               }})
+               Expect(err).NotTo(HaveOccurred())
+               Expect(len(got.Property)).To(Equal(1))
+       })
+       It("lists properties in a container", func() {
                got, err := client.List(context.Background(), 
&propertyv1.ListRequest{Container: md.Container})
                Expect(err).NotTo(HaveOccurred())
                Expect(len(got.Property)).To(Equal(1))

Reply via email to