Skip to content

Commit

Permalink
Merge pull request #713 from NREL/mongo_indexes
Browse files Browse the repository at this point in the history
Mongo indexes
  • Loading branch information
brianlball authored Sep 17, 2023
2 parents eb82244 + 8d9b1aa commit dab7e56
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 16 deletions.
7 changes: 6 additions & 1 deletion server/app/models/analysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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!
Expand Down
7 changes: 6 additions & 1 deletion server/app/models/data_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion server/app/models/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion server/app/models/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ 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)
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
Expand Down Expand Up @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion server/app/models/pareto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Pareto

# Indexes
index({ uuid: 1 }, unique: true)
index(id: 1)
#index(id: 1)
index(analysis_id: 1)

# Validation
Expand Down
7 changes: 6 additions & 1 deletion server/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ class Project

# Indexes
index({ uuid: 1 }, unique: true)
index(id: 1)
#index(id: 1)
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)
Expand All @@ -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!
Expand Down
7 changes: 6 additions & 1 deletion server/app/models/variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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!
Expand Down
78 changes: 75 additions & 3 deletions server/spec/features/docker_stack_algo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
#################################################################################

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 3 additions & 3 deletions server/spec/features/docker_stack_test_apis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
#################################################################################

Expand Down
15 changes: 12 additions & 3 deletions server/spec/features/docker_stack_urbanopt_algo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
#################################################################################

Expand Down Expand Up @@ -267,5 +268,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

0 comments on commit dab7e56

Please sign in to comment.