I could not get the previous version of the classad plugin to work. Somehow the full rails init (via require dutils) was wreaking havoc with my condor instance. Instead, this patch just drags in the models that we need, and fixes up the problem that way. It also adds in additional logging infrastructure so we have a better idea of what is going on.
Signed-off-by: Chris Lalancette <[email protected]> --- src/classad_plugin/classad_plugin.rb | 46 +++++++++++++++------ src/classad_plugin/deltacloud_classad_plugin.cpp | 40 +++++++++++-------- 2 files changed, 56 insertions(+), 30 deletions(-) diff --git a/src/classad_plugin/classad_plugin.rb b/src/classad_plugin/classad_plugin.rb index 15f8700..17beea9 100644 --- a/src/classad_plugin/classad_plugin.rb +++ b/src/classad_plugin/classad_plugin.rb @@ -1,19 +1,39 @@ +require 'rubygems' +require 'active_record' +require 'search_filter' +require 'permissioned_object' +require 'authlogic' +require 'user' +require 'instance' +require 'cloud_account' +require 'pool' +require 'quota' -require 'dutils' +def classad_plugin(logf, conf_path, instance_key, account_id) + ENV['RAILS_ENV'] = 'development' unless ENV['RAILS_ENV'] -def classad_plugin(instance_key, account_id) + logf.puts "loading db config from #{conf_path}" + conf = YAML::load(File.open(conf_path)) + ActiveRecord::Base.establish_connection(conf[ENV['RAILS_ENV']]) - # I left the puts in here because you can run condor_negotiator -f from the command - # line and it will print this stuff out. Very nice for debugging. - puts "getting instance from key #{instance_key}" - instance = Instance.find(:first, :conditions => [ "condor_job_id = ?", instance_key ]) - puts "getting cloud account from id #{account_id}" - cloud_account = CloudAccount.find(:first, :conditions => [ "id = ?", account_id ]) + # I left the puts in here because you can run condor_negotiator -f from the + # command line and it will print this stuff out. Very nice for debugging. + logf.puts "getting instance from key #{instance_key}" + instance = Instance.find(:first, + :conditions => [ "condor_job_id = ?", instance_key ]) + logf.puts "getting cloud account from id #{account_id}" + cloud_account = CloudAccount.find(:first, + :conditions => [ "id = ?", account_id ]) - puts "instance is: #{instance}, cloud account is #{cloud_account}" + logf.puts "instance is: #{instance}, cloud account is #{cloud_account}" - return false if instance.nil? - return false if cloud_account.nil? - puts "checking quota.." - return Quota.can_start_instance?(instance, cloud_account) + return false if instance.nil? + return false if cloud_account.nil? + + logf.puts "checking quota.." + ret = Quota.can_start_instance?(instance, cloud_account) + + ActiveRecord::Base.connection.disconnect! + + return ret end diff --git a/src/classad_plugin/deltacloud_classad_plugin.cpp b/src/classad_plugin/deltacloud_classad_plugin.cpp index af35bc0..aa2ff60 100644 --- a/src/classad_plugin/deltacloud_classad_plugin.cpp +++ b/src/classad_plugin/deltacloud_classad_plugin.cpp @@ -49,7 +49,6 @@ deltacloud_quota_check(const char *name, const ArgumentList &arglist, bool val = false; char *ruby_string; std::stringstream method_args; - static int ruby_initialized = 0; result.SetBooleanValue(false); @@ -86,38 +85,45 @@ deltacloud_quota_check(const char *name, const ArgumentList &arglist, } //print_value(fp, account_id, "account_id"); - if (!ruby_initialized) { - ruby_init(); - ruby_init_loadpath(); - } + ruby_init(); + ruby_init_loadpath(); - method_args << "'" << instance_key << "', " << account_id; + method_args << "'" << DELTACLOUD_INSTALL_DIR << "/config/database.yml', '" + << instance_key << "', " << account_id; asprintf(&ruby_string, "$: << '%s/classad_plugin'\n" - "$: << '%s/dutils'\n" - "$: << '%s/models'\n" + "$: << '%s/app/models'\n" + "logf = File.new('%s', 'a')\n" + "logf.puts \"Loading ruby support file from %s/classad_plugin\"\n" "begin\n" " require 'classad_plugin.rb'\n" - " classad_plugin(%s)\n" + " ret = classad_plugin(logf, %s)\n" "rescue Exception => ex\n" - " f = File.new('%s', 'a')\n" - " f.write \"Error running classad plugin: #{ex.message}\"\n" - " f.write ex.backtrace\n" - " f.close\n" - " false\n" - "end\n", + " logf.puts \"Error running classad plugin: #{ex.message}\"\n" + " logf.puts ex.backtrace\n" + " ret = false\n" + "end\n" + "logf.close\n" + "return ret", DELTACLOUD_INSTALL_DIR, DELTACLOUD_INSTALL_DIR, + LOGFILE, DELTACLOUD_INSTALL_DIR, - method_args.str().c_str(), - LOGFILE); + method_args.str().c_str()); + fprintf(fp, "ruby string is %s\n", ruby_string); fflush(fp); res = rb_eval_string(ruby_string); free(ruby_string); + /* FIXME: I'd like to call ruby_finalize here, but it spews weird errors: + * + * Error running classad plugin: wrong argument type Mutex (expected Data) + */ + //ruby_finalize(); + if (res == Qtrue) { result.SetBooleanValue(true); val = true; -- 1.7.2.3 _______________________________________________ deltacloud-devel mailing list [email protected] https://fedorahosted.org/mailman/listinfo/deltacloud-devel
