// WsClientUniqueIdGenerator_t.cxx #include "dial_ws_uid/WsClientUniqueIdGenerator.h" #include #include #include #include "dataset_util/FileStatus.h" #include "dataset_util/getcwd.h" #include "dataset_util/ssystem.h" #include "dataset_id/SimpleUniqueIdGenerator.h" #include "dial_ws/dial_ws_flags.h" using std::string; using std::cout; using std::endl; using std::ifstream; using dial::WsClientUniqueIdGenerator; #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 WsClientUniqueIdGenerator_t() { signal(SIGPIPE, sigpipe_handler); msg("Create UID files"); SimpleUniqueIdGenerator::create_collection("Task", 101, 0); SimpleUniqueIdGenerator::create_collection("Dataset", 101, 0); /* SimpleUniqueIdGenerator::set_as_default(); string uidcon = UniqueIdGenerator::connection(); cout << uidcon << endl; assert( uidcon.size() ); string uidcom = "DIAL_UIDS=" + uidcon + "; "; */ #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 uidcom = "DIAL_UIDS=" + getcwd() + "/UniqueId;"; string catcom = "DIAL_CATALOG_CONF=resolver.dat; "; string scom = "rm -rf server.log; "; scom += uidcom + catcom + "dialws "; /* scom += "xerces-c:"; scom += "sqlplus:"; scom += "dataset_sql:"; scom += "dataset_base:"; scom += "dataset_catalog:"; scom += "dataset_split:"; scom += "dataset_xml:"; scom += "dataset_mysqlpp:"; scom += "dial_task:"; scom += "dial_job:"; scom += "dial_ws_sched:"; */ scom += "dataset_id:"; scom += "dial_ws_uid:"; scom += "uid 8080 server.log&"; cout << scom << endl; int sysstat = ssystem(scom); assert( sysstat == 0 ); for ( int i=0; i<35; ++i ) { cout << "."; 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("Set generator connection"); string conn = "WsClientUniqueIdGenerator:"; conn += server; conn += ":"; #ifdef WITH_GSI conn += "true"; #endif cout << conn << endl; int gstat = UniqueIdGenerator::set_generator(conn); assert( gstat == 0 ); assert( UniqueIdGenerator::connection() == conn ); UniqueIdGenerator* pdid2 = UniqueIdGenerator::find_generator(conn); msg("Create bad client"); WsClientUniqueIdGenerator bgen("Bad", server); cout << bgen << endl; assert( ! bgen.is_valid() ); msg("Create dataset client"); WsClientUniqueIdGenerator dgen("Dataset", server); cout << dgen << endl; msg("Create task client generically"); UniqueIdGenerator* ptgen = UniqueIdGenerator::find_generator("Task"); assert( ptgen != 0 ); UniqueIdGenerator& tgen = *ptgen; cout << tgen << endl; msg("Check validity"); assert( dgen.is_valid() ); assert( tgen.is_valid() ); msg("Check global"); assert( dgen.is_global() ); assert( tgen.is_global() ); msg("Generate a dataset ID"); UniqueId did1 = dgen.next(); cout << did1 << endl; assert( did1.is_valid() ); assert( did1.is_global() ); msg("Generate another dataset ID"); UniqueId did2 = dgen.next(); cout << did2 << endl; assert( did2.is_valid() ); assert( did2.is_global() ); assert( did2 != did1 ); msg("Generate a task ID"); UniqueId tid1 = tgen.next(); cout << tid1 << endl; assert( tid1.is_valid() ); assert( tid1.is_global() ); assert( tid1 == did1 ); msg("Generate many ID's"); for ( int i=0; i<100; ++i ) { UniqueId did = dgen.next(); assert( did.is_valid() ); } msg("Terminate service."); dgen.terminate_service(); assert( ! dgen.is_valid() ); while ( nloop < 10 ) { cout << "."; if ( ! FileStatus("pid").exists() ) break; sleep(1); ++nloop; } cout << endl; return 0; } #ifdef CTEST_MAIN int main() { return WsClientUniqueIdGenerator_t(); } #endif