This commit is contained in:
DeniskaRediska committed 2020-06-09 13:55:39 +03:00
1 parent 1c66729974
commit 31a4a6f5b8
7 files changed
+15 -45

No files matched your search

-5
View File
@@ -34,7 +34,6 @@ const (
ModuleDisconnectedCommand
DeleteModulesCommand
DeleteVersionConfigCommand
GetAllVersionConfigCommand
ActivateConfigCommand
DeleteConfigsCommand
@@ -102,10 +101,6 @@ func PrepareDeleteConfigVersionCommand(id string) []byte {
return prepareCommand(DeleteVersionConfigCommand, Identity{Id: id})
}
func PrepareGetAllConfigVersionCommand(id string) []byte {
return prepareCommand(GetAllVersionConfigCommand, Identity{Id: id})
}
func prepareCommand(command Command, payload interface{}) []byte {
cmd := make([]byte, 8)
binary.BigEndian.PutUint64(cmd, uint64(command))
+8 -9
View File
@@ -15,18 +15,17 @@ func _() {
_ = x[ModuleDisconnectedCommand-5]
_ = x[DeleteModulesCommand-6]
_ = x[DeleteVersionConfigCommand-7]
_ = x[GetAllVersionConfigCommand-8]
_ = x[ActivateConfigCommand-9]
_ = x[DeleteConfigsCommand-10]
_ = x[UpsertConfigCommand-11]
_ = x[DeleteCommonConfigsCommand-12]
_ = x[UpsertCommonConfigCommand-13]
_ = x[BroadcastEventCommand-14]
_ = x[ActivateConfigCommand-8]
_ = x[DeleteConfigsCommand-9]
_ = x[UpsertConfigCommand-10]
_ = x[DeleteCommonConfigsCommand-11]
_ = x[UpsertCommonConfigCommand-12]
_ = x[BroadcastEventCommand-13]
}
const _Command_name = "UpdateBackendDeclarationCommandDeleteBackendDeclarationCommandUpdateConfigSchemaCommandModuleConnectedCommandModuleDisconnectedCommandDeleteModulesCommandDeleteVersionConfigCommandGetAllVersionConfigCommandActivateConfigCommandDeleteConfigsCommandUpsertConfigCommandDeleteCommonConfigsCommandUpsertCommonConfigCommandBroadcastEventCommand"
const _Command_name = "UpdateBackendDeclarationCommandDeleteBackendDeclarationCommandUpdateConfigSchemaCommandModuleConnectedCommandModuleDisconnectedCommandDeleteModulesCommandDeleteVersionConfigCommandActivateConfigCommandDeleteConfigsCommandUpsertConfigCommandDeleteCommonConfigsCommandUpsertCommonConfigCommandBroadcastEventCommand"
var _Command_index = [...]uint16{0, 31, 62, 87, 109, 134, 154, 180, 206, 227, 247, 266, 292, 317, 338}
var _Command_index = [...]uint16{0, 31, 62, 87, 109, 134, 154, 180, 201, 221, 240, 266, 291, 312}
func (i Command) String() string {
i -= 1
+3 -5
View File
@@ -161,11 +161,9 @@ func (c *config) DeleteConfigVersion(req domain.ConfigIdRequest) (*domain.Delete
// @Router /config/get_all_version [POST]
func (c *config) GetAllVersion(req domain.ConfigIdRequest) ([]entity.VersionConfig, error) {
var response []entity.VersionConfig
command := cluster.PrepareGetAllConfigVersionCommand(req.Id)
err := PerformSyncApplyWithError(command, &response)
if err != nil {
return nil, err
}
c.rstore.VisitReadonlyState(func(state state.ReadonlyState) {
response = state.VersionConfig().GetByConfigId(req.Id)
})
return response, nil
}
+1 -8
View File
@@ -129,10 +129,6 @@ func (cs configService) HandleUpsertConfigCommand(upsertConfig cluster.UpsertCon
}
}
var (
removedVersionId string
versionConfig entity.VersionConfig
)
if upsertConfig.Create {
config = state.WritableConfigs().Create(config)
} else {
@@ -147,7 +143,7 @@ func (cs configService) HandleUpsertConfigCommand(upsertConfig cluster.UpsertCon
config.Version = oldCfg.Version + 1
state.WritableConfigs().UpdateById(config)
versionConfig = ConfigHistory.SaveConfigVersion(upsertConfig.VersionId, oldCfg, state)
ConfigHistory.SaveConfigVersion(upsertConfig.VersionId, oldCfg, state)
}
if holder.ClusterClient.IsLeader() {
@@ -158,9 +154,6 @@ func (cs configService) HandleUpsertConfigCommand(upsertConfig cluster.UpsertCon
"config": config,
}).Errorf(codes.DatabaseOperationError, "upsert config: %v", err)
}
if !upsertConfig.Create {
ConfigHistory.updateDB(versionConfig, removedVersionId)
}
}
cs.BroadcastActiveConfigs(state, config)
+3 -7
View File
@@ -36,14 +36,11 @@ func (configHistoryService) HandleDeleteVersionConfigCommand(cfg cluster.Identit
return cluster.NewResponse(domain.DeleteResponse{Deleted: deleted})
}
func (configHistoryService) HandleGetAllVersionConfigCommand(cfg cluster.Identity,
state state.WritableState) cluster.ResponseWithError {
resp := state.VersionConfig().GetByConfigId(cfg.Id)
return cluster.NewResponse(resp)
func (configHistoryService) GetAllVersionConfigById(id string, state state.ReadonlyState) []entity.VersionConfig {
return state.VersionConfig().GetByConfigId(id)
}
func (s configHistoryService) SaveConfigVersion(id string, oldConfig entity.Config,
state state.WritableState) entity.VersionConfig {
func (s configHistoryService) SaveConfigVersion(id string, oldConfig entity.Config, state state.WritableState) {
cfg := entity.VersionConfig{
Id: id,
ConfigVersion: oldConfig.Version,
@@ -54,7 +51,6 @@ func (s configHistoryService) SaveConfigVersion(id string, oldConfig entity.Conf
if holder.ClusterClient.IsLeader() {
s.updateDB(cfg, removedVersionId)
}
return cfg
}
func (configHistoryService) updateDB(cfg entity.VersionConfig, removedId string) {
-10
View File
@@ -145,13 +145,3 @@ func (s *Store) applyDeleteVersionConfigCommand(data []byte) (interface{}, error
response := service.ConfigHistory.HandleDeleteVersionConfigCommand(cfg, s.state)
return response, nil
}
func (s *Store) applyAllVersionConfigCommand(data []byte) (interface{}, error) {
cfg := cluster.Identity{}
err := json.Unmarshal(data, &cfg)
if err != nil {
return nil, errors.WithMessage(err, "unmarshal cluster.Identity")
}
response := service.ConfigHistory.HandleGetAllVersionConfigCommand(cfg, s.state)
return response, nil
}
-1
View File
@@ -132,7 +132,6 @@ func NewStateStore(st *state.State) *Store {
cluster.UpsertCommonConfigCommand: store.applyUpsertCommonConfigCommand,
cluster.BroadcastEventCommand: store.applyBroadcastEventCommand,
cluster.DeleteVersionConfigCommand: store.applyDeleteVersionConfigCommand,
cluster.GetAllVersionConfigCommand: store.applyAllVersionConfigCommand,
}
return store
}