Commit 7f8fd725 authored by MARGERY David's avatar MARGERY David
Browse files

Migrate to Rails 4.0.x & adapt code so tests pass

parent 7d6d41ae
......@@ -2,7 +2,7 @@
source 'https://rubygems.org'
gem 'rake'
gem 'rails', '~> 3.2.0'
gem 'rails', '~> 4.0.0'
# jQuery is the default JavaScript library in Rails 3.1
gem 'jquery-rails'
......@@ -27,11 +27,9 @@ gem 'nokogiri', '~> 1.5.6' #oldest version that blather handles
gem 'blather', '>= 1.2.0'
group :assets do
gem 'sass-rails', "~> 3.2.3"
gem 'coffee-rails', "~> 3.2.1"
gem 'uglifier', ">= 1.0.3"
end
gem 'sass-rails', "~> 4.0.0"
gem 'coffee-rails', "~> 4.0.0"
gem 'uglifier', ">= 1.0.3"
group :test do
gem 'webmock'
......
......@@ -18,28 +18,31 @@ GEM
activesupport (= 3.2.22.5)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (~> 1.4.5)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.2.1)
activemodel (3.2.22.5)
activesupport (= 3.2.22.5)
builder (~> 3.0.0)
activerecord (3.2.22.5)
activemodel (= 3.2.22.5)
activesupport (= 3.2.22.5)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.22.5)
activemodel (= 3.2.22.5)
activesupport (= 3.2.22.5)
activesupport (3.2.22.5)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
activemodel (4.0.13)
activesupport (= 4.0.13)
builder (~> 3.1.0)
activerecord (4.0.13)
activemodel (= 4.0.13)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.13)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.4)
activesupport (4.0.13)
i18n (~> 0.6, >= 0.6.9)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
arel (3.0.3)
arel (4.0.2)
autotest (4.4.6)
ZenTest (>= 4.4.1)
autotest-growl (0.2.16)
awesome_print (1.8.0)
backports (3.11.3)
blather (1.2.0)
activesupport (>= 2.3.11)
eventmachine (>= 1.0.0)
......@@ -48,9 +51,9 @@ GEM
nokogiri (~> 1.5, >= 1.5.6, <= 1.6.1)
builder (3.0.4)
charlock_holmes (0.7.6)
coffee-rails (3.2.2)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.4.1)
coffee-script-source
execjs
......@@ -81,7 +84,6 @@ GEM
factory_bot_rails (4.11.0)
factory_bot (~> 4.11.0)
railties (>= 3.0.0)
ffi (1.9.25)
girl_friday (0.11.2)
connection_pool (~> 1.0)
rubinius-actor
......@@ -97,15 +99,15 @@ GEM
http_parser.rb (0.6.0)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
journey (1.0.4)
jquery-rails (3.1.5)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.6)
mail (2.5.5)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25.1)
mail (2.7.0)
mini_mime (>= 0.1.1)
mime-types (2.99.3)
mini_mime (1.0.1)
minitest (4.7.5)
multi_json (1.13.1)
mysql2 (0.3.21)
net-ssh (4.2.0)
......@@ -118,34 +120,29 @@ GEM
nokogiri (~> 1.5)
nokogiri (1.5.11)
pg (0.21.0)
polyglot (0.3.5)
posix-spawn (0.3.13)
public_suffix (3.0.3)
rack (1.4.7)
rack (1.5.5)
rack-cache (1.8.0)
rack (>= 0.4)
rack-fiber_pool (0.9.3)
rack-jsonp (1.3.1)
rack
rack-ssl (1.3.4)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (3.2.22.5)
actionmailer (= 3.2.22.5)
actionpack (= 3.2.22.5)
activerecord (= 3.2.22.5)
activeresource (= 3.2.22.5)
activesupport (= 3.2.22.5)
bundler (~> 1.0)
railties (= 3.2.22.5)
railties (3.2.22.5)
actionpack (= 3.2.22.5)
activesupport (= 3.2.22.5)
rack-ssl (~> 1.3.2)
rails (4.0.13)
actionmailer (= 4.0.13)
actionpack (= 4.0.13)
activerecord (= 4.0.13)
activesupport (= 4.0.13)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.13)
sprockets-rails (~> 2.0)
railties (4.0.13)
actionpack (= 4.0.13)
activesupport (= 4.0.13)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
thor (>= 0.18.1, < 2.0)
rake (12.3.1)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
......@@ -156,6 +153,8 @@ GEM
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-autotest (1.0.0)
rspec-core (>= 2.99.0.beta1, < 4.0.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.1)
......@@ -180,25 +179,26 @@ GEM
rubinius-core-api (0.0.1)
ruby-mysql (2.9.14)
safe_yaml (1.0.4)
sass (3.5.7)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sass-rails (3.2.6)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
sass (3.2.19)
sass-rails (4.0.5)
railties (>= 4.0.0, < 5.0)
sass (~> 3.2.2)
sprockets (~> 2.8, < 3.0)
sprockets-rails (~> 2.0)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
sprockets (2.2.3)
sprockets (2.12.5)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.3.3)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
state_machine (1.2.0)
syslogger (1.6.5)
thin (1.5.1)
......@@ -206,10 +206,8 @@ GEM
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
thor (0.20.0)
thread_safe (0.3.6)
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.54)
uglifier (4.1.18)
execjs (>= 0.3.0, < 3)
......@@ -224,7 +222,7 @@ PLATFORMS
DEPENDENCIES
addressable (~> 2.2)
blather (>= 1.2.0)
coffee-rails (~> 3.2.1)
coffee-rails (~> 4.0.0)
em-http-request
em-postgresql-adapter!
em-synchrony
......@@ -240,13 +238,13 @@ DEPENDENCIES
pg (< 1.0.0)
rack-fiber_pool (~> 0.9)
rack-jsonp
rails (~> 3.2.0)
rails (~> 4.0.0)
rake
rspec
rspec-rails
rspec_junit_formatter (~> 0.3.0)
ruby-mysql
sass-rails (~> 3.2.3)
sass-rails (~> 4.0.0)
simplecov
state_machine
syslogger
......
......@@ -28,12 +28,12 @@ class ClustersController < ResourcesController
"links" => [
{
"rel" => "self",
"href" => uri_to(status_site_cluster_path(params[:site_id])),
"href" => uri_to(status_site_cluster_path(params[:site_id],params[:id])),
"type" => media_type(:g5kitemjson)
},
{
"rel" => "parent",
"href" => uri_to(site_cluster_path(params[:site_id])),
"href" => uri_to(site_cluster_path(params[:site_id],params[:id])),
"type" => media_type(:g5kitemjson)
}
]
......
......@@ -26,10 +26,7 @@ class JobsController < ApplicationController
jobs = OAR::Job.list(params)
total = jobs.count
jobs = jobs.offset(offset).limit(limit).find(
:all,
:include => [:job_types, :job_events, :gantt]
)
jobs = jobs.offset(offset).limit(limit).includes(:job_types, :job_events, :gantt)
jobs.each{|job|
job.links = links_for_item(job)
......@@ -51,9 +48,8 @@ class JobsController < ApplicationController
# Display the details of a job
def show
allow :get, :delete; vary_on :accept
job = OAR::Job.expanded.find(
params[:id],
:include => [:job_types, :job_events, :gantt]
job = OAR::Job.expanded.includes(:job_types, :job_events, :gantt).find(
params[:id]
)
job.links = links_for_item(job)
......
......@@ -19,10 +19,9 @@ require "active_record/railtie"
require "action_controller/railtie"
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require *Rails.groups(:assets => %w(development test))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
end
# Explicitly require libs when gem name is not sufficient
......
......@@ -19,9 +19,7 @@ Api::Application.configure do
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
config.eager_load = false #added when migrating to rails 4.0.0 to ensure thread_safe! behaviour
# Show full error reports and disable caching
config.consider_all_requests_local = true
......@@ -42,13 +40,8 @@ Api::Application.configure do
# Expands the lines which load the assets
config.assets.debug = true
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
config.threadsafe!
end
......@@ -18,7 +18,8 @@ Api::Application.configure do
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
config.eager_load = true #added when migrating to rails 4.0.0 to ensure thread_safe! behaviour
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
......@@ -45,7 +46,7 @@ Api::Application.configure do
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
config.assets.js_compressor = :uglifier
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
......@@ -68,9 +69,6 @@ Api::Application.configure do
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
......
......@@ -20,12 +20,10 @@ Api::Application.configure do
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
config.eager_load = false #added when migrating to rails 4.0.0 to ensure thread_safe! behaviour
# config.middleware.insert_after ActionDispatch::BestStandardsSupport, Rack::Async2Sync
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
......@@ -53,8 +51,4 @@ Api::Application.configure do
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
config.threadsafe!
end
......@@ -18,11 +18,11 @@ Api::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
match "/exhibitv2/*rest", :to => redirect {|params,request| "/ui/javascripts/vendor/exhibitv2/#{params[:rest]}"}
match '/versions' => 'versions#index', :via => [:get]
match '/versions/:id' => 'versions#show', :via => [:get]
match '*resource/versions' => 'versions#index', :via => [:get]
match '*resource/versions/:id' => 'versions#show', :via => [:get]
get "/exhibitv2/*rest", :to => redirect {|params,request| "/ui/javascripts/vendor/exhibitv2/#{params[:rest]}"}
get '/versions' => 'versions#index', :via => [:get]
get '/versions/:id' => 'versions#show', :via => [:get]
get '*resource/versions' => 'versions#index', :via => [:get]
get '*resource/versions/:id' => 'versions#show', :via => [:get]
# abasu : 1 line introduced below for correction to bug ref 5065 -- 2015.01.23
resources :environments, :only => [:index, :show], :constraints => { :id => /[0-9A-Za-z\-\.]+/ }
......@@ -49,17 +49,17 @@ Api::Application.routes.draw do
end
resources :notifications, :only => [:index, :create]
match '/ui/events' => redirect('https://www.grid5000.fr/status/')
get '/ui/events' => redirect('https://www.grid5000.fr/status/')
# Could be simplified once we use Rails >= 3.1 (remove the proc)
match '/ui' => redirect(proc {|params, request|
get '/ui' => redirect(proc {|params, request|
Grid5000::Router.new("/ui/dashboard").call(params, request)
})
match '/ui/index' => redirect(proc {|params, request|
get '/ui/index' => redirect(proc {|params, request|
Grid5000::Router.new("/ui/dashboard").call(params, request)
})
match '/ui/:page' => 'ui#show', :via => [:get]
match '/ui/visualizations/:page' => 'ui#visualization', :via => [:get]
get '/ui/:page' => 'ui#show'
get '/ui/visualizations/:page' => 'ui#visualization'
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
......
......@@ -9,9 +9,9 @@
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(:version => 20180821092321) do
ActiveRecord::Schema.define(version: 20180821092321) do
create_table "deployments", :force => true do |t|
t.string "uid"
......
......@@ -16,6 +16,5 @@ module OAR
class Gantt < Base
self.table_name="gantt_jobs_predictions"
self.primary_key=:moldable_job_id
end
end
......@@ -18,7 +18,7 @@ module OAR
self.primary_key = :job_id
has_many :job_types
has_many :job_events, :order => 'date ASC'
has_many :job_events, -> { order "date ASC" }
belongs_to :gantt, :foreign_key => 'assigned_moldable_job', :class_name => 'Gantt'
# There may be a way to do that more cleanly ;-)
......@@ -29,7 +29,30 @@ module OAR
# abasu : Removed "GROUP BY resources.network_address" for bug ref 5694 -- 2015.04.17
# abasu : To show all cores (even if same network address). Required by MPI programme
QUERY_RESOURCES = Proc.new{ "
#has_many :resources, -> {select QUERY_RESOURCES}
attr_accessor :links
def self.list(params = {})
jobs = self.expanded.order("job_id DESC")
jobs = jobs.where(:job_user => params[:user]) unless params[:user].blank?
jobs = jobs.where(:job_name => params[:name]) unless params[:name].blank?
jobs = jobs.where(:project => params[:project]) unless params[:project].blank?
# abasu 1 line introduced below for correction to bug ref 5347 -- 2015.01.23
jobs = jobs.where(:job_id => params[:job_id]) unless params[:job_id].blank?
if params[:state]
states = (params[:state] || "").split(/\s*,\s*/).
map(&:capitalize).
uniq
jobs = jobs.where(:state => states)
end
jobs = jobs.where(:queue_name => params[:queue]) if params[:queue]
jobs
end
def resources
query = "
(
SELECT resources.*
FROM resources
......@@ -55,27 +78,7 @@ module OAR
AND jobs.job_id = moldable_job_descriptions.moldable_job_id
ORDER BY resources.network_address ASC
)"
}
has_many :resources, :finder_sql => QUERY_RESOURCES
attr_accessor :links
def self.list(params = {})
jobs = self.expanded.order("job_id DESC")
jobs = jobs.where(:job_user => params[:user]) unless params[:user].blank?
jobs = jobs.where(:job_name => params[:name]) unless params[:name].blank?
jobs = jobs.where(:project => params[:project]) unless params[:project].blank?
# abasu 1 line introduced below for correction to bug ref 5347 -- 2015.01.23
jobs = jobs.where(:job_id => params[:job_id]) unless params[:job_id].blank?
if params[:state]
states = (params[:state] || "").split(/\s*,\s*/).
map(&:capitalize).
uniq
jobs = jobs.where(:state => states)
end
jobs = jobs.where(:queue_name => params[:queue]) if params[:queue]
jobs
Resource.find_by_sql(query)
end
def state
......
......@@ -206,18 +206,22 @@ module OAR
def get_active_jobs_with_resources(options = {})
active_jobs_by_moldable_id = {}
jobs = options[:waiting] == 'no' ? Job.expanded.active_not_waiting : Job.expanded.active
jobs.find(:all, :include => [:job_types]).
each{|job|
active_jobs_by_moldable_id[job.moldable_id] = {
# using job.resources will generate a query by job,
# and eager loading (the :include => [:job_types, :resources] will not work
# for association defined by :finder_sql such a resources
# initialize resources to an empty set
:resources => Set.new,
:job => job
usefull_jobs=nil
usefull_jobs=jobs.includes(:job_types)
ActiveSupport::Notifications.instrument("OAR::Resource.get_active_jobs_with_resources do the SQL and create active_jobs_by_moldable_id",
options) do
usefull_jobs.
each{|job|
active_jobs_by_moldable_id[job.moldable_id] = {
# using job.resources will generate a query by job,
# and eager loading (the :include => [:job_types, :resources] will not work
# for association defined by :finder_sql such a resources
# initialize resources to an empty set
:resources => Set.new,
:job => job
}
}
}
end
# if there are jobs
if active_jobs_by_moldable_id.length > 0
moldable_ids = active_jobs_by_moldable_id.keys.
......@@ -232,13 +236,13 @@ module OAR
)
).each do |row|
if row.is_a?(Hash)
moldable_job_id=row["moldable_job_id"]
moldable_job_id=row["moldable_job_id"].to_i
resource_id=row["resource_id"].to_i
else
(moldable_job_id,resource_id)=row
resource_id=resource_id.to_i
moldable_job_id=moldable_job_id.to_i
end
active_jobs_by_moldable_id[moldable_job_id][:resources].
add(resource_id)
end # .each do |(moldable_job_id, resource_id)|
......
......@@ -20,7 +20,7 @@ describe ClustersController do
describe "GET /sites/{{site_id}}/clusters/{{id}}/status" do
it "should return the status ONLY for the specified cluster" do
get :status, :site_id => "rennes", :id => "parasilo", :format => :json
get :status, {:site_id => "rennes", :id => "parasilo", :format => "json"}
expect(response.status).to eq 200
assert_media_type(:json)
expect(json['nodes'].keys.map{|k| k.split('-')[0]}.uniq.sort).to eq ['parasilo']
......
......@@ -128,7 +128,7 @@ describe OAR::Job do
# abasu : updated job from "last" to '374191' to return same dump -- 2015.04.07
it "should dump the job" do
result = JSON.parse(
OAR::Job.expanded.active.find(:'374191', :include => [:gantt, :job_events, :job_types]).to_json
OAR::Job.expanded.active.includes(:gantt, :job_events, :job_types).find(374191).to_json
)
expect(result).to eq({
"uid"=>374191,
......
......@@ -17,7 +17,7 @@ require 'spec_helper'
describe OAR::Resource do
it "should return the downcased state" do
expect(OAR::Resource.find(:first).state).to eq "dead"
expect(OAR::Resource.first.state).to eq "dead"
end
it "should return true to #dead? if resource id dead" do
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment