root/saga/trunk/examples/misc/aws.cpp

Revision 3242, 3.2 kB (checked in by amerzky, 11 months ago)

cloud job submission examples, for Kate.
Need aws adaptors and a number of ini settings to work.
A

Line 
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 #define COUNT 100
10
11 void print_io (saga::job::job j)
12 {
13   saga::job::istream out = j.get_stdout ();
14
15   while ( true )
16   {
17     char buffer[255];
18
19     // get stdout
20     out.read (buffer, sizeof (buffer));
21
22     if ( out.gcount () > 0 )
23     {
24       std::cout << std::string (buffer, out.gcount ());
25     }
26
27     if ( out.fail () )
28     {
29       break;
30     }
31   }
32
33   return;
34 }
35
36 ///////////////////////////////////////////////////////////////////////////////
37
38 void test_cloud (saga::job::description jd,
39                  std::string            type,
40                  std::string            instance = "")
41 {
42   saga::url js_url (type + "://" + instance);
43
44   std::cout << " ----------------------- 0 (" << type << ") \n";
45
46   saga::session s1;
47
48   std::cout << " ----------------------- 1 (" << type << ") \n";
49
50   saga::context c1 (type);
51
52   std::cout << " ----------------------- 2 (" << type << ") \n";
53
54   c1.set_defaults ();
55
56   std::cout << " ----------------------- 3 (" << type << ") \n";
57
58   s1.add_context (c1);
59
60   std::cout << " ----------------------- 4 (" << type << " - " << js_url << ") \n";
61
62   saga::job::service js1 (s1, js_url);
63
64   std::cout << " ----------------------- 5 (" << type << ") \n";
65
66   saga::job::job j1 = js1.create_job (jd);
67
68   std::cout << " ----------------------- 6 (" << type << ") \n";
69
70   j1.run ();
71
72   std::cout << " ----------------------- 7 (" << type << ") \n";
73
74   print_io (j1);
75
76   std::cout << " ----------------------- 8 (" << type << ") \n";
77 }
78
79 ///////////////////////////////////////////////////////////////////////////////
80 int main (int argc, char* argv[])
81 {
82   try
83   {
84     // job description is shared by all sessions
85     saga::job::description jd;
86
87     jd.set_attribute (saga::job::attributes::description_executable,  "hostname");
88     jd.set_attribute (saga::job::attributes::description_executable, "/usr/local/packages/saga-1.1/bin/saga-file");
89     jd.set_attribute (saga::job::attributes::description_executable, "/bin/ls");
90     jd.set_attribute (saga::job::attributes::description_interactive, "True");
91
92     std::vector <std::string> args;
93
94     // args.push_back ("list_dir");
95     args.push_back ("/");
96
97     jd.set_vector_attribute (saga::job::attributes::description_arguments, args);
98
99     saga::url t ("file://localhost//Users/merzky/links/saga/projects/applications/MapReduce/samples/file.txt");
100
101     //  FIXME: the job service contact should point to the ec2 service instance.
102     //  Problem: what protocol to use?  We need to denotify the context type (do
103     //  we?), _and_ the ec2 service protocol (http/https).
104     //
105     // "https://ec2.amazonaws.com/"
106     // "http://mayhem9.cs.ucsb.edu:8773/services/Eucalyptus"
107     // "https://tp-vm1.ci.uchicago.edu:8445/wsrf/services/ElasticNimbusService"
108     // "https://vm02.cct.lsu.edu:8443/"
109    
110  // test_cloud (jd, "ec2");
111     test_cloud (jd, "ec2",        "i-d642c7bf");
112  // test_cloud (jd, "eucalyptus", "i-417E085F");
113  // test_cloud (jd, "nimbus");
114  
115   }
116   catch ( saga::exception const & e )
117   {
118     std::cerr << e.what ();
119   }
120
121   return 0;
122 }
123
Note: See TracBrowser for help on using the browser.