singleton-ruby 0.0.4 → 0.0.5

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: ea69ecdb18c928648d4f13c86c49c28eb06ac6debbff0a6b81d00a3aa22a470a
4
- data.tar.gz: 5591f0fd49b0dd594b292fed1d4afce9bba3ab60bb23a3aa697a0b0c93957eb3
3
+ metadata.gz: 41a2068f7bad6dd8f8ce5940386b82897eca3a1f0d4d1d275c80f411ae40fd14
4
+ data.tar.gz: fa7d5bd49e8fb9d04911cfe9b6869eb0ed8489be83ca58dbf74d62dfc08ac6db
5
5
  SHA512:
6
- metadata.gz: 10c04aa1bdd5d23a8057fabe04d4f9e9736d8a109b27042bb8f8133cbe6bbdce3036f4bf9c2e31b9773f48285ffde8c5e5bd590f01c71c72d6c2c9f522228c1a
7
- data.tar.gz: 83393a302754efa12fcb739756b57fec8b4f957f6903357bb091a5f6497740d43544fbffa4bc7ce717c9fedd4eeeb1b041945fc0b0638eb5725f7ce07b489fdf
6
+ metadata.gz: 1f2b1f1350f8bc4c83c9515db52e6a64242ba42bd92af1c1468a3660dad055ec8c064b8a27b5e6185ff20a1eec725ff3fbf76bbd7e2e639bf591fb45ec88e127
7
+ data.tar.gz: 7726b44fd11e02ad674527f949508796a96dd9b56e04ea860dfe68fddac3bed31c4a3bfa92d0da20b9cb3eca0ca0c03e76daafb538077e017f888cc1c8e5f146
data/README.md CHANGED
@@ -4,5 +4,8 @@
4
4
  - Ruby version: 3.0.0 or above
5
5
  - Bundler version: 2.2.3 or above
6
6
 
7
+ ## Run Unit Test
8
+ rake spec:unit
9
+
7
10
 
8
11
 
@@ -28,7 +28,7 @@ module SgtnClient
28
28
  def self.loadBundles(locale)
29
29
  env = SgtnClient::Config.default_environment
30
30
  source_bundle = SgtnClient::Config.configurations[env]["source_bundle"]
31
- SgtnClient.logger.debug "Loading bundles from path: " + source_bundle
31
+ SgtnClient.logger.debug "Loading [" + locale + "] bundles from path: " + source_bundle
32
32
  Dir.children(source_bundle).each do |component|
33
33
  yamlfile = File.join(source_bundle, component + "/" + locale + ".yml")
34
34
  bundle = read_yml(yamlfile)
@@ -46,7 +46,7 @@ module SgtnClient
46
46
  bundlepath = source_bundle + "/" + component + "/en.yml"
47
47
  SgtnClient.logger.debug "Getting source from bundle: " + bundlepath
48
48
  begin
49
- bundle = read_yaml(bundlepath)
49
+ bundle = read_yml(bundlepath)
50
50
  puts bundle
51
51
  rescue => exception
52
52
  SgtnClient.logger.error exception.message
@@ -20,10 +20,10 @@ module SgtnClient
20
20
  SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key
21
21
  end
22
22
  if items.nil?
23
- return key
23
+ return SgtnClient::Source.getSource(component, key)
24
24
  end
25
- str = items["messages"][key]
26
25
 
26
+ str = items["messages"][key]
27
27
  if str.nil?
28
28
  return SgtnClient::Source.getSource(component, key)
29
29
  else
@@ -49,7 +49,7 @@ module SgtnClient
49
49
  product_name = SgtnClient::Config.configurations[env]["product_name"]
50
50
  version = SgtnClient::Config.configurations[env]["version"]
51
51
  translation_bundle = SgtnClient::Config.configurations[env]["translation_bundle"]
52
- bundlepath = translation_bundle + product_name + "/" + version + "/" + component + "/messages_" + locale + ".json"
52
+ bundlepath = translation_bundle + "/" + product_name + "/" + version + "/" + component + "/messages_" + locale + ".json"
53
53
  SgtnClient.logger.debug "Getting translations from offline bundle: " + bundlepath
