| 1 |
// Copyright (c) 2005-2007 Andre Merzky <andre@merzky.net> |
|---|
| 2 |
// |
|---|
| 3 |
// Distributed under the Boost Software License, Version 1.0. |
|---|
| 4 |
// (See accompanying file LICENSE file or copy at |
|---|
| 5 |
// http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 6 |
|
|---|
| 7 |
#include <saga/saga.hpp> |
|---|
| 8 |
|
|---|
| 9 |
void print_io (saga::job::job j) |
|---|
| 10 |
{ |
|---|
| 11 |
saga::job::istream out = j.get_stdout (); |
|---|
| 12 |
|
|---|
| 13 |
while ( true ) |
|---|
| 14 |
{ |
|---|
| 15 |
char buffer[255]; |
|---|
| 16 |
|
|---|
| 17 |
// get stdout |
|---|
| 18 |
out.read (buffer, sizeof (buffer)); |
|---|
| 19 |
|
|---|
| 20 |
if ( out.gcount () > 0 ) |
|---|
| 21 |
{ |
|---|
| 22 |
std::cout << std::string (buffer, out.gcount ()); |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
if ( out.fail () ) |
|---|
| 26 |
{ |
|---|
| 27 |
break; |
|---|
| 28 |
} |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
return; |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
/////////////////////////////////////////////////////////////////////////////// |
|---|
| 35 |
|
|---|
| 36 |
void test_cloud (saga::job::description jd, |
|---|
| 37 |
std::string type, |
|---|
| 38 |
std::string instance = "") |
|---|
| 39 |
{ |
|---|
| 40 |
|
|---|
| 41 |
saga::url js_url (type + "://" + instance); |
|---|
| 42 |
|
|---|
| 43 |
std::cout << " ----------------------- (" << type << " - " << js_url << ") \n"; |
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
// create a context for that cloud type |
|---|
| 47 |
saga::context c (type); |
|---|
| 48 |
c.set_defaults (); |
|---|
| 49 |
|
|---|
| 50 |
// attach it to the session |
|---|
| 51 |
saga::session s; |
|---|
| 52 |
s.add_context (c); |
|---|
| 53 |
|
|---|
| 54 |
// create a job service in that session |
|---|
| 55 |
saga::job::service js (s, js_url); |
|---|
| 56 |
|
|---|
| 57 |
// create and run a job on that job service (i.e. on that VM) |
|---|
| 58 |
saga::job::job j = js.create_job (jd); |
|---|
| 59 |
j.run (); |
|---|
| 60 |
|
|---|
| 61 |
// print job output |
|---|
| 62 |
print_io (j); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
/////////////////////////////////////////////////////////////////////////////// |
|---|
| 66 |
int main (int argc, char* argv[]) |
|---|
| 67 |
{ |
|---|
| 68 |
try |
|---|
| 69 |
{ |
|---|
| 70 |
// job description is shared by all sessions |
|---|
| 71 |
saga::job::description jd; |
|---|
| 72 |
|
|---|
| 73 |
jd.set_attribute (saga::job::attributes::description_executable, "hostname"); |
|---|
| 74 |
jd.set_attribute (saga::job::attributes::description_executable, "/usr/local/packages/saga-1.1/bin/saga-file"); |
|---|
| 75 |
jd.set_attribute (saga::job::attributes::description_executable, "/bin/ls"); |
|---|
| 76 |
jd.set_attribute (saga::job::attributes::description_interactive, "True"); |
|---|
| 77 |
|
|---|
| 78 |
std::vector <std::string> args; |
|---|
| 79 |
|
|---|
| 80 |
// args.push_back ("list_dir"); |
|---|
| 81 |
args.push_back ("/"); |
|---|
| 82 |
|
|---|
| 83 |
jd.set_vector_attribute (saga::job::attributes::description_arguments, args); |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
// FIXME: the job service contact should point to the ec2 service instance. |
|---|
| 87 |
// Problem: what protocol to use? We need to denotify the context type (do |
|---|
| 88 |
// we?), _and_ the ec2 service protocol (http/https). Anyway, this needs to |
|---|
| 89 |
// be fixed in the adaptor. |
|---|
| 90 |
// |
|---|
| 91 |
// "https://ec2.amazonaws.com/" |
|---|
| 92 |
// "http://mayhem9.cs.ucsb.edu:8773/services/Eucalyptus" |
|---|
| 93 |
// "https://tp-vm1.ci.uchicago.edu:8445/wsrf/services/ElasticNimbusService" |
|---|
| 94 |
// "https://vm02.cct.lsu.edu:8443/" |
|---|
| 95 |
|
|---|
| 96 |
// create a new instance on ec2, and run a test job |
|---|
| 97 |
test_cloud (jd, "ec2"); |
|---|
| 98 |
|
|---|
| 99 |
// access a running VM instance on ec2, and run a test job |
|---|
| 100 |
// test_cloud (jd, "ec2", "i-d642c7bf"); |
|---|
| 101 |
|
|---|
| 102 |
// samoe for eucalyptus |
|---|
| 103 |
// test_cloud (jd, "eucalyptus"); |
|---|
| 104 |
// test_cloud (jd, "eucalyptus", "i-417E085F"); |
|---|
| 105 |
|
|---|
| 106 |
// samoe for nimbus |
|---|
| 107 |
// test_cloud (jd, "nimbus"); |
|---|
| 108 |
// test_cloud (jd, "nimbus", "i-3247A527"); |
|---|
| 109 |
|
|---|
| 110 |
} |
|---|
| 111 |
catch ( saga::exception const & e ) |
|---|
| 112 |
{ |
|---|
| 113 |
std::cerr << e.what (); |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
return 0; |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|