[Swift-commit] cog r3820
swift at ci.uchicago.edu
swift at ci.uchicago.edu
Mon Oct 28 13:50:04 CDT 2013
------------------------------------------------------------------------
r3820 | yadunand | 2013-10-28 13:48:27 -0500 (Mon, 28 Oct 2013) | 5 lines
Added Job create, submit, wait functions.
All current functionality tested, tests added to tests/tcl
------------------------------------------------------------------------
Index: modules/provider-coaster-c-client/src/CoasterSWIG.h
===================================================================
--- modules/provider-coaster-c-client/src/CoasterSWIG.h (revision 3819)
+++ modules/provider-coaster-c-client/src/CoasterSWIG.h (working copy)
@@ -8,17 +8,25 @@
#include "CoasterClient.h"
#include "CoasterSWIG.h"
#include "CoasterLoop.h"
+ #include "Settings.h"
%}
#endif
CoasterLoop* CoasterSWIGLoopCreate(void);
int CoasterSWIGLoopDestroy(CoasterLoop* loop);
-CoasterClient* CoasterSWIGClientCreate(CoasterLoop &loop, char* serviceURL);
+CoasterClient* CoasterSWIGClientCreate(CoasterLoop *loop, char* serviceURL);
int CoasterSWIGClientDestroy(CoasterClient *client);
int CoasterSWIGClientSettings(CoasterClient *client, char *settings);
+Job* CoasterSWIGJobCreate(char *cmd_string);
+int CoasterSWIGSubmitJob(CoasterClient *client, Job* job);
+int CoasterSWIGWaitForJob(CoasterClient *client, Job* job);
+int CoasterSWIGTest(CoasterLoop *loop, char *service_URL, CoasterClient *c);
+//int CoasterSWIGTest(CoasterLoop *loop, char *service_URL);
+//int CoasterSWIGTest(CoasterClient *client);
+
Index: modules/provider-coaster-c-client/src/CoasterSWIG.cpp
===================================================================
--- modules/provider-coaster-c-client/src/CoasterSWIG.cpp (revision 3819)
+++ modules/provider-coaster-c-client/src/CoasterSWIG.cpp (working copy)
@@ -22,16 +22,19 @@
return loop;
}
+/* Destroys the loop
+ */
int CoasterSWIGLoopDestroy(CoasterLoop* loop)
{
delete(loop);
return 0;
}
-CoasterClient* CoasterSWIGClientCreate(CoasterLoop &loop, char* serviceURL)
+CoasterClient* CoasterSWIGClientCreate(CoasterLoop *loop, char* serviceURL)
{
cout << "CoasterSWIGClientCreate(" << serviceURL << ")..." << endl;
- CoasterClient* client = new CoasterClient(serviceURL, loop);
+ CoasterClient* client = new CoasterClient(serviceURL, *loop);
+ client->start();
return client;
}
@@ -46,9 +49,9 @@
Settings s;
cout << "CoasterSWIGClientSettings(" << settings << ")" <<endl;
cout << "Client : [" << (void *) client << "]"<<endl;
+
// Parsing logic
// K1=V1, K2=V2 is the format of the settings string
-
std::vector<std::string> elems;
std::stringstream ss(settings);
std::string item, key, value;
@@ -65,8 +68,92 @@
cout << "Key,Value : " << key <<", "<<value << endl;
}
- //TODO: SegFaulting here. Why ?
- cout << "client->getURL() : " << client->getURL() << endl ;
client->setOptions(s);
return 0;
}
+
+Job* CoasterSWIGJobCreate(char *cmd_string)
+{
+ cout << "CoasterSWIGJobCreate("<< cmd_string <<") "<< endl;
+ Job *job = new Job(cmd_string);
+ return job;
+}
+
+int CoasterSWIGSubmitJob(CoasterClient *client, Job* job)
+{
+ client->submit(*job);
+ client->waitForJob(*job);
+ int status = job->getStatus()->getStatusCode();
+ cout << "SubmitJob returns code :" << status << endl;
+ return 0;
+}
+
+int CoasterSWIGWaitForJob(CoasterClient *client, Job *job)
+{
+ client->waitForJob(*job);
+ return 0;
+}
+
+
+/**
+ * This is a test function.
+ */
+int CoasterSWIGTest (CoasterLoop *loop, char *serviceURL, CoasterClient *client)
+{
+ try {
+ //CoasterClient* client = new CoasterClient(serviceURL, *loop);
+
+ //CoasterClient* ptr = &client;
+ CoasterClient* ptr = client;
+ //client.start();
+ //CoasterClient* client = new CoasterClient(serviceURL, *loop);
+
+ Settings s;
+ s.set(Settings::Key::SLOTS, "1");
+ s.set(Settings::Key::MAX_NODES, "1");
+ s.set(Settings::Key::JOBS_PER_NODE, "2");
+
+ //client->setOptions(s);
+ //client.setOptions(s);
+ ptr->setOptions(s);
+
+ Job j1("/bin/date");
+ Job j2("/bin/echo");
+ j2.addArgument("testing");
+ j2.addArgument("1, 2, 3");
+
+
+ ptr->submit(j1);
+ ptr->submit(j2);
+
+ ptr->waitForJob(j1);
+ ptr->waitForJob(j2);
+ list<Job*>* doneJobs = ptr->getAndPurgeDoneJobs();
+ /*
+ client.submit(j1);
+ client.submit(j2);
+
+ client.waitForJob(j1);
+ client.waitForJob(j2);
+ list<Job*>* doneJobs = client.getAndPurgeDoneJobs();
+ */
+ delete doneJobs;
+
+ if (j1.getStatus()->getStatusCode() == FAILED) {
+ cerr << "Job 1 failed: " << *j1.getStatus()->getMessage() << endl;
+ }
+ if (j2.getStatus()->getStatusCode() == FAILED) {
+ cerr << "Job 2 failed: " << *j2.getStatus()->getMessage() << endl;
+ }
+
+ cout << "All done" << endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch (exception& e) {
+ cerr << "Exception caught: " << e.what() << endl;
+ return EXIT_FAILURE;
+ }
+}
+
+
Index: modules/provider-coaster-c-client/tests/tcl/coaster-test-4.tcl
===================================================================
--- modules/provider-coaster-c-client/tests/tcl/coaster-test-4.tcl (revision 0)
+++ modules/provider-coaster-c-client/tests/tcl/coaster-test-4.tcl (revision 3820)
@@ -0,0 +1,19 @@
+load ../../src/.libs/libcoasterclient.so
+
+set loop_ptr [CoasterSWIGLoopCreate]
+
+set client_ptr [CoasterSWIGClientCreate $loop_ptr 140.221.8.81:40568]
+
+set x [CoasterSWIGClientSettings $client_ptr "SLOTS=1,MAX_NODES=1,JOBS_PER_NODE=2"]
+puts "Error code from CoasterSWIGClientSettings "
+puts $x
+
+set job1 [CoasterSWIGJobCreate "/bin/hostname"]
+puts "Job set to /bin/hostname"
+
+set rcode [CoasterSWIGSubmitJob $client_ptr $job1]
+puts "Job1 submitted"
+
+puts "Waiting for Job1"
+set rcode [CoasterSWIGWaitForJob $client_ptr $job1]
+puts "Job1 complete"
Index: modules/provider-coaster-c-client/tests/tcl/coaster-test-5.tcl
===================================================================
--- modules/provider-coaster-c-client/tests/tcl/coaster-test-5.tcl (revision 0)
+++ modules/provider-coaster-c-client/tests/tcl/coaster-test-5.tcl (revision 3820)
@@ -0,0 +1,23 @@
+load ../../src/.libs/libcoasterclient.so
+
+set loop_ptr [CoasterSWIGLoopCreate]
+
+set client_ptr [CoasterSWIGClientCreate $loop_ptr 140.221.8.81:40568]
+
+set x [CoasterSWIGClientSettings $client_ptr "SLOTS=1,MAX_NODES=1,JOBS_PER_NODE=2"]
+puts "Error code from CoasterSWIGClientSettings "
+puts $x
+
+set job1 [CoasterSWIGJobCreate "/bin/hostname"]
+puts "Job set to /bin/hostname"
+
+set rcode [CoasterSWIGSubmitJob $client_ptr $job1]
+puts "Job1 submitted"
+
+puts "Waiting for Job1"
+set rcode [CoasterSWIGWaitForJob $client_ptr $job1]
+puts "Job1 complete"
+
+set rcode [CoasterSWIGClientDestroy $client_ptr]
+
+set rcode [CoasterSWIGLoopDestroy $loop_ptr]
\ No newline at end of file
Index: modules/provider-coaster-c-client/tests/tcl/coaster-jobs.tcl
===================================================================
--- modules/provider-coaster-c-client/tests/tcl/coaster-jobs.tcl (revision 0)
+++ modules/provider-coaster-c-client/tests/tcl/coaster-jobs.tcl (revision 3820)
@@ -0,0 +1,13 @@
+load ../../src/.libs/libcoasterclient.so
+
+set loop_ptr [CoasterSWIGLoopCreate]
+set client_ptr [CoasterSWIGClientCreate $loop_ptr 140.221.8.81:40568]
+
+set x [CoasterSWIGClientSettings $client_ptr "SLOTS=1,MAX_NODES=1"]
+
+set job1_ptr [CoasterSWIGJobCreate "/bin/hostname"]
+
+set returncode [CoasterSWIGSubmitJob $client_ptr $job1_ptr]
+
+set rcode [CoasterSWIGClientDestroy $client_ptr]
+set rcode [CoasterSWIGLoopDestroy $loop_ptr]
Index: modules/provider-coaster-c-client/tests/tcl/coaster-test-10.tcl
===================================================================
--- modules/provider-coaster-c-client/tests/tcl/coaster-test-10.tcl (revision 0)
+++ modules/provider-coaster-c-client/tests/tcl/coaster-test-10.tcl (revision 3820)
@@ -0,0 +1,11 @@
+load ../../src/.libs/libcoasterclient.so
+
+set loop_ptr [CoasterSWIGLoopCreate]
+
+set client_ptr [CoasterSWIGClientCreate $loop_ptr 140.221.8.81:40568]
+
+set result [CoasterSWIGTest $loop_ptr 140.221.8.81:40568 $client_ptr ]
+
+#set result [CoasterSWIGTest $client_ptr]
+
+#set x [CoasterSWIGClientSettings $client_ptr "SLOTS=1,MAX_NODES=1"]
Index: modules/provider-coaster-c-client/tests/tcl/coaster-test-4.tcl~
===================================================================
--- modules/provider-coaster-c-client/tests/tcl/coaster-test-4.tcl~ (revision 0)
+++ modules/provider-coaster-c-client/tests/tcl/coaster-test-4.tcl~ (revision 3820)
@@ -0,0 +1,23 @@
+load ../../src/.libs/libcoasterclient.so
+
+set loop_ptr [CoasterSWIGLoopCreate]
+
+set client_ptr [CoasterSWIGClientCreate $loop_ptr 140.221.8.81:40568]
+
+set x [CoasterSWIGClientSettings $client_ptr "SLOTS=1,MAX_NODES=1,JOBS_PER_NODE=2"]
+puts "Error code from CoasterSWIGClientSettings "
+puts $x
+
+set job1 [CoasterSWIGJobCreate "/bin/hostname"]
+puts "Job set to /bin/hostname"
+
+set rcode [CoasterSWIGSubmitJob $client_ptr $job1]
+puts "Job1 submitted"
+
+puts "Waiting for Job1"
+set rcode [CoasterSWIGWaitForJob $client_ptr $job1]
+puts "Job1 complete"
+
+set rcode [CoasterSWIGClientDestroy $client_ptr]
+
+set rcode [CoasterSWIGLoopDestroy $loop_ptr]
\ No newline at end of file
Index: modules/provider-coaster-c-client/tests/tcl/coaster-test-1.tcl
===================================================================
--- modules/provider-coaster-c-client/tests/tcl/coaster-test-1.tcl (revision 3819)
+++ modules/provider-coaster-c-client/tests/tcl/coaster-test-1.tcl (working copy)
@@ -1,3 +1,4 @@
load ../../src/.libs/libcoasterclient.so
-CoasterSWIGClientCreate http://localhost
+set loop_ptr [CoasterSWIGLoopCreate]
+
Index: modules/provider-coaster-c-client/tests/tcl/coaster-test-2.tcl
===================================================================
--- modules/provider-coaster-c-client/tests/tcl/coaster-test-2.tcl (revision 3819)
+++ modules/provider-coaster-c-client/tests/tcl/coaster-test-2.tcl (working copy)
@@ -1,7 +1,6 @@
load ../../src/.libs/libcoasterclient.so
-set client_ptr [CoasterSWIGClientCreate 140.221.8.81:40568]
-set x [CoasterSWIGClientSettings $client_ptr "SLOTS=1,MAX_NODES=1"]
-puts $x
-#CoasterSWIGTest "SLOTS=1,MAX_NODES=1"
+set loop_ptr [CoasterSWIGLoopCreate]
+set client_ptr [CoasterSWIGClientCreate $loop_ptr "140.221.8.81:40568"]
+
More information about the Swift-commit
mailing list