54
54
  begin
55
55
  file = File.read(bundlepath)
@@ -4,38 +4,64 @@ module SgtnClient::Core
4
4
  class Cache
5
5
  Entry = Struct.new(:expiry, :value)
6
6
 
7
- def self.initialize(opts={})
8
- $data = Hash.new
7
+ def self.initialize(disabled=false, opts={})
9
8
  $opts = opts
9
+ if disabled == false
10
+ $data = Hash.new
11
+ SgtnClient.logger.debug "Cache is enabled!"
12
+ else
13
+ SgtnClient.logger.debug "Cache is disabled!"
14
+ end
10
15
  end
11
16
 
12
17
  def self.keys
18
+ if $data == nil
19
+ return nil
20
+ end
13
21
  $data.keys
14
22
  end
15
23
 
16
24
  def self.get(key)
25
+ if $data == nil
26
+ return nil
27
+ end
17
28
  $data[key][:value] if has(key)
18
29
  end
19
30
 
20
31
  def self.has(key)
32
+ if $data == nil
33
+ return nil
34
+ end
21
35
  $data.has_key? key
22
36
  end
23
37
 
24
38
  def self.put(key, value, ttl=nil)
39
+ if $data == nil
40
+ return nil
41
+ end
25
42
  ttl ||= @opts[:ttl]
26
43
  # hours from new
27
44
  $data[key] = Entry.new(DateTime.new + Rational(ttl, 24), value)
28
45
  end
29
46
 
30
47
  def self.delete(key)
48
+ if $data == nil
49
+ return nil
50
+ end
31
51
  $data.delete key
32
52
  end
33
53
 
34
54
  def self.clear
55
+ if $data == nil
56
+ return nil
57
+ end
35
58
  $data = Hash.new
36
59
  end
37
60
 
38
61
  def self.invalidate
62
+ if $data == nil
63
+ return nil
64
+ end
39
65
  now = DateTime.new
40
66
  $data.delete_if {|k, v| v[:expiry] < now}
41
67
  end
@@ -40,7 +40,7 @@ module SgtnClient
40
40
  :rest_endpoint, :rest_token_endpoint, :client_id, :client_secret,
41
41
  :openid_endpoint, :openid_redirect_uri, :openid_client_id, :openid_client_secret,
42
42
  :verbose_logging, :product_name, :version, :vip_server, :bundle_mode,
43
- :translation_bundle, :source_bundle
43
+ :translation_bundle, :source_bundle, :cache_expiry_period, :disable_cache
44
44
 
45
45
 
46
46
  # Create Config object
@@ -7,6 +7,7 @@ module SgtnClient
7
7
  autoload :Config, "sgtn-client/core/config"
8
8
  autoload :Logging, "sgtn-client/core/logging"
9
9
  autoload :Exceptions, "sgtn-client/core/exceptions"
10
+ autoload :ValidateUtil, "sgtn-client/util/validate-util"
10
11
 
11
12
  class << self
12
13
  def configure(options = {}, &block)
@@ -18,6 +19,7 @@ module SgtnClient
18
19
  # load configuration file
19
20
  begin
20
21
  SgtnClient::Config.load(args[0], args[1])
22
+ SgtnClient::ValidateUtil.validate_config()
21
23
  rescue => exception
22
24
  file = File.open('./error.log', 'a')
23
25
  file.sync = true
@@ -45,7 +47,12 @@ module SgtnClient
45
47
  end
46
48
 
47
49
  # initialize cache
48
- SgtnClient::Core::Cache.initialize()
50
+ disable_cache = SgtnClient::Config.configurations[env]["disable_cache"]
51
+ if disable_cache != nil
52
+ SgtnClient::Core::Cache.initialize(disable_cache)
53
+ else
54
+ SgtnClient::Core::Cache.initialize()
55
+ end
49
56
  end
50
57
 
51
58
  def logger
@@ -8,15 +8,20 @@ module SgtnClient
8
8
  end
9
9
 
10
10
  class CacheUtil
11
-
11
+
12
12
  def self.get_cache(cache_key)
13
13
  items = SgtnClient::Core::Cache.get(cache_key)
14
14
  return items
15
15
  end
16
16
 
17
17
  def self.write_cache(cache_key, items)
18
+ env = SgtnClient::Config.default_environment
19
+ cache_expiry_period = SgtnClient::Config.configurations[env]["cache_expiry_period"]
18
20
  # expired after 24 hours
19
- SgtnClient::Core::Cache.put(cache_key, items, 24)
21
+ if cache_expiry_period == nil
22
+ cache_expiry_period = 24
23
+ end
24
+ SgtnClient::Core::Cache.put(cache_key, items, cache_expiry_period)
20
25
  end
21
26
 
22
27
  def self.get_cachekey(component, locale)
@@ -0,0 +1,44 @@
1
+
2
+ module SgtnClient
3
+
4
+ class ValidateUtil
5
+
6
+ def self.validate_config()
7
+ SgtnClient.logger.debug "-----------Start to validate configuration's setting itmes-----------"
8
+ env = SgtnClient::Config.default_environment
9
+ messages = "\n"
10
+
11
+ mode = SgtnClient::Config.configurations[env]["mode"]
12
+ if mode != 'sandbox' && mode != 'live'
13
+ messages = messages + "Configuration[mode] has to be 'sandbox' or 'live'!\n"
14
+ end
15
+
16
+ bundle_mode = SgtnClient::Config.configurations[env]["bundle_mode"]
17
+ if bundle_mode != 'offline' && mode != 'online'
18
+ messages = messages + "Configuration[bundle_mode] has to be 'offline' or 'online'!\n"
19
+ end
20
+
21
+ version = SgtnClient::Config.configurations[env]["version"]
22
+ if version.is_a? Integer
23
+ messages = messages + "Configuration[version] has to be standard as '#.#.#, e.g '1.0.0'!\n"
24
+ end
25
+
26
+ cache_expiry_period = SgtnClient::Config.configurations[env]["cache_expiry_period"]
27
+ if cache_expiry_period != nil && (cache_expiry_period.is_a? Integer) == false
28
+ messages = messages + "Configuration[cache_expiry_period] has to be a number!\n"
29
+ end
30
+
31
+ disable_cache = SgtnClient::Config.configurations[env]["disable_cache"]
32
+ if disable_cache != nil && disable_cache != false && disable_cache != true
33
+ messages = messages + "Configuration[disable_cache] has to be a 'true' or 'false'!\n"
34
+ end
35
+
36
+ if messages != "\n"
37
+ raise SgtnClient::Exceptions::MissingConfig.new(messages)
38
+ end
39
+ SgtnClient.logger.debug "-----------End to validate configuration's setting itmes-----------"
40
+ end
41
+
42
+ end
43
+
44
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
 
