rubypitaya 3.15.3 → 3.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubypitaya/app-template/.gitignore +0 -0
  3. data/lib/rubypitaya/app-template/.gitlab-ci.yml +0 -0
  4. data/lib/rubypitaya/app-template/.irbrc +0 -0
  5. data/lib/rubypitaya/app-template/Gemfile +4 -4
  6. data/lib/rubypitaya/app-template/Gemfile.lock +94 -82
  7. data/lib/rubypitaya/app-template/Makefile +4 -4
  8. data/lib/rubypitaya/app-template/Rakefile +0 -0
  9. data/lib/rubypitaya/app-template/app/app_initializer.rb +3 -0
  10. data/lib/rubypitaya/app-template/app/bll/player_bll.rb +0 -0
  11. data/lib/rubypitaya/app-template/app/config/initial_player.json +0 -0
  12. data/lib/rubypitaya/app-template/app/constants/status_codes.rb +0 -0
  13. data/lib/rubypitaya/app-template/app/handlers/error_handler.rb +0 -0
  14. data/lib/rubypitaya/app-template/app/handlers/hello_world_handler.rb +0 -0
  15. data/lib/rubypitaya/app-template/app/handlers/player_handler.rb +0 -0
  16. data/lib/rubypitaya/app-template/app/http/hello_world_http.rb +0 -0
  17. data/lib/rubypitaya/app-template/app/http/views/hello_world.erb +0 -0
  18. data/lib/rubypitaya/app-template/app/migrations/1606736477_create_player_migration.rb +0 -0
  19. data/lib/rubypitaya/app-template/app/models/player.rb +0 -0
  20. data/lib/rubypitaya/app-template/app/models/user.rb +0 -0
  21. data/lib/rubypitaya/app-template/app/setup/rubypitaya.yml +1 -1
  22. data/lib/rubypitaya/app-template/config/routes.rb +0 -0
  23. data/lib/rubypitaya/app-template/docker/dev/Dockerfile +4 -7
  24. data/lib/rubypitaya/app-template/docker/prod/Dockerfile +8 -8
  25. data/lib/rubypitaya/app-template/docker/stag/docker-compose.stag.yaml +67 -0
  26. data/lib/rubypitaya/app-template/docker/stag/update_image +6 -0
  27. data/lib/rubypitaya/app-template/docker-compose.yml +8 -5
  28. data/lib/rubypitaya/app-template/features/hello_world.feature +0 -0
  29. data/lib/rubypitaya/app-template/features/player.feature +0 -0
  30. data/lib/rubypitaya/app-template/features/step_definitions/player_steps.rb +0 -0
  31. data/lib/rubypitaya/app-template/features/step_definitions/rubypitaya_steps.rb +0 -0
  32. data/lib/rubypitaya/app-template/features/support/env.rb +0 -0
  33. data/lib/rubypitaya/app-template/helm/Chart.yaml +0 -0
  34. data/lib/rubypitaya/app-template/helm/templates/config-maps/nginx-config.yaml +0 -0
  35. data/lib/rubypitaya/app-template/helm/templates/deployments/connector.yaml +0 -0
  36. data/lib/rubypitaya/app-template/helm/templates/deployments/gameserver-nginx.yaml +0 -0
  37. data/lib/rubypitaya/app-template/helm/templates/deployments/rubypitaya.yaml +0 -0
  38. data/lib/rubypitaya/app-template/helm/templates/pods/gameserver.yaml +0 -0
  39. data/lib/rubypitaya/app-template/helm/templates/role-bindings/rubypitaya.yaml +0 -0
  40. data/lib/rubypitaya/app-template/helm/templates/roles/rubypitaya.yaml +0 -0
  41. data/lib/rubypitaya/app-template/helm/templates/service-accounts/rubypitaya.yaml +0 -0
  42. data/lib/rubypitaya/app-template/helm/templates/services/connector.yaml +0 -0
  43. data/lib/rubypitaya/app-template/helm/templates/services/etcd.yaml +0 -0
  44. data/lib/rubypitaya/app-template/helm/templates/services/gameserver-nginx.yaml +0 -0
  45. data/lib/rubypitaya/app-template/helm/templates/services/gameserver.yaml +0 -0
  46. data/lib/rubypitaya/app-template/helm/templates/services/nats.yaml +0 -0
  47. data/lib/rubypitaya/app-template/helm/templates/services/redis.yaml +0 -0
  48. data/lib/rubypitaya/app-template/helm/templates/services/rubypitaya.yaml +0 -0
  49. data/lib/rubypitaya/app-template/helm/templates/statefulsets/etcd.yaml +0 -0
  50. data/lib/rubypitaya/app-template/helm/templates/statefulsets/nats.yaml +0 -0
  51. data/lib/rubypitaya/app-template/helm/templates/statefulsets/redis.yaml +0 -0
  52. data/lib/rubypitaya/app-template/helm/values.yaml +0 -0
  53. data/lib/rubypitaya/app-template/kubernetes/README.md +0 -0
  54. data/lib/rubypitaya/app-template/kubernetes/deployment-connector.yaml +0 -0
  55. data/lib/rubypitaya/app-template/kubernetes/deployment-rubypitaya.yaml +0 -0
  56. data/lib/rubypitaya/app-template/kubernetes/gameplay/deployment-nginx.yaml +0 -0
  57. data/lib/rubypitaya/app-template/kubernetes/gameplay/gameplay-template.yaml +0 -0
  58. data/lib/rubypitaya/app-template/kubernetes/gameplay/nginx.conf +0 -0
  59. data/lib/rubypitaya/app-template/kubernetes/gameplay/service-nginx.yaml +0 -0
  60. data/lib/rubypitaya/app-template/kubernetes/persistent-volume.yaml +0 -0
  61. data/lib/rubypitaya/app-template/kubernetes/role-rubypitaya.yaml +0 -0
  62. data/lib/rubypitaya/app-template/kubernetes/rolebinding-rubypitaya.yaml +0 -0
  63. data/lib/rubypitaya/app-template/kubernetes/service-connector.yaml +0 -0
  64. data/lib/rubypitaya/app-template/kubernetes/service-etcd.yaml +0 -0
  65. data/lib/rubypitaya/app-template/kubernetes/service-nats.yaml +0 -0
  66. data/lib/rubypitaya/app-template/kubernetes/service-postgres.yaml +0 -0
  67. data/lib/rubypitaya/app-template/kubernetes/service-redis.yaml +0 -0
  68. data/lib/rubypitaya/app-template/kubernetes/service-rubypitaya.yaml +0 -0
  69. data/lib/rubypitaya/app-template/kubernetes/statefulset-etcd.yaml +0 -0
  70. data/lib/rubypitaya/app-template/kubernetes/statefulset-nats.yaml +0 -0
  71. data/lib/rubypitaya/app-template/kubernetes/statefulset-postgres.yaml +0 -0
  72. data/lib/rubypitaya/app-template/kubernetes/statefulset-redis.yaml +0 -0
  73. data/lib/rubypitaya/app-template/plugins.yaml +0 -0
  74. data/lib/rubypitaya/app-template/spec/hello_world_handler_spec.rb +0 -0
  75. data/lib/rubypitaya/app-template/spec/player_handler_spec.rb +0 -0
  76. data/lib/rubypitaya/app-template/spec/redis_service_spec.rb +0 -0
  77. data/lib/rubypitaya/app-template/spec/spec_helper.rb +0 -0
  78. data/lib/rubypitaya/core/app/migrations/0000000001_create_user_migration.rb +0 -0
  79. data/lib/rubypitaya/core/app/models/user.rb +0 -0
  80. data/lib/rubypitaya/core/app/services/redis_service.rb +0 -0
  81. data/lib/rubypitaya/core/application_files_importer.rb +0 -0
  82. data/lib/rubypitaya/core/config.rb +0 -0
  83. data/lib/rubypitaya/core/config_core.rb +0 -0
  84. data/lib/rubypitaya/core/config_hash_extension.rb +0 -0
  85. data/lib/rubypitaya/core/database_config.rb +2 -0
  86. data/lib/rubypitaya/core/database_connector.rb +0 -0
  87. data/lib/rubypitaya/core/etcd_connector.rb +16 -6
  88. data/lib/rubypitaya/core/handler_base.rb +0 -0
  89. data/lib/rubypitaya/core/handler_router.rb +2 -0
  90. data/lib/rubypitaya/core/helpers/setup_helper.rb +0 -0
  91. data/lib/rubypitaya/core/http_base.rb +0 -0
  92. data/lib/rubypitaya/core/http_routes.rb +1 -1
  93. data/lib/rubypitaya/core/initializer_base.rb +0 -0
  94. data/lib/rubypitaya/core/initializer_broadcast.rb +0 -0
  95. data/lib/rubypitaya/core/initializer_content.rb +3 -2
  96. data/lib/rubypitaya/core/instance_holder.rb +0 -0
  97. data/lib/rubypitaya/core/main.rb +62 -60
  98. data/lib/rubypitaya/core/nats_connector.rb +0 -0
  99. data/lib/rubypitaya/core/parameters.rb +0 -0
  100. data/lib/rubypitaya/core/path.rb +0 -0
  101. data/lib/rubypitaya/core/postman.rb +0 -0
  102. data/lib/rubypitaya/core/protos/nats_connector.proto +0 -0
  103. data/lib/rubypitaya/core/protos/nats_connector_pb.rb +0 -0
  104. data/lib/rubypitaya/core/route_error.rb +0 -0
  105. data/lib/rubypitaya/core/routes_base.rb +0 -0
  106. data/lib/rubypitaya/core/service_base.rb +0 -0
  107. data/lib/rubypitaya/core/service_holder.rb +0 -0
  108. data/lib/rubypitaya/core/session.rb +0 -0
  109. data/lib/rubypitaya/core/setup.rb +0 -0
  110. data/lib/rubypitaya/core/spec-helpers/app_spec_helper.rb +2 -1
  111. data/lib/rubypitaya/core/spec-helpers/app_spec_helper_class.rb +0 -0
  112. data/lib/rubypitaya/core/spec-helpers/config_spec_helper.rb +0 -0
  113. data/lib/rubypitaya/core/spec-helpers/postman_spec_helper.rb +0 -0
  114. data/lib/rubypitaya/core/spec-helpers/rubypitaya_spec_helper.rb +1 -1
  115. data/lib/rubypitaya/core/spec-helpers/setup_spec_helper.rb +0 -0
  116. data/lib/rubypitaya/core/status_codes.rb +0 -0
  117. data/lib/rubypitaya/core/templates/template_migration.rb.erb +0 -0
  118. data/lib/rubypitaya/version.rb +1 -1
  119. data/lib/rubypitaya.rb +0 -0
  120. metadata +34 -32
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -13,6 +13,7 @@ module RubyPitaya
13
13
  'encoding' => 'unicode',
