// FileSystemWsClient_t.cxx #include "dial_ws_file/FileSystemWsClient.h" #include #include #include #include "dataset_util/FileStatus.h" #include "dataset_util/getcwd.h" #include "dataset_util/ssystem.h" #include "dataset_util/Text.h" #include "dial_ws/dial_ws_flags.h" using std::string; using std::cout; using std::endl; using std::ifstream; using dial::FileSystemWsClient; #ifdef WITH_GSI #include "gsi.h" #endif void msg(string txt) { cout << "*** "; cout << txt; cout << " ***" << endl; } void sigpipe_handler(int) { cout << "Another broken pipe" << endl; } #ifdef WITH_GSI int client_authorization(struct soap* psoap) { struct gsi_plugin_data* pgsiplug = (struct gsi_plugin_data *) soap_lookup_plugin(psoap, GSI_PLUGIN_ID); //string client_identity = pgsiplug->client_identity; string service_identity = pgsiplug->server_identity; //cout << "GSI Client ID: " << client_identity << endl; cout << "GSI Service ID: " << service_identity << endl; return 0; } #endif int FileSystemWsClient_t() { signal(SIGPIPE, sigpipe_handler); #ifdef WITH_GSI // Create auth file. string globus_version = "3"; string gcom = "rm -f authorized_dn"; gcom += "; "; if ( globus_version == "2" ) { gcom += "grid-proxy-info -subject"; gcom += " | sed 's#/CN=proxy##g'"; } else { gcom += "grid-proxy-info -identity"; } gcom += " > authorized_dn"; system(gcom.c_str()); #endif int pid = -1; if ( FileStatus("pid").exists() ) { msg("Clean up from earlier test"); ifstream pidfile("pid"); pidfile >> pid; if ( pid > 0 ) { cout << "Killing process " << pid << endl; kill(pid, SIGKILL); } unlink("pid"); pid = -1; sleep(1); // Give system time to free up port } msg("Start server"); assert( ! FileStatus("pid").exists() ); string com = "rm -rf server.log; "; com += "dialws dial_ws_file:filesystem 8080 server.log"; com += " gsi"; com += " service"; com += " >service.log 2>&1 &"; cout << com << endl; int sysstat = system(com.c_str()); assert( sysstat == 0 ); for ( int i=0; i<35; ++i ) { cout << "."; cout.flush(); if ( FileStatus("pid").exists() ) break; sleep(1); } cout << endl; assert( FileStatus("pid").exists() ); msg("Set server URL"); #ifdef WITH_GSI string server = "http://127.0.0.1:8080"; #else string server = "http://127.0.0.1:8080"; #endif msg("Check server process"); int nloop = 0; while ( nloop < 10 ) { if ( FileStatus("pid").exists() ) break; sleep(1); ++nloop; } assert( nloop < 10 ); { ifstream pidfile("pid"); pidfile >> pid; } cout << "Server process ID is " << pid << endl; assert( pid > 0 ); msg("Create client"); FileSystemWsClient client(server); msg("Check validity"); sleep(1); assert( client.is_valid() ); msg("Check nonexisting file"); string dir = getcwd(); string badfile = dir + "/bad.dat"; ssystem("rm -f " + badfile); assert( ! client.exists(badfile) ); msg("Check existing file"); string goodfile = dir + "/good.dat"; Text gtxt(goodfile); gtxt.append("This is a good text file"); gtxt.append("Isn't it?"); gtxt.write(); assert( client.exists(goodfile) ); msg("List nonexisting file"); string listing = client.listing(badfile); if ( listing.size() ) cout << listing << endl; assert( listing.size() == 0 ); msg("List existing file"); listing = client.listing(goodfile); if ( listing.size() ) cout << '"' << listing << '"' << endl; assert( listing.size() != 0 ); msg("List directory"); string dname = getcwd(); FileSystemWsClient::NameList dirfiles = client.directory_files(dname); for ( FileSystemWsClient::NameList::const_iterator inam=dirfiles.begin(); inam!=dirfiles.end(); ++inam ) { cout << " " << *inam << endl; } assert( dirfiles.size() ); assert( find(dirfiles.begin(), dirfiles.end(), "bad.dat") == dirfiles.end() ); assert( find(dirfiles.begin(), dirfiles.end(), "good.dat") != dirfiles.end() ); msg("Get file"); unlink("copy.dat"); int cstat = client.get(goodfile, "copy.dat"); assert( FileStatus("copy.dat").exists() ); assert( Text("copy.dat") == gtxt ); msg("Terminate service."); client.terminate_service(); assert( ! client.is_valid() ); while ( nloop < 10 ) { cout << "."; if ( ! FileStatus("pid").exists() ) break; sleep(1); ++nloop; } cout << endl; return 0; } #ifdef CTEST_MAIN int main() { return FileSystemWsClient_t(); } #endif