diff options
author | mr <mr@mrautenberg.de> | 2011-01-12 09:52:05 +0100 |
---|---|---|
committer | mr <mr@mrautenberg.de> | 2011-01-12 09:52:05 +0100 |
commit | 768e2b96891e9deaa1e71826dadbcd532742fa4c (patch) | |
tree | 72c7f34a8067d4d394760bf01e32e63b49a47284 | |
parent | 4c089275d34ba42014e1add97a41ccf351790260 (diff) | |
parent | ecdd0347a347bd2ac5fa9e6a41ec7475b007309d (diff) |
helper A&A cuts URI after ID
-rw-r--r-- | lib/authorization.rb | 4 | ||||
-rw-r--r-- | lib/helper.rb | 5 | ||||
-rw-r--r-- | lib/model.rb | 8 | ||||
-rw-r--r-- | lib/policy.rb | 9 | ||||
-rw-r--r-- | lib/task.rb | 12 |
5 files changed, 26 insertions, 12 deletions
diff --git a/lib/authorization.rb b/lib/authorization.rb index f9499e6..dab228a 100644 --- a/lib/authorization.rb +++ b/lib/authorization.rb @@ -114,7 +114,9 @@ module OpenTox begin resource = RestClient::Resource.new("#{AA_SERVER}/pol") out = resource.get(:subjectid => subjectid) - return out.split("\n") + return out.split("\n") + rescue RestClient::InternalServerError => e + raise e.response rescue return nil end diff --git a/lib/helper.rb b/lib/helper.rb index cb80018..857c5b5 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -34,7 +34,8 @@ helpers do # @param [String] uri def clean_uri(uri) out = URI.parse(uri) - "#{out.scheme}:" + (out.port != 80 ? out.port : "") + "//#{out.host}#{out.path.chomp(File.extname(out.path))}" + out.path = out.path[0, out.path.rindex(/[0-9]/) + 1] if out.path.rindex(/[0-9]/) #cuts after id for a&a + "#{out.scheme}:" + (out.port != 80 ? out.port : "") + "//#{out.host}#{out.path}" end def check_subjectid(subjectid) @@ -48,6 +49,8 @@ helpers do case env['REQUEST_URI'] when /\/login$|\/logout$|\/predict$|\/toxcreate\/models$/ return true + when /\/features/ + return false when /\/compound|\/feature|\/task|\/toxcreate/ #to fix: read from config | validation should be protected return true else diff --git a/lib/model.rb b/lib/model.rb index 32f5604..7aa3f5c 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -60,8 +60,8 @@ module OpenTox # Get URIs of all lazar models # @return [Array] List of lazar model URIs - def self.all - RestClientWrapper.get(CONFIG[:services]["opentox-model"]).to_s.split("\n") + def self.all(subjectid=nil) + RestClientWrapper.get(CONFIG[:services]["opentox-model"], :subjectid => subjectid).to_s.split("\n") end # Find a lazar model @@ -77,7 +77,7 @@ module OpenTox def self.create(params) lazar_algorithm = OpenTox::Algorithm::Generic.new File.join( CONFIG[:services]["opentox-algorithm"],"lazar") model_uri = lazar_algorithm.run(params) - OpenTox::Model::Lazar.find(model_uri) + OpenTox::Model::Lazar.find(model_uri, params[:subjectid]) end # Get a parameter value @@ -98,7 +98,7 @@ module OpenTox DC.title => URI.decode(File.basename( @metadata[OT.dependentVariables] )), OT.parameters => [{DC.title => "dataset_uri", OT.paramValue => dataset_uri}] }) - d = Dataset.new(dataset_uri) + d = Dataset.new(dataset_uri,subjectid) d.load_compounds d.compounds.each do |compound_uri| predict(compound_uri,false,subjectid) diff --git a/lib/policy.rb b/lib/policy.rb index 0ef8298..9c81fbd 100644 --- a/lib/policy.rb +++ b/lib/policy.rb @@ -33,6 +33,15 @@ module OpenTox return true end + #drop all policies in a policies instance + def names + out = [] + @policies.each do |name, policy| + out << name + end + return out + end + #loads a default policy template in policies instance def load_default_policy(user, uri, group="member") template = case user diff --git a/lib/task.rb b/lib/task.rb index 18fba6e..9cf909f 100644 --- a/lib/task.rb +++ b/lib/task.rb @@ -50,12 +50,12 @@ module OpenTox cpu_load = `cat /proc/loadavg`.split(/\s+/)[0..2].collect{|c| c.to_f} nr_cpu_cores = `cat /proc/cpuinfo |grep "cpu cores"|cut -d ":" -f2|tr -d " "`.split("\n").collect{|c| c.to_i}.inject{|sum,n| sum+n} nr_cpu_cores = 1 if !nr_cpu_cores - if cpu_load[0] > nr_cpu_cores and cpu_load[0] > cpu_load[1] and cpu_load[1] > cpu_load[2] # average CPU load of the last minute is high and CPU load is increasing - LOGGER.warn "Cannot start task - CPU load too high (#{cpu_load.join(", ")})" - task.cancel - return task - #raise "Server too busy to start a new task" - end + #if cpu_load[0] > nr_cpu_cores and cpu_load[0] > cpu_load[1] and cpu_load[1] > cpu_load[2] # average CPU load of the last minute is high and CPU load is increasing + # LOGGER.warn "Cannot start task - CPU load too high (#{cpu_load.join(", ")})" + # task.cancel + # return task + # #raise "Server too busy to start a new task" + #end task_pid = Spork.spork(:logger => LOGGER) do |