-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
- Loading branch information
Showing
4 changed files
with
131 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package models | ||
|
||
import ( | ||
etcdpbv2 "github.com/milvus-io/birdwatcher/proto/v2.2/etcdpb" | ||
) | ||
|
||
// Database birdwatcher model for database entity. | ||
type Database struct { | ||
ID int64 | ||
Name string | ||
TenantID string | ||
State DatabaseState | ||
key string | ||
CreatedTime uint64 | ||
} | ||
|
||
type DatabaseState int32 | ||
|
||
const ( | ||
DatabaseStateDatabaseUnknown DatabaseState = 0 | ||
DatabaseStateDatabaseCreated DatabaseState = 1 | ||
DatabaseStateDatabaseCreating DatabaseState = 2 | ||
DatabaseStateDatabaseDropping DatabaseState = 3 | ||
DatabaseStateDatabaseDropped DatabaseState = 4 | ||
) | ||
|
||
var DatabaseStatename = map[int32]string{ | ||
0: "DatabaseUnknown", | ||
1: "DatabaseCreated", | ||
2: "DatabaseCreating", | ||
3: "DatabaseDropping", | ||
4: "DatabaseDropped", | ||
} | ||
|
||
var DatabaseStatevalue = map[string]int32{ | ||
"DatabaseUnknown": 0, | ||
"DatabaseCreated": 1, | ||
"DatabaseCreating": 2, | ||
"DatabaseDropping": 3, | ||
"DatabaseDropped": 4, | ||
} | ||
|
||
func (x DatabaseState) String() string { | ||
return EnumName(DatabaseStatename, int32(x)) | ||
} | ||
|
||
func NewDatabase(info *etcdpbv2.DatabaseInfo, key string) *Database { | ||
return &Database{ | ||
ID: info.GetId(), | ||
Name: info.GetName(), | ||
TenantID: info.GetTenantId(), | ||
State: DatabaseState(info.GetState()), | ||
CreatedTime: info.GetCreatedTime(), | ||
} | ||
} |
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,33 @@ | ||
package common | ||
|
||
import ( | ||
"context" | ||
"path" | ||
|
||
"github.com/milvus-io/birdwatcher/models" | ||
"github.com/milvus-io/birdwatcher/proto/v2.2/etcdpb" | ||
"github.com/samber/lo" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
) | ||
|
||
const ( | ||
// DataBaseMetaPrefix is prefix for rootcoord database meta. | ||
DataBaseMetaPrefix = `root-coord/database/db-info` | ||
) | ||
|
||
// ListDatabase returns all database info from etcd meta converted to models. | ||
func ListDatabase(ctx context.Context, cli clientv3.KV, basePath string) ([]*models.Database, error) { | ||
prefix := path.Join(basePath, DataBaseMetaPrefix) | ||
dbs, keys, err := ListProtoObjects(ctx, cli, prefix, func(*etcdpb.DatabaseInfo) bool { | ||
return true | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
result := lo.Map(dbs, func(db etcdpb.DatabaseInfo, idx int) *models.Database { | ||
return models.NewDatabase(&db, keys[idx]) | ||
}) | ||
return result, nil | ||
} |
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,41 @@ | ||
package show | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/milvus-io/birdwatcher/models" | ||
"github.com/milvus-io/birdwatcher/states/etcd/common" | ||
"github.com/spf13/cobra" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
) | ||
|
||
// DatabaseCommand returns show database comand. | ||
func DatabaseCommand(cli clientv3.KV, basePath string) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "database", | ||
Short: "display Database info from rootcoord meta", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
dbs, err := common.ListDatabase(ctx, cli, basePath) | ||
if err != nil { | ||
fmt.Println("failed to list database info", err.Error()) | ||
return | ||
} | ||
|
||
for _, db := range dbs { | ||
printDatabaseInfo(db) | ||
} | ||
|
||
fmt.Printf("--- Total Database(s): %d\n", len(dbs)) | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
func printDatabaseInfo(db *models.Database) { | ||
fmt.Println("=============================") | ||
fmt.Printf("ID: %d\tName: %s\n", db.ID, db.Name) | ||
fmt.Printf("TenantID: %s\t State: %s\n", db.TenantID, db.State.String()) | ||
} |