Skip to content
This repository has been archived by the owner on Jul 14, 2020. It is now read-only.

Update for new schema #60

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5.1'
gem 'rails', '~> 4.2'

gem 'bootstrap-sass', '~> 3.3.4.1'
gem 'autoprefixer-rails'
Expand Down
88 changes: 45 additions & 43 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.5.1)
actionpack (= 4.2.5.1)
actionview (= 4.2.5.1)
activejob (= 4.2.5.1)
actionmailer (4.2.7)
actionpack (= 4.2.7)
actionview (= 4.2.7)
activejob (= 4.2.7)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.5.1)
actionview (= 4.2.5.1)
activesupport (= 4.2.5.1)
actionpack (4.2.7)
actionview (= 4.2.7)
activesupport (= 4.2.7)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.5.1)
activesupport (= 4.2.5.1)
actionview (4.2.7)
activesupport (= 4.2.7)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (4.2.5.1)
activesupport (= 4.2.5.1)
activejob (4.2.7)
activesupport (= 4.2.7)
globalid (>= 0.3.0)
activemodel (4.2.5.1)
activesupport (= 4.2.5.1)
activemodel (4.2.7)
activesupport (= 4.2.7)
builder (~> 3.1)
activerecord (4.2.5.1)
activemodel (= 4.2.5.1)
activesupport (= 4.2.5.1)
activerecord (4.2.7)
activemodel (= 4.2.7)
activesupport (= 4.2.7)
arel (~> 6.0)
activesupport (4.2.5.1)
activesupport (4.2.7)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
Expand Down Expand Up @@ -83,7 +83,7 @@ GEM
execjs
coffee-script-source (1.9.1)
colorize (0.7.7)
concurrent-ruby (1.0.0)
concurrent-ruby (1.0.2)
database_cleaner (1.4.1)
diff-lcs (1.2.5)
domain_name (0.5.25)
Expand All @@ -99,7 +99,7 @@ GEM
multipart-post (>= 1.2, < 3)
friendly_id (5.1.0)
activerecord (>= 4.0.0)
globalid (0.3.6)
globalid (0.3.7)
activesupport (>= 4.1.0)
http-cookie (1.0.2)
domain_name (~> 0.5)
Expand All @@ -126,11 +126,11 @@ GEM
capistrano-bundle_audit (>= 0.0.3)
capistrano-one_time_key
capistrano-releaseboard
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.99)
mini_portile2 (2.0.0)
minitest (5.8.4)
mail (2.6.4)
mime-types (>= 1.16, < 4)
mime-types (2.99.2)
mini_portile2 (2.1.0)
minitest (5.9.0)
multi_json (1.11.1)
multipart-post (2.0.0)
net-ping (1.7.7)
Expand All @@ -139,12 +139,14 @@ GEM
net-ssh (2.9.2)
netrc (0.11.0)
newrelic_rpm (3.10.0.279)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
pg (0.18.1)
pg_csv (0.1.8)
activerecord
pg (~> 0.17)
pkg-config (1.1.7)
poltergeist (1.6.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
Expand All @@ -153,16 +155,16 @@ GEM
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.5.1)
actionmailer (= 4.2.5.1)
actionpack (= 4.2.5.1)
actionview (= 4.2.5.1)
activejob (= 4.2.5.1)
activemodel (= 4.2.5.1)
activerecord (= 4.2.5.1)
activesupport (= 4.2.5.1)
rails (4.2.7)
actionmailer (= 4.2.7)
actionpack (= 4.2.7)
actionview (= 4.2.7)
activejob (= 4.2.7)
activemodel (= 4.2.7)
activerecord (= 4.2.7)
activesupport (= 4.2.7)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.5.1)
railties (= 4.2.7)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
Expand All @@ -174,12 +176,12 @@ GEM
loofah (~> 2.0)
rails_config (0.4.2)
activesupport (>= 3.0)
railties (4.2.5.1)
actionpack (= 4.2.5.1)
activesupport (= 4.2.5.1)
railties (4.2.7)
actionpack (= 4.2.7)
activesupport (= 4.2.7)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.5.0)
rake (11.2.2)
rdoc (4.2.0)
json (~> 1.4)
ref (1.0.5)
Expand Down Expand Up @@ -216,10 +218,10 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
sprockets (3.5.2)
sprockets (3.7.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.0.0)
sprockets-rails (3.1.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
Expand Down Expand Up @@ -284,7 +286,7 @@ DEPENDENCIES
pg
pg_csv
poltergeist
rails (= 4.2.5.1)
rails (~> 4.2)
rails_config
rake
rest-client
Expand All @@ -300,4 +302,4 @@ DEPENDENCIES
whenever

BUNDLED WITH
1.10.6
1.12.5
10 changes: 10 additions & 0 deletions app/models/endpoint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Endpoint < ActiveRecord::Base
has_many :pings
belongs_to :host
validates :url, presence: true
has_many :layers

def last_ping_status
pings.recent_status
end
end
8 changes: 2 additions & 6 deletions app/models/host.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Host < ActiveRecord::Base
belongs_to :institution
has_many :layers
has_many :pings
has_many :endpoints
has_many :layers, through: :endpoints
validates :institution_id, presence: true
before_create :check_and_increment

Expand All @@ -18,10 +18,6 @@ def overall_status(options = {})
end
end

def last_ping_status
pings.recent_status
end

def layers_count(options = {})
if options[:force_update]
Rails.cache.write("host/#{id}/layers_count", calculate_layers_count)
Expand Down
3 changes: 2 additions & 1 deletion app/models/institution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Institution < ActiveRecord::Base

def layer_count
hosts = Host.where(institution_id: id).ids
Layer.where(host_id: hosts).count
endpoints = Endpoint.where(host: hosts)
Layer.where(endpoint: endpoints).count
end
end
8 changes: 5 additions & 3 deletions app/models/layer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class Layer < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: [:slugged, :finders]
belongs_to :host, counter_cache: true
validates :host_id, presence: true
belongs_to :endpoint
has_one :host, through: :endpoint
validates :endpoint_id, presence: true
has_many :statuses
has_one :latest_status,
-> (object) { where("latest = ?", true) }, :class_name => 'Status'
Expand Down Expand Up @@ -38,7 +39,8 @@ def update_solr_score
end

def self.current_recent_status(params)
where(host_id: params[:id], active: true)
endpoints = Endpoint.where(host: params[:id])
where(endpoint: endpoints, active: true)
.with_current_status(params[:status])
.includes(:latest_status)
.order(updated_at: :desc)
Expand Down
12 changes: 6 additions & 6 deletions app/models/ping.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
class Ping < ActiveRecord::Base
belongs_to :host, counter_cache: true, touch: true
belongs_to :endpoint, counter_cache: true, touch: true

def self.check_status(host)
Geomonitor.logger.debug "Pinging #{host.url} ..."
def self.check_status(endpoint)
Geomonitor.logger.debug "Pinging #{endpoint.url} ..."
begin
p = Net::Ping::HTTP.new(host.url).ping?
p = Net::Ping::HTTP.new(endpoint.url).ping?
rescue URI::InvalidURIError => error
Geomonitor.logger.error "#{error} url is \"#{host.url}\" for host_id #{host.id}"
p = false
end
Geomonitor.logger.info "Ping result: #{p}"
current = Ping.create(host_id: host.id, status: p, latest: true)
current = Ping.create(endpoint: endpoint, status: p, latest: true)

old_pings = Ping.where(host_id: host.id).where('id != ?', current.id)
old_pings = Ping.where(endpoint: endpoint).where('id != ?', current.id)

if old_pings.length > 0
old_pings.each do |old|
Expand Down
2 changes: 1 addition & 1 deletion app/views/hosts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<% @hosts.each do |host| %>
<tr>
<td><%= ping_status(host.last_ping_status) if host.last_ping_status %> <%= link_to host.name, host %></td>
<td><%= link_to host.name, host %></td>
<td><%= link_to host.url, host %></td>
<td><%= link_to host.institution_name, host.institution %></td>
<td><%= number_with_delimiter(host.layers_count) %></td>
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20160802114709_create_endpoints.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateEndpoints < ActiveRecord::Migration
def change
create_table :endpoints do |t|
t.string :name
t.string :url
t.references :host
t.timestamps null: false
end
end
end
6 changes: 6 additions & 0 deletions db/migrate/20160802121117_add_endpoint_to_layer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddEndpointToLayer < ActiveRecord::Migration
def change
add_reference :layers, :endpoint, index: true, foreign_key: true
remove_reference(:layers, :host, index: true)
end
end
8 changes: 8 additions & 0 deletions db/migrate/20160802134412_add_ping_to_endpoint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddPingToEndpoint < ActiveRecord::Migration
def change
add_reference :pings, :endpoint, index: true
remove_reference(:pings, :host, index: true)
add_column(:endpoints, :pings_count, :integer)
remove_column(:hosts, :pings_count)
end
end
21 changes: 15 additions & 6 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150123224019) do
ActiveRecord::Schema.define(version: 20160802134412) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "endpoints", force: :cascade do |t|
t.string "name"
t.string "url"
t.integer "host_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "pings_count"
end

