Skip to content

Commit

Permalink
feat: fetch info for requested backup runs (#112)
Browse files Browse the repository at this point in the history
* fix: add mapstructure to telemetryconfig

* feat: support replay and backup for all downstream namespaces

* feat: add ignored jobs/resources list to replay and backup dry run

* refactor: remove GetAllWithNamespace and reuse GetJobNamespaces

* refactor: change backup result table name postfix to use timestamp instead of uuid

* refactor: revert backup table to use uuid suffix

* refactor: backup table name to use time suffix and add additional infos in list

* feat: add backup detail subcommand

* feat: store replay ignore downstream option and show in replay list

* refactor: remove ignore downstream usage from replay

* refactor: rename backup detail and list method in datastore, catch error in backup detail

* refactor: rename to GetBackup and CreateBackup
  • Loading branch information
arinda-arif authored Jan 4, 2022
1 parent 12d3877 commit 4e7c152
Show file tree
Hide file tree
Showing 27 changed files with 2,856 additions and 1,494 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ NAME = "github.com/odpf/optimus"
LAST_COMMIT := $(shell git rev-parse --short HEAD)
LAST_TAG := "$(shell git rev-list --tags --max-count=1)"
OPMS_VERSION := "$(shell git describe --tags ${LAST_TAG})-next"
PROTON_COMMIT := "2e1bc719ec2382cd5c135b27b889224b71b06785"
PROTON_COMMIT := "ae233f3d942e8e72e2ec3f66ed404c57390d37fb"

all: build

Expand Down
59 changes: 56 additions & 3 deletions api/handler/v1/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ func (sv *RuntimeServiceServer) ListReplays(ctx context.Context, req *pb.ListRep
StartDate: timestamppb.New(replaySpec.StartDate),
EndDate: timestamppb.New(replaySpec.EndDate),
State: replaySpec.Status,
Config: replaySpec.Config,
CreatedAt: timestamppb.New(replaySpec.CreatedAt),
})
}
Expand Down Expand Up @@ -1050,7 +1051,7 @@ func (sv *RuntimeServiceServer) BackupDryRun(ctx context.Context, req *pb.Backup
}, nil
}

func (sv *RuntimeServiceServer) Backup(ctx context.Context, req *pb.BackupRequest) (*pb.BackupResponse, error) {
func (sv *RuntimeServiceServer) CreateBackup(ctx context.Context, req *pb.CreateBackupRequest) (*pb.CreateBackupResponse, error) {
projectSpec, err := sv.getProjectSpec(ctx, req.ProjectName)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1096,7 +1097,7 @@ func (sv *RuntimeServiceServer) Backup(ctx context.Context, req *pb.BackupReques
return nil, status.Errorf(codes.Internal, "error while doing backup: %v", err)
}

return &pb.BackupResponse{
return &pb.CreateBackupResponse{
Urn: result.Resources,
IgnoredResources: result.IgnoredResources,
}, nil
Expand All @@ -1108,7 +1109,7 @@ func (sv *RuntimeServiceServer) ListBackups(ctx context.Context, req *pb.ListBac
return nil, err
}

results, err := sv.resourceSvc.ListBackupResources(ctx, projectSpec, req.DatastoreName)
results, err := sv.resourceSvc.ListResourceBackups(ctx, projectSpec, req.DatastoreName)
if err != nil {
return nil, status.Errorf(codes.Internal, "error while getting backup list: %v", err)
}
Expand All @@ -1120,13 +1121,65 @@ func (sv *RuntimeServiceServer) ListBackups(ctx context.Context, req *pb.ListBac
ResourceName: result.Resource.Name,
CreatedAt: timestamppb.New(result.CreatedAt),
Description: result.Description,
Config: result.Config,
})
}
return &pb.ListBackupsResponse{
Backups: backupList,
}, nil
}

func (sv *RuntimeServiceServer) GetBackup(ctx context.Context, req *pb.GetBackupRequest) (*pb.GetBackupResponse, error) {
projectSpec, err := sv.getProjectSpec(ctx, req.ProjectName)
if err != nil {
return nil, err
}

uuid, err := uuid.Parse(req.Id)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "error while parsing backup ID: %v", err)
}

backupDetail, err := sv.resourceSvc.GetResourceBackup(ctx, projectSpec, req.DatastoreName, uuid)
if err != nil {
if err == store.ErrResourceNotFound {
return nil, status.Errorf(codes.NotFound, "%s: backup with ID %s not found", err.Error(), uuid.String())
}
return nil, status.Errorf(codes.Internal, "error while getting backup detail: %v", err)
}

var results []string
for _, result := range backupDetail.Result {
backupResult, ok := result.(map[string]interface{})
if !ok {
return nil, status.Errorf(codes.Internal, "error while parsing backup result: %v", ok)
}

backupURN, ok := backupResult[models.BackupSpecKeyURN]
if !ok {
return nil, status.Errorf(codes.Internal, "%s is not found in backup result", models.BackupSpecKeyURN)
}

backupURNStr, ok := backupURN.(string)
if !ok {
return nil, status.Errorf(codes.Internal, "invalid backup URN: %v", backupURN)
}

results = append(results, backupURNStr)
}

return &pb.GetBackupResponse{
Spec: &pb.BackupSpec{
Id: backupDetail.ID.String(),
ResourceName: backupDetail.Resource.Name,
CreatedAt: timestamppb.New(backupDetail.CreatedAt),
Description: backupDetail.Description,
Config: backupDetail.Config,
},
Urn: results,
}, nil
}

func (sv *RuntimeServiceServer) RunJob(ctx context.Context, req *pb.RunJobRequest) (*pb.RunJobResponse, error) {
// create job run in db
projSpec, err := sv.projectRepoFactory.New().GetByName(ctx, req.ProjectName)
Expand Down
Loading

0 comments on commit 4e7c152

Please sign in to comment.