Commit 35ca0253 authored by Samir Noir's avatar Samir Noir 🧀
Browse files

Cleanup by removing some comments, useless files and fixing code comestics

parent 15cf355d
load 'config/deploy' # remove this line to skip loading any of the default tasks
\ No newline at end of file
......@@ -23,9 +23,9 @@ class ApplicationController < ActionController::Base
before_action :parse_json_payload, :only => [:create, :update, :destroy]
before_action :set_default_format
# abasu : additional classes introduced to handle all possible exceptions - 02.04.2015
# abasu : as per status codes https://api.grid5000.fr/doc/stable/reference/spec.html
# abasu : class & subclasses to handle client-side exceptions (Error codes 4xx)
# additional classes introduced to handle all possible exceptions
# as per status codes https://api.grid5000.fr/doc/stable/reference/spec.html
# class & subclasses to handle client-side exceptions (Error codes 4xx)
class ClientError < ActionController::ActionControllerError; end
class BadRequest < ClientError; end # Error code 400
class AuthorizationRequired < ClientError; end # Error code 401
......@@ -44,7 +44,7 @@ class ApplicationController < ActionController::Base
# This thing must alway come first, or it will override other rescue_from.
rescue_from Exception, :with => :server_error
# abasu : exception-handlers for client-side exceptions - 02.04.2015
# exception-handlers for client-side exceptions
rescue_from BadRequest, :with => :bad_request # for 400
rescue_from AuthorizationRequired, :with => :authorization_required # for 401
rescue_from Forbidden, :with => :forbidden # for 403
......@@ -54,9 +54,9 @@ class ApplicationController < ActionController::Base
rescue_from NotAcceptable, :with => :not_acceptable # for 406
rescue_from PreconditionFailed, :with => :precondition_failed # for 412
# abasu : exception-handlers for client-side exceptions - 02.04.2015
# exception-handlers for client-side exceptions
rescue_from UnsupportedMediaType, :with => :server_error # for 415
# abasu : agreed to send exception to server_error (instead of unsupported_media_type)
# agreed to send exception to server_error (instead of unsupported_media_type)
rescue_from ServerError, :with => :server_error # for 500
rescue_from BadGateway, :with => :bad_gateway # for 502
rescue_from ServerUnavailable, :with => :server_unavailable # for 503
......@@ -202,10 +202,10 @@ class ApplicationController < ActionController::Base
# ===============
# = HTTP Errors =
# ===============
# abasu : Most of the new methods added are just stubs for introduced for
# abasu : the sake of completeness of HTTP error codes handling.
# abasu : If such error conditions become prominent in the the future,
# abasu : they should be overloaded in subclasses.
# Most of the new methods added are just stubs for introduced for
# the sake of completeness of HTTP error codes handling.
# If such error conditions become prominent in the the future,
# they should be overloaded in subclasses.
def bad_request(exception)
opts = {:status => 400}
opts[:message] = "Bad Request" if exception.message == exception.class.name
......
......@@ -14,14 +14,14 @@
require 'resources_controller'
# abasu : changed inheritance of class ClustersController - bug ref 5856 -- 2015.3.19
# changed inheritance of class ClustersController - bug 5856
# from ResourcesController to SitesController
# Logic for changing inheritance : From the perspective of a controller,
# the ClustersController is a special case of a SitesController,
# the ClustersController is a special case of a SitesController,
# for specific clusters, insofar that this attribute is limited to the status function
class ClustersController < ResourcesController
# abasu : method to return status of a specific cluster - bug ref 5856 -- 2015.03.19
# method to return status of a specific cluster - bug 5856
def status
result = {
"uid" => Time.now.to_i,
......@@ -50,12 +50,13 @@ class ClustersController < ResourcesController
end
protected
def collection_path # abasu the parameter passed should be :site_id not :id (cluster)
site_clusters_path(params[:site_id])
# the parameter passed should be :site_id not :id (cluster)
def collection_path
site_clusters_path(params[:site_id])
end
# abasu : method to prepare links for status of a cluster - bug ref 5856 -- 2015.04.17
# method to prepare links for status of a cluster - bug 5856
def links_for_item(item)
links = super(item)
......@@ -66,5 +67,4 @@ class ClustersController < ResourcesController
})
links
end
end
......@@ -114,8 +114,6 @@ class DeploymentsController < ApplicationController
end
raise BadRequest, "The deployment you are trying to submit is not valid: #{dpl.errors.to_a.join("; ")}" unless dpl.valid?
# WARN: this is a blocking call as it creates a file on disk.
# we may want to defer it or implement it natively with EventMachine
files_base_uri = uri_to(parent_path+"/files",:in, :absolute)
dpl.transform_blobs_into_files!(Rails.tmp, files_base_uri)
......@@ -134,7 +132,6 @@ class DeploymentsController < ApplicationController
dpl.links = links_for_item(dpl)
render_opts = {
#:methods => [:resources_by_type, :assigned_nodes],
:location => location_uri,
:status => 201
}
......@@ -239,50 +236,4 @@ class DeploymentsController < ApplicationController
:out
)
end
# Not useful atm
=begin
def wrap_item(item,params,orig=false)
ret = item
item = item.dup
ret.clear
ret['orig'] = item if orig
ret['uid'] = item['wid'] || item['id']
ret['site_uid'] = params[:site_id]
ret['user_uid'] = item['user']
#item['created_at'] = item['start_time']
if item['nodes'].is_a?(Hash)
nodes = item['nodes']
ret['nodes'] = []
ret['result'] = {}
nodes['ok'].each do |node|
ret['nodes'] << node
ret['result'][node] = { 'state' => 'OK' }
end
nodes['processing'].each do |node|
ret['nodes'] << node
ret['result'][node] = { 'state' => 'OK' }
end
nodes['ko'].each do |node|
ret['nodes'] << node
ret['result'][node] = { 'state' => 'KO' }
end
else
ret['nodes'] = item['nodes']
end
if item['error']
ret['status'] = :error
elsif item['done']
ret['status'] = :terminated
else
ret['status'] = :processing
end
ret['links'] = links_for_item(ret)
ret
end
=end
end
......@@ -17,7 +17,7 @@ require 'resources_controller'
class EnvironmentsController < ResourcesController
protected
def collection_path
if params[:site_id]
site_environments_path(params[:site_id])
......@@ -25,5 +25,4 @@ class EnvironmentsController < ResourcesController
environments_path
end
end
end
......@@ -25,5 +25,4 @@ class NetworkEquipmentsController < ResourcesController
network_equipments_path
end
end
end
......@@ -21,5 +21,4 @@ class NodesController < ResourcesController
def collection_path
site_cluster_nodes_path(params[:site_id], params[:cluster_id])
end
end
......@@ -17,8 +17,8 @@ require 'resources_controller'
class PdusController < ResourcesController
protected
def collection_path
site_pdus_path(params[:site_id])
end
end
......@@ -81,21 +81,15 @@ class ResourcesController < ApplicationController
branch = ['origin', branch].join("/") unless Rails.env == "test"
params[:branch]=branch
# abasu : Added code for getting 'queues' element in hash params - 11.12.2015
# abasu : In request to feature bug ref. #6363
# abasu : params_queues is the array with 'queues' values passed in 'params'
if params[:queues].nil? # no filter, so assign everything except "production"
params[:queues] = ["admin","default"]
# As of 11.12.2015 the queues accepted are:
# "all" or any combination of "admin", "default", "production"
if params[:queues].nil?
params[:queues] = ["admin","default"]
else
if params[:queues] == "all" # for use by sys-admin
params[:queues] = ["admin","default","production"]
else
params[:queues] = params[:queues].split(",")
end # if params[:queues] == "all"
end # if params[:queues].nil?
if params[:queues] == "all"
params[:queues] = ["admin","default","production"]
else
params[:queues] = params[:queues].split(",")
end
end
end
def lookup_path(path, params)
......
......@@ -13,41 +13,6 @@
# limitations under the License.
class RootController < ResourcesController
# Display links to sub resources.
#
# def show
# root = {
# :uid => "grid5000",
# :version => Grid5000::VERSION,
# :timestamp => Time.now.to_i,
# :links => [
# {
# :rel => "self",
# :href => uri_to(root_path)
# },
# {
# :rel => "environments",
# :href => uri_to(environments_path)
# },
# {
# :rel => "sites",
# :href => uri_to(sites_path)
# },
# {
# :rel => "users",
# :href => uri_to("/users")
# },
# {
# :rel => "notifications",
# :href => uri_to(notifications_path)
# }
# ]
# }
# respond_to do |format|
# format.g5kitemjson { render :json => root }
# format.json { render :json => root }
# end
# end
protected
......
......@@ -14,13 +14,13 @@
require 'resources_controller'
# This initial ServersController prepared in response to bug ref. 7301 -- 2016.10.24
# This initial ServersController prepared in response to bug ref. 7301
# To be decorated later as features develop for /servers
class ServersController < ResourcesController
protected
def collection_path
def collection_path
if params[:site_id]
site_servers_path(params[:site_id])
else
......@@ -31,5 +31,4 @@ class ServersController < ResourcesController
def links_for_item(item)
super(item)
end
end
......@@ -58,13 +58,13 @@ class SitesController < ResourcesController
format.json { render :json => result }
end
end
protected
def collection_path
sites_path
end
def links_for_item(item)
links = super(item)
%w{jobs deployments vlans metrics}.each do |rel|
......@@ -81,5 +81,4 @@ class SitesController < ResourcesController
})
links
end
end
......@@ -15,7 +15,6 @@
class VersionsController < ApplicationController
MAX_AGE = 60.seconds
def index
vary_on :accept; allow :get
versions = repository.versions_for(
......
......@@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
module OAR
class Base < ActiveRecord::Base
self.abstract_class = true
......
......@@ -28,7 +28,6 @@ module OAR
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*/).
......@@ -113,7 +112,6 @@ module OAR
state && state == "running"
end
def assigned_nodes
(resources_by_type['cores'] || []).uniq
end
......@@ -145,7 +143,6 @@ module OAR
h
end
def to_reservation(options = {})
without = [options[:without] || []].flatten
h = {}
......@@ -189,22 +186,20 @@ module OAR
h
end
class << self
def active
where("state IN ('Waiting','Hold','toLaunch','toError','toAckReservation','Launching','Running','Suspended','Resuming','Finishing')")
end # def active
end
def active_not_waiting
where("state IN ('Hold','toLaunch','toError','toAckReservation','Launching','Running','Suspended','Resuming','Finishing')")
end # def active_not_waiting
end
def expanded
Job.select("jobs.*, moldable_job_descriptions.moldable_walltime AS walltime, gantt_jobs_predictions.start_time AS predicted_start_time, moldable_job_descriptions.moldable_id").
joins("LEFT OUTER JOIN moldable_job_descriptions ON jobs.job_id = moldable_job_descriptions.moldable_job_id").
joins("LEFT OUTER JOIN gantt_jobs_predictions ON gantt_jobs_predictions.moldable_job_id = moldable_job_descriptions.moldable_id")
end # def expanded
joins("LEFT OUTER JOIN gantt_jobs_predictions ON gantt_jobs_predictions.moldable_job_id = moldable_job_descriptions.moldable_id")
end
end
end
end
......@@ -16,15 +16,15 @@ module OAR
class JobEvent < Base
self.table_name = "event_logs"
self.primary_key = :event_id
# disable inheritance guessed by Rails because of the "type" column.
self.inheritance_column = :_type_disabled
def as_json(*args)
{
:uid => event_id,
:created_at => date,
:type => type,
:uid => event_id,
:created_at => date,
:type => type,
:description => description
}
end
......
......@@ -16,10 +16,10 @@ module OAR
class JobType < Base
self.table_name = "job_types"
self.primary_key = :job_type_id
# disable inheritance guessed by Rails because of the "type" column.
self.inheritance_column = :_type_disabled
def name
type
end
......
......@@ -51,7 +51,6 @@ module OAR
end
class << self
def api_type(oar_type)
if oar_type=="default"
"nodes"
......@@ -61,14 +60,14 @@ module OAR
end
def list_some(options)
# Do OAR resources have a comment column
# Do OAR resources have a comment column
include_comment = columns.find{|c| c.name == "comment"}
# Do OAR resources have a disk column
# Do OAR resources have a disk column
include_disk = columns.find{|c| c.name == "disk"}
# abasu for bug 5106 : we need cluster & core
# dmargery for bug 9230 : we need type, disk and diskpath
# bug 5106 : we need cluster & core
# bug 9230 : we need type, disk and diskpath
resources = Resource.select(
"resource_id, type, cluster, host, network_address, #{include_disk ? "disk, diskpath,":""} core, state, available_upto#{include_comment ? ", comment" : ""}"
)
......@@ -113,7 +112,7 @@ module OAR
# },
# {...}
# }
#
def status(options = {})
# Handle options
......@@ -135,7 +134,7 @@ module OAR
# Build the list of active jobs with the resources they use
active_jobs=get_active_jobs_with_resources(options).values
api_status = {}
api_status_data = {} # used later to aggregate oar resource status date at api resource level
......@@ -146,7 +145,7 @@ module OAR
api_status_data[api_type(oar_type)]={}
end
resources={}
resources = {}
# Go though the list of resource (oar's definition) to
# - index by resource_id (.index_by(&:resource_id))
......@@ -155,17 +154,17 @@ module OAR
# status of multiple OAR resources (eg. nodes)
resource_list.each do |resource|
next if resource.nil?
resources[resource.resource_id]=resource
resources[resource.resource_id] = resource
api_status[resource.api_type][resource.api_name] ||= initial_status_for(resource, include_details)
api_status_data[resource.api_type][resource.api_name] ||= initial_status_data_for(resource, include_details)
api_status_data[resource.api_type][resource.api_name]=
api_status_data[resource.api_type][resource.api_name] =
update_with_resource(api_status_data[resource.api_type][resource.api_name],
resource,
include_details)
end # .each do |resource_id, resource|
end
# Go through active jobs and update status data for all the
# resources of the job
......@@ -187,8 +186,8 @@ module OAR
api_status_data[resource.api_type][resource.api_name],
h[:job],
job_for_api)
end # .each do |resource_id|
end # .each do |h|
end
end
# We now compute the final status from the api_status_data
api_status_data.each do |api_type, type_status_data|
......@@ -259,6 +258,7 @@ module OAR
if resource.state == 'absent' && resource.available_upto && resource.available_upto == STANDBY_AVAILABLE_UPTO
h[:hard] = 'standby'
end
case resource.type
when 'default'
h[:soft]= resource.dead? ? "unknown" : "free"
......@@ -268,7 +268,7 @@ module OAR
h[:diskpath] = resource.diskpath
end
h
end # def initial_status_for
end
# Creates accumulator for resources described at API level
# that are an aggregation of OAR resources
......@@ -319,20 +319,21 @@ module OAR
#do specific calculation for some api_types
if api_type=="nodes"
# abasu : At this stage we have the the complete status over all cores in each node (network_address)
# abasu : Now add logic to sum up the status over all cores and push final status to api_status hash table
# At this stage we have the the complete status over all cores in each node (network_address)
# Now add logic to sum up the status over all cores and push final status to api_status hash table
if current_data[:busycounter] > 0
if current_data[:busycounter] <= current_data[:totalcores] / 2
derived_status[:soft] = "free_busy" # more free cores in node than busy cores
derived_status[:soft] = "free_busy" # more free cores in node than busy cores
elsif current_data[:busycounter] > current_data[:totalcores] / 2 && current_data[:busycounter] < current_data[:totalcores]
derived_status[:soft] = "busy_free" # more busy cores in node than free cores
derived_status[:soft] = "busy_free" # more busy cores in node than free cores
else
derived_status[:soft] = "busy" # all cores in node are busy
end
end
if current_data[:besteffortcounter] > 0
derived_status[:soft] += "_besteffort" # add "_besteffort" after status if it is so
derived_status[:soft] += "_besteffort" # add "_besteffort" after status if it is so
end
end
unless derived_status[:soft]=="unknown"
derived_status[:free_slots]=current_data[:totalcores]-current_data[:busycounter]
derived_status[:freeable_slots]=current_data[:besteffortcounter]
......
......@@ -17,6 +17,7 @@ class RackDebugger
@app = app
@logger = logger
end
def call(env)
@logger.info [" HEAD:", env['REQUEST_METHOD'], env['PATH_INFO'], "-", env.reject{|k,v|
k !~ /^HTTP\_/ || ["HTTP_X_FORWARDED_HOST", "HTTP_VIA", "HTTP_X_FORWARDED_SERVER", "HTTP_X_FORWARDED_FOR", "HTTP_AUTHORIZATION"].include?(k)
......@@ -29,4 +30,4 @@ class RackDebugger
@app.call(env)
end
end
\ No newline at end of file
end
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