2
- VERSION_INFO = [0, 0, 4].freeze
2
+ VERSION_INFO = [0, 0, 5].freeze
3
3
  VERSION = VERSION_INFO.map(&:to_s).join('.').freeze
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "component" : "JAVA",
3
3
  "messages" : {
4
+ "hello": "@hello@",
4
5
  "com.vmware.loginsight.web.settings.stats.StatsTable.host" : "Host",
5
6
  "com.vmware.loginsight.web.settings.stats.StatsTableType.eventsIngestionRatePerSecond" : "Events Ingestion Rate (Per Second)",
6
7
  "com.vmware.loginsight.web.settings.stats.StatsTableType.eventsIngestionRatePerSecond.help" : "The actual ingestion rate (syslog + API) of each node after message rebalancing.<br />Log Insight nodes will rebalance messages to attempt uniform ingestion per node for balanced retention and performance.<br /><br />Note that the ingestion rate of each node must be below the ingestion rate configuration maximum for a node.<br /><br />For the actual rate of events being sent directly to each node prior to message rebalancing, see the Syslog Events Incoming Rate (Per Second) and API Events Incoming Rate (Per Second) tables below.",
@@ -0,0 +1,11 @@
1
+ {
2
+ "component" : "JAVA",
3
+ "messages" : {
4
+ "com.vmware.loginsight.web.settings.stats.StatsTable.host" : "主机",
5
+ "com.vmware.loginsight.web.settings.stats.StatsTableType.eventsIngestionRatePerSecond" : "事件载入速率 (每秒)",
6
+ "com.vmware.loginsight.web.settings.stats.StatsTableType.eventsIngestionRatePerSecond.help" : "消息再平衡之后每个节点的实际载入速率 (syslog + API)。<br />Log Insight 节点将再平衡消息以尝试每节点的统一载入,从而实现平衡保留和性能。<br /><br />请注意,每个节点的载入速率必须低于配置的最大节点载入速率。<br /><br />有关消息再平衡之前直接发送到每个节点的事件的实际速率,请参见下述“Syslog 事件入站速率 (每秒)”和“API 事件入站速率 (每秒)”表。",
7
+ "com.vmware.loginsight.web.settings.stats.StatsTableType.syslogEventsIncomingRatePerSecond" : "Syslog 事件入站速率 (每秒)",
8
+ "com.vmware.loginsight.web.utilities.EmailUtil.upgrade.body48" : "{0} 现在正在运行版本 {1}。下面是 {1} 版本中新增的一些出色功能。我们感谢您一如既往地支持,同时非常重视您通过 Twitter 针对我们的 {3} 和 {4} 提供的反馈。<br /><br /><b>vRealize Log Insight 服务器功能</b><br />• TODO 增加服务器功能。<br /><br /><b>vRealize Log Insight 代理功能</b><br />• TODO 增加代理功能。<br /><br />有关 {0} 的新功能的详细信息,请查看 {0} v{1} {2}。<br /><br />祝您使用愉快!<br />{0} 团队<br /><br />"
9
+ },
10
+ "locale" : "zh-Hans"
11
+ }
@@ -0,0 +1,48 @@
1
+ test: &default
2
+
3
+ # Credentials for REST APIs
4
+ client_id: tee
5
+ client_secret: 89987
6
+
7
+ # Mode can be 'live' or 'sandbox'
8
+ mode: sandbox1
9
+
10
+ # Credentials for Classic APIs
11
+ app_id: APP-80W284485P519543T
12
+ username: linr
13
+ password: fdasf
14
+ signature: sfds-RWy
15
+ # # With Certificate
16
+ # cert_path: "config/cert_key.pem"
17
+ sandbox_email_address: linr@vmware.com
18
+
19
+ # #Product Name
20
+ product_name: logInsight
21
+
22
+ # # bundle version
23
+ version: 481
24
+
25
+ # # HTTP Proxy
26
+ vip_server: https://g11n-vip-dev-1.eng.vmware.com:8090
27
+
28
+ # # mode of bundle: online/offline
29
+ bundle_mode: offline1www
30
+
31
+ # # translation bundle Path
32
+ translation_bundle: ./spec/config/locales/l10n/bundles
33
+
34
+ # # source bundle Path
35
+ source_bundle: ./spec/config/locales/default
36
+
37
+ # # memory cache's expration(hours), default value is 24
38
+ cache_expiry_period: 36t
39
+
40
+ # # disable cache, it's optional setting
41
+ disable_cache: true1
42
+
43
+ development:
44
+ <<: *default
45
+
46
+ production:
47
+ <<: *default
48
+ mode: live
@@ -28,12 +28,18 @@ test: &default
28
28
  # # mode of bundle: online/offline
29
29
  bundle_mode: offline
30
30
 
31
- # # Offline Bundle Path
31
+ # # translation bundle Path
32
32
  translation_bundle: ./spec/config/locales/l10n/bundles
33
33
 
34
- # # Offline Bundle Path
34
+ # # source bundle Path
35
35
  source_bundle: ./spec/config/locales/default
36
36
 
37
+ # # memory cache's expration(hours), default value is 24
38
+ cache_expiry_period: 36
39
+
40
+ # # disable cache, it's optional setting
41
+ ##disable_cache: true
42
+
37
43
  development:
38
44
  <<: *default
39
45
 
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require_relative '../../lib/sgtn-client/sgtn-client.rb'
3
+
4
+ describe SgtnClient do
5
+
6
+ describe "loadinconfig" do
7
+
8
+ before :each do
9
+ #SgtnClient.load("./spec/config/sgtnclient-invalide.yml", "test", './sgtnclient_config.log')
10
+ end
11
+
12
+ it "validate_configuration" do
13
+ SgtnClient.load("./spec/config/sgtnclient-invalidate.yml", "test", './sgtnclient_config.log')
14
+ end
15
+
16
+ end
17
+ end
@@ -5,7 +5,7 @@ describe SgtnClient do
5
5
 
6
6
  before :each do
7
7
  env = SgtnClient::Config.default_environment
8
- SgtnClient::Config.configurations[env]["bundle_mode"] = 'online'
8
+ SgtnClient::Config.configurations[env]["bundle_mode"] = 'offline'
9
9
  SgtnClient::Source.loadBundles("en")
10
10
  end
11
11
 
@@ -15,6 +15,12 @@ describe SgtnClient do
15
15
  expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh-Hans")).to eq '主机'
16
16
  end
17
17
 
18
+ it "GET_zh_CN" do
19
+ expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh_CN")).to eq '主机'
20
+ # get from cache in 2nd time
21
+ expect(SgtnClient::Translation.getString("JAVA", "com.vmware.loginsight.web.settings.stats.StatsTable.host", "zh_CN")).to eq '主机'
22
+ end
23
+
18
24
  it "NonExistingKey" do
19
25
  expect(SgtnClient::Translation.getString("JAVA", "hello", "zh-Hans")).to eq 'Hello world'
20
26
  # get from cache in 2nd time
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singleton-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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: 2021-05-27 00:00:00.000000000 Z
11
+ date: 2021-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -225,6 +225,7 @@ files:
225
225
  - lib/sgtn-client/core/request.rb
226
226
  - lib/sgtn-client/sgtn-client.rb
227
227
  - lib/sgtn-client/util/cache-util.rb
228
+ - lib/sgtn-client/util/validate-util.rb
228
229
  - lib/singleton-ruby.rb
229
230
  - lib/version.rb
230
231
  - spec/config/locales/default/JAVA/en.yml
@@ -233,14 +234,17 @@ files:
233
234
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_latest.json
234
235
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hans.json
235
236
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hant.json
237
+ - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh_CN.json
236
238
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/creation.json
237
239
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/version.json
238
240
  - spec/config/sample_data.yml
241
+ - spec/config/sgtnclient-invalidate.yml
239
242
  - spec/config/sgtnclient.yml
240
243
  - spec/log/http.log
241
244
  - spec/spec_helper.rb
242
245
  - spec/support/sample_data.rb
243
246
  - spec/unit/config_spec.rb
247
+ - spec/unit/inconfig_spec.rb
244
248
  - spec/unit/logging_spec.rb
245
249
  - spec/unit/offclient_spec.rb
246
250
  - spec/unit/restclient_spec.rb
@@ -275,14 +279,17 @@ test_files:
275
279
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_latest.json
276
280
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hans.json
277
281
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh-Hant.json
282
+ - spec/config/locales/l10n/bundles/logInsight/4.8.1/JAVA/messages_zh_CN.json
278
283
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/creation.json
279
284
  - spec/config/locales/l10n/bundles/logInsight/4.8.1/version.json
280
285
  - spec/config/sample_data.yml
286
+ - spec/config/sgtnclient-invalidate.yml
281
287
  - spec/config/sgtnclient.yml
282
288
  - spec/log/http.log
283
289
  - spec/spec_helper.rb
284
290
  - spec/support/sample_data.rb
285
291
  - spec/unit/config_spec.rb
292
+ - spec/unit/inconfig_spec.rb
286
293
  - spec/unit/logging_spec.rb
287
294
  - spec/unit/offclient_spec.rb
288
295
  - spec/unit/restclient_spec.rb