Commit dcdce026 authored by BASU Anirvan's avatar BASU Anirvan Committed by Lucas Nussbaum
Browse files

Modified the mechanism for URI construction - for test & development...

Modified the mechanism for URI construction - for test & development environments. Added spec tests also.
parent 307eecf3
......@@ -25,15 +25,23 @@ class Job
:scheduled_at, :walltime, :queue, :state, :mode,
:command, :directory, :exit_code, :signal, :checkpoint, :anterior,
:message, :stderr, :stdout]
# abasu bug ref. 7360 - added :job_key_from_file --- 29.11.2016
# OAR expects these as import-job-key-from-file
READ_ONLY_UNDERSCORE_ATTRIBUTES = [:import_job_key_from_file]
READ_WRITE_ATTRIBUTES = [:name, :project]
attr_reader *READ_ONLY_ATTRIBUTES
attr_reader *READ_ONLY_UNDERSCORE_ATTRIBUTES
attr_accessor *READ_WRITE_ATTRIBUTES
def initialize(h = {})
@errors = []
h = h.symbolize_keys
(READ_ONLY_ATTRIBUTES+READ_WRITE_ATTRIBUTES).each do |attribute|
value = h[attribute]
(READ_ONLY_ATTRIBUTES+READ_WRITE_ATTRIBUTES+READ_ONLY_UNDERSCORE_ATTRIBUTES).each do |attribute|
if READ_ONLY_UNDERSCORE_ATTRIBUTES.include?(attribute)
value = h[attribute.to_s.gsub('_','-').to_sym]
else
value = h[attribute]
end
value.symbolize_keys! if value.kind_of?(Hash)
instance_variable_set "@#{attribute.to_s}", value
end
......@@ -63,10 +71,16 @@ class Job
h["reservation"] = Time.at(reservation).strftime("%Y-%m-%d %H:%M:%S") unless reservation.nil?
h["property"] = properties unless properties.nil? || properties.empty?
h["type"] = types unless types.nil? || types.empty?
%w{walltime queue directory name project signal checkpoint stderr stdout}.each do |prop|
value = instance_variable_get "@#{prop}"
h[prop] = value unless value.nil?
end
# abasu bug ref. 7360 - added import_job_key_from_file --- 29.11.2016
%w{import-job-key-from-file}.each do |prop|
value = instance_variable_get "@#{prop.gsub('-','_')}"
h[prop] = value unless value.nil?
end
# --hold
# --stdout=<file>
# --stderr=<file>
......@@ -82,6 +96,7 @@ class Job
h["links"] = link_proc.call(self)
end
end
h
end
......
......@@ -33,31 +33,43 @@ module Grid5000
nil
else
File.join("/", (request.env['HTTP_X_API_VERSION'] || ""))
end
end # api_version = if request.env['HTTP_X_API_VERSION'].blank?
path_prefix = if request.env['HTTP_X_API_PATH_PREFIX'].blank?
nil
else
File.join("/", (request.env['HTTP_X_API_PATH_PREFIX'] || ""))
end
end # path_prefix = if request.env['HTTP_X_API_PATH_PREFIX'].blank?
mount_path = if request.env['HTTP_X_API_MOUNT_PATH'].blank?
nil
else
File.join("/", (request.env['HTTP_X_API_MOUNT_PATH'] || ""))
end
end # mount_path = if request.env['HTTP_X_API_MOUNT_PATH'].blank?
uri = File.join("/", *[api_version, path_prefix, path].compact)
uri.gsub!(mount_path, '') unless mount_path.nil?
uri = "/" if uri.blank?
# abasu / dmargery - bug ref 7360 - for correct URI construction
if in_or_out == :out || relative_or_absolute == :absolute
uri = URI.join(base_uri(in_or_out), uri).to_s
end
root_uri=URI(base_uri(in_or_out))
if root_uri.path.blank?
root_path=''
else
root_path=root_uri.path+'/'
end # if root_uri.path.blank?
uri = URI.join(root_uri, root_path+uri).to_s
end # if in_or_out == :out || relative_or_absolute == :absolute
uri
end
end # def uri_to()
# FIXME: move Rails.config to Grid5000.config
def base_uri(in_or_out = :in)
Rails.my_config("base_uri_#{in_or_out}".to_sym)
end
end # def base_uri()
end
end
end
\ No newline at end of file
end
......@@ -40,4 +40,20 @@ describe Grid5000::Router do
})
Grid5000::Router.uri_to(request, "/sites/rennes/jobs").should == "/sid/grid5000/sites/rennes/jobs"
end
end
\ No newline at end of file
it "should take into account the parameters of the config file with empty path" do
Rails.my_config("base_uri_out".to_sym).should == "http://api-out.local"
request = mock(Rack::MockRequest, :env => {
'HTTP_X_API_VERSION' => 'sid'
})
Grid5000::Router.uri_to(request, "/sites/rennes/internal/oarapi/jobs/374172.json", :out).should == "http://api-out.local/sid/sites/rennes/internal/oarapi/jobs/374172.json"
end
it "should take into account the parameters of the config file with path (for dev environment)" do
Api::Application::CONFIG["base_uri_out"] = "http://api-out.local/sid"
Rails.my_config("base_uri_out".to_sym).should == "http://api-out.local/sid"
request = mock(Rack::MockRequest, :env => {})
Grid5000::Router.uri_to(request, "/sites/rennes/internal/oarapi/jobs/374172.json", :out).should == "http://api-out.local/sid/sites/rennes/internal/oarapi/jobs/374172.json"
end
end
......@@ -109,6 +109,22 @@ describe Grid5000::Job do
"resource"=>"/nodes=1"
}
end
# abasu bug ref. 7360 - added test for import job_key_from_file --- 29.11.2016
it "should copy import-job-key-from-file to a hash structure" do
reservation = Time.parse("2009-11-10 15:54:56Z")
job = Grid5000::Job.new(:resources => "/nodes=1", :reservation => reservation, :command => "id", :types => ["deploy", "idempotent"], :walltime => 3600, :checkpoint => 40, :'import-job-key-from-file' => "file://abcd")
job.should be_valid
job.to_hash(:destination => "oar-2.4-submission").should == {
"script"=>"id",
"checkpoint"=>40,
"walltime"=>3600,
"reservation"=>"2009-11-10 15:54:56",
"resource"=>"/nodes=1",
"type"=>["deploy", "idempotent"],
"import-job-key-from-file"=> "file://abcd"
}
end # it "should copy import-job-key-from-file to a hash structure" do
end
describe "Creating for future submission" 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