-
Notifications
You must be signed in to change notification settings - Fork 35
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
base: main
Are you sure you want to change the base?
Making sure that the parameters provided in the metadatalocation getting passed to the nfs provider #144
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
|
@@ -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 { | ||
|
@@ -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, | ||
}, | ||
}, | ||
}) | ||
|
@@ -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{} | ||
ctrl.logger.Infof("Preparing backup for backup location: %s ", locationName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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("paramteres in deleteMetadataBackup:%v", parameters) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed |
||
|
||
metaservice, grpcConn, err := ctrl.fetchMetaServiceClient(backup.Spec.MetadataLocation) | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
} | ||
|
@@ -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) | ||
|
@@ -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("attributes in upload are: %v", attributes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow log msg convention, applicable for other places as well |
||
|
||
reader := bufio.NewReader(file) | ||
buffer := make([]byte, 1024) | ||
|
@@ -130,7 +132,7 @@ func (repo *backupRepository) Download(fileID string, attributes map[string]stri | |
FileIdentifier: fileID, | ||
Attributes: attributes, | ||
} | ||
|
||
log.Infof("attributes are in Download : %v", attributes) | ||
repoClient, err := repo.client.Download(context.Background(), downloadReq) | ||
if err != nil { | ||
return "", err | ||
|
@@ -187,7 +189,7 @@ func (repo *backupRepository) Delete(fileID string, attributes map[string]string | |
FileIdentifier: fileID, | ||
Attributes: attributes, | ||
} | ||
|
||
log.Infof("attributes are in Delete :%v", attributes) | ||
IsBackupFileExist, err := repo.client.ObjectExists(context.Background(), objectExistsReq) | ||
if err != nil || IsBackupFileExist == nil { | ||
return err | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be deleted |
||
|
||
archiveFileName := backupHandle + archiveFileFormat | ||
|
||
|
@@ -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) | ||
|
@@ -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) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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