singleton-client 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fa11214d62c5669477f86cf9cdd5535112c9fa48ec46504e192048e008173cc
4
- data.tar.gz: 29675027bf9d235c59728680dd791a11665209c4e99445032410c38166db6463
3
+ metadata.gz: 43d840f37ce5f60b23e16623db0b4393f014eaeaafa0ddf91520225a93bd9c57
4
+ data.tar.gz: d3c1e045e6c75f7e09cd2790de733a217516afede51dbfede1224cbabcbd3b53
5
5
  SHA512:
6
- metadata.gz: f62c62c7e7d0e49124e8cdbd648154099e8d3b6bf5a8ac295b25817acefaf71a89dd09d6a8e1ef4f766f9e42d2ffb398af5e92f832933e650fef556aab767d53
7
- data.tar.gz: 0d97b5eb531a64e9be1543edf3bebcc78ebc094fa06db9f711a1bb1e365ec42c4cfc0a96ffa5130f220a1c39f38ab57f10fb3120fea266ad698607557069143a
6
+ metadata.gz: 56593be0f8686d669216a849592b9100bb47f52087bf10938d1fae79fb123b9b4ee68baa10e8e627c2ef263e79f2f056aac777e2e5ebc3d8d7f5fbd15b758ce5
7
+ data.tar.gz: 5eca696945202e002be5c489ee37153d63c6498e4cc8639f5ea3ad11666ac63e4fffee59572e29fbeb0ff4c7489ff29b06a77cb57e2f9f077cde0663ca5e115b
@@ -6,18 +6,18 @@ module SgtnClient
6
6
  class Source
7
7
 
8
8
  def self.getSource(component, key, locale)
9
+ SgtnClient.logger.debug "[Source][getSource]component=#{component}, key=#{key}, locale=#{locale}"
9
10
  cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
10
11
  expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
11
12
  if items.nil?
12
- items = getBundle(component, locale)
13
- SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
13
+ items = getBundle(component, locale)
14
14
  SgtnClient::CacheUtil.write_cache(cache_key, items)
15
15
  else
16
- SgtnClient.logger.debug "Getting sources from cache with key: " + cache_key
16
+ SgtnClient.logger.debug "[Source][getSource]getting sources from cache with key: " + cache_key
17
17
  end
18
18
  s = items.nil?? nil : items[locale][key]
19
19
  if items.nil? || s.nil?
20
- SgtnClient.logger.debug "Source not found, return key: " + key
20
+ SgtnClient.logger.debug "[Source][getSource]source not found, return key: " + key
21
21
  #return key
22
22
  return nil
23
23
  else
@@ -26,23 +26,23 @@ module SgtnClient
26
26
  end
27
27
 
28
28
  def self.getSources(component, locale)
29
+ SgtnClient.logger.debug "[Source][getSources]component=#{component}, locale=#{locale}"
29
30
  cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale)
30
31
  expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
31
32
  if items.nil? || expired
32
33
  items = getBundle(component, locale)
33
- SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key
34
34
  SgtnClient::CacheUtil.write_cache(cache_key, items)
35
35
  else
36
- SgtnClient.logger.debug "Getting sources from cache with key: " + cache_key
36
+ SgtnClient.logger.debug "[Source][getSources]getting sources from cache with key: " + cache_key
37
37
  end
38
38
  return items
39
39
  end
40
40
 
41
41
  def self.loadBundles(locale)
42
+ SgtnClient.logger.debug "[Source][loadBundles]locale=#{locale}"
42
43
  env = SgtnClient::Config.default_environment
43
44
  SgtnClient::Config.configurations.default = locale
44
45
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
45
- SgtnClient.logger.debug "Loading [" + locale + "] source bundles from path: " + source_bundle
46
46
  Dir.foreach(source_bundle) do |component|
47
47
  next if component == '.' || component == '..'
48
48
  yamlfile = File.join(source_bundle, component + "/" + locale + ".yml")
@@ -54,10 +54,10 @@ module SgtnClient
54
54
 
55
55
  private
56
56
  def self.getBundle(component, locale)
57
+ SgtnClient.logger.debug "[Source][getBundle]component=#{component}, locale=#{locale}"
57
58
  env = SgtnClient::Config.default_environment
58
59
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
59
60
  bundlepath = source_bundle + "/" + component + "/" + locale + ".yml"
60
- SgtnClient.logger.debug "Getting source from bundle: " + bundlepath
61
61
  begin
62
62
  bundle = SgtnClient::FileUtil.read_yml(bundlepath)
63
63
  rescue => exception
@@ -12,22 +12,24 @@ module SgtnClient
12
12
  class Translation
13
13
 
14
14
  def self.getString(component, key, locale)
15
+ SgtnClient.logger.debug "[Translation.getString]component: #{component}, key: #{key}, locale: #{locale}"
15
16
  str = getTranslation(component, key, locale)