14
14
  'pool' => setup.fetch('rubypitaya.database.pool', 5),
15
15
  'host' => setup['rubypitaya.database.host'],
16
+ 'port' => setup['rubypitaya.database.port'],
16
17
  'user' => setup['rubypitaya.database.user'],
17
18
  'password' => setup['rubypitaya.database.password'],
18
19
  'database' => setup['rubypitaya.database.name'],
@@ -33,6 +34,7 @@ module RubyPitaya
33
34
  'encoding': config['encoding'],
34
35
  'pool': config['pool'],
35
36
  'host': config['host'],
37
+ 'port': config['port'],
36
38
  'user': config['user'],
37
39
  'password': config['password'],
38
40
  'database': config['database'],
File without changes
@@ -6,7 +6,7 @@ module RubyPitaya
6
6
  class EtcdConnector
7
7
 
8
8
  def initialize(server_uuid, desktop_name, server_name, etcd_prefix,
9
- etcd_address, allow_reconnect, lease_seconds)
9
+ etcd_address, allow_reconnect, lease_seconds, log)
10
10
  @server_uuid = server_uuid
11
11
  @server_name = server_name
12
12
  @desktop_name = desktop_name
@@ -14,6 +14,7 @@ module RubyPitaya
14
14
  @etcd_address = etcd_address
