From b53f044d254bcda171690f95a6a3bd006ae91a44 Mon Sep 17 00:00:00 2001 From: brianlball Date: Thu, 14 Sep 2023 17:59:54 -0400 Subject: [PATCH 1/5] remove index(id: 1) since there is index automatically on _id --- server/app/models/analysis.rb | 2 +- server/app/models/data_point.rb | 2 +- server/app/models/job.rb | 2 +- server/app/models/measure.rb | 2 +- server/app/models/pareto.rb | 2 +- server/app/models/project.rb | 2 +- server/app/models/variable.rb | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/server/app/models/analysis.rb b/server/app/models/analysis.rb index 34a58a7f0..e5340655a 100644 --- a/server/app/models/analysis.rb +++ b/server/app/models/analysis.rb @@ -71,7 +71,7 @@ class Analysis # Indexes index({ uuid: 1 }, unique: true) - index(id: 1) + #index(id: 1) index(name: 1) index(created_at: 1) index(updated_at: -1) diff --git a/server/app/models/data_point.rb b/server/app/models/data_point.rb index b62996193..955ff2b7d 100644 --- a/server/app/models/data_point.rb +++ b/server/app/models/data_point.rb @@ -37,7 +37,7 @@ class DataPoint # Indexes index({ uuid: 1 }, unique: true) - index(id: 1) + #index(id: 1) index(name: 1) index(status: 1) index(analysis_id: 1, created_at: 1) diff --git a/server/app/models/job.rb b/server/app/models/job.rb index f3c7255bb..9ba37ca18 100644 --- a/server/app/models/job.rb +++ b/server/app/models/job.rb @@ -22,7 +22,7 @@ class Job belongs_to :analysis - index(id: 1) + #index(id: 1) index(created_at: 1) index(analysis_id: 1) index(analysis_id: 1, index: 1, analysis_type: 1) diff --git a/server/app/models/measure.rb b/server/app/models/measure.rb index 9c6ffc833..aedbba0ad 100644 --- a/server/app/models/measure.rb +++ b/server/app/models/measure.rb @@ -24,7 +24,7 @@ class Measure # Indexes index({ uuid: 1 }, unique: true) - index(id: 1) + #index(id: 1) index(name: 1) index(analysis_id: 1) index(analysis_id: 1, uuid: 1) diff --git a/server/app/models/pareto.rb b/server/app/models/pareto.rb index 3c7ff776f..08d336347 100644 --- a/server/app/models/pareto.rb +++ b/server/app/models/pareto.rb @@ -20,7 +20,7 @@ class Pareto # Indexes index({ uuid: 1 }, unique: true) - index(id: 1) + #index(id: 1) index(analysis_id: 1) # Validation diff --git a/server/app/models/project.rb b/server/app/models/project.rb index fafcb2ea6..3f138f0ac 100644 --- a/server/app/models/project.rb +++ b/server/app/models/project.rb @@ -17,7 +17,7 @@ class Project # Indexes index({ uuid: 1 }, unique: true) - index(id: 1) + #index(id: 1) index(name: 1) # Callbacks diff --git a/server/app/models/variable.rb b/server/app/models/variable.rb index 56e0028ec..97c0b0446 100644 --- a/server/app/models/variable.rb +++ b/server/app/models/variable.rb @@ -63,7 +63,7 @@ class Variable # Indexes index({ uuid: 1 }, unique: true) - index(id: 1) + #index(id: 1) index(name: 1) index(r_index: 1) index(analysis_id: 1) From d6bba83646bbb0165bf72adbb6a6267aa65760b5 Mon Sep 17 00:00:00 2001 From: brianlball Date: Fri, 15 Sep 2023 12:57:00 -0400 Subject: [PATCH 2/5] add def set_uuid_from_id and run at callback :before_create --- server/app/models/analysis.rb | 5 +++++ server/app/models/data_point.rb | 5 +++++ server/app/models/measure.rb | 5 +++++ server/app/models/project.rb | 5 +++++ server/app/models/variable.rb | 5 +++++ 5 files changed, 25 insertions(+) diff --git a/server/app/models/analysis.rb b/server/app/models/analysis.rb index e5340655a..188f38386 100644 --- a/server/app/models/analysis.rb +++ b/server/app/models/analysis.rb @@ -82,6 +82,7 @@ class Analysis validates_attachment_content_type :seed_zip, content_type: ['application/zip'] # Callbacks + before_create :set_uuid_from_id after_create :verify_uuid before_destroy :queue_delete_files @@ -510,6 +511,10 @@ def queue_delete_files end end + def set_uuid_from_id + self.uuid = id + end + def verify_uuid self.uuid = id if uuid.nil? save! diff --git a/server/app/models/data_point.rb b/server/app/models/data_point.rb index 955ff2b7d..f3009f781 100644 --- a/server/app/models/data_point.rb +++ b/server/app/models/data_point.rb @@ -50,6 +50,7 @@ class DataPoint index(analysis_id: 1, status: 1, status_message: 1, created_at: 1) # Callbacks + before_create :set_uuid_from_id after_create :verify_uuid before_destroy :destroy_background_job @@ -125,6 +126,10 @@ def set_queued_state protected + def set_uuid_from_id + self.uuid = id + end + def verify_uuid self.uuid = id if uuid.nil? save! diff --git a/server/app/models/measure.rb b/server/app/models/measure.rb index aedbba0ad..72a8b875a 100644 --- a/server/app/models/measure.rb +++ b/server/app/models/measure.rb @@ -31,6 +31,7 @@ class Measure index({ analysis_id: 1, name: 1 }, unique: true) # Callbacks + before_create :set_uuid_from_id after_create :verify_uuid # Parse Analysis JSON to pull out the measures and variables @@ -145,6 +146,10 @@ def self.create_from_os_json(analysis_id, os_json, pat_json) protected + def set_uuid_from_id + self.uuid = id + end + def verify_uuid self.uuid = id if uuid.nil? save! diff --git a/server/app/models/project.rb b/server/app/models/project.rb index 3f138f0ac..772dacbd0 100644 --- a/server/app/models/project.rb +++ b/server/app/models/project.rb @@ -21,6 +21,7 @@ class Project index(name: 1) # Callbacks + before_create :set_uuid_from_id after_create :verify_uuid def create_single_analysis(analysis_uuid, analysis_name, problem_uuid, problem_name) @@ -36,6 +37,10 @@ def create_single_analysis(analysis_uuid, analysis_name, problem_uuid, problem_n protected + def set_uuid_from_id + self.uuid = id + end + def verify_uuid self.uuid = id if uuid.nil? save! diff --git a/server/app/models/variable.rb b/server/app/models/variable.rb index 97c0b0446..034d5af13 100644 --- a/server/app/models/variable.rb +++ b/server/app/models/variable.rb @@ -76,6 +76,7 @@ class Variable # validates_attachment :seed_zip, content_type: { content_type: "application/zip" } # Callbacks + before_create :set_uuid_from_id after_create :verify_uuid before_destroy :destroy_preflight_images @@ -382,6 +383,10 @@ def map_discrete_hash_to_array protected + def set_uuid_from_id + self.uuid = id + end + def verify_uuid self.uuid = id if uuid.nil? save! From 4b93ea6efb0a15976aea6d84062a8135559848db Mon Sep 17 00:00:00 2001 From: brianlball Date: Fri, 15 Sep 2023 14:16:53 -0400 Subject: [PATCH 3/5] add test for checking mongo indexes --- .../spec/features/docker_stack_algo_spec.rb | 72 +++++++++++++++++++ .../docker_stack_urbanopt_algo_spec.rb | 8 +++ 2 files changed, 80 insertions(+) diff --git a/server/spec/features/docker_stack_algo_spec.rb b/server/spec/features/docker_stack_algo_spec.rb index e24032cf7..9a43afe73 100644 --- a/server/spec/features/docker_stack_algo_spec.rb +++ b/server/spec/features/docker_stack_algo_spec.rb @@ -213,6 +213,14 @@ sleep Random.new.rand(1.0..10.0) retry if get_count <= get_count_max end + + puts 'check logs for mongo index errors' + a = RestClient.get "http://#{@host}/analyses/#{analysis_id}/debug_log" + expect(a.headers[:status]).to eq("200 OK") + expect(a.body).not_to include "OperationFailure" + expect(a.body).not_to include "FATAL" + expect(a.body).to include "Created indexes" + end # cli_test it 'run spea_nrel analysis', :spea_nrel, js: true do @@ -346,6 +354,14 @@ sleep Random.new.rand(1.0..10.0) retry if get_count <= get_count_max end + + puts 'check logs for mongo index errors' + a = RestClient.get "http://#{@host}/analyses/#{analysis_id}/debug_log" + expect(a.headers[:status]).to eq("200 OK") + expect(a.body).not_to include "OperationFailure" + expect(a.body).not_to include "FATAL" + expect(a.body).to include "Created indexes" + end # spea_nrel it 'run pso analysis', :pso, js: true do @@ -479,6 +495,14 @@ sleep Random.new.rand(1.0..10.0) retry if get_count <= get_count_max end + + puts 'check logs for mongo index errors' + a = RestClient.get "http://#{@host}/analyses/#{analysis_id}/debug_log" + expect(a.headers[:status]).to eq("200 OK") + expect(a.body).not_to include "OperationFailure" + expect(a.body).not_to include "FATAL" + expect(a.body).to include "Created indexes" + end # pso it 'run rgenoud analysis', :rgenoud, js: true do @@ -613,6 +637,14 @@ sleep Random.new.rand(1.0..10.0) retry if get_count <= get_count_max end + + puts 'check logs for mongo index errors' + a = RestClient.get "http://#{@host}/analyses/#{analysis_id}/debug_log" + expect(a.headers[:status]).to eq("200 OK") + expect(a.body).not_to include "OperationFailure" + expect(a.body).not_to include "FATAL" + expect(a.body).to include "Created indexes" + end # rgenoud it 'run sobol analysis', :sobol, js: true do @@ -770,6 +802,14 @@ expect(a.headers[:content_type]).to eq("application/zip") expect(a.size).to be >(30000) expect(a.size).to be <(40000) + + puts 'check logs for mongo index errors' + a = RestClient.get "http://#{@host}/analyses/#{analysis_id}/debug_log" + expect(a.headers[:status]).to eq("200 OK") + expect(a.body).not_to include "OperationFailure" + expect(a.body).not_to include "FATAL" + expect(a.body).to include "Created indexes" + end # sobol it 'run lhs analysis', :lhs, js: true do @@ -908,6 +948,14 @@ sleep Random.new.rand(1.0..10.0) retry if get_count <= get_count_max end + + puts 'check logs for mongo index errors' + a = RestClient.get "http://#{@host}/analyses/#{analysis_id}/debug_log" + expect(a.headers[:status]).to eq("200 OK") + expect(a.body).not_to include "OperationFailure" + expect(a.body).not_to include "FATAL" + expect(a.body).to include "Created indexes" + end # lhs it 'run lhs_discrete analysis', :lhs_discrete, js: true do @@ -1051,6 +1099,14 @@ sleep Random.new.rand(1.0..10.0) retry if get_count <= get_count_max end + + puts 'check logs for mongo index errors' + a = RestClient.get "http://#{@host}/analyses/#{analysis_id}/debug_log" + expect(a.headers[:status]).to eq("200 OK") + expect(a.body).not_to include "OperationFailure" + expect(a.body).not_to include "FATAL" + expect(a.body).to include "Created indexes" + end # lhs_discrete it 'run morris analysis', :morris, js: true do @@ -1196,6 +1252,14 @@ expect(a.headers[:content_type]).to eq("application/zip") expect(a.size).to be >(170000) expect(a.size).to be <(200000) + + puts 'check logs for mongo index errors' + a = RestClient.get "http://#{@host}/analyses/#{analysis_id}/debug_log" + expect(a.headers[:status]).to eq("200 OK") + expect(a.body).not_to include "OperationFailure" + expect(a.body).not_to include "FATAL" + expect(a.body).to include "Created indexes" + end # morris it 'run single_run analysis', :single_run, js: true do @@ -1325,5 +1389,13 @@ sleep Random.new.rand(1.0..10.0) retry if get_count <= get_count_max end + + puts 'check logs for mongo index errors' + a = RestClient.get "http://#{@host}/analyses/#{analysis_id}/debug_log" + expect(a.headers[:status]).to eq("200 OK") + expect(a.body).not_to include "OperationFailure" + expect(a.body).not_to include "FATAL" + expect(a.body).to include "Created indexes" + end # single_run end diff --git a/server/spec/features/docker_stack_urbanopt_algo_spec.rb b/server/spec/features/docker_stack_urbanopt_algo_spec.rb index ba1c48466..6fb71b6e0 100644 --- a/server/spec/features/docker_stack_urbanopt_algo_spec.rb +++ b/server/spec/features/docker_stack_urbanopt_algo_spec.rb @@ -267,5 +267,13 @@ sleep Random.new.rand(1.0..10.0) retry if get_count <= get_count_max end + + puts 'check logs for mongo index errors' + a = RestClient.get "http://#{@host}/analyses/#{analysis_id}/debug_log" + expect(a.headers[:status]).to eq("200 OK") + expect(a.body).not_to include "OperationFailure" + expect(a.body).not_to include "FATAL" + expect(a.body).to include "Created indexes" + end # urbanopt_single_run end From ed21666f9c120503fc0c964683019b482281a62b Mon Sep 17 00:00:00 2001 From: brianlball Date: Fri, 15 Sep 2023 15:49:47 -0400 Subject: [PATCH 4/5] update comments on how to run tests locally --- server/spec/features/docker_stack_algo_spec.rb | 6 +++--- server/spec/features/docker_stack_urbanopt_algo_spec.rb | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/server/spec/features/docker_stack_algo_spec.rb b/server/spec/features/docker_stack_algo_spec.rb index 9a43afe73..2cf4dfceb 100644 --- a/server/spec/features/docker_stack_algo_spec.rb +++ b/server/spec/features/docker_stack_algo_spec.rb @@ -7,10 +7,10 @@ # To Run this test manually: # # start a server stack with /spec added and ssh into the Web container +# you may need to ADD the spec folder in the Dockerfile # >ruby /opt/openstudio/bin/openstudio_meta install_gems -# >cd /opt/openstudio/spec/ -# >gem install rspec -# >rspec openstudio_algo_spec.rb +# >bundle install --with development test +# >rspec spec/features/docker_stack_algo_spec.rb # ################################################################################# diff --git a/server/spec/features/docker_stack_urbanopt_algo_spec.rb b/server/spec/features/docker_stack_urbanopt_algo_spec.rb index 6fb71b6e0..cfcd7482c 100644 --- a/server/spec/features/docker_stack_urbanopt_algo_spec.rb +++ b/server/spec/features/docker_stack_urbanopt_algo_spec.rb @@ -7,9 +7,10 @@ # To Run this test manually: # # start a server stack with /spec added and ssh into the Web container -# >cd /opt/openstudio/server/spec/ -# >gem install rest-client rails_helper json rspec rspec-retry -# >rspec openstudio_algo_spec.rb +# you may need to ADD the spec folder in the Dockerfile +# >ruby /opt/openstudio/bin/openstudio_meta install_gems +# >bundle install --with development test +# >rspec spec/features/docker_stack_urbanopt_algo_spec.rb # ################################################################################# From 8d9b1aa8d1e61bd128b9b65ff4b8f50d45408840 Mon Sep 17 00:00:00 2001 From: Brian Ball Date: Fri, 15 Sep 2023 18:20:06 -0400 Subject: [PATCH 5/5] Update docker_stack_test_apis_spec.rb --- server/spec/features/docker_stack_test_apis_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/spec/features/docker_stack_test_apis_spec.rb b/server/spec/features/docker_stack_test_apis_spec.rb index 321010642..fe776d719 100644 --- a/server/spec/features/docker_stack_test_apis_spec.rb +++ b/server/spec/features/docker_stack_test_apis_spec.rb @@ -7,10 +7,10 @@ # To Run this test manually: # # start a server stack with /spec added and ssh into the Web container +# you may need to ADD the spec folder in the Dockerfile # >ruby /opt/openstudio/bin/openstudio_meta install_gems -# >cd /opt/openstudio/spec/ -# >gem install rspec -# >rspec openstudio_algo_spec.rb +# >bundle install --with development test +# >rspec spec/features/docker_stack_test_apis_spec.rb # #################################################################################