Skip to content

Commit

Permalink
rename to BackupConfigCopy()
Browse files Browse the repository at this point in the history
  • Loading branch information
korotkov-aerospike committed Dec 30, 2024
1 parent 43a97f7 commit d18fd2f
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions internal/server/handlers/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (s *Service) readAllBackups(w http.ResponseWriter, r *http.Request, isFullB
return
}

response, err := dto.Serialize(dto.ConvertBackupDetailsMap(backups, s.config.GetBackupConfig()), dto.JSON)
response, err := dto.Serialize(dto.ConvertBackupDetailsMap(backups, s.config.BackupConfigCopy()), dto.JSON)
if err != nil {
hLogger.Error("failed to marshal backup list",
slog.Any("error", err),
Expand Down Expand Up @@ -169,7 +169,7 @@ func (s *Service) readBackupsForRoutine(w http.ResponseWriter, r *http.Request,
http.Error(w, "failed to retrieve backup list: "+err.Error(), http.StatusInternalServerError)
return
}
backupConfig := s.config.GetBackupConfig()
backupConfig := s.config.BackupConfigCopy()
backupDetails := dto.ConvertModelsToDTO(backups, func(m *model.BackupDetails) *dto.BackupDetails {
return dto.NewBackupDetailsFromModel(m, backupConfig)
})
Expand Down
4 changes: 2 additions & 2 deletions internal/server/handlers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s *Service) updateConfig(w http.ResponseWriter, r *http.Request) {
}

err = s.changeConfig(r.Context(), func(config *model.Config) error {
config.SetBackupConfig(newConfigModel.GetBackupConfig())
config.SetBackupConfig(newConfigModel.BackupConfigCopy())
return nil
})

Expand Down Expand Up @@ -135,7 +135,7 @@ func (s *Service) ApplyConfig(w http.ResponseWriter, r *http.Request) {
return
}

backupConfig := config.GetBackupConfig()
backupConfig := config.BackupConfigCopy()
s.config.SetBackupConfig(backupConfig)
err = s.configApplier.ApplyNewRoutines(r.Context(), backupConfig.BackupRoutines)

Expand Down
6 changes: 3 additions & 3 deletions internal/server/handlers/config_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *Service) addAerospikeCluster(w http.ResponseWriter, r *http.Request) {
func (s *Service) ReadAerospikeClusters(w http.ResponseWriter, _ *http.Request) {
hLogger := s.logger.With(slog.String("handler", "ReadAerospikeClusters"))

backupConfig := s.config.GetBackupConfig()
backupConfig := s.config.BackupConfigCopy()
clusters := backupConfig.AerospikeClusters
toDTO := dto.ConvertModelMapToDTO(clusters, func(m *model.AerospikeCluster) *dto.AerospikeCluster {
return dto.NewClusterFromModel(m, backupConfig)
Expand Down Expand Up @@ -134,7 +134,7 @@ func (s *Service) readAerospikeCluster(w http.ResponseWriter, r *http.Request) {
http.Error(w, clusterNameNotSpecifiedMsg, http.StatusBadRequest)
return
}
backupConfig := s.config.GetBackupConfig()
backupConfig := s.config.BackupConfigCopy()
cluster, ok := backupConfig.AerospikeClusters[clusterName]
if !ok {
hLogger.Error("cluster not found",
Expand Down Expand Up @@ -197,7 +197,7 @@ func (s *Service) updateAerospikeCluster(w http.ResponseWriter, r *http.Request)
return
}

err = s.nsValidator.ValidateRoutines(cluster, s.config.GetBackupConfig().BackupRoutines)
err = s.nsValidator.ValidateRoutines(cluster, s.config.BackupConfigCopy().BackupRoutines)
if err != nil {
hLogger.Error("cluster namespace validation failed",
slog.String("name", clusterName),
Expand Down
4 changes: 2 additions & 2 deletions internal/server/handlers/config_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *Service) addPolicy(w http.ResponseWriter, r *http.Request) {
func (s *Service) ReadPolicies(w http.ResponseWriter, _ *http.Request) {
hLogger := s.logger.With(slog.String("handler", "ReadPolicies"))

policies := dto.ConvertModelMapToDTO(s.config.GetBackupConfig().BackupPolicies, dto.NewBackupPolicyFromModel)
policies := dto.ConvertModelMapToDTO(s.config.BackupConfigCopy().BackupPolicies, dto.NewBackupPolicyFromModel)
jsonResponse, err := dto.Serialize(policies, dto.JSON)
if err != nil {
hLogger.Error("failed to marshal backup policies",
Expand Down Expand Up @@ -121,7 +121,7 @@ func (s *Service) readPolicy(w http.ResponseWriter, r *http.Request) {
http.Error(w, policyNameNotSpecifiedMsg, http.StatusBadRequest)
return
}
policy, ok := s.config.GetBackupConfig().BackupPolicies[policyName]
policy, ok := s.config.BackupConfigCopy().BackupPolicies[policyName]
if !ok {
hLogger.Error("policy not found")
http.Error(w, fmt.Sprintf("policy %s could not be found", policyName), http.StatusNotFound)
Expand Down
4 changes: 2 additions & 2 deletions internal/server/handlers/config_routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *Service) addRoutine(w http.ResponseWriter, r *http.Request) {
http.Error(w, routineNameNotSpecifiedMsg, http.StatusBadRequest)
return
}
toModel, err := newRoutine.ToModel(s.config.GetBackupConfig(), s.nsValidator)
toModel, err := newRoutine.ToModel(s.config.BackupConfigCopy(), s.nsValidator)
if err != nil {
hLogger.Error("failed to create routine",
slog.String("name", name),
Expand Down Expand Up @@ -188,7 +188,7 @@ func (s *Service) updateRoutine(w http.ResponseWriter, r *http.Request) {
return
}

toModel, err := updatedRoutine.ToModel(s.config.GetBackupConfig(), s.nsValidator)
toModel, err := updatedRoutine.ToModel(s.config.BackupConfigCopy(), s.nsValidator)
if err != nil {
hLogger.Error("failed to create routine",
slog.String("name", name),
Expand Down
4 changes: 2 additions & 2 deletions internal/server/handlers/config_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *Service) addStorage(w http.ResponseWriter, r *http.Request) {
func (s *Service) ReadAllStorage(w http.ResponseWriter, _ *http.Request) {
hLogger := s.logger.With(slog.String("handler", "ReadAllStorage"))

backupConfig := s.config.GetBackupConfig()
backupConfig := s.config.BackupConfigCopy()
toDTO := dto.ConvertStorageMapToDTO(backupConfig.Storage, backupConfig)
jsonResponse, err := dto.Serialize(toDTO, dto.JSON)
if err != nil {
Expand Down Expand Up @@ -123,7 +123,7 @@ func (s *Service) readStorage(w http.ResponseWriter, r *http.Request) {
http.Error(w, storageNameNotSpecifiedMsg, http.StatusBadRequest)
return
}
backupConfig := s.config.GetBackupConfig()
backupConfig := s.config.BackupConfigCopy()
storage, ok := backupConfig.Storage[storageName]
if !ok {
http.Error(w, fmt.Sprintf("Storage %s could not be found", storageName), http.StatusNotFound)
Expand Down
2 changes: 1 addition & 1 deletion pkg/dto/backup_routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func NewRoutineFromModel(m *model.BackupRoutine, config *model.Config) *BackupRo
}

b := &BackupRoutine{}
b.fromModel(m, config.GetBackupConfig())
b.fromModel(m, config.BackupConfigCopy())
return b
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/dto/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewConfigFromModel(m *model.Config) *Config {

func (c *Config) fromModel(m *model.Config) {
c.ServiceConfig.fromModel(&m.ServiceConfig)
backupConfig := m.GetBackupConfig()
backupConfig := m.BackupConfigCopy()

c.AerospikeClusters = make(map[string]*AerospikeCluster)
for name, a := range backupConfig.AerospikeClusters {
Expand Down Expand Up @@ -173,7 +173,7 @@ func (c *Config) ToModel(nsValidator aerospike.NamespaceValidator) (*model.Confi
}
}

backupConfig := modelConfig.GetBackupConfig()
backupConfig := modelConfig.BackupConfigCopy()
// routines must be added after storage, secret agents and policies.
for k, v := range c.BackupRoutines {
toModel, err := v.ToModel(backupConfig, nsValidator)
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var (
ErrInUse = fmt.Errorf("item is in use")
)

func (c *Config) GetBackupConfig() *BackupConfig {
func (c *Config) BackupConfigCopy() *BackupConfig {
c.RLock()
defer c.RUnlock()
return c.backupConfig.copy()
Expand Down

0 comments on commit d18fd2f

Please sign in to comment.