15
15
  @allow_reconnect = allow_reconnect
16
16
  @lease_seconds = lease_seconds
17
+ @log = log
17
18
 
18
19
  @renew_connection_seconds = lease_seconds / 2.0
19
20
 
@@ -27,7 +28,7 @@ module RubyPitaya
27
28
  connection_value = get_connection_value
28
29
 
29
30
  @connection = Etcdv3.new(endpoints: @etcd_address,
30
- allow_reconnect: @allow_reconnect)
31
+ allow_reconnect: @allow_reconnect)
31
32
 
32
33
  @lease = @connection.lease_grant(@lease_seconds)
33
34
 
@@ -40,6 +41,7 @@ module RubyPitaya
40
41
  end
41
42
 
42
43
  def disconnect
44
+ stop_renew_connection
43
45
  @connection.del(get_connection_key)
44
46
  end
45
47
 
@@ -60,15 +62,23 @@ module RubyPitaya
60
62
  loop do
61
63
  sleep(@renew_connection_seconds)
62
64
 
63
- @lease = @connection.lease_grant(@lease_seconds)
64
- @connection.put(@renew_connection_key, @renew_connection_value,
65
- lease: @lease.ID)
65
+ begin
66
+ @lease = @connection.lease_keep_alive_once(@lease.ID)
67
+
68
+ if @lease.TTL == 0
69
+ @lease = @connection.lease_grant(@lease_seconds)
70
+ @connection.put(@renew_connection_key, @renew_connection_value, lease: @lease.ID)
71
+ end
72
+
73
+ rescue Exception => error
74
+ @log.error "ETCD RENEW ERROR: #{error.class} | #{error.message}} \n #{error.backtrace.join("\n")}"
75
+ end
66
76
  end
