kill added
authorTamas Jung <tamasjung@gmail.com>
Tue, 4 Jan 2011 22:55:25 +0000 (23:55 +0100)
committerTamas Jung <tamasjung@gmail.com>
Tue, 4 Jan 2011 22:55:25 +0000 (23:55 +0100)
Manifest.txt
README.rdoc
ext/arc_kill.cpp [new file with mode: 0644]
ext/arc_kill.h [new file with mode: 0644]
lib/arc_client_c_wrapper.rb
lib/arc_client_r.rb
test/test_kill.rb [new file with mode: 0644]

index 7dacabf..04a90fb 100644 (file)
@@ -18,6 +18,8 @@ script/destroy
 script/generate
 ext/arc_get.cpp
 ext/arc_get.h
+ext/arc_kill.cpp
+ext/arc_kill.h
 ext/arc_libs.h
 ext/arc_stat.cpp
 ext/arc_stat.h
index 1b04005..417dab8 100644 (file)
@@ -20,7 +20,7 @@ FIX (describe your package)
 
 == INSTALL:
 
-* FIX (sudo gem install, anything else)
+* rake install_gem
 
 == LICENSE:
 
diff --git a/ext/arc_kill.cpp b/ext/arc_kill.cpp
new file mode 100644 (file)
index 0000000..0f43583
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ *  arc_kill.cpp
+ *  arcclientc
+ *
+ *  Created by Tamas Jung on 10/25/10.
+ *  Copyright 2010 Epl. All rights reserved.
+ *
+ */
+
+#include "arc_kill.h"
+
+// -*- indent-tabs-mode: nil -*-
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "logger.h"
+
+
+#include <iostream>
+#include <list>
+#include <string>
+#include <algorithm>
+#include "arc_libs.h"
+
+int  arc_kill(int argc, char **argv) {
+
+  Arc::OptionParser options(istring("[job ...]"),
+                            istring("The arckill command is used to kill "
+                                    "running jobs."),
+                            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"));
+
+  bool all = false;
+  options.AddOption('a', "all",
+                    istring("all jobs"),
+                    all);
+
+  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);
+
+  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) {
+    logger.msg(Arc::ERROR, "Failed configuration initialization");
+    return 1;
+  }
+
+  if (timeout > 0)
+    usercfg.Timeout(timeout);
+
+  if ((!joblist.empty() || !status.empty()) && jobs.empty() && clusters.empty())
+    all = true;
+
+  if (jobs.empty() && clusters.empty() && !all) {
+    logger.msg(Arc::ERROR, "No jobs given");
+    return 1;
+  }
+
+  if (!jobs.empty() || all)
+    usercfg.ClearSelectedServices();
+
+  if (!clusters.empty()) {
+    usercfg.ClearSelectedServices();
+    usercfg.AddServices(clusters, Arc::COMPUTING);
+  }
+
+  // If the user specified a joblist on the command line joblist equals
+  // usercfg.JobListFile(). If not use the default, ie. usercfg.JobListFile().
+  Arc::JobSupervisor jobmaster(usercfg, jobs);
+  if (!jobmaster.JobsFound()) {
+    logger.msg(Arc::ERROR, "No jobs");
+    return 0;
+  }
+  std::list<Arc::JobController*> jobcont = jobmaster.GetJobControllers();
+
+  if (jobcont.empty()) {
+    logger.msg(Arc::ERROR, "No job controller plugins loaded");
+    return 1;
+  }
+
+  int retval = 0;
+  for (std::list<Arc::JobController*>::iterator it = jobcont.begin();
+       it != jobcont.end(); it++)
+    if (!(*it)->Kill(status, keep))
+      retval = 1;
+
+  return retval;
+}
\ No newline at end of file
diff --git a/ext/arc_kill.h b/ext/arc_kill.h
new file mode 100644 (file)
index 0000000..74a6b3b
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ *  arc_kill.h
+ *  arcclientc
+ *
+ *  Created by Tamas Jung on 10/25/10.
+ *  Copyright 2010 Epl. All rights reserved.
+ *
+ */
+
+#ifndef arc_kill_
+#define arc_kill_
+
+#include "common_utils.h"
+
+
+
+PUBLIC_C int arc_kill(int argc, char **argv);
+
+#endif
\ No newline at end of file
index 249b2c9..3532aa0 100644 (file)
@@ -95,6 +95,7 @@ class ArcClientCWrapper
   attach_function :arc_submit, [:int, :pointer], :pointer
   attach_function :arc_stat, [:int, :pointer], :pointer
   attach_function :arc_get, [:int, :pointer], :pointer
+  attach_function :arc_kill, [:int, :pointer], :int
   
   def self.string_array_as_pointer(arr)
     result = FFI::MemoryPointer.new(:pointer, arr.size)
index e6d0540..ce5dcf4 100644 (file)
@@ -43,4 +43,10 @@ class ArcClientR
     end
   end
   
+  def kill(the_args)
+    args = the_args.unshift
+    args_pointer = ArcClientCWrapper::string_array_as_pointer(args)
+    @wrapper.arc_kill(args.size, args_pointer)
+  end
+  
 end
\ No newline at end of file
diff --git a/test/test_kill.rb b/test/test_kill.rb
new file mode 100644 (file)
index 0000000..0668215
--- /dev/null
@@ -0,0 +1,11 @@
+require File.join(File.dirname(__FILE__), 'test_helper')
+require 'arc_client_r'
+
+class TestGet < ::Test::Unit::TestCase
+  
+  def test_base
+    arc_client = ArcClientR.new
+    result = arc_client.kill(["-j", "test_job_list.xml", "https://interop.grid.niif.hu:2010/arex-x509/218791288114550534117300"])
+    p result
+  end
+end
\ No newline at end of file