summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMartin Gütlein <martin.guetlein@gmail.com>2010-03-26 11:23:15 +0100
committerMartin Gütlein <martin.guetlein@gmail.com>2010-03-26 11:23:15 +0100
commit7b8d85cb91c0a0a6ec530fc527be6ec67f70df99 (patch)
tree05fac83528f95542d57c1e756c5db874f37ee073 /lib
parent0230d687322bab8c0fd24cf41e33a28554a364db (diff)
changes related to feature-encode-problem
Diffstat (limited to 'lib')
-rw-r--r--lib/environment.rb10
-rw-r--r--lib/model.rb4
-rw-r--r--lib/utils.rb53
3 files changed, 64 insertions, 3 deletions
diff --git a/lib/environment.rb b/lib/environment.rb
index 2838c29..e784777 100644
--- a/lib/environment.rb
+++ b/lib/environment.rb
@@ -40,6 +40,14 @@ if @@config[:database]
end
end
+class Sinatra::Base
+ # overwriting halt to log halts (!= 202)
+ def halt(status,msg)
+ LOGGER.error "halt "+status.to_s+" "+msg.to_s if (status != 202)
+ throw :halt, [status, msg]
+ end
+end
+
# logging
class MyLogger < Logger
@@ -57,7 +65,7 @@ class MyLogger < Logger
n = 2
line = lines[n]
- while (line =~ /spork.rb/ or line =~ /as_task/)
+ while (line =~ /spork.rb/ or line =~ /as_task/ or line =~ /environment.rb/)
#puts "skip line "+line.to_s
n += 1
line = lines[n]
diff --git a/lib/model.rb b/lib/model.rb
index e8eee09..9f03c4b 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -20,6 +20,8 @@ module OpenTox
@dependent_variables = owl.dependentVariables
@independent_variables = owl.independentVariables
@predicted_variables = owl.predictedVariables
+
+ raise "invalid model: "+self.to_yaml unless @dependent_variables.to_s.size>0 && @independent_variables.to_s.size>0 && @predicted_variables.to_s.size>0
end
end
@@ -28,7 +30,7 @@ module OpenTox
def self.build( algorithm_uri, algorithm_params )
- LOGGER.debug "Build model, algorithm_uri:"+algorithm_uri.to_s+", algorithm_parms: "+algorithm_params.to_s
+ LOGGER.debug "Build model, algorithm_uri:"+algorithm_uri.to_s+", algorithm_parms: "+algorithm_params.inspect.to_s
uri = OpenTox::RestClientWrapper.post(algorithm_uri,algorithm_params).to_s
uri = OpenTox::Task.find(uri).wait_for_resource.to_s if Utils.task_uri?(uri)
return PredictionModel.find(uri)
diff --git a/lib/utils.rb b/lib/utils.rb
index bbb750d..ed35563 100644
--- a/lib/utils.rb
+++ b/lib/utils.rb
@@ -22,5 +22,56 @@ module OpenTox
end
end
- end
+end
+
+
+ module RestClientWrapper
+
+ def self.get(uri, headers=nil)
+ execute( "get", uri, nil, headers )
+ end
+
+ def self.post(uri, payload=nil, headers=nil)
+ execute( "post", uri, payload, headers )
+ end
+
+ def self.delete(uri, headers=nil)
+ execute( "delete", uri, nil, headers )
+ end
+
+ private
+ def self.execute( rest_call, uri, payload, headers )
+
+ do_halt 400,"uri is null",uri,payload,headers unless uri
+ begin
+ if payload
+ RestClient.send(rest_call, uri, payload, headers)
+ else
+ RestClient.send(rest_call, uri, headers)
+ end
+ rescue RestClient::RequestFailed, RestClient::RequestTimeout => ex
+ do_halt 502,ex.message,uri,payload,headers
+ rescue SocketError, RestClient::ResourceNotFound => ex
+ do_halt 400,"X"+ex.message,uri,payload,headers
+ rescue Exception => ex
+ do_halt 500,"add error '"+ex.class.to_s+"'' to rescue in OpenTox::RestClientWrapper::execute(), msg: '"+ex.message.to_s+"'",uri,payload,headers
+ end
+ end
+
+ def self.do_halt(status, msg, uri, payload, headers)
+
+ message = msg+""
+ message += ", uri: '"+uri.to_s+"'" if uri
+ message += ", payload: '"+payload.inspect+"'" if payload
+ message += ", headers: '"+headers.inspect+"'" if headers
+
+ if defined?(halt)
+ halt(status,message)
+ elsif defined?($sinatra)
+ $sinatra.halt(status,message)
+ else
+ raise "halt '"+status.to_s+"' '"+message+"'"
+ end
+ end
+ end
end