67
77
  end
68
78
  end
69
79
 
70
80
  def stop_renew_connection
71
- @renew_connection_thread.exit unless @renew_connection_thread.nil?
81
+ @renew_connection_thread.exit.join unless @renew_connection_thread.nil?
72
82
  end
73
83
 
74
84
  def get_server_data
File without changes
@@ -8,6 +8,8 @@ module RubyPitaya
8
8
 
9
9
  INVALID_ACTION_NAMES = ['initialize', 'set_attributes']
10
10
 
11
+ attr_reader :handlers
12
+
11
13
  def initialize(is_cheats_enabled)
12
14
  @is_cheats_enabled = is_cheats_enabled
13
15
 
File without changes
File without changes
@@ -44,7 +44,7 @@ module RubyPitaya
44
44
  end
45
45
 
46
46
  after do
47
- ActiveRecord::Base.clear_active_connections!
47
+ ActiveRecord::Base.connection_handler.clear_active_connections!
48
48
  end
49
49
 
50
50
  private
File without changes
File without changes
@@ -2,13 +2,14 @@ module RubyPitaya
2
2
 
3
3
  class InitializerContent
4
4
 
5
- attr_reader :log, :services, :setup, :config
5
+ attr_reader :log, :services, :setup, :config, :handlers
6
6
 
7
- def initialize(log, services, setup, config)
7
+ def initialize(log, services, setup, config, handlers)
8
8
  @log = log
9
9
  @services = services
