Below is a sample HelloWorld program.
#define _GNU_SOURCE // mandatory to use get_current_dir_name #include <unistd.h> #include "globus_common.h" #include "itso_gram_job.h" #include "itso_gass_copy.h" #include <iostream> #include <fstream> #include "itso_gass_server.C" #include <cc++/socket.h> #include <cstdlib> #ifdef CCXX_NAMESPACE using namespace std; using namespace ost; #endif // static variables used by the FrontEndServer threads. // They are initialized at startup and readonly. // Note that for a real production case, ticket will probably // variable. A locking mechanism with mutex needs to be // used. static char hostname[MAXHOSTNAMELEN]; static long ticket; //************************************************************** // We use here the GNU Common C++ classes to implement the // basic server that will listen onb port 4096 to manages client // request and redirects them on the application server // The Server class is derived from TCPSocket class // Each client Session object (Thread) is from class TCPSession // The member run() is executed for each acceped connection. // and http://www.gnu.org/software/commonc++/docs/refman/html/classes.html // for details //************************************************************** //************************************************************** class GridApp : public TCPSocket { protected: bool onAccept(const InetHostAddress &ia, tpport_t port); public: GridApp(InetAddress &ia); }; GridApp::GridApp(InetAddress &ia) : TCPSocket(ia, 4096) {}; bool GridApp::onAccept(const InetHostAddress &ia, tpport_t port) { cout << "accepting from: " << ia.getHostname() << ":" << port << endl;; return true; } class GridAppSession : public TCPSession { private: void run(void); void final(void); public: GridAppSession(TCPSocket &server); }; GridAppSession::GridAppSession(TCPSocket &server) : TCPSession(server) { cout << "creating session client object" << endl; }; void GridAppSession::run(void) { string node; node = "t0"; // node = getNode(MDS, SLA, Workload, ...) in a real production // case. For simplicity here, we use a fixed address. InetAddress addr = getPeer(); *tcp() << "welcome to " << addr.getHostname() << endl; *tcp() << "ticket: " << ticket << endl; *tcp() << "hostname: " << node << endl; endSocket(); } void GridAppSession::final(void) { delete this; } //************************************************************** main() { // We start here the GASS server that will be used: // - to transfer the Compile script to the application nodes // to perform the library compilation // - to transfer the HelloServer used on the remote hosts to // manage clients requests // The GASS server arbitraly listens on port 20000 StartGASSServer(20000); // get the hostname using the globus function globus_libc_gethostname(hostname, MAXHOSTNAMELEN); // ITSO_GRAM_CLIENT does not start the module // lets do it if (globus_module_activate(GLOBUS_GRAM_CLIENT_MODULE) != GLOBUS_SUCCESS) { cerr << " Cannot start GRAM module"; exit(2); }; string node; // we use a fixed address for this simple example but // nodes=getNodes(SLA, MDS, Workload, ...) in a more complex example // we should get here the list of nodes where the application is // supposed to run. node = "t0"; // variable used in all for loops int i; // Here we want test the existence of the file as there is // no such checking in the ITSO_GLOBUS_FTP_CLIENT class FILE* fd = fopen("commoncpp2-1.0.8.tar.gz","r"); if(fd == NULL) { printf("Error opening commoncpp2-1.0.8.tar.gz file"); exit(2); } else { //that fine, lets go for FTP // we can close fd descriptor because a new one // will be opened for each ITSO_GLOBUS_FTP_CLIENT object fclose(fd); //never forget to activate the Globus module you want to use globus_module_activate(GLOBUS_GASS_COPY_MODULE); //************************************************************ // In this section we perform the transfer of the dynamic library // to the "application server". // We use the ITSO_GLOBUS_FTP_CLIENT class to do the task // Note that we use the local directory to perform the task. // In a real case example, a storage server would be used // instead of a local directory => // globus-url-copy gsiftp://storage_server/commoncpp2-1.0.8.tar.gz // gsiftp://application_server/commoncpp2-1.0.8.tar.gz //************************************************************ GLOBUS_URL source,destination; source.setURL("gsiftp://m0/tmp/commoncpp2-1.0.8.tar.gz"); string dst; dst="gsiftp://"+node+"/~/commoncpp2-1.0.8.tar.gz"; destination.setURL(dst); globus_module_activate(GLOBUS_GASS_COPY_MODULE); ITSO_GASS_TRANSFER transfer; transfer.Transfer(source,destination); transfer.Wait(); globus_module_deactivate(GLOBUS_GASS_COPY_MODULE); //************************************************************ // In this section we submit the compilation of the // dynamic libray. The script Compile that must be in the // current directory is transferred to the remote host // and executed. The result is the installation // of the CommonC++ toolkit in the tmp directory of the // user under which the script was executed. // (globus in the lab environement of the redbook) //************************************************************ // used to store the RSL commands. string rsl_req; ITSO_GRAM_JOB job; cout << "library compilation on " << node << endl;; rsl_req = "&(executable=https://"; rsl_req +=hostname; rsl_req += ":20000"; rsl_req +=get_current_dir_name(); rsl_req += "/Compile) (count=1)"; // submit it to the GRAM cout << rsl_req << endl; //job.Submit(node,rsl_req); //job.Wait(); //************************************************************ // ticket=getTicket(time, IP address, SLA, ...) in a // real production case ticket=random(); // node=getNodes(SLA, MDS, Workload, Application Type, ...) // in a real production case node="t0"; ITSO_GRAM_JOB job2; cout << "start app server on " << node << endl;; rsl_req = "&(executable=https://"; rsl_req +=hostname; rsl_req += ":20000"; rsl_req +=get_current_dir_name(); rsl_req += "/HelloServer) (environment=(LD_LIBRARY_PATH $(HOME)/tmp/lib) ) (count=1) (arguments="; char tmpstr[20]; sprintf(tmpstr,"%ld ",ticket); rsl_req += tmpstr; rsl_req += node; rsl_req += ")"; // submit it to the GRAM cout << rsl_req << endl; job2.Submit(node,rsl_req); job2.Wait(); // Front End server startup // We use the GNU CommonC++ classes to implement a // very basic server. See below for explanation // and http://www.gnu.org/software/commonc++/docs/refman/html/classes.html // for details GridAppSession *tcp; BroadcastAddress addr; addr = "localhost"; cout << "binding for: " << addr.getHostname() << ":" << 4096 << endl; GridApp server(addr); while(server.isPendingConnection(300000)) // the server runs for // a limited period of time { tcp = new GridAppSession(server); tcp->detach(); // the new thread is daemonize to manage // the client connection }; }; // Stop the GASS server when exiting the program StopGASSServer(); }
#include <cc++/socket.h> #include <cstdlib> #ifdef CCXX_NAMESPACES using namespace std; using namespace ost; #endif class GridApp : public TCPSocket { public: GridApp(InetAddress &ia); void end(); }; GridApp::GridApp(InetAddress &ia) : TCPSocket(ia, 4097) {}; void GridApp::end() { endSocket(); }; int main(int argc,char** argv ) { tcpstream tcp; long ticket; ticket=atol(argv[1]); InetAddress addr; addr = argv[2]; cout << "addr: " << addr << ":" << 4097 << endl; GridApp server(addr); long i; // daemonize long l =fork(); if (l>0) exit(0); // parent exits here while(server.isPendingConnection(300000)) { tcp.open(server); if(tcp.isPending(Socket::pendingInput, 2000)) { tcp >> i; cout << "user entered " << i << ticket << endl; if (i!=ticket) tcp << "Bad ticket" << endl; else tcp << "Hello World !"; } cout << "exiting now" << endl; tcp.close(); }; };
#include <cc++/socket.h> #include <string> using namespace std; using namespace ost; // g++ -g -I/usr/include/cc++2 -L/usr/lib -o S Ser2.C -lccgnu2 -lpthread -ldl class GridApp : public TCPStream { char line[200]; public: GridApp(InetHostAddress &ia) : TCPStream(ia, 4097) {}; char* readline() { tcp()->getline(line,200); return line; } }; int main(int argc,char** argv) { InetHostAddress FrontEndServerAddress,AppServerAddress; FrontEndServerAddress=argv[1]; TCPStream str(FrontEndServerAddress,4096); string hostname,ticket; str >> ticket; str >> ticket; str >> ticket; str >> ticket; str >> ticket; cout << "Ticket:" << ticket << endl; str >> hostname; str >> hostname; str >> hostname; cout << "Hostname:" << hostname << endl; AppServerAddress=hostname.c_str(); GridApp App(AppServerAddress); App << ticket << endl; cout << App. readline(); };
globus-makefile-header --flavor=gcc32 globus_io globus_gass_copy globus_gss_assist globus_ftp_client globus_ftp_control globus_gram_job globus_common globus_gram_client globus_gass_server_ez > globus_header include globus_header all: HelloServer HelloClient HelloFrontEnd %.o: %.C g++ -c $(GLOBUS_CPPFLAGS) $< -o $@ HelloServer: HelloServer.C g++ -g -I/usr/local/include/cc++2 -L/usr/local/lib -o $@ $^ -lccgnu2 -lpthread -ldl HelloClient: HelloClient.C g++ -g -I/usr/local/include/cc++2 -L/usr/local/lib -o $@ @^ -lccgnu2 -lpthread -ldl HelloFrontEnd: HelloFrontEnd.C itso_gram_job.C itso_cb.C itso_gass_copy.C itso_gass_server.C g++ -o $@ -I/usr/local/include/cc++2 -L/usr/local/lib $(GLOBUS_CPPFLAGS) $(GLOBUS_LDFLAGS) $^ $(GLOBUS_PKG_LIBS) -lccgnu2 -lpthread -ldl
18.117.189.228