github.com/ydb-platform/ydb-go-sdk/v3@v3.89.2/internal/grpcwrapper/rawtopic/describe_topic.go (about)

     1  package rawtopic
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Topic"
     8  
     9  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/clone"
    10  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawscheme"
    11  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawtopic/rawtopiccommon"
    12  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/grpcwrapper/rawydb"
    13  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/operation"
    14  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
    15  )
    16  
    17  type DescribeTopicRequest struct {
    18  	OperationParams rawydb.OperationParams
    19  	Path            string
    20  }
    21  
    22  func (req *DescribeTopicRequest) ToProto() *Ydb_Topic.DescribeTopicRequest {
    23  	return &Ydb_Topic.DescribeTopicRequest{
    24  		OperationParams: req.OperationParams.ToProto(),
    25  		Path:            req.Path,
    26  	}
    27  }
    28  
    29  type DescribeTopicResult struct {
    30  	Operation rawydb.Operation
    31  
    32  	Self                              rawscheme.Entry
    33  	PartitioningSettings              PartitioningSettings
    34  	Partitions                        []PartitionInfo
    35  	RetentionPeriod                   time.Duration
    36  	RetentionStorageMB                int64
    37  	SupportedCodecs                   rawtopiccommon.SupportedCodecs
    38  	PartitionWriteSpeedBytesPerSecond int64
    39  	PartitionWriteBurstBytes          int64
    40  	Attributes                        map[string]string
    41  	Consumers                         []Consumer
    42  	MeteringMode                      MeteringMode
    43  }
    44  
    45  func (res *DescribeTopicResult) FromProto(response operation.Response) error {
    46  	if err := res.Operation.FromProtoWithStatusCheck(response.GetOperation()); err != nil {
    47  		return err
    48  	}
    49  
    50  	protoResult := &Ydb_Topic.DescribeTopicResult{}
    51  	if err := response.GetOperation().GetResult().UnmarshalTo(protoResult); err != nil {
    52  		return xerrors.WithStackTrace(fmt.Errorf("ydb: describe topic result failed on unmarshal grpc result: %w", err))
    53  	}
    54  
    55  	if err := res.Self.FromProto(protoResult.GetSelf()); err != nil {
    56  		return err
    57  	}
    58  
    59  	if err := res.PartitioningSettings.FromProto(protoResult.GetPartitioningSettings()); err != nil {
    60  		return err
    61  	}
    62  
    63  	protoPartitions := protoResult.GetPartitions()
    64  	res.Partitions = make([]PartitionInfo, len(protoPartitions))
    65  	for i, protoPartition := range protoPartitions {
    66  		res.Partitions[i].mustFromProto(protoPartition)
    67  	}
    68  
    69  	res.RetentionPeriod = protoResult.GetRetentionPeriod().AsDuration()
    70  	res.RetentionStorageMB = protoResult.GetRetentionStorageMb()
    71  
    72  	for _, v := range protoResult.GetSupportedCodecs().GetCodecs() {
    73  		res.SupportedCodecs = append(res.SupportedCodecs, rawtopiccommon.Codec(v))
    74  	}
    75  
    76  	res.PartitionWriteSpeedBytesPerSecond = protoResult.GetPartitionWriteSpeedBytesPerSecond()
    77  	res.PartitionWriteBurstBytes = protoResult.GetPartitionWriteBurstBytes()
    78  
    79  	res.Attributes = protoResult.GetAttributes()
    80  
    81  	res.Consumers = make([]Consumer, len(protoResult.GetConsumers()))
    82  	for i := range res.Consumers {
    83  		res.Consumers[i].MustFromProto(protoResult.GetConsumers()[i])
    84  	}
    85  
    86  	res.MeteringMode = MeteringMode(protoResult.GetMeteringMode())
    87  
    88  	return nil
    89  }
    90  
    91  type PartitionInfo struct {
    92  	PartitionID        int64
    93  	Active             bool
    94  	ChildPartitionIDs  []int64
    95  	ParentPartitionIDs []int64
    96  }
    97  
    98  func (pi *PartitionInfo) mustFromProto(proto *Ydb_Topic.DescribeTopicResult_PartitionInfo) {
    99  	pi.PartitionID = proto.GetPartitionId()
   100  	pi.Active = proto.GetActive()
   101  
   102  	pi.ChildPartitionIDs = clone.Int64Slice(proto.GetChildPartitionIds())
   103  	pi.ParentPartitionIDs = clone.Int64Slice(proto.GetParentPartitionIds())
   104  }