10
10
  @setup = setup
11
11
  @config = config
12
+ @handlers = handlers
12
13
  end
13
14
  end
14
15
  end
File without changes
@@ -50,12 +50,12 @@ module RubyPitaya
50
50
 
51
51
  @etcd_prefix = @setup['rubypitaya.etcd.prefix']
52
52
  @etcd_address = @setup['rubypitaya.etcd.url']
53
- @etcd_lease_seconds = @setup['rubypitaya.etcd.leaseSeconds'].to_i
53
+ @etcd_lease_seconds = @setup['rubypitaya.etcd.leaseSeconds']
54
54
  @allow_reconnect = false
55
55
  @etcd_connector = EtcdConnector.new(@service_uuid, @desktop_name,
56
56
  @server_name, @etcd_prefix,
57
57
  @etcd_address, @allow_reconnect,
58
- @etcd_lease_seconds)
58
+ @etcd_lease_seconds, @log)
59
59
  @etcd_connector.connect
60
60
 
61
61
  @nats_address = @setup['rubypitaya.nats.url']
@@ -72,15 +72,16 @@ module RubyPitaya
72
72
 
73
73
  @services = ServiceHolder.new
74
74
 
75
+ @handler_router = HandlerRouter.new(@is_cheats_enabled)
76
+
75
77
  @initializer_content = InitializerContent.new(@log,
76
78
  @services,
77
79
  @setup,
78
- @config)
80
+ @config,
81
+ @handler_router.handlers)
79
82
  @initializer_broadcast = InitializerBroadcast.new
80
83
  @initializer_broadcast.run(@initializer_content)
81
84
 
82
- @handler_router = HandlerRouter.new(@is_cheats_enabled)
83
-
84
85
  connect_services
85
86
 
86
87
  run_http
@@ -148,63 +149,64 @@ module RubyPitaya
148
149
  end
149
150
 
150
151
  def run_nats_connection
