atadas
authorTamas Jung <tamasjung@gmail.com>
Fri, 29 Oct 2010 09:18:18 +0000 (11:18 +0200)
committerTamas Jung <tamasjung@gmail.com>
Fri, 29 Oct 2010 09:18:18 +0000 (11:18 +0200)
21 files changed:
ruby/21879128810430113901471/err.txt [new file with mode: 0644]
ruby/21879128810430113901471/out.txt [new file with mode: 0644]
ruby/218791288114550534117300/err.txt [new file with mode: 0644]
ruby/218791288114550534117300/out.txt [new file with mode: 0644]
ruby/ext/extconf.rb [new file with mode: 0644]
ruby/lib/arc_client_c_wrapper.rb [new file with mode: 0644]
ruby/lib/arc_client_r.rb [new file with mode: 0644]
ruby/lib/ffi_libc.rb [new file with mode: 0644]
ruby/test_job_list.xml [new file with mode: 0644]
ruby/tests/test_base.rb [new file with mode: 0644]
ruby/tests/test_get.rb [new file with mode: 0644]
ruby/tests/test_helper.rb [new file with mode: 0644]
ruby/tests/test_stat.rb [new file with mode: 0644]
ruby/tests/test_submit.rb [new file with mode: 0644]
src/arc_get.cpp [new file with mode: 0644]
src/arc_get.h [new file with mode: 0644]
src/arc_stat.cpp [new file with mode: 0644]
src/arc_stat.h [new file with mode: 0644]
src/arc_submit.cpp [new file with mode: 0644]
src/arc_submit.h [new file with mode: 0644]
src/arcclientc.cpp