16
17
  if str.nil?
17
18
  str = SgtnClient::Source.getSource(component, key, SgtnClient::Config.configurations.default)
18
19
  if str.nil?
19
- SgtnClient.logger.error "Can't find the key '" + key + "' in source path!"
20
+ SgtnClient.logger.debug "[Translation][getString] Missing source string with key: #{key}, component: #{component}, locale: #{locale}"
20
21
  end
21
22
  end
22
23
  str
23
24
  end
24
25
 
25
26
  def self.getString_p(component, key, plural_args, locale)
27
+ SgtnClient.logger.debug "[Translation][getString_p]component=#{component}, key=#{key}, locale=#{locale}"
26
28
  str = getTranslation(component, key, locale)
27
29
  if str.nil?
28
30
  str = SgtnClient::Source.getSource(component, key, SgtnClient::Config.configurations.default)
29
31
  if str.nil?
30
- SgtnClient.logger.error "Can't find the key '" + key + "' in source path!"
32
+ SgtnClient.logger.debug "[Translation][getString_p] Missing source string with key: #{key}, component: #{component}, locale: #{locale}"
31
33
  return nil
32
34
  end
33
35
  str.to_plural_s(:en, plural_args)
@@ -37,6 +39,7 @@ module SgtnClient
37
39
  end
38
40
 
39
41
  def self.getString_f(component, key, args, locale, *optionals)
42
+ SgtnClient.logger.debug "[Translation][getString_f]component=#{component}, key=#{key}, locale=#{locale}"
40
43
  s = getString(component, key, locale, *optionals)
41
44
  if s.nil?
42
45
  return nil
@@ -52,13 +55,14 @@ module SgtnClient
52
55
  end
53
56
 
54
57
  def self.getStrings(component, locale)
58
+ SgtnClient.logger.debug "[Translation][getStrings]component=#{component}, locale=#{locale}"
55
59
  items = get_cs(component, locale)
56
60
  default = SgtnClient::Config.configurations.default
57
61
  if items.nil? || items["messages"] == nil
58
62
  items = {}
59
63
  s = SgtnClient::Source.getSources(component, default)
60
64
  if s.nil?
61
- SgtnClient.logger.error "Can't find the component '" + component + "' in source path!"
65
+ SgtnClient.logger.error "[Translation][getStrings] Missing component: #{component}, locale: #{locale}"
62
66
  else
63
67
  default_component, value = s.first
64
68
  items["component"] = component
@@ -84,6 +88,7 @@ module SgtnClient
84
88
  def self.get_cs(component, locale)
85
89
  flocale = SgtnClient::LocaleUtil.fallback(locale)
86
90
  cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale)
91
+ SgtnClient.logger.debug "[Translation][get_cs]cache_key=#{cache_key}"
87
92
  expired, items = SgtnClient::CacheUtil.get_cache(cache_key)
88
93
  if items.nil? || expired
89
94
  items = load(component, flocale)
@@ -94,7 +99,7 @@ module SgtnClient
94
99
  SgtnClient::CacheUtil.write_cache(cache_key, items)
95
100
  end
96
101
  else
97
- SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
102
+ SgtnClient.logger.debug "[Translation]get translations from cache with key: " + cache_key
98
103
  end
99
104
 
100
105
  return items
@@ -103,6 +108,7 @@ module SgtnClient
103
108
  def self.load(component, locale)
104
109
  env = SgtnClient::Config.default_environment
105
110
  mode = SgtnClient::Config.configurations[env]["bundle_mode"]
111
+ SgtnClient.logger.debug "[Translation][load]mode=#{mode}"
106
112
  if mode == 'offline'
107
113
  return load_o(component, locale)
108
114
  else
@@ -116,7 +122,6 @@ module SgtnClient
116
122
  version = SgtnClient::Config.configurations[env]["version"].to_s
117
123
  translation_bundle = SgtnClient::Config.configurations[env]["translation_bundle"]
118
124
  bundlepath = translation_bundle + "/" + product_name + "/" + version + "/" + component + "/messages_" + locale + ".json"
119
- SgtnClient.logger.debug "Getting translations from offline bundle: " + bundlepath
120
125
  SgtnClient::FileUtil.read_json(bundlepath)
121
126
  end
122
127
 
@@ -124,10 +129,8 @@ module SgtnClient
124
129
  env = SgtnClient::Config.default_environment
125
130
  product_name = SgtnClient::Config.configurations[env]["product_name"]
126
131
  vip_server = SgtnClient::Config.configurations[env]["vip_server"]
127
- SgtnClient.logger.debug "Getting translations from server: " + vip_server
128
132
  version = SgtnClient::Config.configurations[env]["version"].to_s
