[Swift-commit] cog r3938

swift at ci.uchicago.edu swift at ci.uchicago.edu
Fri Jun 20 18:50:03 CDT 2014


------------------------------------------------------------------------
r3938 | timgarmstrong | 2014-06-20 18:45:58 -0500 (Fri, 20 Jun 2014) | 1 line

Implement a few more functions to modify job
------------------------------------------------------------------------
Index: modules/provider-coaster-c-client/src/coasters.cpp
===================================================================
--- modules/provider-coaster-c-client/src/coasters.cpp	(revision 3937)
+++ modules/provider-coaster-c-client/src/coasters.cpp	(working copy)
@@ -62,6 +62,11 @@
 static coaster_rc coaster_error_rc(const CoasterError &err);
 static coaster_rc exception_rc(const std::exception &ex);
 
+// Check for error
+// TODO: store error message somewhere instead of printing?
+#define COASTER_CONDITION(cond, err_rc, err_msg) { \
+  if (!(cond)) { fprintf(stderr, (err_msg)); return (err_rc); }}
+
 coaster_rc coaster_client_start(const char *serviceURL,
                                 coaster_client **client)
                                 COASTERS_THROWS_NOTHING {
@@ -244,22 +249,101 @@
     return COASTER_ERROR_INVALID;
   }
   
-  // Accessor methods shouldn't throw exceptions
-  std::string *stdin_str = (stdin_loc == NULL) ?
-                            NULL : new string(stdin_loc);
-  job->job.setStdinLocation(*stdin_str);
+  try {
+    std::string *stdin_str = (stdin_loc == NULL) ?
+                              NULL : new string(stdin_loc);
+    job->job.setStdinLocation(*stdin_str);
+    
+    std::string *stdout_str = (stdout_loc == NULL) ?
+                              NULL : new string(stdout_loc);
+    job->job.setStdinLocation(*stdout_str);
+    
+    std::string *stderr_str = (stderr_loc == NULL) ?
+                              NULL : new string(stderr_loc);
+    job->job.setStdinLocation(*stderr_str);
+
+    return COASTER_SUCCESS;
+  } catch (const CoasterError& err) {
+    return coaster_error_rc(err);
+  } catch (const std::exception& ex) {
+    return exception_rc(ex);
+  }
+}
+
+coaster_rc
+coaster_job_set_directory(coaster_job *job, const char *dir)
+                  COASTERS_THROWS_NOTHING {
+  if (job == NULL) {
+    return COASTER_ERROR_INVALID;
+  }
   
-  std::string *stdout_str = (stdout_loc == NULL) ?
-                            NULL : new string(stdout_loc);
-  job->job.setStdinLocation(*stdout_str);
+  try {
+    std::string *dir_str = (dir == NULL) ?
+                              NULL : new string(dir);
+    job->job.setDirectory(*dir_str);
+
+    return COASTER_SUCCESS;
+  } catch (const CoasterError& err) {
+    return coaster_error_rc(err);
+  } catch (const std::exception& ex) {
+    return exception_rc(ex);
+  }
+}
+
+coaster_rc
+coaster_job_set_envs(coaster_job *job, int nvars, const char **names,
+                    const char **values) COASTERS_THROWS_NOTHING {
+  if (job == NULL) {
+    return COASTER_ERROR_INVALID;
+  }
   
-  std::string *stderr_str = (stderr_loc == NULL) ?
-                            NULL : new string(stderr_loc);
-  job->job.setStdinLocation(*stderr_str);
+  try {
+    for (int i = 0; i < nvars; i++)
+    {
+      const char *name = names[i];
+      const char *value = values[i];
+      COASTER_CONDITION(name != NULL && value != NULL,
+            COASTER_ERROR_INVALID, "Env var name or value was NULL");
+      job->job.setEnv(name, value);
+    }
 
-  return COASTER_SUCCESS;
+    return COASTER_SUCCESS;
+  } catch (const CoasterError& err) {
+    return coaster_error_rc(err);
+  } catch (const std::exception& ex) {
+    return exception_rc(ex);
+  }
 }
 
+/*
+ * Add attributes for the job.  Will overwrite any previous atrributes
+ * if names match.
+ */
+coaster_rc
+coaster_job_set_attrs(coaster_job *job, int nattrs, const char **names,
+                    const char **values) COASTERS_THROWS_NOTHING {
+  if (job == NULL) {
+    return COASTER_ERROR_INVALID;
+  }
+  
+  try {
+    for (int i = 0; i < nattrs; i++)
+    {
+      const char *name = names[i];
+      const char *value = values[i];
+      COASTER_CONDITION(name != NULL && value != NULL,
+            COASTER_ERROR_INVALID, "Attribute name or value was NULL");
+      job->job.setAttribute(name, value);
+    }
+
+    return COASTER_SUCCESS;
+  } catch (const CoasterError& err) {
+    return coaster_error_rc(err);
+  } catch (const std::exception& ex) {
+    return exception_rc(ex);
+  }
+}
+
 const char *
 coaster_job_get_id(coaster_job *job) COASTERS_THROWS_NOTHING {
   // Shouldn't throw anything from accessor method
@@ -308,5 +392,6 @@
 
 static coaster_rc exception_rc(const std::exception &ex) {
   // TODO: store error info?
+  // TODO: handle specific types, e.g. bad_alloc
   return COASTER_ERROR_UNKNOWN;
 }
Index: modules/provider-coaster-c-client/src/coasters.h
===================================================================
--- modules/provider-coaster-c-client/src/coasters.h	(revision 3937)
+++ modules/provider-coaster-c-client/src/coasters.h	(working copy)
@@ -157,10 +157,34 @@
                   const char *stdout_loc, const char *stderr_loc)
                   COASTERS_THROWS_NOTHING;
 
-// TODO: functions for setting directory, env vars, attributes,
-//       stageins, stageouts, cleanups
+/*
+ * Set job directory.
+ */
+coaster_rc
+coaster_job_set_directory(coaster_job *job, const char *dir)
+                  COASTERS_THROWS_NOTHING;
 
 /*
+ * Add environment variables for the job.  Will overwrite any
+ * previous values if names match.
+ * name and value strings should not be NULL.
+ */
+coaster_rc
+coaster_job_set_envs(coaster_job *job, int nvars, const char **names,
+                    const char **values) COASTERS_THROWS_NOTHING;
+
+/*
+ * Add attributes for the job.  Will overwrite any previous atrributes
+ * if names match.
+ * name and value strings should not be NULL.
+ */
+coaster_rc
+coaster_job_set_attrs(coaster_job *job, int nattrs, const char **names,
+                    const char **values) COASTERS_THROWS_NOTHING;
+
+// TODO: functions for setting  stageins, stageouts, cleanups
+
+/*
  * Get local job ID string.
  * Return value points to job state: will be invalid if job is freed.
  */



More information about the Swift-commit mailing list