diff --git a/ruby/21879128810430113901471/err.txt b/ruby/21879128810430113901471/err.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/ruby/21879128810430113901471/out.txt b/ruby/21879128810430113901471/out.txt
new file mode 100644 (file)
index 0000000..7bee7a7
--- /dev/null
@@ -0,0 +1 @@
+Linux interop 2.6.26-2-686-bigmem #1 SMP Thu Sep 16 20:29:07 UTC 2010 i686 GNU/Linux
diff --git a/ruby/218791288114550534117300/err.txt b/ruby/218791288114550534117300/err.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/ruby/218791288114550534117300/out.txt b/ruby/218791288114550534117300/out.txt
new file mode 100644 (file)
index 0000000..7bee7a7
--- /dev/null
@@ -0,0 +1 @@
+Linux interop 2.6.26-2-686-bigmem #1 SMP Thu Sep 16 20:29:07 UTC 2010 i686 GNU/Linux
diff --git a/ruby/ext/extconf.rb b/ruby/ext/extconf.rb
new file mode 100644 (file)
index 0000000..8fb210d
--- /dev/null
@@ -0,0 +1,28 @@
+require 'mkmf'
+dirs = <<-EODIRS
+/opt/local/include/libxml2 
+/opt/local/include/giomm-2.4 
+/opt/local/lib/giomm-2.4/include 
+/opt/local/include/glibmm-2.4 
+/opt/local/lib/glibmm-2.4/include 
+/opt/local/include/glib-2.0 
+/opt/local/lib/glib-2.0/include 
+/opt/local/include 
+/opt/local/include/sigc++-2.0 
+/opt/local/lib/sigc++-2.0/include
+EODIRS
+
+dirs.split.each do |dir|
+  $INCFLAGS << " " << "-I#{dir}"
+end
+
+
+["/opt/local"].each do |prefix|
+
+  find_header "libxml/xmlmemory.h", "#{prefix}/include/libxml2"
+  find_header "sigc++/slot.h", "#{prefix}/include/sigc++-2.0"
+  find_header "sigc++/slot.h", "#{prefix}/lib/sigc++-2.0/include"
+end
+
+create_makefile("arc_client_r")
+
diff --git a/ruby/lib/arc_client_c_wrapper.rb b/ruby/lib/arc_client_c_wrapper.rb
new file mode 100644 (file)
index 0000000..12e8301
--- /dev/null
@@ -0,0 +1,75 @@
+require 'ffi'
+require 'ffi_libc'
+class ArcClientCWrapper
+  
+  class BaseStruct < FFI::Struct
+    
+    def get_str(name)
+      result = nil
+      val = self[name]
+      if(!val.null?)
+        result = val.read_string
+      end
+      result
+    end
+       
+    def free_pointer(name)
+      val = self[name]
+      if(val.is_a? FFI::Pointer)
+        LibC::free(val)
+      end
+    end
+    
+    def free_pointer_members
+      members.each do |member|
+        free_pointer member
+      end
+    end
+  end
+
+  class SubmitResult < BaseStruct
+    layout     :message,  :pointer,\
+            :job_id,  :pointer
+            
+  end
+  class StatResult < BaseStruct
+    layout     :message,  :pointer,\
+            :stat,  :pointer
+    
+  end
+  
+  class GetResult < BaseStruct
+    layout  :message, :pointer, \
+            :get, :int
+
+  end
+
+
+  extend FFI::Library
+  
+  ffi_lib "/Users/tamas/work/iface/grid/ws/gp-arc-client-c/build/Debug/libarcclientc.dylib"
+  #ffi_lib "/Users/tamas/tmp/bbbb/gp-arc-client-c/src/arc_client_r.bundle"
+  
+  attach_function :initialize, [], :string
+  
+  attach_function :arc_submit, [:int, :pointer], :pointer
+  attach_function :arc_stat, [:int, :pointer], :pointer
+  attach_function :arc_get, [:int, :pointer], :pointer
+  
+  def self.string_array_as_pointer(arr)
+    result = FFI::MemoryPointer.new(:pointer, arr.size)
+       result.write_array_of_pointer(arr.map {|item| FFI::MemoryPointer.from_string(item.to_s)})
+  end
+  
+  def self.free_array_of_pointer(arr, length)
+    pointers = arr.read_array_of_pointer length
+    
+    pointers.each do |i| 
+      p "freeeeeeeeeee#{i}"
+      LibC::free(i) 
+    end
+
+    LibC::free(arr)
+  end
+
+end
\ No newline at end of file
diff --git a/ruby/lib/arc_client_r.rb b/ruby/lib/arc_client_r.rb
new file mode 100644 (file)
index 0000000..e6d0540
--- /dev/null
@@ -0,0 +1,46 @@
+require 'arc_client_c_wrapper'
+require 'ffi_libc'
+
+class ArcClientR
+  
+  def initialize
+    @wrapper = ArcClientCWrapper.new
+  end
+  
+  def generic_call(the_args)
+    args = the_args.unshift ""##optparser cuts the first arg TODO
+    args_pointer = ArcClientCWrapper::string_array_as_pointer(args)
+    result, ruby_result = yield(args.size, args_pointer)
+    result.free_pointer_members
+    #ArcClientCWrapper::free_array_of_pointer(args_pointer, args.size)
+    ruby_result
+  end
+  
+  def submit(the_args)
+    generic_call(the_args) do |args_size, args_pointer|
+      c_result = @wrapper.arc_submit(args_size, args_pointer)
+      result = ArcClientCWrapper::SubmitResult.new(c_result)
+      ruby_result = [result.get_str(:message), result.get_str(:job_id)]
+      [result, ruby_result]
+    end
+  end
+  
+  def stat(the_args)
+    generic_call(the_args) do |args_size, args_pointer|
+      c_result = @wrapper.arc_stat(args_size, args_pointer)
+      result = ArcClientCWrapper::StatResult.new(c_result)
+      ruby_result = [result.get_str(:message), result.get_str(:stat)]
+      [result, ruby_result]
+    end
+  end
+  
+  def get(the_args)
+    generic_call(the_args) do |args_size, args_pointer|
+      c_result = @wrapper.arc_get(args_size, args_pointer)
+      result = ArcClientCWrapper::GetResult.new(c_result)
+      ruby_result = [result.get_str(:message), result[:get]]
+      [result, ruby_result]
+    end
+  end
+  
+end
\ No newline at end of file
diff --git a/ruby/lib/ffi_libc.rb b/ruby/lib/ffi_libc.rb
new file mode 100644 (file)
index 0000000..0df92ce
--- /dev/null
@@ -0,0 +1,7 @@
+#borrowed from ffi-ttc
+module LibC
+  extend FFI::Library
+  ffi_lib [FFI::CURRENT_PROCESS, 'c']
+  attach_function :malloc, [ :uint ], :pointer
+  attach_function :free, [ :pointer ], :void
+end
\ No newline at end of file
diff --git a/ruby/test_job_list.xml b/ruby/test_job_list.xml
new file mode 100644 (file)
index 0000000..026fa4d
--- /dev/null
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ArcConfig/>
\ No newline at end of file
diff --git a/ruby/tests/test_base.rb b/ruby/tests/test_base.rb
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/ruby/tests/test_get.rb b/ruby/tests/test_get.rb
new file mode 100644 (file)
index 0000000..e532de4
--- /dev/null
@@ -0,0 +1,14 @@
+require File.join(File.dirname(__FILE__), 'test_helper')
+require 'arc_client_r'
+
+class TestGet < ::Test::Unit::TestCase
+  
+  def test_base
+    arc_client = ArcClientR.new
+    1.times do
+    message, get = arc_client.get(["-j", "test_job_list.xml", "https://interop.grid.niif.hu:2010/arex-x509/218791288114550534117300"])
+    p message
+    p get
+    end
+  end
+end
\ No newline at end of file
diff --git a/ruby/tests/test_helper.rb b/ruby/tests/test_helper.rb
new file mode 100644 (file)
index 0000000..e74674b
--- /dev/null
@@ -0,0 +1,31 @@
+require 'test/unit'
+
+UNAME_JSDL = <<-EO_XML
+<?xml version="1.0" encoding="UTF-8"?>
+<JobDefinition
+  xmlns="http://schemas.ggf.org/jsdl/2005/11/jsdl"
+  xmlns:posix="http://schemas.ggf.org/jsdl/2005/11/jsdl-posix"
+  xmlns:arc="http://www.nordugrid.org/ws/schemas/jsdl-arc">
+  <JobDescription>
+    <JobIdentification>
+      <JobName>hostname</JobName>
+    </JobIdentification>
+    <Application>
+     <posix:POSIXApplication>
+        <posix:Executable>/bin/uname</posix:Executable>
+             <posix:Argument>-a</posix:Argument>
+        <posix:Output>out.txt</posix:Output>
+        <posix:Error>err.txt</posix:Error>
+      </posix:POSIXApplication>
+    </Application>
+    <DataStaging>
+      <FileName>out.txt</FileName>
+      <DeleteOnTermination>false</DeleteOnTermination>
+    </DataStaging>
+    <DataStaging>
+      <FileName>err.txt</FileName>
+      <DeleteOnTermination>false</DeleteOnTermination>
+    </DataStaging>
+  </JobDescription>
+</JobDefinition>
+EO_XML
diff --git a/ruby/tests/test_stat.rb b/ruby/tests/test_stat.rb
new file mode 100644 (file)
index 0000000..5c67065
--- /dev/null
@@ -0,0 +1,14 @@
+require File.join(File.dirname(__FILE__), 'test_helper')
+require 'arc_client_r'
+
+class TestStat < ::Test::Unit::TestCase
+  
+  def test_base
+    arc_client = ArcClientR.new
+    2.times do 
+    message, stat = arc_client.stat(["-j", "test_job_list.xml", "https://interop.grid.niif.hu:2010/arex-x509/218791288114550534117300"])
+    p message
+    p stat
+  end
+  end
+end
\ No newline at end of file
diff --git a/ruby/tests/test_submit.rb b/ruby/tests/test_submit.rb
new file mode 100644 (file)
index 0000000..4106bea
--- /dev/null
@@ -0,0 +1,13 @@
+require File.join(File.dirname(__FILE__), 'test_helper')
+require 'arc_client_r'
+
+class TestSubmit < ::Test::Unit::TestCase
+  
+  def xtest_base
+    arc_client = ArcClientR.new
+    message, job_id = arc_client.submit(["-e", UNAME_JSDL, "-j", "test_job_list.xml"])
+    p message
+    p job_id
+  end
+  
+end
\ No newline at end of file
diff --git a/src/arc_get.cpp b/src/arc_get.cpp
new file mode 100644 (file)
index 0000000..8d17a29
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ *  get.cpp
+ *  arcclientc
+ *
+ *  Created by Tamas Jung on 10/25/10.
+ *  Copyright 2010 Apple. All rights reserved.
+ *
+ */
+
+#include "arc_get.h"
+
+// -*- indent-tabs-mode: nil -*-
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <iostream>
+#include <list>
+#include <string>
+#include "arc_libs.h"
+
+
+get_result_t* arc_get(int argc, char **argv) {
+       
+       
+       get_result_t* result = (get_result_t*)malloc(sizeof(get_result_t));
+       if (!result) {
+               return NULL;//TBD: throw sth?
+       }
+       result->message = NULL;
+       result->get = NULL;
+       
+       Arc::OptionParser options(istring("[job ...]"),
+                                                         istring("The arcget command is used for "
+                                                                         "retrieving the results from a job."),
+                                                         istring("Argument to -c has the format "
+                                                                         "Flavour:URL e.g.\n"
+                                                                         "ARC0:ldap://grid.tsl.uu.se:2135/"
+                                                                         "nordugrid-cluster-name=grid.tsl.uu.se,"
+                                                                         "Mds-Vo-name=local,o=grid"));
+       
+       
+       std::string joblist;
+       options.AddOption('j', "joblist",
+                                         istring("file containing a list of jobs"),
+                                         istring("filename"),
+                                         joblist);
+       
+       std::list<std::string> clusters;
+       options.AddOption('c', "cluster",
+                                         istring("explicitly select or reject a specific resource"),
+                                         istring("[-]name"),
+                                         clusters);
+       
+       std::list<std::string> status;
+       options.AddOption('s', "status",
+                                         istring("only select jobs whose status is statusstr"),
+                                         istring("statusstr"),
+                                         status);
+       
+       std::string downloaddir;
+       options.AddOption('D', "dir",
+                                         istring("download directory (the job directory will"
+                                                         " be created in this directory)"),
+                                         istring("dirname"),
+                                         downloaddir);
+       
+       bool keep = false;
+       options.AddOption('k', "keep",
+                                         istring("keep the files on the server (do not clean)"),
+                                         keep);
+       
+       int timeout = -1;
+       options.AddOption('t', "timeout", istring("timeout in seconds (default 20)"),
+                                         istring("seconds"), timeout);
+       
+       std::string conffile;
+       options.AddOption('z', "conffile",
+                                         istring("configuration file (default ~/.arc/client.conf)"),
+                                         istring("filename"), conffile);
+       
+       
+       
+       std::list<std::string> jobs = options.Parse(argc, argv);
+       
+
+               
+               
+       Arc::UserConfig usercfg(conffile, joblist);
+       if (!usercfg) {
+               result -> message = new_str("Failed configuration initialization");
+               result -> get = 1;
+               return result;
+       }
+               
+       if (timeout > 0)
+       usercfg.Timeout(timeout);
+               
+       if (jobs.empty() && clusters.empty()) {
+               result -> message = new_str("No jobs given");
+               result -> get = 1;
+               return result;
+       }
+       
+       if (!jobs.empty())
+               usercfg.ClearSelectedServices();
+       
+       if (!clusters.empty()) {
+               usercfg.ClearSelectedServices();
+               usercfg.AddServices(clusters, Arc::COMPUTING);
+       }
+       
+       Arc::JobSupervisor jobmaster(usercfg, jobs);
+       if (!jobmaster.JobsFound()) {
+               result -> message = new_str("No jobs");
+               result -> get = 0;
+               return result;
+       }
+       std::list<Arc::JobController*> jobcont = jobmaster.GetJobControllers();
+       
+       // If the user specified a joblist on the command line joblist equals
+       // usercfg.JobListFile(). If not use the default, ie. usercfg.JobListFile().
+       if (jobcont.empty()) {
+               result -> message = new_str("No job controller plugins loaded");
+               result -> get = 1;
+               return result;
+       }
+       
+       for (std::list<Arc::JobController*>::iterator it = jobcont.begin();
+                it != jobcont.end(); it++){
+               if (!(*it)->Get(status, downloaddir, keep)){
+                       result -> get = 1;
+               }
+       }
+       
+       return result;
+}
diff --git a/src/arc_get.h b/src/arc_get.h
new file mode 100644 (file)
index 0000000..05fb12d
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ *  get.h
+ *  arcclientc
+ *
+ *  Created by Tamas Jung on 10/25/10.
+ *  Copyright 2010 Epl. All rights reserved.
+ *
+ */
+
+#ifndef arc_get_
+#define arc_get_
+
+#include "common_utils.h"
+
+typedef struct{
+       char* message;//might be NULL
+       int get;//might be NULL
+} get_result_t;
+
+PUBLIC_C get_result_t* arc_get(int argc, char **argv);
+
+#endif
\ No newline at end of file
diff --git a/src/arc_stat.cpp b/src/arc_stat.cpp
new file mode 100644 (file)
index 0000000..84cbb0a
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ *  arc_stat.cpp
+ *  arcclientc
+ *
+ *  Created by Tamas Jung on 10/25/10.
+ *  Copyright 2010 Apple. All rights reserved.
+ *
+ */
+
+#include "arc_stat.h"
+
+// -*- indent-tabs-mode: nil -*-
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <iostream>
+#include <list>
+#include <string>
+#include <algorithm>
+#include "arc_libs.h"
+
+stat_result_t*  arc_stat(int argc, char **argv) {
+       
+       stat_result_t* result = (stat_result_t*)malloc(sizeof(stat_result_t));
+       if (!result) {
+               return NULL;//TBD: throw sth?
+       }
+       result->message = NULL;
+       result->stat = NULL;
+       
+       
+       Arc::OptionParser options(istring("[job ...]"),
+                                                         istring("The arcstat command is used for "
+                                                                         "obtaining the status of jobs that have\n"
+                                                                         "been submitted to Grid enabled resources."),
+                                                         istring("Argument to -c has the format "
+                                                                         "Flavour:URL e.g.\n"
+                                                                         "ARC0:ldap://grid.tsl.uu.se:2135/"
+                                                                         "nordugrid-cluster-name=grid.tsl.uu.se,"
+                                                                         "Mds-Vo-name=local,o=grid"));
+       
+       
+       std::string joblist;
+       options.AddOption('j', "joblist",
+                                         istring("file containing a list of jobs"),
+                                         istring("filename"),
+                                         joblist);
+       
+       std::list<std::string> clusters;
+       options.AddOption('c', "cluster",
+                                         istring("explicitly select or reject a specific resource"),
+                                         istring("[-]name"),
+                                         clusters);
+       
+       
+       int timeout = -1;
+       options.AddOption('t', "timeout", istring("timeout in seconds (default 20)"),
+                                         istring("seconds"), timeout);
+       
+       std::string conffile;
+       options.AddOption('z', "conffile",
+                                         istring("configuration file (default ~/.arc/client.conf)"),
+                                         istring("filename"), conffile);
+               
+       
+       std::list<std::string> jobs = options.Parse(argc, argv);
+       
+       
+               
+       Arc::UserConfig usercfg(conffile, joblist);
+       if (!usercfg) {
+               result  -> message = new_str("Failed configuration initialization");
+               return result;
+       }
+               
+       if (timeout > 0)
+       usercfg.Timeout(timeout);
+       
+
+       
+       if (!jobs.empty())
+       usercfg.ClearSelectedServices();
+       
+       if (!clusters.empty()) {
+               usercfg.ClearSelectedServices();
+               usercfg.AddServices(clusters, Arc::COMPUTING);
+       }
+       
+       Arc::JobSupervisor jobmaster(usercfg, jobs);
+       if (!jobmaster.JobsFound()) {
+               result -> message = new_str("No jobs");
+               return result;
+       }
+       std::list<Arc::JobController*> jobcont = jobmaster.GetJobControllers();
+       
+       if (jobcont.empty()) {
+               result -> message = new_str("No job controller plugins loaded");
+               return result;
+       }
+       
+       if (jobcont.size() != 1){
+               result -> message = new_str("Too many jobs found");
+               return result;
+       } 
+       Arc::JobController* it = jobcont.front();
+       
+       it->GetJobInformation();
+       
+       std::list<Arc::Job> jobs_list = it->GetJobs();
+       
+       if (jobs_list.size() != 1) {
+               result -> message = new_str("Ambiguous job");
+               return result;
+       }
+       
+       Arc::Job& job = jobs_list.front();
+       
+       result -> stat = new_str(job.State().c_str());
+       
+       return result;
+       
+       
+}
diff --git a/src/arc_stat.h b/src/arc_stat.h
new file mode 100644 (file)
index 0000000..aafd2ed
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ *  stat.h
+ *  arcclientc
+ *
+ *  Created by Tamas Jung on 10/25/10.
+ *  Copyright 2010 Apple. All rights reserved.
+ *
+ */
+
+#ifndef stat_
+#define stat_
+
+#include "common_utils.h"
+
+typedef struct{
+       char* message;//might be NULL
+       char* stat;//might be NULL
+} stat_result_t;
+
+PUBLIC_C stat_result_t* arc_stat(int argc, char **argv);
+
+#endif
diff --git a/src/arc_submit.cpp b/src/arc_submit.cpp
new file mode 100644 (file)
index 0000000..f9333d8
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ *  submit.cpp
+ *  arcclientc
+ *
+ *  Created by Tamas Jung on 4/7/10.
+ *  Copyright 2010 Interface Kft. All rights reserved.
+ *
+ */
+
+#include "arc_submit.h"
+#include "logger.h"
+#include "config.h" //TBD: Kell ez?
+// -*- indent-tabs-mode: nil -*-
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <fstream>
+#include <iostream>
+#include <list>
+#include <string>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "arc_libs.h"
+
+
+submit_result_t* arc_submit(int argc, char **argv) {
+       
+       
+       submit_result_t* result = (submit_result_t*)malloc(sizeof(submit_result_t));
+       if (!result) {
+               return NULL;//TBD: throw sth?
+       }
+       result->message = NULL;
+       result->job_id = NULL;
+       
+       
+
+       //TODO: what necessary here?
+       Arc::OptionParser options(istring("[filename ...]"),
+                                                         istring("The arcsub command is used for "
+                                                                         "submitting jobs to grid enabled "
+                                                                         "computing\nresources."),
+                                                         istring("Argument to -i has the format "
+                                                                         "Flavour:URL e.g.\n"
+                                                                         "ARC0:ldap://grid.tsl.uu.se:2135/"
+                                                                         "mds-vo-name=sweden,O=grid\n"
+                                                                         "CREAM:ldap://cream.grid.upjs.sk:2170/"
+                                                                         "o=grid\n"
+                                                                         "\n"
+                                                                         "Argument to -c has the format "
+                                                                         "Flavour:URL e.g.\n"
+                                                                         "ARC0:ldap://grid.tsl.uu.se:2135/"
+                                                                         "nordugrid-cluster-name=grid.tsl.uu.se,"
+                                                                         "Mds-Vo-name=local,o=grid"));
+       
+       std::list<std::string> clusters;
+       options.AddOption('c', "cluster",
+                                         istring("explicity select or reject a specific cluster"),
+                                         istring("[-]name"),
+                                         clusters);
+       
+       std::list<std::string> indexurls;
+       options.AddOption('i', "index",
+                                         istring("explicity select or reject an index server"),
+                                         istring("[-]name"),
+                                         indexurls);
+       
+       std::string jobdescriptionstring;
+       options.AddOption('e', "jobdescrstring",
+                                         istring("jobdescription string describing the job to "
+                                                         "be submitted"),
+                                         istring("string"),
+                                         jobdescriptionstring);
+       
+
+       
+       
+       //jt: dryrun was commented out in the original file, I try to use it TODO:
+     bool dryrun = false;
+     options.AddOption('D', "dryrun", istring("add dryrun option"),
+        dryrun);
+        
+       std::string joblist;
+       options.AddOption('j', "joblist",
+                                         istring("file where the jobs will be stored"),
+                                         istring("filename"),
+                                         joblist);
+       
+       
+       int timeout = -1;
+       options.AddOption('t', "timeout", istring("timeout in seconds (default 20)"),
+                                         istring("seconds"), timeout);
+       
+       std::string conffile;
+       options.AddOption('z', "conffile",
+                                         istring("configuration file (default ~/.arc/client.conf)"),
+                                         istring("filename"), conffile);
+               
+       std::string broker;
+       options.AddOption('b', "broker",
+                                         istring("select broker method (Random (default), FastestQueue, or custom)"),
+                                         istring("broker"), broker);
+       
+       
+       std::list<std::string> params = options.Parse(argc, argv);
+       
+       
+       Arc::UserConfig usercfg(conffile, joblist);
+       if (!usercfg) {
+               result->message = new_str("Failed configuration initialization");
+               return result;  
+       }
+       
+       if (timeout > 0)
+               usercfg.Timeout(timeout);
+       
+       if (!broker.empty())
+               usercfg.Broker(broker);
+               
+       if (!clusters.empty() || !indexurls.empty())
+               usercfg.ClearSelectedServices();
+       
+       if (!clusters.empty())
+               usercfg.AddServices(clusters, Arc::COMPUTING);
+       
+       if (!indexurls.empty())
+               usercfg.AddServices(indexurls, Arc::INDEX);
+       
+       if (jobdescriptionstring.empty()) {
+               result->message = new_str("No job description input specified");
+               return result;
+       }
+       
+       
+
+               
+       Arc::JobDescription jobdesc;
+       
+       jobdesc.Parse(jobdescriptionstring);
+       
+       if (!jobdesc){
+               std::ostringstream sstr;
+               sstr << "Invalid JobDescription:";
+               sstr << jobdescriptionstring;
+               result->message = ostringstream2cstring(sstr);
+               return result;
+       }
+       
+       Arc::TargetGenerator targen(usercfg);
+       targen.GetTargets(0, 1);
+       
+       if (targen.FoundTargets().empty()) {
+               
+               result->message = new_str("Job submission aborted because no clusters returned any information");
+               return result;
+       }
+       
+       
+       
+       Arc::BrokerLoader loader;
+       Arc::Broker *ChosenBroker = loader.load(usercfg.Broker().first, usercfg);
+       if (!ChosenBroker) {
+               std::ostringstream sstream;
+               sstream << "Unable to load broker " << usercfg.Broker().first;
+               result->message = ostringstream2cstring(sstream);
+               return result;
+       }
+       logger.msg(Arc::INFO, "Broker %s loaded", usercfg.Broker().first);
+       
+               
+       ChosenBroker->PreFilterTargets(targen.ModifyFoundTargets(), jobdesc);
+       
+       while (true) {
+               const Arc::ExecutionTarget* target = ChosenBroker->GetBestTarget();
+               
+               if (!target) {
+                       result->message = new_str("Job submission failed, no more possible targets");
+                       break;
+               }
+               
+               Arc::Submitter *submitter = target->GetSubmitter(usercfg);
+                               
+               if (dryrun) {
+                       result->message = new_str("Dry run, job submission is skipped");
+                       break;
+               }
+               //submit the job
+               Arc::URL jobid = submitter->Submit(jobdesc, *target);
+               if (!jobid) {
+                       logger.msg(Arc::INFO, "Submission to %s failed, trying next target", target->url.str());
+                       continue;
+               }
+               
+               ChosenBroker->RegisterJobsubmission();
+               result->job_id = new_str(jobid.str().c_str());
+               logger.msg(Arc::DEBUG, "Job submitted with jobid: %s", jobid.str());
+               
+               break;
+       } //end loop over all possible targets
+       
+       return result;
+}
+
+
diff --git a/src/arc_submit.h b/src/arc_submit.h
new file mode 100644 (file)
index 0000000..e37bd03
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ *  submit.h
+ *  arcclientc
+ *
+ *  Created by Tamas Jung on 4/7/10.
+ *  Copyright 2010 Interface Kft. All rights reserved.
+ *
+ */
+
+#ifndef submit_
+#define submit_
+
+#include "common_utils.h"
+
+typedef struct{
+       char* message;//might be NULL
+       char* job_id;//might be NULL
+} submit_result_t;
+
+PUBLIC_C submit_result_t* arc_submit(int argc, char **argv);
+
+#endif
+
index 9366562..1965a06 100644 (file)
 #include "common_utils.h"
 
 
-
+bool log_initialized = false;
 char* initialize(){
        
-       setlocale(LC_ALL, "");//TBD: do we need this?
-               
-       
-       static Arc::LogStream  logcerr(std::cerr);
-       
-       logcerr.setFormat(Arc::ShortFormat);
-       Arc::Logger::getRootLogger().addDestination(logcerr);
-       Arc::Logger::getRootLogger().setThreshold(Arc::ERROR);
-       
        
+               
+       if (! log_initialized) {
+               log_initialized = true;
+               setlocale(LC_ALL, "");//TBD: do we need this?
+               static Arc::LogStream  logcerr(std::cerr);
+               
+               logcerr.setFormat(Arc::ShortFormat);
+               Arc::Logger::getRootLogger().addDestination(logcerr);
+               Arc::Logger::getRootLogger().setThreshold(Arc::DEBUG);
+               
+       }       
        return new_str(ARCCLIENTC_VERSION);
 }