Example #1
0
/**
 * \brief The listQueues function gets queues information
 * \param sessionKey : The session key
 * \param machineId : The id of the machine
 * \param listofQueues : The list of queues
 * \param queueName The option value, if it is given, listQueues gives information only of this queue
 * \return int : an error code
 */
int
vishnu::listQueues(const std::string& sessionKey,
                   const std::string& machineId,
                   TMS_Data::ListQueues& listofQueues,
                   const std::string& queueName)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {
  checkEmptyString(sessionKey, "The session key");
  checkEmptyString(machineId, "The machine id");

  std::string serviceName = (boost::format("%1%@%2%") % SERVICES_TMS[GETLISTOFQUEUES] % machineId).str();

  SessionProxy sessionProxy(sessionKey);
  QueryProxy<std::string, TMS_Data::ListQueues>
      query(queueName, sessionProxy, serviceName, machineId);

  TMS_Data::ListQueues* listQueues_ptr = NULL ;
  try {
    listQueues_ptr = query.list();
  } catch(...) {
    throw ;
  }

  if(listQueues_ptr != NULL) {
    TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
    for(unsigned int i = 0; i < listQueues_ptr->getQueues().size(); i++) {
      TMS_Data::Queue_ptr queue = ecoreFactory->createQueue();
      //To copy the content and not the pointer
      *queue = *listQueues_ptr->getQueues().get(i);
      listofQueues.getQueues().push_back(queue);
    }
    listofQueues.setNbQueues(listofQueues.getNbQueues()+listQueues_ptr->getQueues().size());
    delete listQueues_ptr;
  }
  return 0;
}
Example #2
0
/**
 * \brief The listQueues function gets queues information
 * \param sessionKey : The session key
 * \param machineId : The id of the machine
 * \param listofQueues : The list of queues
 * \param queueName The option value, if it is given, listQueues gives information only of this queue
 * \return int : an error code
 */
int
vishnu::listQueues(const std::string& sessionKey,
		const std::string& machineId,
		ListQueues& listofQueues,
		const std::string& queueName)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

	checkEmptyString(sessionKey, "The session key");
	checkEmptyString(machineId, "The machine id");

	std::string serviceName = "getListOfQueues_";
	serviceName.append(machineId);

	SessionProxy sessionProxy(sessionKey);

	QueryProxy<std::string, TMS_Data::ListQueues>
	query(queueName, sessionProxy, serviceName, machineId);

	TMS_Data::ListQueues* listQueues_ptr = query.list();

	if(listQueues_ptr != NULL) {
		TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
		for(unsigned int i = 0; i < listQueues_ptr->getQueues().size(); i++) {
			TMS_Data::Queue_ptr queue = ecoreFactory->createQueue();
			//To copy the content and not the pointer
			*queue = *listQueues_ptr->getQueues().get(i);
			listofQueues.getQueues().push_back(queue);
		}
		listofQueues.setNbQueues(listQueues_ptr->getQueues().size());
		delete listQueues_ptr;
	}
	return 0;

}
Example #3
0
/**
 * \brief Function to request the status of queues
 * \param optQueueName (optional) the name of the queue to request
 * \return The requested status in to ListQueues data structure
 */
