Skip to content

Commit

Permalink
feat: implement GetOperation (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
vovaspace authored Aug 20, 2024
1 parent e888635 commit a9c5147
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 35 deletions.
33 changes: 31 additions & 2 deletions cmd/ydbcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,37 @@ func (s *server) CancelOperation(ctx context.Context, request *pb.CancelOperatio
}

func (s *server) GetOperation(ctx context.Context, request *pb.GetOperationRequest) (*pb.Operation, error) {
//TODO implement me
panic("implement me")
xlog.Debug(ctx, "GetOperation", zap.String("request", request.String()))
requestId, err := types.ParseObjectId(request.GetId())
if err != nil {
return nil, fmt.Errorf("failed to parse uuid %s: %w", request.GetId(), err)
}
operations, err := s.driver.SelectOperations(
ctx, queries.NewReadTableQuery(
queries.WithTableName("Operations"),
queries.WithSelectFields(queries.AllOperationFields...),
queries.WithQueryFilters(
queries.QueryFilter{
Field: "id",
Values: []table_types.Value{table_types.UUIDValue(requestId)},
},
),
),
)
if err != nil {
xlog.Error(ctx, "can't select operations", zap.Error(err))
return nil, err
}
if len(operations) == 0 {
return nil, errors.New("no operation with such Id") // TODO: Permission denied?
}
// TODO: Need to check access to operation resource by operationID
if _, err := s.checkAuth(ctx, auth.PermissionBackupGet, operations[0].GetContainerId(), ""); err != nil {
return nil, err
}

xlog.Debug(ctx, "GetOperation", zap.String("operation", types.OperationToString(operations[0])))
return operations[0].Proto(), nil
}

func main() {
Expand Down
10 changes: 10 additions & 0 deletions internal/types/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ type OperationState string
type Operation interface {
GetId() ObjectID
SetId(id ObjectID)
GetContainerId() string
GetType() OperationType
SetType(t OperationType)
GetState() OperationState
Expand Down Expand Up @@ -132,6 +133,9 @@ func (o *TakeBackupOperation) GetId() ObjectID {
func (o *TakeBackupOperation) SetId(id ObjectID) {
o.Id = id
}
func (o *TakeBackupOperation) GetContainerId() string {
return o.ContainerID
}
func (o *TakeBackupOperation) GetType() OperationType {
return OperationTypeTB
}
Expand Down Expand Up @@ -186,6 +190,9 @@ func (o *RestoreBackupOperation) GetId() ObjectID {
func (o *RestoreBackupOperation) SetId(id ObjectID) {
o.Id = id
}
func (o *RestoreBackupOperation) GetContainerId() string {
return o.ContainerID
}
func (o *RestoreBackupOperation) GetType() OperationType {
return OperationTypeRB
}
Expand Down Expand Up @@ -240,6 +247,9 @@ func (o *GenericOperation) GetId() ObjectID {
func (o *GenericOperation) SetId(id ObjectID) {
o.Id = id
}
func (o *GenericOperation) GetContainerId() string {
return o.ContainerID
}
func (o *GenericOperation) GetType() OperationType {
return o.Type
}
Expand Down
60 changes: 29 additions & 31 deletions pkg/proto/ydbcp/v1alpha1/operation_service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/proto/ydbcp/v1alpha1/operation_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ message CancelOperationRequest {
}

message GetOperationRequest {
string operation_id = 1;
string id = 1;
}
2 changes: 1 addition & 1 deletion pkg/proto/ydbcp/v1alpha1/operation_service_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a9c5147

Please sign in to comment.