Пример #1
0
int main(void) {

  Arc::Logger logger(Arc::Logger::rootLogger, "Test");
  Arc::LogStream logcerr(std::cerr);
  Arc::Logger::rootLogger.addDestination(logcerr);
  logger.msg(Arc::INFO, "Creating client side chain");

  std::string id;
  std::string url("https://localhost/arex");
  Arc::NS ns("a-rex", "http://www.nordugrid.org/schemas/a-rex");
  Arc::MCCConfig cfg;
  Arc::UserConfig uc;
  uc.ApplyToConfig(cfg);

  Arc::ClientSOAP client(cfg, url, 60);
  std::string faultstring;

  Arc::PayloadSOAP request(ns);
  Arc::XMLNode req = request.NewChild("a-rex:CacheCheck").NewChild("a-rex:TheseFilesNeedToCheck");
  req.NewChild("a-rex:FileURL") = "http://example.org/test.txt";

  Arc::PayloadSOAP* response;

  Arc::MCC_Status status = client.process(&request, &response);

  if (!status) {
    std::cerr << "Request failed" << std::endl;
  }

  std::string str;
  response->GetDoc(str, true);
  std::cout << str << std::endl;

  return 0;
}
Пример #2
0
int main(int argc, char** argv) {
  signal(SIGTTOU,SIG_IGN);
  signal(SIGTTIN,SIG_IGN);
  signal(SIGINT, do_shutdown);

  // Log to stderr
  Arc::LogStream logcerr(std::cerr);
  Arc::Logger::getRootLogger().addDestination(logcerr);
  Arc::Logger::getRootLogger().setThreshold(Arc::INFO);

  Generator generator;
  int num = 10;
  if (argc == 1 || argc == 2) { // run mock a number of times
    if (argc == 2 && (std::string(argv[1]) == "-h" || !Arc::stringto(argv[1], num))) {
      usage();
      return 1;
    }
    generator.start();
    for (int i = 0; i < num; ++i) {
      std::string source = "mock://mocksrc/mock." + Arc::tostring(i);
      std::string destination = "mock://mockdest/mock." + Arc::tostring(i);
      generator.run(source, destination);
    }
  }
  else if (argc == 3) { // run with given source and destination
    generator.start();
    generator.run(argv[1], argv[2]);
  }
  else {
    usage();
    return 1;
  }

  while (generator.counter.get() > 0 && run) {
    sleep(1);
  }
  return 0;
}
Пример #3
0
int main(void) {
  signal(SIGTTOU,SIG_IGN);
  signal(SIGTTIN,SIG_IGN);
  Arc::Logger logger(Arc::Logger::rootLogger, "Test");
  Arc::LogStream logcerr(std::cerr);
  Arc::Logger::rootLogger.addDestination(logcerr);


  /******** Test to gridsite delegation service **********/
  std::string gs_deleg_url_str("https://cream.grid.upjs.sk:8443/ce-cream/services/gridsite-delegation");
  Arc::URL gs_deleg_url(gs_deleg_url_str);
  Arc::MCCConfig gs_deleg_mcc_cfg;
 
  //Use voms-proxy-init or arcproxy to generate a gsi legacy proxy, and 
  //put put it into mcc configuraton by using "AddProxy"
  gs_deleg_mcc_cfg.AddProxy("proxy.pem");

  //gs_deleg_mcc_cfg.AddPrivateKey("../echo/userkey-nopass.pem");
  //gs_deleg_mcc_cfg.AddCertificate("../echo/usercert.pem");
  gs_deleg_mcc_cfg.AddCADir("../echo/certificates");
  //Create a delegation SOAP client
  logger.msg(Arc::INFO, "Creating a delegation soap client");
  Arc::ClientX509Delegation *gs_deleg_client = NULL;
  gs_deleg_client = new Arc::ClientX509Delegation(gs_deleg_mcc_cfg, gs_deleg_url);
  std::string gs_delegation_id;
  gs_delegation_id = Arc::UUID();
  if(gs_deleg_client) {
    if(!(gs_deleg_client->createDelegation(Arc::DELEG_GRIDSITE, gs_delegation_id))) {
      logger.msg(Arc::ERROR, "Delegation to gridsite delegation service failed");
      throw std::runtime_error("Delegation to gridsite delegation service failed");
    }
  }
  logger.msg(Arc::INFO, "Delegation ID: %s", gs_delegation_id.c_str());
  if(gs_deleg_client) delete gs_deleg_client;

  return 0;
}
Пример #4
0
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;
}
Пример #5
0
int main(void){
  signal(SIGTTOU,SIG_IGN);
  signal(SIGTTIN,SIG_IGN);
  signal(SIGPIPE,SIG_IGN);
  Arc::Logger logger(Arc::Logger::rootLogger, "PDPTest");
  Arc::LogStream logcerr(std::cerr);
  Arc::Logger::rootLogger.addDestination(logcerr);
  logger.msg(Arc::INFO, "Start test");

  ArcSec::EvaluatorLoader eval_loader;

  //TEST: XACMLEvaluator, XACMLPolicy, XACMLRequest

  //Load the Evaluator
  ArcSec::Evaluator* eval = NULL;
  std::string evaluator = "xacml.evaluator";
  eval = eval_loader.getEvaluator(evaluator);  
  if(eval == NULL) {
    logger.msg(Arc::ERROR, "Can not dynamically produce Evaluator");
    return 0;  
  }

  ArcSec::Policy* policy = NULL;
  std::string policyclassname = "xacml.policy";
  ArcSec::SourceFile policy_source("XACML_Policy.xml");
  policy = eval_loader.getPolicy(policyclassname, policy_source);
  if(policy == NULL)
    logger.msg(Arc::ERROR, "Can not dynamically produce Policy");

  ArcSec::Request* request = NULL;
  std::string requestclassname = "xacml.request";
  ArcSec::SourceFile request_source("XACML_Request.xml");
  request = eval_loader.getRequest(requestclassname, request_source);

  if(request == NULL)
    logger.msg(Arc::ERROR, "Can not dynamically produce Request");

  /**Two options to add policy into evaluator*/ 
  //eval->addPolicy(policy_source);
  eval->addPolicy(policy);
 
   ArcSec::Response *resp = NULL;
 
  /**Feed evaluator with request to execute evaluation*/
  resp = eval->evaluate(request_source);
  //resp = eval->evaluate(request_source, policy);
  //resp = eval->evaluate(request, policy_source);
  //resp = eval->evaluate(request_source, policy_source);  
  //resp = eval->evaluate(request, policy);

  /**Get the response*/
  ArcSec::ResponseList rlist = resp->getResponseItems();
  std::cout<<rlist[0]->res<<std::endl;

  if(resp){
    delete resp;
    resp = NULL;
  } 
  delete eval;
  delete request;

  return 0;
}
Пример #6
0
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;
}
Пример #7
0
int main(int argc, char* argv[]){
  // Some variables...
  int numberOfThreads;
  int duration;
  int i;
  Glib::Thread** threads;
  const char* config_file = NULL;
  int debug_level = -1;
  Arc::LogStream logcerr(std::cerr);

  // Process options - quick hack, must use Glib options later
  while(argc >= 3) {
    if(strcmp(argv[1],"-c") == 0) {
      config_file = argv[2];
      argv[2]=argv[0]; argv+=2; argc-=2;
    } else if(strcmp(argv[1],"-d") == 0) {
      debug_level=Arc::string_to_level(argv[2]);
      argv[2]=argv[0]; argv+=2; argc-=2;
    } else if(strcmp(argv[1],"-r") == 0) {
      alwaysReconnect=true; argv+=1; argc-=1;
    } else {
      break;
    };
  } 
  if(debug_level >= 0) {
    Arc::Logger::getRootLogger().setThreshold((Arc::LogLevel)debug_level);
    Arc::Logger::getRootLogger().addDestination(logcerr);
  }
  // Extract command line arguments.
  if (argc!=4){
    std::cerr << "Wrong number of arguments!" << std::endl
	      << std::endl
	      << "Usage:" << std::endl
	      << "perftest [-c config] [-d debug] [-r] url threads duration" << std::endl
	      << std::endl
	      << "Arguments:" << std::endl
	      << "url       The url of the service." << std::endl
	      << "threads   The number of concurrent requests." << std::endl
	      << "duration  The duration of the test in seconds." << std::endl
	      << "-c config The file containing client chain XML configuration with " << std::endl
              << "          'soap' entry point and HOSTNAME, PORTNUMBER and PATH " << std::endl
              << "           keyword for hostname, port and HTTP path of 'echo' service." << std::endl
	      << "-d debug   The textual representation of desired debug level. Available " << std::endl
              << "           levels: DEBUG, VERBOSE, INFO, WARNING, ERROR, FATAL." << std::endl
	      << "-r         If specified close connection and reconnect after " << std::endl
              << "           every request." << std::endl;
    exit(EXIT_FAILURE);
  }
  url_str = std::string(argv[1]);
  numberOfThreads = atoi(argv[2]);
  duration = atoi(argv[3]);

  // Start threads.
  run=true;
  finishedThreads=0;
  //Glib::thread_init();
  mutex=new Glib::Mutex;
  threads = new Glib::Thread*[numberOfThreads];
  for (i=0; i<numberOfThreads; i++)
    threads[i]=Glib::Thread::create(sigc::ptr_fun(sendRequests),true);

  // Sleep while the threads are working.
  Glib::usleep(duration*1000000);

  // Stop the threads
  run=false;
  while(finishedThreads<numberOfThreads)
    Glib::usleep(100000);

  // Print the result of the test.
  Glib::Mutex::Lock lock(*mutex);
  totalRequests = completedRequests+failedRequests;
  totalTime = completedTime+failedTime;
  std::cout << "========================================" << std::endl;
  std::cout << "URL: "
	    << url_str << std::endl;
  std::cout << "Number of threads: "
	    << numberOfThreads << std::endl;
  std::cout << "Duration: "
	    << duration << " s" << std::endl;
  std::cout << "Number of requests: "
	    << totalRequests << std::endl;
  std::cout << "Completed requests: "
	    << completedRequests << " ("
	    << Round(completedRequests*100.0/totalRequests)
	    << "%)" << std::endl;
  std::cout << "Failed requests: "
	    << failedRequests << " ("
	    << Round(failedRequests*100.0/totalRequests)
	    << "%)" << std::endl;
  std::cout << "Completed requests per second: "
            << Round(completedRequests/duration)
            << std::endl;
  std::cout << "Average response time for all requests: "
	    << Round(1000*totalTime.as_double()/totalRequests)
	    << " ms" << std::endl;
  if (completedRequests!=0)
    std::cout << "Average response time for completed requests: "
	      << Round(1000*completedTime.as_double()/completedRequests)
	      << " ms" << std::endl;
  if (failedRequests!=0)
    std::cout << "Average response time for failed requests: "
	      << Round(1000*failedTime.as_double()/failedRequests)
	      << " ms" << std::endl;
  std::cout << "========================================" << std::endl;

  return 0;
}
Пример #8
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;
}
Пример #9
0
int main(void) {
  signal(SIGTTOU,SIG_IGN);
  signal(SIGTTIN,SIG_IGN);
  Arc::Logger logger(Arc::Logger::rootLogger, "Test");
  Arc::LogStream logcerr(std::cerr);
  Arc::Logger::rootLogger.addDestination(logcerr);
  logger.msg(Arc::INFO, "Creating client side chain");
  // Create client chain
  Arc::XMLNode client_doc("\
    <ArcConfig\
      xmlns=\"http://www.nordugrid.org/schemas/ArcConfig/2007\"\
      xmlns:tcp=\"http://www.nordugrid.org/schemas/ArcMCCTCP/2007\">\
     <ModuleManager>\
        <Path>.libs/</Path>\
        <Path>../../hed/mcc/http/.libs/</Path>\
        <Path>../../hed/mcc/soap/.libs/</Path>\
        <Path>../../hed/mcc/tls/.libs/</Path>\
        <Path>../../hed/mcc/tcp/.libs/</Path>\
        <Path>../../hed/shc/.libs/</Path>\
     </ModuleManager>\
     <Plugins><Name>mcctcp</Name></Plugins>\
     <Plugins><Name>mcctls</Name></Plugins>\
     <Plugins><Name>mcchttp</Name></Plugins>\
     <Plugins><Name>mccsoap</Name></Plugins>\
     <Plugins><Name>arcshc</Name></Plugins>\
     <Chain>\
      <Component name='tcp.client' id='tcp'><tcp:Connect><tcp:Host>127.0.0.1</tcp:Host><tcp:Port>50000</tcp:Port></tcp:Connect></Component>\
      <Component name='tls.client' id='tls'><next id='tcp'/>\
        <!--For proxy certificate, KeyPath and CertificatePath are supposed to be the same-->\
        <KeyPath>./testkey-nopass.pem</KeyPath>\
        <CertificatePath>./testcert.pem</CertificatePath>\
        <CACertificatePath>./testcacert.pem</CACertificatePath>\
      </Component>\
      <Component name='http.client' id='http'><next id='tcp'/>\
        <Method>POST</Method>\
        <Endpoint>/Echo</Endpoint>\
      </Component>\
      <Component name='soap.client' id='soap' entry='soap'>\
        <next id='http'/>\
      </Component>\
     </Chain>\
    </ArcConfig>");
  Arc::Config client_config(client_doc);
  if(!client_config) {
    logger.msg(Arc::ERROR, "Failed to load client configuration");
    return -1;
  };
  Arc::MCCLoader client_loader(client_config);
  logger.msg(Arc::INFO, "Client side MCCs are loaded");
  Arc::MCC* client_entry = client_loader["soap"];
  if(!client_entry) {
    logger.msg(Arc::ERROR, "Client chain does not have entry point");
    return -1;
  };

  // for (int i = 0; i < 10; i++) {
  // Create and send echo request
  logger.msg(Arc::INFO, "Creating and sending request");
  Arc::NS echo_ns; echo_ns["echo"]="http://www.nordugrid.org/schemas/echo";
  Arc::PayloadSOAP req(echo_ns);
  req.NewChild("echo").NewChild("say")="HELLO";
  Arc::Message reqmsg;
  Arc::Message repmsg;
  reqmsg.Payload(&req);
  // It is a responsibility of code initiating first Message to
  // provide Context and Attributes as well.
  Arc::MessageAttributes attributes_req;
  Arc::MessageAttributes attributes_rep;
  Arc::MessageContext context;
  reqmsg.Attributes(&attributes_req);
  reqmsg.Context(&context);
  repmsg.Attributes(&attributes_rep);
  repmsg.Context(&context);
  Arc::MCC_Status status = client_entry->process(reqmsg,repmsg);
  if(!status) {
    logger.msg(Arc::ERROR, "Request failed");
    std::cerr << "Status: " << std::string(status) << std::endl;
    return -1;
  };
  Arc::PayloadSOAP* resp = NULL;
  if(repmsg.Payload() == NULL) {
    logger.msg(Arc::ERROR, "There is no response");
    return -1;
  };
  try {
    resp = dynamic_cast<Arc::PayloadSOAP*>(repmsg.Payload());
  } catch(std::exception&) { };
  if(resp == NULL) {
    logger.msg(Arc::ERROR, "Response is not SOAP");
    return -1;
  };
  std::string xml;
  resp->GetXML(xml);
  std::cout << "XML: "<< xml << std::endl;
  std::cout << "Response: " << (std::string)((*resp)["echoResponse"]["hear"]) << std::endl;
  //}    
  return 0;
}
Пример #10
0
int main(int argc, char **argv) {

  Arc::LogStream logcerr(std::cerr);
  Arc::Logger::getRootLogger().addDestination(logcerr);
  Arc::Logger::getRootLogger().setThreshold(Arc::WARNING);

  Arc::OptionParser options("", "", "");

  int nJobs = -1;
  options.AddOption('N', "NJobs", "njobs", "number of jobs to write/read to/from storage", nJobs);
  
  int bunchSize = 100000;
  options.AddOption('B', "bunchSize", "", "size of bunches of job objects to pass to JobInformationStorage object methods", bunchSize);

  std::string action = "write";
  options.AddOption('a', "action", "write, append, appendreturnnew, read, readall, remove", "Action to perform", action);
  
  std::string filename = "";
  options.AddOption('f', "filename", "", "", filename);
  
  std::string typeS = "";
  options.AddOption('t', "type", "BDB or XML", "Type of storage back-end to use", typeS);
  
  std::string hostname = "test.nordugrid.org";
  options.AddOption(0, "hostname", "", "", hostname);

  std::list<std::string> endpoints;
  options.AddOption(0, "endpoint", "", "", endpoints);

  std::list<std::string> rejectEndpoints;
  options.AddOption(0, "rejectEndpoint", "reject", "Reject jobs with JobManagementURL matching specified endpoints (matching algorithm: URL::StringMatches)", rejectEndpoints);

  std::string jobidinfile;
  options.AddOption('i', "jobids-from-file", "a file containing a list of job IDs", "filename", jobidinfile);

  std::string jobidoutfile;
  options.AddOption('o', "jobids-to-file", "the IDs of jobs will be appended to this file", "filename", jobidoutfile);

  std::string debug;
  options.AddOption('d', "debug",
                    "FATAL, ERROR, WARNING, INFO, VERBOSE or DEBUG",
                    "debuglevel", debug);

  options.Parse(argc, argv);

  if (!debug.empty()) Arc::Logger::getRootLogger().setThreshold(Arc::string_to_level(debug));

  if (filename.empty()) {
    std::cerr << "ERROR: No filename specified." << std::endl;
    return 1;
  }

  Arc::JobInformationStorage** jisPointer = NULL;
  if      (typeS == "XML") {
    Arc::JobInformationStorageXML *jisXML = new Arc::JobInformationStorageXML(filename);
    jisPointer = (Arc::JobInformationStorage**)&jisXML;
  }
#ifdef DBJSTORE_ENABLED
  else if (typeS == "BDB") {
    Arc::JobInformationStorageBDB *jisDB4 = new Arc::JobInformationStorageBDB(filename);
    jisPointer = (Arc::JobInformationStorage**)&jisDB4;
  }
#endif
  else {
    std::cerr << "ERROR: Unable to determine storage back-end to use." << std::endl;
    return 1;
  }

  Arc::JobInformationStorage& jis = **jisPointer;
  
  Arc::Period timing;
  if      (action == "write" || action == "append") {
    if (nJobs <= 0) {
      std::cerr << "ERROR: Invalid number of jobs specified (nJobs = " << nJobs << ")" << std::endl;
      goto error;
    }
    if (bunchSize <= 0) {
      std::cerr << "ERROR: Invalid bunch size (bunchSize = " << bunchSize << ")" << std::endl;
      goto error;
    }
    
    if (action == "write") {
      remove(filename.c_str());
    }
    else {
      Arc::FileCopy(filename, "append-" + filename);
      filename = "append-" + filename;
    }
    
    Arc::Job j;
    j.ServiceInformationInterfaceName = "org.nordugrid.test";
    j.JobStatusInterfaceName = "org.nordugrid.test";
    j.JobManagementInterfaceName = "org.nordugrid.test";
    j.JobDescriptionDocument = "&( executable = \"/bin/echo\" )( arguments = \"Hello World\" )( stdout = \"std.out\" )( stderr = \"std.out\" )( cputime = \"PT1M\" )( outputfiles = ( \"std.out\" \"\" ) ( \"std.out\" \"\" ) )( queue = \"gridlong\" )( jobname = \"Hello World\" )( clientsoftware = \"libarccompute-trunk\" )( clientxrsl = \"&( executable = \"\"/bin/echo\"\" )( arguments = \"\"Hello World\"\" )( stdout = \"\"std.out\"\" )( join = \"\"yes\"\" )( cputime = \"\"1\"\" )( jobname = \"\"Hello World\"\" )\" )( hostname = \"x220-skou\" )( savestate = \"yes\" )";
  
    srand(Arc::Time().GetTimeNanoseconds());
  
    for (int m = 0; m <= nJobs/bunchSize; ++m) {
      std::list<Arc::Job> jobs;
      const int bunchEnd = (m != nJobs/bunchSize)*(m+1)*bunchSize + (m == nJobs/bunchSize)*(nJobs%bunchSize);
      for (int n = m*bunchSize; n < bunchEnd; ++n) {
        j.Name = "Job " + Arc::tostring(n);
        j.IDFromEndpoint = Arc::tostring(rand())+Arc::tostring(n)+Arc::tostring(rand());
        j.JobID = "http://" + hostname + "/" + j.IDFromEndpoint;
        j.ServiceInformationURL = Arc::URL("http://" + hostname + "/serviceinfo");
        j.JobStatusURL = Arc::URL("http://" + hostname + "/jobstatus");
        j.JobManagementURL = Arc::URL("http://" + hostname + "/jobmanagement");
        j.StageInDir = Arc::URL("http://" + hostname + "/stagein/" + j.IDFromEndpoint);
        j.StageOutDir = Arc::URL("http://" + hostname + "/stageout/" + j.IDFromEndpoint);
        j.SessionDir = Arc::URL("http://" + hostname + "/session/" + j.IDFromEndpoint);
        j.LocalSubmissionTime = Arc::Time();
        jobs.push_back(j);
      }
      
      if (!jobidoutfile.empty()) {
        Arc::Job::WriteJobIDsToFile(jobs, jobidoutfile);
      }
      
      Arc::Time tBefore;
      jis.Write(jobs);
      timing += Arc::Time()-tBefore;
    }
  }
  else if (action == "appendreturnnew") {
    if (nJobs <= 0) {
      std::cerr << "ERROR: Invalid number of jobs specified (nJobs = " << nJobs << ")" << std::endl;
      goto error;
    }
    if (bunchSize <= 0) {
      std::cerr << "ERROR: Invalid bunch size (bunchSize = " << bunchSize << ")" << std::endl;
      goto error;
    }
    Arc::FileCopy(filename, "append-" + filename);
    filename = "append-" + filename;
    
    Arc::Job j;
    j.ServiceInformationInterfaceName = "org.nordugrid.test";
    j.JobStatusInterfaceName = "org.nordugrid.test";
    j.JobManagementInterfaceName = "org.nordugrid.test";
    j.JobDescriptionDocument = "&( executable = \"/bin/echo\" )( arguments = \"Hello World\" )( stdout = \"std.out\" )( stderr = \"std.out\" )( cputime = \"PT1M\" )( outputfiles = ( \"std.out\" \"\" ) ( \"std.out\" \"\" ) )( queue = \"gridlong\" )( jobname = \"Hello World\" )( clientsoftware = \"libarccompute-trunk\" )( clientxrsl = \"&( executable = \"\"/bin/echo\"\" )( arguments = \"\"Hello World\"\" )( stdout = \"\"std.out\"\" )( join = \"\"yes\"\" )( cputime = \"\"1\"\" )( jobname = \"\"Hello World\"\" )\" )( hostname = \"x220-skou\" )( savestate = \"yes\" )";

    std::list<std::string> identifiers;
    Arc::Job::ReadJobIDsFromFile(jobidinfile, identifiers);
    for (int m = 0; m <= nJobs/bunchSize; ++m) {
      std::list<Arc::Job> jobs;
      std::set<std::string> prunedServices;
      const int bunchEnd = (m != nJobs/bunchSize)*(m+1)*bunchSize + (m == nJobs/bunchSize)*(nJobs%bunchSize);
      for (int n = m*bunchSize; n < bunchEnd; ++n) {
        std::string jobHostName = hostname;
        if (!identifiers.empty()) {
          Arc::URL temp(identifiers.front());
          identifiers.pop_front();
          jobHostName = temp.Host();
          j.IDFromEndpoint = temp.Path();
        }
        else {
          j.IDFromEndpoint = Arc::tostring(rand())+Arc::tostring(rand());
        }
        prunedServices.insert(jobHostName);
        j.Name = "Job " + Arc::tostring(n);
        j.JobID = "http://" +  jobHostName + "/" + j.IDFromEndpoint;
        j.ServiceInformationURL = Arc::URL("http://" + jobHostName + "/serviceinfo");
        j.JobStatusURL = Arc::URL("http://" + jobHostName + "/jobstatus");
        j.JobManagementURL = Arc::URL("http://" + jobHostName + "/jobmanagement");
        j.StageInDir = Arc::URL("http://" + jobHostName + "/stagein/" + j.IDFromEndpoint);
        j.StageOutDir = Arc::URL("http://" + jobHostName + "/stageout/" + j.IDFromEndpoint);
        j.SessionDir = Arc::URL("http://" + jobHostName + "/session/" + j.IDFromEndpoint);
        j.LocalSubmissionTime = Arc::Time();
        jobs.push_back(j);
      }
      
      std::list<const Arc::Job*> newJobs;
      Arc::Time tBefore;
      jis.Write(jobs, prunedServices, newJobs);
      timing += Arc::Time()-tBefore;
    }
  }
  else if (action == "readall") {
    std::list<Arc::Job> jobs;
    
    Arc::Time tBefore;
    jis.ReadAll(jobs, rejectEndpoints);
    timing += Arc::Time()-tBefore;
  }
  else if (action == "read") {
    std::list<Arc::Job> jobs;
    std::list<std::string> identifiers;
    Arc::Job::ReadJobIDsFromFile(jobidinfile, identifiers);
    Arc::Time tBefore;
    jis.Read(jobs, identifiers, endpoints, rejectEndpoints);
    timing += Arc::Time()-tBefore;
  }
  else if (action == "remove") {
    std::list<std::string> identifiers;
    Arc::Job::ReadJobIDsFromFile(jobidinfile, identifiers);
    Arc::Time tBefore;
    jis.Remove(identifiers);
    timing += Arc::Time()-tBefore;
  }
  else {
    std::cerr << "ERROR: Invalid action specified (action = \"" << action << "\")" << std::endl;
    delete *jisPointer;
    return 1;
  }
  delete *jisPointer;
  
  {
  int nanosecs = timing.GetPeriodNanoseconds();
  std::string zerosToPrefix = "";
  for (int i = 100000000; i > 1; i /= 10) {
    if (nanosecs / i == 0) zerosToPrefix += "0";
    else break;
  }
  std::cout << timing.GetPeriod() << "." << zerosToPrefix << nanosecs/1000 << std::endl;
  }
 return 0;
 
error:
  delete *jisPointer;
  return 1;
}