TMS_Data::ListQueues*
SGEServer::listQueues(const std::string& optqueueName) {

  TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
  mlistQueues = ecoreFactory->createListQueues();
  std::string exe = boost::process::find_executable_in_path("qconf");
  std::vector<std::string> args;
  std::vector<std::string> argss;
  std::vector<std::string> queueNames;
  boost::process::context ctx;
  ctx.streams[boost::process::stdout_id] = boost::process::behavior::pipe();
  args.push_back("-sq");
  char diagnosis[DRMAA_ERROR_STRING_BUFFER];
  int drmaa_errno;
  drmaa_errno = drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1);
  if ((drmaa_errno!= DRMAA_ERRNO_SUCCESS)&&
      (drmaa_errno!= DRMAA_ERRNO_ALREADY_ACTIVE_SESSION)){
    throw TMSVishnuException(ERRCODE_BATCH_SCHEDULER_ERROR,
                             "SGE ERROR: "+std::string(diagnosis));
  }
  if(optqueueName.size()!=0) {
    queueNames.push_back(optqueueName.c_str());
  } else {
    argss.push_back("-sql");
    boost::process::child c = boost::process::create_child(exe, argss, ctx);
    boost::process::pistream is(c.get_handle(boost::process::stdout_id));
    std::string line;

    while (std::getline(is, line)){
      queueNames.push_back(line.c_str());
    }

  }
  vector<std::string>::iterator it;


  for ( it=queueNames.begin() ; it < queueNames.end(); ++it ){

    args.push_back((*it).c_str());
    boost::process::child c1 = boost::process::create_child(exe, args, ctx);
    boost::process::pistream iss(c1.get_handle(boost::process::stdout_id));
    std::string line;
    if (iss){
      TMS_Data::Queue_ptr queue = ecoreFactory->createQueue();
      while (std::getline(iss, line)){
        if(boost::algorithm::starts_with(line, "qname")){
          line = line.substr(5);
          boost::algorithm::trim_left(line);
          queue->setName(line);
        }
        if(boost::algorithm::starts_with(line, "priority")){
          line = line.substr(8);
          boost::algorithm::trim_left(line);
          int priority = boost::lexical_cast<int>(line);
          queue->setPriority(priority);
        }
        if(boost::algorithm::starts_with(line, "slots")){
          line = line.substr(5);
          boost::algorithm::trim_left(line);
          size_t pos = line.find(",");
          int MaxJob =0;
          while(pos!=std::string::npos){
            std::string jobnb = line.substr(0,pos);
            size_t position;
            position = jobnb.find("=");
            if(position!=std::string::npos ){
              jobnb = jobnb.substr(position +1);
            }
            MaxJob += boost::lexical_cast<int>(jobnb);
            line = line.substr(pos+1);
            pos = line.find(",");
          }

          queue->setMaxJobCpu(MaxJob);
        }
        if(boost::algorithm::starts_with(line, "hostlist")){
          line = line.substr(8);
          boost::algorithm::trim_left(line);
          int nodes =0 ;
          if (line != "NONE"){
            nodes = (int) std::count(line.begin(),line.end(),',') +1;
          }
          queue->setNode(nodes);
        }
        if(boost::algorithm::starts_with(line, "h_rt")){
          line = line.substr(4);
          boost::algorithm::trim_left(line);
          if (line != "INFINITY"){
            queue->setWallTime(vishnu::convertStringToWallTime(line));
          }
        }



      }
      /*get Queue Status*/

      std::vector<std::string> argument;
      argument.push_back("-f");
      argument.push_back("-q");
      argument.push_back((*it).c_str());
      argument.push_back("-u");
      argument.push_back("*");
      std::string exec = boost::process::find_executable_in_path("qstat");
      boost::process::child c3 = boost::process::create_child(exec, argument,
                                                              ctx);
      boost::process::pistream isstream(c3.get_handle(boost::process::stdout_id));
      argument.pop_back();
      std::string cline;
      if (isstream){

        while (std::getline(isstream, cline)){
          int state =0;
          if (boost::algorithm::starts_with(cline,(*it).c_str() )){

            std::vector< std::string >  SplitVec;
            boost::algorithm::split( SplitVec, cline,
                                     boost::algorithm::is_any_of(" "),
                                     boost::algorithm::token_compress_on );
            std::vector<std::string>::iterator itt;

            itt = SplitVec.end()-1;

            if (boost::algorithm::contains(*itt, "u")){
              queue->setState(0);
              state =0;
            } else if  (boost::algorithm::contains(*itt, "a")) {
              queue->setState(2);
              state =1;
            } else if  (boost::algorithm::contains(*itt, "A") ||
                        boost::algorithm::contains(*itt, "C") ||
                        boost::algorithm::contains(*itt, "D") ||
                        boost::algorithm::contains(*itt, "s")){
              queue->setState(1);
              state =0;
            } else if  (boost::algorithm::contains(*itt, "S") ||
                        boost::algorithm::contains(*itt, "d") ||
                        boost::algorithm::contains(*itt, "E") ||
                        boost::algorithm::contains(*itt, "o")){
              state =0;
            } else if (boost::algorithm::contains(*itt, "")){
              queue->setState(2);
              state =1;
            }
          }
          if(state){
            break;
          }

        }
      }


      std::vector<std::string> arg;
      arg.push_back("-q");
      arg.push_back((*it).c_str());
      std::string ex = boost::process::find_executable_in_path("qstat");
      boost::process::child c2 = boost::process::create_child(ex, arg, ctx);
      boost::process::pistream isss(c2.get_handle(boost::process::stdout_id));
      arg.pop_back();
      std::string lines;
      int nbrunningjobs = 0;
      int nbjobsinqueue = 0;
      if (isss){
        while (std::getline(isss, lines)){
          if (boost::algorithm::contains(lines, " r ") ||
              boost::algorithm::contains(lines, " t ") ||
              boost::algorithm::contains(lines, " R ")){
            nbrunningjobs++;
          }
          if (boost::algorithm::contains(lines, " qw ") ||
              boost::algorithm::contains(lines, " s ") ||
              boost::algorithm::contains(lines, " w ")){
            nbjobsinqueue++;
          }
        }
      }
      queue->setNbRunningJobs(nbrunningjobs);
      queue->setNbJobsInQueue(nbjobsinqueue);

      queue->setMemory(-1);//UNDEFINED in SGE
      queue->setDescription("");//UNDEFINED in SGE
      queue->setMaxProcCpu(-1);//UNDEFINED in SGE

      mlistQueues->getQueues().push_back(queue);
    }
    args.pop_back();

  }
  mlistQueues->setNbQueues(mlistQueues->getQueues().size());


  drmaa_exit(NULL, 0);
  return mlistQueues;
}