From 8a0ebe803a69133ac0aa175d90eb33dc26c04ec0 Mon Sep 17 00:00:00 2001 From: Maxim Merzhanov Date: Fri, 1 Nov 2019 15:08:37 +0300 Subject: [PATCH] up --- .version | 2 +- CHANGELOG.md | 2 ++ controller/application.go | 3 +-- controller/token.go | 12 +++++------- invoker/redis.go | 9 +++++++++ main.go | 12 ++++++------ migrations/0004_2018-04-27_initialize.go | 2 +- 7 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 invoker/redis.go diff --git a/.version b/.version index 1b87bcd..227cea2 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -1.1.4 \ No newline at end of file +2.0.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0671fd2..c96a840 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +### v2.0.0 +* update to new isp-lib & config service ### v1.1.3 * update to new log * migrate to new db client diff --git a/controller/application.go b/controller/application.go index c9c9c2e..a8ba33f 100644 --- a/controller/application.go +++ b/controller/application.go @@ -4,7 +4,6 @@ import ( "isp-system-service/entity" "isp-system-service/model" - "github.com/integration-system/isp-lib/database" _ "github.com/integration-system/isp-lib/structure" "github.com/integration-system/isp-lib/utils" "google.golang.org/grpc/codes" @@ -146,7 +145,7 @@ func DeleteApplications(list []int32) (DeleteResponse, error) { return DeleteResponse{}, status.Errorf(codes.InvalidArgument, "At least one id are required") } var count = 0 - err := database.RunInTransaction(func(appRep model.AppRepository, tokenRep model.TokenRepository) error { + err := model.DbClient.RunInTransaction(func(appRep model.AppRepository, tokenRep model.TokenRepository) error { for _, appId := range list { _, err := revokeTokensForApp(Identity{appId}, &tokenRep) if err != nil { diff --git a/controller/token.go b/controller/token.go index 5ce8b6b..bf71af8 100644 --- a/controller/token.go +++ b/controller/token.go @@ -1,6 +1,7 @@ package controller import ( + "isp-system-service/invoker" "time" "isp-system-service/conf" @@ -10,7 +11,7 @@ import ( "fmt" "github.com/go-redis/redis" "github.com/integration-system/isp-lib/config" - "github.com/integration-system/isp-lib/redis" + rd "github.com/integration-system/isp-lib/redis" "github.com/integration-system/isp-lib/token-gen" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -71,7 +72,6 @@ func CreateToken(req CreateTokenRequest) (*AppWithToken, error) { CreatedAt: time.Now(), } - c := rd.GetClient() err = SetIdentityMapForToken(token, m) if err != nil { return nil, err @@ -79,7 +79,7 @@ func CreateToken(req CreateTokenRequest) (*AppWithToken, error) { token, err = model.TokenRep.SaveToken(token) if err != nil { - c.Del(token.Token) + invoker.RedisClient.Del(token.Token) return nil, err } @@ -146,9 +146,8 @@ func GetTokensByAppId(identity Identity) ([]entity.Token, error) { } func SetIdentityMapForTokenV2(token string, expireTime int64, idMap map[string]interface{}) error { - c := rd.GetClient() cfg := config.Get().(*conf.Configuration) - _, e := c.UseDbTx(rd.ApplicationTokenDb, func(p redis.Pipeliner) error { + _, e := invoker.RedisClient.UseDbTx(rd.ApplicationTokenDb, func(p redis.Pipeliner) error { t := fmt.Sprintf("%s|%s", token, cfg.InstanceUuid) stat := p.HMSet(t, idMap) err := stat.Err() @@ -229,8 +228,7 @@ func revokeTokens(tokens []string, tokenRep *model.TokenRepository) (*DeleteResp if len(tokens) == 0 { return &DeleteResponse{0}, nil } - c := rd.GetClient() - _, e := c.UseDbTx(rd.ApplicationTokenDb, func(p redis.Pipeliner) error { + _, e := invoker.RedisClient.UseDbTx(rd.ApplicationTokenDb, func(p redis.Pipeliner) error { deleted, err := tokenRep.DeleteTokens(tokens) count = deleted if err != nil { diff --git a/invoker/redis.go b/invoker/redis.go new file mode 100644 index 0000000..1b20b60 --- /dev/null +++ b/invoker/redis.go @@ -0,0 +1,9 @@ +package invoker + +import ( + "github.com/integration-system/isp-lib/redis" +) + +var ( + RedisClient = redis.NewRxClient() +) diff --git a/main.go b/main.go index 79ee3f9..59ac206 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "github.com/integration-system/isp-lib/config/schema" "github.com/integration-system/isp-lib/structure" + "isp-system-service/invoker" "os" "isp-system-service/conf" @@ -82,15 +83,14 @@ func socketConfiguration(cfg interface{}) structure.SocketConfiguration { func onShutdown(_ context.Context, _ os.Signal) { backend.StopGrpcServer() _ = model.DbClient.Close() + _ = invoker.RedisClient.Close() } func onRemoteConfigReceive(remoteConfig, oldConfig *conf.RemoteConfig) { - if remoteConfig.RedisAddress.GetAddress() != oldConfig.RedisAddress.GetAddress() { - rd.InitClient(structure.RedisConfiguration{ - Address: remoteConfig.RedisAddress, - DefaultDB: int(rd.ApplicationTokenDb), - }) - } + invoker.RedisClient.ReceiveConfiguration(structure.RedisConfiguration{ + Address: remoteConfig.RedisAddress, + DefaultDB: int(redis.ApplicationTokenDb), + }) model.DbClient.ReceiveConfiguration(remoteConfig.DB) metric.InitCollectors(remoteConfig.Metrics, oldConfig.Metrics) metric.InitHttpServer(remoteConfig.Metrics) diff --git a/migrations/0004_2018-04-27_initialize.go b/migrations/0004_2018-04-27_initialize.go index f52de6c..7908925 100644 --- a/migrations/0004_2018-04-27_initialize.go +++ b/migrations/0004_2018-04-27_initialize.go @@ -29,7 +29,7 @@ func init() { } func Up(tx *sql.Tx) error { - path := path2.Join(database.ResolveMigrationsDirectrory(), initFile) + path := path2.Join(database.ResolveMigrationsDirectory(), initFile) bytes, err := ioutil.ReadFile(path) if err != nil { return err