create_table "friendly_id_slugs", force: :cascade do |t|
t.string "slug", null: false
t.integer "sluggable_id", null: false
Expand All @@ -35,7 +44,6 @@
t.string "url"
t.integer "institution_id"
t.integer "layers_count"
t.integer "pings_count"
t.datetime "created_at"
t.datetime "updated_at"
end
Expand All @@ -57,25 +65,25 @@
t.string "access"
t.text "description"
t.string "bbox"
t.integer "host_id"
t.integer "statuses_count"
t.datetime "created_at"
t.datetime "updated_at"
t.string "slug"
t.boolean "active"
t.integer "endpoint_id"
end

add_index "layers", ["host_id"], name: "index_layers_on_host_id", using: :btree
add_index "layers", ["endpoint_id"], name: "index_layers_on_endpoint_id", using: :btree

create_table "pings", force: :cascade do |t|
t.boolean "status"
t.boolean "latest"
t.integer "host_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "endpoint_id"
end

add_index "pings", ["host_id"], name: "index_pings_on_host_id", using: :btree
add_index "pings", ["endpoint_id"], name: "index_pings_on_endpoint_id", using: :btree

create_table "statuses", force: :cascade do |t|
t.string "res_code"
Expand All @@ -92,4 +100,5 @@

add_index "statuses", ["layer_id"], name: "index_statuses_on_layer_id", using: :btree

add_foreign_key "layers", "endpoints"
end
2 changes: 1 addition & 1 deletion lib/geomonitor/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def request_params
# url used for tile request
# @return [String]
def url
@layer.host.url + '/wms'
@layer.endpoint.url + '/wms'
end

##
Expand Down
3 changes: 1 addition & 2 deletions lib/geomonitor/indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def query_solr(search_params = params || {})
end

def update_by_id(params)
uuid = uuid_from_id(params[:id])
data = [{ uuid: uuid, layer_availability_score_f: { set: params[:score] } }]
data = [{ layer_slug_s: params[:id], layer_availability_score_f: { set: params[:score] } }]
update(data)
end

Expand Down
Loading