int RUNMAIN(arccat)(int argc, char **argv) { setlocale(LC_ALL, ""); Arc::Logger logger(Arc::Logger::getRootLogger(), "arccat"); Arc::LogStream logcerr(std::cerr); logcerr.setFormat(Arc::ShortFormat); Arc::Logger::getRootLogger().addDestination(logcerr); Arc::Logger::getRootLogger().setThreshold(Arc::WARNING); Arc::ArcLocation::Init(argv[0]); ClientOptions opt(ClientOptions::CO_CAT, istring("[job ...]"), istring("The arccat command performs the cat " "command on the stdout, stderr or grid\n" "manager's error log of the job.")); std::list<std::string> jobidentifiers = opt.Parse(argc, argv); if (opt.showversion) { std::cout << Arc::IString("%s version %s", "arccat", VERSION) << std::endl; return 0; } // If debug is specified as argument, it should be set before loading the configuration. if (!opt.debug.empty()) Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(opt.debug)); if (opt.show_plugins) { std::list<std::string> types; types.push_back("HED:JobControllerPlugin"); showplugins("arccat", types, logger); return 0; } Arc::UserConfig usercfg(opt.conffile, opt.joblist); if (!usercfg) { logger.msg(Arc::ERROR, "Failed configuration initialization"); return 1; } if (!checkproxy(usercfg)) { return 1; } if (opt.debug.empty() && !usercfg.Verbosity().empty()) Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(usercfg.Verbosity())); for (std::list<std::string>::const_iterator it = opt.jobidinfiles.begin(); it != opt.jobidinfiles.end(); it++) { if (!Arc::Job::ReadJobIDsFromFile(*it, jobidentifiers)) { logger.msg(Arc::WARNING, "Cannot read specified jobid file: %s", *it); } } if (opt.timeout > 0) usercfg.Timeout(opt.timeout); if ((!opt.joblist.empty() || !opt.status.empty()) && jobidentifiers.empty() && opt.clusters.empty()) opt.all = true; if (jobidentifiers.empty() && opt.clusters.empty() && !opt.all) { logger.msg(Arc::ERROR, "No jobs given"); return 1; } std::list<std::string> selectedURLs; if (!opt.clusters.empty()) { selectedURLs = getSelectedURLsFromUserConfigAndCommandLine(usercfg, opt.clusters); } std::list<std::string> rejectManagementURLs = getRejectManagementURLsFromUserConfigAndCommandLine(usercfg, opt.rejectmanagement); std::list<Arc::Job> jobs; Arc::JobInformationStorageXML jobList(usercfg.JobListFile()); if (( opt.all && !jobList.ReadAll(jobs, rejectManagementURLs)) || (!opt.all && !jobList.Read(jobs, jobidentifiers, selectedURLs, rejectManagementURLs))) { logger.msg(Arc::ERROR, "Unable to read job information from file (%s)", usercfg.JobListFile()); return 1; } if (!opt.all) { for (std::list<std::string>::const_iterator itJIDAndName = jobidentifiers.begin(); itJIDAndName != jobidentifiers.end(); ++itJIDAndName) { std::cout << Arc::IString("Warning: Job not found in job list: %s", *itJIDAndName) << std::endl; } } Arc::JobSupervisor jobmaster(usercfg, jobs); jobmaster.Update(); jobmaster.SelectValid(); if (!opt.status.empty()) { jobmaster.SelectByStatus(opt.status); } jobs = jobmaster.GetSelectedJobs(); if (jobs.empty()) { std::cout << Arc::IString("No jobs") << std::endl; return 1; } std::string resourceName; Arc::Job::ResourceType resource; if (opt.show_joblog) { resource = Arc::Job::JOBLOG; resourceName = "joblog"; } else if (opt.show_stderr) { resource = Arc::Job::STDERR; resourceName = "stderr"; } else { resource = Arc::Job::STDOUT; resourceName = "stdout"; } // saving to a temp file is necessary because chunks from server // may arrive out of order std::string filename = Glib::build_filename(Glib::get_tmp_dir(), "arccat.XXXXXX"); int tmp_h = Glib::mkstemp(filename); if (tmp_h == -1) { logger.msg(Arc::INFO, "Could not create temporary file \"%s\"", filename); logger.msg(Arc::ERROR, "Cannot create output of %s for any jobs", resourceName); return 1; } Arc::URL dst("stdio:///"+Arc::tostring(tmp_h)); if (!dst) { logger.msg(Arc::ERROR, "Cannot create output of %s for any jobs", resourceName); logger.msg(Arc::INFO, "Invalid destination URL %s", dst.str()); close(tmp_h); unlink(filename.c_str()); return 1; } int retval = 0; for (std::list<Arc::Job>::const_iterator it = jobs.begin(); it != jobs.end(); it++) { if (!it->State || (!opt.status.empty() && std::find(opt.status.begin(), opt.status.end(), it->State()) == opt.status.end() && std::find(opt.status.begin(), opt.status.end(), it->State.GetGeneralState()) == opt.status.end())) { continue; } if (it->State == Arc::JobState::DELETED) { logger.msg(Arc::WARNING, "Job deleted: %s", it->JobID); retval = 1; continue; } // The job-log might be available before the job has started (middleware dependent). if (!opt.show_joblog && !it->State.IsFinished() && it->State != Arc::JobState::RUNNING && it->State != Arc::JobState::FINISHING) { logger.msg(Arc::WARNING, "Job has not started yet: %s", it->JobID); retval = 1; continue; } if ((opt.show_joblog && it->LogDir.empty()) || (!opt.show_joblog && opt.show_stderr && it->StdErr.empty()) || (!opt.show_joblog && !opt.show_stderr && it->StdOut.empty())) { logger.msg(Arc::ERROR, "Cannot determine the %s location: %s", resourceName, it->JobID); retval = 1; continue; } Arc::URL src; it->GetURLToResource(resource, src); if (!src) { logger.msg(Arc::ERROR, "Cannot create output of %s for job (%s): Invalid source %s", resourceName, it->JobID, src.str()); retval = 1; continue; } if (!it->CopyJobFile(usercfg, src, dst)) { retval = 1; continue; } logger.msg(Arc::VERBOSE, "Catting %s for job %s", resourceName, it->JobID); std::ifstream is(filename.c_str()); char c; while (is.get(c)) { std::cout.put(c); } is.close(); } close(tmp_h); unlink(filename.c_str()); return retval; }
// Send requests and collect statistics. void sendRequests(){ // Some variables... unsigned long completedRequests = 0; unsigned long failedRequests = 0; Glib::TimeVal completedTime(0,0); Glib::TimeVal failedTime(0,0); Glib::TimeVal tBefore; Glib::TimeVal tAfter; bool connected; //std::string url_str("https://127.0.0.1:60000/echo"); Arc::URL url(url_str); Arc::MCCConfig mcc_cfg; Arc::UserConfig usercfg(""); usercfg.ApplyToConfig(mcc_cfg); Arc::NS echo_ns; echo_ns["echo"]="http://www.nordugrid.org/schemas/echo"; while(run){ // Create a Client. Arc::ClientSOAP *client = NULL; client = new Arc::ClientSOAP(mcc_cfg,url,60); connected=true; while(run and connected){ // Prepare the request. Arc::PayloadSOAP req(echo_ns); req.NewChild("echo:echo").NewChild("echo:say")="HELLO"; // Send the request and time it. tBefore.assign_current_time(); Arc::PayloadSOAP* resp = NULL; //std::string str; //req.GetXML(str); //std::cout<<"request: "<<str<<std::endl; Arc::MCC_Status status = client->process(&req,&resp); tAfter.assign_current_time(); if(!status) { // Request failed. failedRequests++; failedTime+=tAfter-tBefore; connected=false; } else { if(resp == NULL) { // Response was not SOAP or no response at all. failedRequests++; failedTime+=tAfter-tBefore; connected=false; } else { //std::string xml; //resp->GetXML(xml); if (std::string((*resp)["echoResponse"]["hear"]).size()==0){ // The response was not what it should be. failedRequests++; failedTime+=tAfter-tBefore; connected=false; } else{ // Everything worked just fine! completedRequests++; completedTime+=tAfter-tBefore; } } } if(resp) delete resp; if(alwaysReconnect) connected=false; } if(client) delete client; } // Update global variables. Glib::Mutex::Lock lock(*mutex); ::completedRequests+=completedRequests; ::failedRequests+=failedRequests; ::completedTime+=completedTime; ::failedTime+=failedTime; finishedThreads++; std::cout << "Number of finished threads: " << finishedThreads << std::endl; }
int RUNMAIN(arcinfo)(int argc, char **argv) { setlocale(LC_ALL, ""); Arc::Logger logger(Arc::Logger::getRootLogger(), "arcinfo"); Arc::LogStream logcerr(std::cerr); logcerr.setFormat(Arc::ShortFormat); Arc::Logger::getRootLogger().addDestination(logcerr); Arc::Logger::getRootLogger().setThreshold(Arc::WARNING); Arc::ArcLocation::Init(argv[0]); ClientOptions opt(ClientOptions::CO_INFO, istring("[resource ...]"), istring("The arcinfo command is used for " "obtaining the status of computing " "resources on the Grid.")); { std::list<std::string> clusterstmp = opt.Parse(argc, argv); opt.clusters.insert(opt.clusters.end(), clusterstmp.begin(), clusterstmp.end()); } if (opt.showversion) { std::cout << Arc::IString("%s version %s", "arcinfo", VERSION) << std::endl; return 0; } // If debug is specified as argument, it should be set before loading the configuration. if (!opt.debug.empty()) Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(opt.debug)); if (opt.show_plugins) { std::list<std::string> types; types.push_back("HED:ServiceEndpointRetrieverPlugin"); types.push_back("HED:TargetInformationRetrieverPlugin"); showplugins("arcinfo", types, logger); return 0; } Arc::UserConfig usercfg(opt.conffile); if (!usercfg) { logger.msg(Arc::ERROR, "Failed configuration initialization"); return 1; } if (opt.list_configured_services) { std::map<std::string, Arc::ConfigEndpoint> allServices = usercfg.GetAllConfiguredServices(); std::cout << "Configured registries:" << std::endl; for (std::map<std::string, Arc::ConfigEndpoint>::const_iterator it = allServices.begin(); it != allServices.end(); it++) { if (it->second.type == Arc::ConfigEndpoint::REGISTRY) { std::cout << " " << it->first << ": " << it->second.URLString; if (!it->second.InterfaceName.empty()) { std::cout << " (" << it->second.InterfaceName << ")"; } std::cout << std::endl; } } std::cout << "Configured computing elements:" << std::endl; for (std::map<std::string, Arc::ConfigEndpoint>::const_iterator it = allServices.begin(); it != allServices.end(); it++) { if (it->second.type == Arc::ConfigEndpoint::COMPUTINGINFO) { std::cout << " " << it->first << ": " << it->second.URLString; if (!it->second.InterfaceName.empty() || !it->second.RequestedSubmissionInterfaceName.empty()) { std::cout << " (" << it->second.InterfaceName; if (!it->second.InterfaceName.empty() && !it->second.RequestedSubmissionInterfaceName.empty()) { std::cout << " / "; } std::cout << it->second.RequestedSubmissionInterfaceName + ")"; } std::cout << std::endl; } } return 0; } if (opt.debug.empty() && !usercfg.Verbosity().empty()) Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(usercfg.Verbosity())); if (opt.timeout > 0) usercfg.Timeout(opt.timeout); std::list<Arc::Endpoint> endpoints = getServicesFromUserConfigAndCommandLine(usercfg, opt.indexurls, opt.clusters, opt.requestedSubmissionInterfaceName, opt.infointerface); std::set<std::string> preferredInterfaceNames; if (usercfg.InfoInterface().empty()) { preferredInterfaceNames.insert("org.nordugrid.ldapglue2"); } else { preferredInterfaceNames.insert(usercfg.InfoInterface()); } std::list<std::string> rejectDiscoveryURLs = getRejectDiscoveryURLsFromUserConfigAndCommandLine(usercfg, opt.rejectdiscovery); Arc::ComputingServiceUniq csu; Arc::ComputingServiceRetriever csr(usercfg, std::list<Arc::Endpoint>(), rejectDiscoveryURLs, preferredInterfaceNames); csr.addConsumer(csu); for (std::list<Arc::Endpoint>::const_iterator it = endpoints.begin(); it != endpoints.end(); ++it) { csr.addEndpoint(*it); } csr.wait(); std::list<Arc::ComputingServiceType> services = csu.getServices(); for (std::list<Arc::ComputingServiceType>::const_iterator it = services.begin(); it != services.end(); ++it) { if (opt.longlist) { if (it != services.begin()) std::cout << std::endl; std::cout << *it; std::cout << std::flush; } else { std::cout << "Computing service: " << (**it).Name; if (!(**it).QualityLevel.empty()) { std::cout << " (" << (**it).QualityLevel << ")"; } std::cout << std::endl; std::stringstream infostream, submissionstream; for (std::map<int, Arc::ComputingEndpointType>::const_iterator itCE = it->ComputingEndpoint.begin(); itCE != it->ComputingEndpoint.end(); ++itCE) { if (itCE->second->Capability.count(Arc::Endpoint::GetStringForCapability(Arc::Endpoint::COMPUTINGINFO))) { infostream << " " << Arc::IString("Information endpoint") << ": " << itCE->second->URLString << std::endl; } if (itCE->second->Capability.empty() || itCE->second->Capability.count(Arc::Endpoint::GetStringForCapability(Arc::Endpoint::JOBSUBMIT)) || itCE->second->Capability.count(Arc::Endpoint::GetStringForCapability(Arc::Endpoint::JOBCREATION))) { submissionstream << " "; submissionstream << Arc::IString("Submission endpoint") << ": "; submissionstream << itCE->second->URLString; submissionstream << " (" << Arc::IString("status") << ": "; submissionstream << itCE->second->HealthState << ", "; submissionstream << Arc::IString("interface") << ": "; submissionstream << itCE->second->InterfaceName << ")" << std::endl; } } std::cout << infostream.str() << submissionstream.str(); } } bool anEndpointFailed = false; // Check if querying endpoint succeeded. Arc::EndpointStatusMap statusMap = csr.getAllStatuses(); for (std::list<Arc::Endpoint>::const_iterator it = endpoints.begin(); it != endpoints.end(); ++it) { Arc::EndpointStatusMap::const_iterator itStatus = statusMap.find(*it); if (itStatus != statusMap.end() && itStatus->second != Arc::EndpointQueryingStatus::SUCCESSFUL && itStatus->second != Arc::EndpointQueryingStatus::SUSPENDED_NOTREQUIRED) { if (!anEndpointFailed) { anEndpointFailed = true; std::cerr << Arc::IString("ERROR: Failed to retrieve information from the following endpoints:") << std::endl; } std::cerr << " " << it->URLString; if (!itStatus->second.getDescription().empty()) { std::cerr << " (" << itStatus->second.getDescription() << ")"; } std::cerr << std::endl; } } if (anEndpointFailed) return 1; if (services.empty()) { std::cerr << Arc::IString("ERROR: Failed to retrieve information"); if (!endpoints.empty()) { std::cerr << " " << Arc::IString("from the following endpoints:") << std::endl; for (std::list<Arc::Endpoint>::const_iterator it = endpoints.begin(); it != endpoints.end(); ++it) { std::cerr << " " << it->URLString << std::endl; } } else { std::cerr << std::endl; } return 1; } return 0; }
int main(int argc, char **argv) { setlocale(LC_ALL, ""); Arc::LogStream logcerr(std::cerr); logcerr.setFormat(Arc::ShortFormat); Arc::Logger::getRootLogger().addDestination(logcerr); Arc::Logger::getRootLogger().setThreshold(Arc::WARNING); Arc::ArcLocation::Init(argv[0]); Arc::OptionParser options(istring("url"), istring("The arcls command is used for listing " "files in grid storage elements " "and file\nindex catalogues.")); bool longlist = false; options.AddOption('l', "long", istring("long format (more information)"), longlist); bool locations = false; options.AddOption('L', "locations", istring("show URLs of file locations"), locations); bool metadata = false; options.AddOption('m', "metadata", istring("display all available metadata"), metadata); bool infinite_recursion = false; options.AddOption('r', "recursive", istring("operate recursively"), infinite_recursion); int recursion = 0; options.AddOption('D', "depth", istring("operate recursively up to specified level"), istring("level"), recursion); bool nolist = false; options.AddOption('n', "nolist", istring("show only description of requested object, do not list content of directories"), nolist); bool forcelist = false; options.AddOption('f', "forcelist", istring("treat requested object as directory and always try to list content"), forcelist); bool checkaccess = false; options.AddOption('c', "checkaccess", istring("check readability of object, does not show any information about object"), checkaccess); bool show_plugins = false; options.AddOption('P', "listplugins", istring("list the available plugins (protocols supported)"), show_plugins); int timeout = 20; options.AddOption('t', "timeout", istring("timeout in seconds (default 20)"), istring("seconds"), timeout); std::string conffile; options.AddOption('z', "conffile", istring("configuration file (default ~/.arc/client.conf)"), istring("filename"), conffile); std::string debug; options.AddOption('d', "debug", istring("FATAL, ERROR, WARNING, INFO, VERBOSE or DEBUG"), istring("debuglevel"), debug); bool version = false; options.AddOption('v', "version", istring("print version information"), version); std::list<std::string> params = options.Parse(argc, argv); if (version) { std::cout << Arc::IString("%s version %s", "arcls", VERSION) << std::endl; return 0; } // If debug is specified as argument, it should be set before loading the configuration. if (!debug.empty()) Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(debug)); if (show_plugins) { std::list<Arc::ModuleDesc> modules; Arc::PluginsFactory pf(Arc::BaseConfig().MakeConfig(Arc::Config()).Parent()); pf.scan(Arc::FinderLoader::GetLibrariesList(), modules); Arc::PluginsFactory::FilterByKind("HED:DMC", modules); std::cout << Arc::IString("Protocol plugins available:") << std::endl; for (std::list<Arc::ModuleDesc>::iterator itMod = modules.begin(); itMod != modules.end(); itMod++) { for (std::list<Arc::PluginDesc>::iterator itPlug = itMod->plugins.begin(); itPlug != itMod->plugins.end(); itPlug++) { std::cout << " " << itPlug->name << " - " << itPlug->description << std::endl; } } return 0; } // credentials will be initialised later if necessary Arc::UserConfig usercfg(conffile, Arc::initializeCredentialsType::TryCredentials); if (!usercfg) { logger.msg(Arc::ERROR, "Failed configuration initialization"); return 1; } usercfg.UtilsDirPath(Arc::UserConfig::ARCUSERDIRECTORY); if (debug.empty() && !usercfg.Verbosity().empty()) Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(usercfg.Verbosity())); // Analyze options if (params.size() != 1) { logger.msg(Arc::ERROR, "Wrong number of parameters specified"); return 1; } if(forcelist && nolist) { logger.msg(Arc::ERROR, "Incompatible options --nolist and --forcelist requested"); return 1; } if(recursion && nolist) { logger.msg(Arc::ERROR, "Requesting recursion and --nolist has no sense"); return 1; } if(infinite_recursion) recursion = INT_MAX; std::list<std::string>::iterator it = params.begin(); if(!arcls(*it, usercfg, longlist, locations, metadata, nolist, forcelist, checkaccess, recursion, timeout)) return 1; return 0; }