129
133
  url = vip_server + "/i18n/api/v2/translation/products/" + product_name + "/versions/" + version + "/locales/" + locale + "/components/" + component+ "?checkTranslationStatus=false&machineTranslation=false&pseudo=false"
130
- SgtnClient.logger.debug url
131
134
  begin
132
135
  obj = SgtnClient::Core::Request.get(url)
133
136
  rescue => exception
@@ -7,13 +7,12 @@ module SgtnClient::Core
7
7
  def self.initialize(disabled=false, opts={})
8
8
  @@opts = opts
9
9
  @mutex = Mutex.new
10
- SgtnClient.logger.debug "Initialize cache......"
11
10
  if disabled == false
12
11
  @@data = Hash.new
13
- SgtnClient.logger.debug "Cache is enabled!"
12
+ SgtnClient.logger.debug "[Cache][initialize]cache is enabled!"
14
13
  else
15
14
  @@data = nil
16
- SgtnClient.logger.debug "Cache is disabled!"
15
+ SgtnClient.logger.debug "[Cache][initialize]cache is disabled!"
17
16
  end
18
17
  end
19
18
 
@@ -21,7 +20,7 @@ module SgtnClient::Core
21
20
  if @@data == nil
22
21
  return nil
23
22
  end
24
- SgtnClient.logger.debug "Get cache keys"
23
+ SgtnClient.logger.debug "[Cache][keys]get cache keys"
25
24
  @@data.keys
26
25
  end
27
26
 
@@ -29,7 +28,7 @@ module SgtnClient::Core
29
28
  if @@data == nil
30
29
  return nil, nil
31
30
  end
32
- SgtnClient.logger.debug "Get cache for key: " + key
31
+ SgtnClient.logger.debug "[Cache][get]get cache for key: " + key
33
32
  invalidate(key)
34
33
  end
35
34
 
@@ -37,7 +36,7 @@ module SgtnClient::Core
37
36
  if @@data == nil
38
37
  return nil
39
38
  end
40
- SgtnClient.logger.debug "Check if the cache has key: #{(@@data.has_key? key)}"
39
+ SgtnClient.logger.debug "[Cache][has]check if the cache has key: #{(@@data.has_key? key)}"
41
40
  @@data.has_key? key
42
41
  end
43
42
 
@@ -48,7 +47,7 @@ module SgtnClient::Core
48
47
  end
49
48
  ttl ||= @@opts[:ttl]
50
49
  # hours from new
51
- SgtnClient.logger.debug "Put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
50
+ SgtnClient.logger.debug "[Cache][put]put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
52
51
  @@data[key] = Entry.new(Time.now + ttl*60, value)
53
52
  end
54
53
  end
@@ -58,7 +57,7 @@ module SgtnClient::Core
58
57
  if @@data == nil
59
58
  return nil
60
59
  end
61
- SgtnClient.logger.debug "Delete cache for key: " + key
60
+ SgtnClient.logger.debug "[Cache][delete]delete cache for key: " + key
62
61
  @@data.delete key
63
62
  end
64
63
  end
@@ -68,7 +67,7 @@ module SgtnClient::Core
68
67
  if @@data == nil
69
68
  return nil
70
69
  end
71
- SgtnClient.logger.debug "Clear cache!"
70
+ SgtnClient.logger.debug "[Cache][clear]clear cache!"
72
71
  @@data = Hash.new
73
72
  end
74
73
  end
@@ -78,16 +77,16 @@ module SgtnClient::Core
78
77
  if @@data == nil
79
78
  return nil, nil
80
79
  end
81
- SgtnClient.logger.debug "Invalidating expired cache......"
80
+ SgtnClient.logger.debug "[Cache][invalidate]invalidate expired cache......"
82
81
  now = Time.now
83
82
  if has(key)
84
83
  v = @@data[key]
85
84
  expired = false
86
- SgtnClient.logger.debug "Checking cache: key=#{key}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
85
+ SgtnClient.logger.debug "[Cache][invalidate]check cache: key=#{key}, expiredtime=#{v[:expiry]}, now=#{now}, expired=#{(v[:expiry] < now)}"
87
86
  if v[:expiry] < now
88
- SgtnClient.logger.debug "Before deleting the cache: data=#{@@data}"
87
+ SgtnClient.logger.debug "[Cache][invalidate]before deleting the cache: data=#{@@data}"
89
88
  @@data.delete(key)
90
- SgtnClient.logger.debug "After deleting the cache: data=#{@@data}"
89
+ SgtnClient.logger.debug "[Cache][invalidate]after deleting the cache: data=#{@@data}"
91
90
  expired = true
92
91
  end
93
92
  return expired, v[:value]
@@ -4,7 +4,7 @@ require 'multi_json'
4
4
  module SgtnClient::Core
5
5
  class Request
6
6
  def self.get(url)
