Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making sure that the parameters provided in the metadatalocation getting passed to the nfs provider #144

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions controllers/backup/backupmetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (ctrl *controller) processMetadataBackup(backup *kahuapi.Backup) (*kahuapi.
}

provider := metaLocation.Spec.ProviderName
parameters := metaLocation.Spec.Config
ctrl.logger.Infof("Preparing backup request for Provider:%s", provider)
prepareBackupReq := ctrl.prepareBackupRequest(backup)

Expand All @@ -71,7 +72,7 @@ func (ctrl *controller) processMetadataBackup(backup *kahuapi.Backup) (*kahuapi.
}

// Initialize hooks
err = ctrl.runBackup(prepareBackupReq, backupClient)
err = ctrl.runBackup(prepareBackupReq, backupClient, parameters)
if err != nil {
prepareBackupReq.Status.State = kahuapi.BackupStateFailed
} else {
Expand Down Expand Up @@ -127,14 +128,15 @@ func (ctrl *controller) getResultant(backup *PrepareBackup) []string {
}

func (ctrl *controller) runBackup(backup *PrepareBackup,
backupClient metaservice.MetaService_BackupClient) (returnErr error) {
backupClient metaservice.MetaService_BackupClient, paramteres map[string]string) (returnErr error) {
ctrl.logger.Infoln("Starting to run backup")
var backupStatus = []string{}

err := backupClient.Send(&metaservice.BackupRequest{
Backup: &metaservice.BackupRequest_Identifier{
Identifier: &metaservice.BackupIdentifier{
BackupHandle: backup.Name,
Parameters: paramteres,
},
},
})
Expand Down Expand Up @@ -277,11 +279,23 @@ func (ctrl *controller) deleteMetadataBackup(backup *kahuapi.Backup) error {
return nil
}

// Validate the Metadatalocation
locationName := backup.Spec.MetadataLocation
backup.Status.ValidationErrors = []string{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required to update ValidationErrors

ctrl.logger.Infof("Preparing backup for backup location: %s ", locationName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the delete flow, update accordingly

metaLocation, err := ctrl.backupLocationLister.Get(locationName)
if err != nil {
ctrl.logger.Errorf("failed to validate backup location, reason: %s", err)
return err
}
parameters := metaLocation.Spec.Config
deleteRequest := &metaservice.DeleteRequest{
Id: &metaservice.BackupIdentifier{
BackupHandle: backup.Name,
Parameters: parameters,
},
}
ctrl.logger.Infof("8888paramteres in deleteMetadataBackup*******:%v", parameters)

metaservice, grpcConn, err := ctrl.fetchMetaServiceClient(backup.Spec.MetadataLocation)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions providerframework/metaservice/backuprespository/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

type BackupRepository interface {
Upload(filePath string) error
Upload(filePath string, attributes map[string]string) error
Download(fileID string, attributes map[string]string) (string, error)
Delete(filePath string, attributes map[string]string) error
}
Expand Down Expand Up @@ -68,7 +68,7 @@ func NewBackupRepository(backupRepositoryAddress string) (BackupRepository, grpc
}, grpcConnection, nil
}

func (repo *backupRepository) Upload(filePath string) error {
func (repo *backupRepository) Upload(filePath string, attributes map[string]string) error {
log.Infof("Archive file path %s", filePath)

file, err := os.Open(filePath)
Expand All @@ -87,12 +87,14 @@ func (repo *backupRepository) Upload(filePath string) error {
Data: &pb.UploadRequest_Info{
Info: &pb.UploadRequest_FileInfo{
FileIdentifier: path.Base(filePath),
Attributes: attributes,
},
},
})
if err != nil {
return err
}
log.Infof("88888attributes are:8888 %v", attributes)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do change the logs properly.....don't add 888 etc . please do change this all the places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


reader := bufio.NewReader(file)
buffer := make([]byte, 1024)
Expand Down Expand Up @@ -130,7 +132,7 @@ func (repo *backupRepository) Download(fileID string, attributes map[string]stri
FileIdentifier: fileID,
Attributes: attributes,
}

log.Infof("88888attributes are in Download :8888 %v", attributes)
repoClient, err := repo.client.Download(context.Background(), downloadReq)
if err != nil {
return "", err
Expand Down Expand Up @@ -187,7 +189,7 @@ func (repo *backupRepository) Delete(fileID string, attributes map[string]string
FileIdentifier: fileID,
Attributes: attributes,
}

log.Infof("88888attributes are in Delete :8888 %v", attributes)
IsBackupFileExist, err := repo.client.ObjectExists(context.Background(), objectExistsReq)
if err != nil || IsBackupFileExist == nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (suite *ClientTestSuite) AfterTest(suiteName, testName string) {
}

func (suite *ClientTestSuite) TestUploadInvalidPath() {
err := suite.repo.Upload(suite.filePath)
err := suite.repo.Upload(suite.filePath, map[string]string{})
assert.NotNil(suite.T(), err)
}

Expand All @@ -131,7 +131,7 @@ func (suite *ClientTestSuite) TestDownloadFail() {
}

func (suite *ClientTestSuite) TestUploadValid() {
err := suite.repo.Upload(suite.filePath)
err := suite.repo.Upload(suite.filePath, map[string]string{})
assert.Nil(suite.T(), err)

}
Expand Down
20 changes: 10 additions & 10 deletions providerframework/metaservice/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ func NewMetaServiceServer(ctx context.Context,
}

func (server *metaServer) Backup(service pb.MetaService_BackupServer) error {
log.Info("Backup Called .... ")

backupHandle, err := getBackupHandle(service)
log.Info("Backup Called .... ******")
backupHandle, parameters, err := getBackupHandleAndParameters(service)
if err != nil {
return status.Errorf(codes.Unknown, "failed to get backup handle during backup")
return status.Errorf(codes.Unknown, "failed to get backupHandle and parameters during backup")
}
log.Infof("***parameters are******%v", parameters)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be deleted


archiveFileName := backupHandle + archiveFileFormat

Expand Down Expand Up @@ -105,7 +105,7 @@ func (server *metaServer) Backup(service pb.MetaService_BackupServer) error {
}

// upload backup to backup-location
err = server.backupRepo.Upload(archiveFile)
err = server.backupRepo.Upload(archiveFile, parameters)
if err != nil {
log.Errorf("failed to upload backup. %s", err)
return status.Errorf(codes.Internal, "failed to upload backup. %s", err)
Expand Down Expand Up @@ -133,20 +133,20 @@ func (server *metaServer) Delete(ctx context.Context, req *pb.DeleteRequest) (*p
return empty, err
}

func getBackupHandle(service pb.MetaService_BackupServer) (string, error) {
func getBackupHandleAndParameters(service pb.MetaService_BackupServer) (string, map[string]string, error) {
backupRequest, err := service.Recv()
if err != nil {
return "", status.Errorf(codes.Unknown, "failed with error %s", err)
return "", map[string]string{}, status.Errorf(codes.Unknown, "failed with error %s", err)
}

identifier := backupRequest.GetIdentifier()
if identifier == nil {
return "", status.Errorf(codes.InvalidArgument, "first request is not backup identifier")
return "", map[string]string{}, status.Errorf(codes.InvalidArgument, "first request is not backup identifier")
}

// use backup handle name for file
parameters := identifier.GetParameters()
backupHandle := identifier.GetBackupHandle()
return backupHandle, nil
return backupHandle, parameters, nil
}

func deleteFile(filePath string) {
Expand Down
9 changes: 9 additions & 0 deletions providers/nfs/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func (server *nfsServer) Upload(service pb.MetaBackup_UploadServer) error {
if fileId == "" {
return status.Error(codes.Internal, "upload failed, invalid file identifier")
}
attributes := fileInfo.GetAttributes()
log.Infof("******attributes are***** %v", attributes)

fileName := server.options.DataPath + "/" + fileId
file, err := os.Create(fileName)
Expand Down Expand Up @@ -165,8 +167,11 @@ func (server *nfsServer) Download(request *pb.DownloadRequest,
if fileId == "" {
return status.Error(codes.InvalidArgument, "download file id is empty")
}
attributes := request.GetAttributes()
log.Infof("******attributes in Download are***** %v", attributes)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine this with subsequent log


log.Printf("Download file id %v", fileId)

fileName := filepath.Join(server.options.DataPath, fileId)
file, err := os.Open(fileName)
if err != nil {
Expand Down Expand Up @@ -226,6 +231,10 @@ func (server *nfsServer) Delete(ctxt context.Context,
log.Info("Delete Called ...")

fileId := request.GetFileIdentifier()

attributes := request.GetAttributes()
log.Infof("******attributes in Delete are***** %v", attributes)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine this with subsequent log


empty := pb.Empty{}
log.Printf("file to delete %v", fileId)
fileName := server.options.DataPath + "/" + fileId
Expand Down