151
- @nats_connector.connect do |request|
152
- start_time_seconds = Time.now.to_f
153
-
154
- message_route = request[:msg][:route]
155
- message_data = request[:msg][:data]
156
- message_json = JSON.parse(message_data) if !message_data.nil? && !message_data.empty?
157
-
158
- params = Parameters.new(message_json || {})
159
-
160
- session_id = request[:session][:id]
161
- session_uid = request[:session].fetch(:uid, '')
162
- session_data = request[:session][:data]
163
- session_data = JSON.parse(session_data, symbolize_names: true)
164
- frontend_id = request[:frontendID]
165
- metadata = request[:metadata]
166
- metadata = JSON.parse(metadata, symbolize_names: true)
167
-
168
- @session.update(session_id, session_uid, session_data, metadata,
169
- frontend_id)
170
-
171
- handler_name, action_name = message_route.scan(/\A\w+\.(\w+)\.(\w+)\z/)[0]
172
-
173
- @log.info "request -> route: #{message_route}"
174
- @log.info " -> data: #{message_data}"
175
-
176
- @config.clear_cache
177
-
178
- response = {}
179
-
180
- begin
181
- response = @handler_router.call(handler_name, action_name, @session,
182
- @postman, @services, @setup, @config,
183
- @log, params)
184
- rescue RouteError => error
185
- @log.error "ROUTE ERROR: #{error.code} | #{error.class} | #{error.message} \n #{error.backtrace.join("\n")}"
186
- response = {
187
- code: error.code,
188
- message: error.message
189
- }
190
- rescue Exception => error
191
- @log.error "INTERNAL ERROR: #{error.class} | #{error.message} \n #{error.backtrace.join("\n")}"
192
- response = {
193
- code: StatusCodes::CODE_INTERNAL_ERROR,
194
- message: StatusCodes::MESSAGE_INTERNAL_ERROR,
195
- }
152
+ loop do
153
+ @nats_connector.connect do |request|
154
+ start_time_seconds = Time.now.to_f
155
+
156
+ message_route = request[:msg][:route]
157
+ message_data = request[:msg][:data]
158
+ message_json = JSON.parse(message_data) if !message_data.nil? && !message_data.empty?
159
+
160
+ params = Parameters.new(message_json || {})
161
+
162
+ session_id = request[:session][:id]
163
+ session_uid = request[:session].fetch(:uid, '')
164
+ session_data = request[:session][:data]
165
+ session_data = JSON.parse(session_data, symbolize_names: true)
166
+ frontend_id = request[:frontendID]
167
+ metadata = request[:metadata]
168
+ metadata = JSON.parse(metadata, symbolize_names: true)
169
+
170
+ @session.update(session_id, session_uid, session_data, metadata,
171
+ frontend_id)
172
+
173
+ handler_name, action_name = message_route.scan(/\A\w+\.(\w+)\.(\w+)\z/)[0]
174
+
175
+ @log.info "request -> route: #{message_route}"
176
+ @log.info " -> data: #{message_data}"
177
+
178
+ @config.clear_cache
179
+
180
+ response = {}
181
+
182
+ begin
183
+ response = @handler_router.call(handler_name, action_name, @session,
184
+ @postman, @services, @setup, @config,
185
+ @log, params)
186
+ rescue RouteError => error
187
+ @log.error "ROUTE ERROR: #{error.code} | #{error.class} | #{error.message} \n #{error.backtrace.join("\n")}"
188
+ response = {
189
+ code: error.code,
190
+ message: error.message
191
+ }
192
+ rescue Exception => error
193
+ @log.error "INTERNAL ERROR: #{error.class} | #{error.message} \n #{error.backtrace.join("\n")}"
194
+ response = {
195
+ code: StatusCodes::CODE_INTERNAL_ERROR,
196
+ message: StatusCodes::MESSAGE_INTERNAL_ERROR,
197
+ }
198
+ end
199
+
200
+ response_json = JSON.generate(response)
201
+ delta_time_seconds = ((Time.now.to_f - start_time_seconds) * 1000).round(2)
202
+
203
+ @log.info "response [#{delta_time_seconds}ms] -> #{response_json}"
204
+
205
+ response_json
196
206
  end
197
-
198
- response_json = JSON.generate(response)
199
- delta_time_seconds = ((Time.now.to_f - start_time_seconds) * 1000).round(2)
200
-
201
- @log.info "response [#{delta_time_seconds}ms] -> #{response_json}"
202
-
203
- response_json
207
+ rescue Exception => error
208
+ @log.error "INTERNAL ERROR: #{error.class} | #{error.message}} \n #{error.backtrace.join("\n")}"
204
209
  end
205
- rescue Exception => error
206
- @log.error "INTERNAL ERROR: #{error.class} | #{error.message}} \n #{error.backtrace.join("\n")}"
207
- run_nats_connection
208
210
  end
209
211
  end
210
212
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -27,7 +27,8 @@ module RubyPitaya
27
27
  @@initializer_content = InitializerContent.new(@@log,
28
28
  @@services,
29
29
  @@setup,
30
- @@config)
30
+ @@config,
31
+ @@handler_router.handlers)
31
32
  @@initializer_broadcast = InitializerBroadcast.new
32
33
  @@initializer_broadcast.run(@@initializer_content)
33
34
 
@@ -22,6 +22,6 @@ RSpec.configure do |config|
22
22
  end
23
23
 
24
24
  config.after(:each) do
25
- ActiveRecord::Base.clear_active_connections!
25
+ ActiveRecord::Base.connection_handler.clear_active_connections!
26
26
  end
27
27
  end
File without changes
@@ -1,3 +1,3 @@
1
1
  module RubyPitaya
2
- VERSION = '3.15.3'
2
+ VERSION = '3.17.0'
3
3
  end
data/lib/rubypitaya.rb CHANGED
File without changes