7
- #res = RestClient.get(url)
7
+ SgtnClient.logger.debug "[Request][get]url=#{url}"
8
8
  res = RestClient::Resource.new(
9
9
  url,
10
10
  :verify_ssl => false
@@ -38,6 +38,7 @@ module SgtnClient
38
38
 
39
39
  # create log file
40
40
  file = './sgtnclient_d.log'
41
+ SgtnClient.logger.debug "[Client][load]create log file=#{file}"
41
42
  if args[2] != nil
42
43
  file = args[2]
43
44
  end
@@ -48,7 +49,7 @@ module SgtnClient
48
49
  # Set log level for sandbox mode
49
50
  env = SgtnClient::Config.default_environment
50
51
  mode = SgtnClient::Config.configurations[env]["mode"]
51
- SgtnClient.logger.info "Current mode is: " + mode
52
+ SgtnClient.logger.debug "[Client][load]set log level, mode=#{mode}"
52
53
  if mode == 'sandbox'
53
54
  SgtnClient.logger.level = Logger::DEBUG
54
55
  else
@@ -57,6 +58,7 @@ module SgtnClient
57
58
 
58
59
  # initialize cache
59
60
  disable_cache = SgtnClient::Config.configurations[env]["disable_cache"]
61
+ SgtnClient.logger.debug "[Client][load]cache initialize, disable_cache=#{disable_cache}"
60
62
  if disable_cache != nil
61
63
  SgtnClient::Core::Cache.initialize(disable_cache)
62
64
  else
@@ -11,16 +11,17 @@ module SgtnClient
11
11
 
12
12
  def self.get_cache(cache_key)
13
13
  expired, items = SgtnClient::Core::Cache.get(cache_key)
14
+ SgtnClient.logger.debug "[CacheUtil]get cache with key #{cache_key}, expired #{expired}"
14
15
  return expired, items
15
16
  end
16
17
 
17
18
  def self.clear_cache()
18
19
  SgtnClient::Core::Cache.clear()
20
+ SgtnClient.logger.debug "[CacheUtil]clear cache"
19
21
  end
20
22
 
21
23
  def self.write_cache(cache_key, items)
22
24
  if items.nil?
23
- SgtnClient.logger.debug "write cache with key #{cache_key}, itmes #{items}"
24
25
  return nil
25
26
  end
26
27
  env = SgtnClient::Config.default_environment
@@ -29,6 +30,7 @@ module SgtnClient
29
30
  if cache_expiry_period == nil
30
31
  cache_expiry_period = 24*60
31
32
  end
33
+ SgtnClient.logger.debug "[CacheUtil]write cache with key #{cache_key}, cache_expiry_period #{cache_expiry_period}, itmes #{items}"
32
34
  SgtnClient::Core::Cache.put(cache_key, items, cache_expiry_period)
33
35
  end
34
36
 
@@ -41,6 +43,7 @@ module SgtnClient
41
43
  default_l = 'en'
42
44
  end
43
45
  lc = locale == default_l ? SgtnClient::Config.configurations.default: locale
46
+ SgtnClient.logger.debug "[CacheUtil]get cache key: #{lc}"
44
47
  return product_name + "_" + version + "_" + component + "_" + lc
45
48
  end
46
49
  end
@@ -8,6 +8,7 @@ module SgtnClient
8
8
  @mutex = Mutex.new
9
9
 
10
10
  def self.read_json(bundlepath)
11
+ SgtnClient.logger.debug "[FileUtil]read json file from: " + bundlepath
11
12
  @mutex.synchronize do
12
13
  data_hash = nil
13
14
  begin
@@ -21,6 +22,7 @@ module SgtnClient
21
22
  end
22
23
 
23
24
  def self.read_yml(file_name)
25
+ SgtnClient.logger.debug "[FileUtil]read yml file from: " + file_name
24
26
  @mutex.synchronize do
25
27
  erb = ERB.new(File.read(file_name))
26
28
  erb.filename = file_name
@@ -4,8 +4,8 @@ module SgtnClient
4
4
  class ValidateUtil
5
5
 
6
6
  def self.validate_config()
7
- SgtnClient.logger.debug "-----------Start to validate configuration's setting itmes-----------"
8
7
  env = SgtnClient::Config.default_environment
8
+ SgtnClient.logger.debug "[ValidateUtil][validate_config] env = #{env}"
9
9
  messages = "\n"
10
10
 
11
11
  mode = SgtnClient::Config.configurations[env]["mode"]
@@ -36,7 +36,6 @@ module SgtnClient
36
36
  if messages != "\n"
37
37
  raise SgtnClient::Exceptions::MissingConfig.new(messages)
38
38
  end
39
- SgtnClient.logger.debug "-----------End to validate configuration's setting itmes-----------"
40
39
  end
41
40
 
42
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singleton-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware G11n Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-28 00:00:00.000000000 Z
11
+ date: 2022-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client