Exemplo n.º 1
0
int
LSFParser::convertWallTimeToTime(const std::string& date,
                                 const std::string& compErrMsg) {
    int wallTime;
    int minute = -1;

    std::string errMsg = "illegal time  option value "+date+":";
    std::vector<std::string> tokens = getTimeToKens(date);
    if (tokens.empty()) {
        errMsg += " Empty time value. At least one fields must be specified.";
        throw UMSVishnuException(ERRCODE_INVALID_PARAM, errMsg+" "+compErrMsg);
    }
    for(std::vector<std::string>::iterator iter = tokens.begin(); iter!=tokens.end(); ++iter) {
        if (!isNumerical(*iter)) {
            errMsg += " The fields values must be intergers.";
            throw UMSVishnuException(ERRCODE_INVALID_PARAM, errMsg+" "+compErrMsg);
        }
    }

    //hour
    minute = vishnu::convertToInt(tokens[0]);
    wallTime = minute;
    //day
    if (tokens.size() >= 2) {
        int hour = vishnu::convertToInt(tokens[1]);
        wallTime += hour*60;
    }

    return wallTime;
}
Exemplo n.º 2
0
void verifyQuotaCharacter(const std::string& str, const char& quote) {

    std::string quoteStr;
    quoteStr.push_back(quote);
    std::string errorMsg = "Error: invalid value option in option "+str;
    errorMsg +=". A text started by the quote character "+quoteStr+" must be closed by the quote character "+quoteStr;
    //First character quote
    size_t pos = str.find(quote);
    if (pos!=std::string::npos) {
        //Second character quote
        pos = str.find(quote, pos+1);
        if (pos==std::string::npos) {
            throw UMSVishnuException(ERRCODE_INVALID_PARAM, errorMsg);
        }

        //First character quote
        pos = str.find(quote, pos+1);
        while(pos!=std::string::npos) {
            if (pos!=std::string::npos) {
                //Second character quote
                pos = str.find(quote, pos+1);
                if (pos==std::string::npos) {
                    throw UMSVishnuException(ERRCODE_INVALID_PARAM, errorMsg);
                }
            }
            //First character quote
            pos = str.find(quote, pos+1);
        }
    }

}
Exemplo n.º 3
0
  /**
   * \brief Function to treat the listSessionServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListSessionServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListSessionOptions_ptr& options, std::string& query)
  {
    boost::posix_time::ptime pt;
    bool listAll = options->isAdminListOption();

    if (! userServer.isAdmin()
        && (! options->getUserId().empty() || listAll)) {
      throw UMSVishnuException (ERRCODE_NO_ADMIN);
    }

    if(! options->getMachineId().empty()) {
      addOptionRequest("clmachine.name", options->getMachineId(), query);
    }

    if(! options->getUserId().empty()) {
      addOptionRequest("users.userid", options->getUserId(), query);
    } else {
      if (! listAll) {
        addOptionRequest("users.userid", userServer.getData().getUserId(), query);
      }
    }

    int status = options->getStatus();
    if (status == vishnu::STATUS_UNDEFINED) {
      status = vishnu::STATUS_ACTIVE;
    }

    addIntegerOptionRequest("state", status, query);

    if (options->getSessionClosePolicy()) {
      addIntegerOptionRequest("closepolicy", options->getSessionClosePolicy(), query);
    }

    if (options->getSessionInactivityDelay() < 0) {
      throw UMSVishnuException(ERRCODE_INCORRECT_TIMEOUT);
    }

    if (options->getSessionInactivityDelay()) {
      addIntegerOptionRequest("timeout", options->getSessionInactivityDelay(), query);
    }

    if (! options->getSessionId().empty()) {
      addOptionRequest("vsessionid", options->getSessionId(), query);
    }

    time_t startDate = static_cast<time_t>(options->getStartDateOption());
    if (startDate > 0) {
      addTimeRequest("creation", vishnu::timeToTimestamp(startDate), query, ">=");
    }

    time_t endDate = static_cast<time_t>(options->getEndDateOption());
    if (endDate > 0) {
      addTimeRequest("closure", vishnu::timeToTimestamp(endDate), query, "<=");
    }
  }
Exemplo n.º 4
0
/**
* \brief Function to update a VISHNU machine
* \return raises an exception on error
*/
int
MachineServer::update() {

  std::string sqlCommand = "";

  UserServer userServer = UserServer(msessionServer);
  userServer.init();

  //if the user exists
  if (! userServer.exist()) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_USER);
  }
  if (! userServer.isAdmin()) {
    throw UMSVishnuException (ERRCODE_NO_ADMIN);
  }

  //if the machine to update exists
  std::string numMachineId = getEntryAttribute(mmachine->getMachineId(), "nummachineid");
  if (numMachineId.empty()) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_MACHINE);
  }

  if (! mmachine->getAddress().empty()) {
    std::string query = boost::str(boost::format("UPDATE machine SET address='%1%'"
                                                 " WHERE nummachineid='%2%';")
                                   % mdatabase->escapeData(mmachine->getAddress())
                                   % numMachineId);
    sqlCommand.append(query);
  }

  if (mmachine->getStatus() != vishnu::STATUS_UNDEFINED) {
    std::string query = boost::str(
                          boost::format("UPDATE machine SET status='%1%'"
                                        " WHERE nummachineid='%2%';")
                          % mmachine->getStatus()
                          % numMachineId);
    sqlCommand.append(query);
  }

  if (! mmachine->getDescription().empty()) {
    std::string query = boost::str(
                          boost::format("UPDATE machine SET description='%1%'"
                                        " WHERE machine_nummachineid='%2%';")
                          % mdatabase->escapeData(mmachine->getDescription())
                          % numMachineId);

    sqlCommand.append(query);
  }

  if (! sqlCommand.empty()) {
    mdatabase->process(sqlCommand);
  }

  return 0;
}
Exemplo n.º 5
0
/**
* \brief Function to check the machineId
* \return raises an exception
*/
void MachineServer::checkMachine() {

  std::string result = getEntryAttribute(mmachine->getMachineId(), "status");
  if (result.empty()) {
    throw UMSVishnuException(ERRCODE_UNKNOWN_MACHINE,
                             boost::str(boost::format("No machine with this id (%1%)")
                                        % mmachine->getMachineId()));
  }

  if (vishnu::convertToInt(result) == vishnu::STATUS_LOCKED) {
    throw UMSVishnuException(ERRCODE_MACHINE_LOCKED);
  }
}
Exemplo n.º 6
0
/**
 * \brief The getCompletedJobsOutput() function gets standard output and error output files
 * of completed jobs (applies only once for each job)
 * \param sessionKey : The session key
 * \param machineId : The id of the machine
 * \param listOfResults : Is the list of jobs results
 * \param outDir : The output directory where the files will be stored (default is current directory)
 * \return int : an error code
 */
int
vishnu::getCompletedJobsOutput(const std::string& sessionKey,
		const std::string& machineId,
		ListJobResults& listOfResults,
		const std::string& outDir)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

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

	if((outDir.size()!=0)&&(!boost::filesystem::exists(outDir))) {
		throw UMSVishnuException(ERRCODE_INVALID_PARAM, "The directory "+outDir+" does not exist");
	}

	SessionProxy sessionProxy(sessionKey);
	JobOutputProxy jobOutputProxy(sessionProxy, machineId, outDir);

	TMS_Data::ListJobResults_ptr listJobResults_ptr = jobOutputProxy.getCompletedJobsOutput();

	if(listJobResults_ptr != NULL) {
		TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
		for(unsigned int i = 0; i < listJobResults_ptr->getResults().size(); i++) {
			TMS_Data::JobResult_ptr jobResult = ecoreFactory->createJobResult();
			//To copy the content and not the pointer
			*jobResult = *listJobResults_ptr->getResults().get(i);
			listOfResults.getResults().push_back(jobResult);
		}
		listOfResults.setNbJobs(listJobResults_ptr->getNbJobs());
		delete listJobResults_ptr;
	}
	return 0;
}
Exemplo n.º 7
0
/**
 * \brief The getJobOutput function gets outputPath and errorPath of a job from its id
 * \param sessionKey : The session key
 * \param jobId : The Id of the job
 * \param outputInfo : The  Job object  containing the job output information (e.g: outputPath and errorPath) of the job to submit
 * \param options : Object containing the user-provided options (e.g: it contains a possible output directory set by the user)
 * \return 0 on success, or raises exception on error
 */
int
vishnu::getJobOutput(const std::string& sessionKey,
                     const std::string& jobId,
                     TMS_Data::JobResult& outputInfo,
                     const TMS_Data::JobOutputOptions& options)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

  checkEmptyString(sessionKey, "The session key");

  std::string outputDir = options.getOutputDir();
  if (! outputDir.empty() && ! boost::filesystem::exists(outputDir)) {
    throw UMSVishnuException(ERRCODE_INVALID_PARAM, "The output directory does not exist: "+ outputDir);
  }

  // If no machine id provided, find where the job has been submitted
  std::string machineId =  options.getMachineId();
  if (machineId.empty()) {
    TMS_Data::Job jobInfo;
    getJobInfo(sessionKey, jobId, machineId, jobInfo);
    machineId = jobInfo.getMachine();
  }

  // Now process the request
  SessionProxy sessionProxy(sessionKey);
  JobOutputProxy jobOutputProxy(sessionProxy, machineId);

  outputInfo = jobOutputProxy.getJobOutPut(jobId, options);
  return 0;
}
Exemplo n.º 8
0
/**
* \brief Function to get a certain user account property
* \param machineId The machine identifier of machine on which the user have a account
* \param property The property name
* \return the user account login
*/
std::string
UserServer::getUserAccountProperty(const std::string& machineId, const std::string& property) {

  init();

  std::string userId = getData().getUserId();
  UMS_Data::LocalAccount_ptr account = new UMS_Data::LocalAccount();
  account->setMachineId(machineId);
  account->setUserId(userId);
  LocalAccountServer localAccount(account, *msessionServer);

  UMS_Data::Machine_ptr machine = new UMS_Data::Machine();
  machine->setMachineId(machineId);
  MachineServer machineServer(machine);

  //To get the database number id of the machine
  std::string numMachine = machineServer.getAttribut("where machineid='"+localAccount.getData()->getMachineId()+"'");
  //To get the database number id of the user
  std::string numUser = getAttribut("where userid='"+localAccount.getData()->getUserId()+"'");

  std::string value;
  if ((numMachine.size() > 0) && (numUser.size() > 0)) {
	  value = localAccount.getAttribut("where machine_nummachineid="+numMachine+" and users_numuserid="+numUser, property);
  }

  if(value.size()==0) {
    delete account;
    delete machine;
    throw UMSVishnuException(ERRCODE_UNKNOWN_LOCAL_ACCOUNT, "You have not a local account on this machine");
  }

  delete account;
  delete machine;
  return value;
}
Exemplo n.º 9
0
/**
 * \brief Function to change user password
 * \param oldPassword the old password of the user
 * \param newPassword the new password of the user
 * \return raises an exception on error
 */
int
UserProxy::changePassword(const std::string& password,
                          const std::string& newPassword) {

    std::string errorInfo;
    std::string msg = "call of function diet_string_set is rejected ";
    std::string versionToString;

    UMS_Data::Version_ptr versionObj = vishnu::parseVersion(VISHNU_VERSION);
    if (versionObj == NULL) {
        throw UMSVishnuException(ERRCODE_INVALID_PARAM, "The format of the VISHNU VERSION is incorrect");
    } else {
        // SERIALIZE DATA MODEL
        ::ecorecpp::serializer::serializer _ser;
        //To serialize the version object in to versionToString
        versionToString =  _ser.serialize_str(versionObj);
    }

    diet_profile_t* profile = diet_profile_alloc(SERVICES_UMS[USERPASSWORDCHANGE], 4);
    diet_string_set(profile,0, muser.getUserId());
    diet_string_set(profile,1, password);
    diet_string_set(profile,2, newPassword);
    diet_string_set(profile,3, versionToString);

    if (diet_call(profile)) {
        raiseCommunicationMsgException("RPC call failed");
    }
    raiseExceptionOnErrorResult(profile);

    diet_profile_free(profile);
    delete versionObj;

    return 0;
}
Exemplo n.º 10
0
  /**
   * \brief Function to treat the ListUsersServer options
   * \param userServer the object which encapsulates user information
   * \param options The object which encapsulates the information of ListUsersServer  options
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListUsersOptions_ptr& options, std::string& sqlRequest) {


    if(! userServer.isAdmin()) {
      throw UMSVishnuException (ERRCODE_NO_ADMIN);
    }
    std::string  userId = options->getUserId();
    if(userId.size()!=0) {
      //To check if the user id is correct
      checkUserId(options->getUserId());
      addOptionRequest("userid", userId, sqlRequest);
    }

    std::string  authSystemId = options->getAuthSystemId();
    if(authSystemId.size()!=0) {
      //To check if the authSystem identifier is correct
      checkAuthSystemId(authSystemId);
      //addOptionRequest("authsystemid", authSystemId, sqlRequest);
      std::string luserCmd = boost::str(boost::format("SELECT userid "
                                                      " FROM authsystem, users, authaccount "
                                                      " WHERE authaccount.authsystem_authsystemid=authsystem.numauthsystemid"
                                                      " AND authaccount.users_numuserid=users.numuserid"
                                                      " AND authsystemid='%1%'"
                                                      " AND authsystem.status!=%2%"
                                                      " AND users.status!=%2%"
                                                      " AND authaccount.status!=%2%"
                                                      )
                                        % mdatabaseInstance->escapeData(authSystemId)
                                        % vishnu::STATUS_DELETED);
      sqlRequest.append(" AND userid IN ("+mdatabaseInstance->escapeData(luserCmd)+")");
    }

  }
Exemplo n.º 11
0
/**
 * \brief Function to change user password
 * \fn  int changePassword(const std::string& password, const std::string& newPassword)
 * \param oldPassword the old password of the user
 * \param newPassword the new password of the user
 * \return raises an exception on error
 */
int UserProxy::changePassword(const std::string& password, const std::string& newPassword)
{

  diet_profile_t* profile = NULL;
  char* errorInfo;
  std::string msg = "call of function diet_string_set is rejected ";
  std::string versionToString;

  UMS_Data::Version_ptr versionObj = vishnu::parseVersion(VISHNU_VERSION);
  if (versionObj == NULL) {
    throw UMSVishnuException(ERRCODE_INVALID_PARAM, "The format of the VISHNU VERSION is incorrect");
  } else {
    // SERIALIZE DATA MODEL
    ::ecorecpp::serializer::serializer _ser;
    //To serialize the version object in to versionToString
    versionToString =  _ser.serialize_str(versionObj);
  }
  profile = diet_profile_alloc("userPasswordChange", 3, 3, 4);

  //IN Parameters
  if(diet_string_set(diet_parameter(profile,0), strdup((muser.getUserId()).c_str()), DIET_VOLATILE)) {
    msg += "with sessionKey parameter "+msessionProxy->getSessionKey();
    raiseDietMsgException(msg);
  }

  if(diet_string_set(diet_parameter(profile,1), strdup(password.c_str()), DIET_VOLATILE)) {
    msg += "with password parameter "+password;
    raiseDietMsgException(msg);
  }

  if(diet_string_set(diet_parameter(profile,2), strdup(newPassword.c_str()), DIET_VOLATILE)) {
    msg += "with newPassword parameter "+newPassword;
    raiseDietMsgException(msg);
  }

  if(diet_string_set(diet_parameter(profile,3), strdup(versionToString.c_str()), DIET_VOLATILE)) {
      msg += "with version parameter "+versionToString;
      raiseDietMsgException(msg);
  }

  //OUT Parameters
  diet_string_set(diet_parameter(profile,4), NULL, DIET_VOLATILE);

  if(!diet_call(profile)) {
    if(diet_string_get(diet_parameter(profile,4), &errorInfo, NULL)){
      msg += "by receiving errorInfo message";
      raiseDietMsgException(msg);
    }
  }
  else {
    raiseDietMsgException("DIET call failure");
  }
  /*To raise a vishnu exception if the receiving message is not empty*/
  raiseExceptionIfNotEmptyMsg(errorInfo);

  diet_profile_free(profile);
  delete versionObj;

  return 0;
}
Exemplo n.º 12
0
  /**
   * \brief Function to treat the ListLocalAccountsServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListLocalAccountsServer options
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void processOptions(UserServer userServer, const UMS_Data::ListLocalAccOptions_ptr& options, std::string& sqlRequest)
  {

    if (! userServer.isAdmin()
        && (! options->getUserId().empty() || options->isAdminListOption())) {
      throw UMSVishnuException(ERRCODE_NO_ADMIN);
    }

    if(! options->isAdminListOption()) {
      addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
    }

    //The admin option
    if (! options->getUserId().empty()) {
      addOptionRequest("users.userid", options->getUserId(), sqlRequest);
    }

    if (! options->getMachineId().empty()) {
      addOptionRequest("machine.machineid", options->getMachineId(), sqlRequest);

      if (! options->isAdminListOption()
          && options->getUserId().empty()) {
        addOptionRequest("users.userid", userServer.getData().getUserId(), sqlRequest);
      }
    }
  }
Exemplo n.º 13
0
/**
 * @brief checkPrivilege: Check if a privilege is valid
 * @param privilege : the privilege value
 */
void
checkPrivilege(int privilege)
{
    if (privilege != vishnu::PRIVILEGE_USER && privilege != vishnu::PRIVILEGE_ADMIN) {
        throw UMSVishnuException(ERRCODE_INVALID_PARAM,
                                 "Invalid Privilege value: valid options are 0 or 1");
    }
}
Exemplo n.º 14
0
/**
 * @brief Function to check the vaidity of a component status
 * @param state The value
 * \return raises an exception on error
 */
void
checkEntityStatus(int state)
{
    if (state != vishnu::STATUS_LOCKED && state != vishnu::STATUS_ACTIVE) {
        throw UMSVishnuException(ERRCODE_INVALID_PARAM,
                                 "Invalid state: valid options are 0 or 1");
    }
}
Exemplo n.º 15
0
/**
 * \brief Function to check if a text is empty
 * \param text The text to check
 * \param comMsg The complementary message to print
 * \param exceptionType The type of exception to raise
 * \return raises an exception on error
 */
void
checkIfTextIsEmpty(const std::string& text,
                   const std::string& compMsg,
                   const int& exceptionType) {
    if (text.empty()) {
        throw UMSVishnuException(exceptionType, compMsg);
    }
}
Exemplo n.º 16
0
/**
 * \brief Function to check if a given user identifier exists
 * \param userId the user identifier
 * \return raises an exception on error
 */
void
FileTransferServer::checkUserId(std::string userId) {
  std::string sqlUserRequest = "SELECT userid from users where userid='"+FileTransferServer::getDatabaseInstance()->escapeData(userId)+"'";
  boost::scoped_ptr<DatabaseResult> user(FileTransferServer::getDatabaseInstance()->getResult(sqlUserRequest.c_str()));
  if (user->getNbTuples() == 0) {
    throw UMSVishnuException(ERRCODE_UNKNOWN_USERID);
  }
}
Exemplo n.º 17
0
/**
* \brief Function to add a new VISHNU machine
* \return raises an exception on error
*/
int
MachineServer::add(void) {

  UserServer userServer = UserServer(msessionServer);
  userServer.init();

  if (! userServer.exist()) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_USER);
  }

  if (! userServer.isAdmin()) {
    throw UMSVishnuException (ERRCODE_NO_ADMIN);
  }

  dbSave();

  return 0;
}
Exemplo n.º 18
0
/**
 * \brief Function to check if an email is valid
 * \param mail The email to check
 * \return raises an exception on error
 */
void
checkEmail(const std::string& mail) {
    // Regex taken from http://www.regular-expressions.info/email.html
    boost::regex reg("^[[:alnum:]._%+-]+@[[:alnum:]-]+(?:\\.[[:alnum:]]+)*");

    if (!boost::regex_match(mail, reg)) {
        throw UMSVishnuException(ERRCODE_INVALID_MAIL_ADRESS);
    }
}
Exemplo n.º 19
0
  /**
   * \brief Function to list sessions information
   * \return The pointer to the UMS_Data::ListSessions containing sessions information
   * \return raises an exception on error
   */
  UMS_Data::ListSessions*
  list(UMS_Data::ListSessionOptions_ptr option)
  {
    std::string query = (boost::format("SELECT DISTINCT vsessionid, userid, sessionkey, state, closepolicy, "
                                       "                timeout, lastconnect, creation, closure, authid "
                                       " FROM vsession, users, clmachine"
                                       " WHERE vsession.state            = %1%"
                                       "    AND users.status             = %1%"
                                       "    AND vsession.users_numuserid = users.numuserid"
                                       "    AND vsession.clmachine_numclmachineid=clmachine.numclmachineid")
                         % vishnu::STATUS_ACTIVE).str();

    std::vector<std::string>::iterator dbResultIter;
    std::vector<std::string> dbResults;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListSessions();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();

    if (! userServer.exist()) {
      throw UMSVishnuException (ERRCODE_UNKNOWN_USER);
    }

    processOptions(userServer, option, query);
    query.append(" order by creation");
    //To get the list of sessions from the database
    boost::scoped_ptr<DatabaseResult> ListOfSessions (mdatabase->getResult(query));

    if (ListOfSessions->getNbTuples() != 0){
      for (size_t i = 0; i < ListOfSessions->getNbTuples(); ++i) {
        dbResults.clear();
        dbResults = ListOfSessions->get(i);
        dbResultIter = dbResults.begin();

        UMS_Data::Session_ptr session = ecoreFactory->createSession();
        session->setSessionId(*(dbResultIter));
        session->setUserId(*(++dbResultIter));
        session->setSessionKey(*(++dbResultIter));
        session->setStatus(vishnu::convertToInt(*(++dbResultIter)));
        session->setClosePolicy(vishnu::convertToInt(*(++dbResultIter)));
        session->setTimeout(vishnu::convertToInt(*(++dbResultIter)));
        session->setDateLastConnect(convertToTimeType(*(++dbResultIter)));
        session->setDateCreation(convertToTimeType(*(++dbResultIter)));
        session->setDateClosure(convertToTimeType(*(++dbResultIter)));
        session->setAuthenId(*(++dbResultIter));
        mlistObject->getSessions().push_back(session);
      }
    }

    return mlistObject;
  }
Exemplo n.º 20
0
/**
 * \brief Function to update machine description
 * \fn  int update()
 * \return raises an exception on error
 */
int MachineProxy::update()
{
  diet_profile_t* updateProfile = NULL;
  std::string sessionKey;
  std::string machineToString;
  char* errorInfo;
  std::string msg = "call of function diet_string_set is rejected ";

  updateProfile = diet_profile_alloc("machineUpdate", 1, 1, 2);
  sessionKey = msessionProxy.getSessionKey();

  ::ecorecpp::serializer::serializer _ser;
  //To serialize the mmachine object in to machineToString
  machineToString =  _ser.serialize_str(const_cast<UMS_Data::Machine_ptr>(&mmachine));

  std::string sshKeyFilePath = mmachine.getSshPublicKey();
  if(sshKeyFilePath.find("\"")!=std::string::npos) {
    throw UMSVishnuException(ERRCODE_INVALID_PARAM, " The machine SshPublicKey contains special character double quote \"");
  }

  //IN Parameters
  if(diet_string_set(diet_parameter(updateProfile,0), strdup(sessionKey.c_str()), DIET_VOLATILE)) {
    msg += "with sessionKey parameter "+sessionKey;
    raiseDietMsgException(msg);
  }
  if(diet_string_set(diet_parameter(updateProfile,1), strdup(machineToString.c_str()), DIET_VOLATILE)) {
    msg += "with machineToString parameter "+machineToString;
    raiseDietMsgException(msg);
  }

  //OUT Parameters
  diet_string_set(diet_parameter(updateProfile,2), NULL, DIET_VOLATILE);

  if(!diet_call(updateProfile)) {
    if(diet_string_get(diet_parameter(updateProfile,2), &errorInfo, NULL)){
      msg += "by receiving errorInfo message";
      raiseDietMsgException(msg);
    }
  }
  else {
    raiseDietMsgException("DIET call failure");
  }

  /*To raise a vishnu exception if the receiving message is not empty*/
  raiseExceptionIfNotEmptyMsg(errorInfo);

  diet_profile_free(updateProfile);

  return 0;
}
Exemplo n.º 21
0
  /**
   * \brief Function to list locoal accounts information
   * \return The pointer to the UMS_Data::ListLocalAccounts containing local accounts information
   * \return raises an exception on error
   */
  UMS_Data::ListLocalAccounts* list(UMS_Data::ListLocalAccOptions_ptr option)
  {
    std::string query = boost::str(boost::format("SELECT DISTINCT machineid, userid, aclogin, home"
                                                 " FROM account, machine, users"
                                                 " WHERE account.status               = %1%"
                                                 "   AND machine.status               = %1%"
                                                 "   AND users.status                 = %1%"
                                                 "   AND account.machine_nummachineid = machine.nummachineid"
                                                 "   AND account.users_numuserid      = users.numuserid"
                                                 ) % vishnu::STATUS_ACTIVE);


    std::vector<std::string>::iterator dbResultIter;
    std::vector<std::string> dbResults;
    UMS_Data::UMS_DataFactory_ptr ecoreFactory = UMS_Data::UMS_DataFactory::_instance();
    mlistObject = ecoreFactory->createListLocalAccounts();

    //Creation of the object user
    UserServer userServer = UserServer(msessionServer);
    userServer.init();
    if (! userServer.exist()) {
      throw UMSVishnuException (ERRCODE_UNKNOWN_USER);
    }

    //To process options
    processOptions(userServer, option, query);

    boost::scoped_ptr<DatabaseResult> resultAccount(mdatabase->getResult(query));
    if (resultAccount->getNbTuples() != 0){
      for (size_t i = 0; i < resultAccount->getNbTuples(); ++i) {
        dbResults.clear();
        dbResults = resultAccount->get(i);
        dbResultIter = dbResults.begin();

        UMS_Data::LocalAccount_ptr localAccount = ecoreFactory->createLocalAccount();
        localAccount->setMachineId(*dbResultIter);
        localAccount->setUserId(*(++dbResultIter));
        localAccount->setAcLogin(*(++dbResultIter));
        localAccount->setHomeDirectory(*(++dbResultIter));

        mlistObject->getAccounts().push_back(localAccount);
      }
    }

    return mlistObject;
  }
Exemplo n.º 22
0
void
SysInfoServer::setSysInfo(IMS_Data::SystemInfo_ptr sys) {
  bool added = false;
  if (!msession.isAdmin()){
    throw UMSVishnuException(ERRCODE_NO_ADMIN, "set system info is an admin function. A user cannot call it");
  }
  // No update needed
  if (sys->getMemory()==0 && sys->getDiskSpace()==0) {
    return;
  }
  if (sys->getMachineId().compare("")==0) {
    throw UserException(ERRCODE_INVALID_PARAM, "Error missing the machine id. ");
  }
  string reqnmid = "SELECT nummachineid from machine where  machineid ='"+sys->getMachineId()+"'";
  boost::scoped_ptr<DatabaseResult> result(mdatabase->getResult(reqnmid.c_str()));
  if(result->getNbTuples() == 0) {
    throw IMSVishnuException(ERRCODE_INVPROCESS, "Unknown machine id");
  }

  string request = "update machine set ";
  if (sys->getDiskSpace() < 0 || sys->getMemory() < 0) {
    throw UserException(ERRCODE_INVALID_PARAM, "Invalid negative value");
  }
  if (sys->getDiskSpace()>0) {
    request += "  diskspace ="+convertToString(sys->getDiskSpace());
    added = true;
  }
  if (sys->getMemory()>0) {
    if (added) {
      request += ",";
    }
    request += "  memory ="+convertToString(sys->getMemory());
  }
  request += " where  machineid ='"+sys->getMachineId()+"'";

  request += " AND vishnu_vishnuid=";
  request += convertToString(mvishnuId);

  try{
    mdatabase->process(request.c_str());
  }catch(SystemException& e){
    e.appendMsgComp(" Error inserting new system states ");
    throw(e);
  }
}
Exemplo n.º 23
0
/**
 * \brief Gets standard output files of all completed jobs (applies only once for each job)
 * \param sessionKey : The session key
 * \param options: object containing options
 * \param listOfResults : Is the list of jobs results
   * \param options: Object containing options
 * \return int : an error code
 */
int
vishnu::getCompletedJobsOutput(const std::string& sessionKey,
                               TMS_Data::ListJobResults& listOfResults,
                               const TMS_Data::JobOutputOptions& options)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

  checkEmptyString(sessionKey, "The session key");

  std::string outputDir = options.getOutputDir();
  if (! outputDir.empty() && ! boost::filesystem::exists(outputDir)) {
    throw UMSVishnuException(ERRCODE_INVALID_PARAM, "The ouput directory does not exist: "+outputDir);
  }

  UMS_Data::ListMachines machines;
  if (options.getMachineId().empty()) {
    vishnu::listMachinesWithUserLocalAccount(sessionKey, machines);
  } else {
    UMS_Data::Machine_ptr machine = new UMS_Data::Machine(); // delete by EMF
    machine->setMachineId(options.getMachineId());
    machines.getMachines().push_back(machine);
  }

  int machineCount = machines.getMachines().size();
  for (int index = 0; index < machineCount; ++index) {
    SessionProxy sessionProxy(sessionKey);
    JobOutputProxy jobOutputProxy(sessionProxy, machines.getMachines().get(index)->getMachineId());

    TMS_Data::ListJobResults_ptr listJobResults_ptr = jobOutputProxy.getCompletedJobsOutput(options);

    if (listJobResults_ptr != NULL) {
      TMS_Data::TMS_DataFactory_ptr ecoreFactory = TMS_Data::TMS_DataFactory::_instance();
      for(unsigned int i = 0; i < listJobResults_ptr->getResults().size(); i++) {
        TMS_Data::JobResult_ptr jobResult = ecoreFactory->createJobResult();
        //To copy the content and not the pointer
        *jobResult = *listJobResults_ptr->getResults().get(i);
        listOfResults.getResults().push_back(jobResult);
      }
      listOfResults.setNbJobs(listJobResults_ptr->getNbJobs());
      delete listJobResults_ptr;
    }
  }
  return 0;
}
Exemplo n.º 24
0
  /**
   * \brief Function to treat the ListMachinesServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListMachinesServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListMachineOptions_ptr& options, std::string& sqlRequest)
  {
    std::string sqlJoinLstMachines = boost::str(boost::format("SELECT DISTINCT machineid, address, machine.status, description, userid "
                                                              " FROM machine, account, users"
                                                              " WHERE account.machine_nummachineid = machine.nummachineid "
                                                              " AND account.users_numuserid = users.numuserid "
                                                              " AND machine.status != %1%"
                                                              " AND account.status != %1%"
                                                              " AND users.status   != %1%"
                                                              ) % vishnu::STATUS_DELETED);
    std::string sqlListofMachinesIntial = sqlRequest;
    bool isListAll = options->isListAllMachine();

    if (! userServer.isAdmin() && ! options->getUserId().empty()) {
      throw UMSVishnuException (ERRCODE_NO_ADMIN);
    }

    if(! isListAll) {
      sqlRequest = sqlJoinLstMachines;
      addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
    }

    //The admin option
    if (! options->getUserId().empty()) {
      sqlRequest = sqlJoinLstMachines;
      addOptionRequest("users.numuserid", getNumUser(options->getUserId()), sqlRequest);
    }

    if (! options->getMachineId().empty()) {
      getNumMachine( options->getMachineId() );

      if(! isListAll && options->getUserId().empty()) {
        sqlRequest = sqlListofMachinesIntial;
      }

      addOptionRequest("machineid", options->getMachineId(), sqlRequest);
    }
  }
Exemplo n.º 25
0
  /**
   * \brief Function to treat the ListCommandsServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListCommandsServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListCmdOptions_ptr& options, std::string& sqlRequest)
  {
    boost::posix_time::ptime pt;
    bool listAll = options->isAdminListOption();

    if (! userServer.isAdmin()
        && (! options->getUserId().empty() || listAll)) {
      throw UMSVishnuException (ERRCODE_NO_ADMIN);
    }

    if(! options->getUserId().empty()) {
      addOptionRequest("users.numuserid", getNumUser(options->getUserId()), sqlRequest);
    } else {
      if(! listAll) {
        addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
      }
    }

    if (! options->getSessionId().empty()) {
      checkSessionId(options->getSessionId());

      addOptionRequest("vsessionid", options->getSessionId(), sqlRequest);
    }

    time_t startDate = static_cast<time_t>(options->getStartDateOption());
    if (startDate != -1) {
      pt =  boost::posix_time::from_time_t(startDate);
      std::string startDateStr =  boost::posix_time::to_iso_string(pt);
      addTimeRequest("starttime", startDateStr, sqlRequest, ">=");
    }

    time_t endDate = static_cast<time_t>(options->getEndDateOption());
    if(endDate!=-1) {
      pt =  boost::posix_time::from_time_t(endDate);
      std::string endDateStr =  boost::posix_time::to_iso_string(pt);
      addTimeRequest("endtime", endDateStr, sqlRequest, "<=");
    }
  }
Exemplo n.º 26
0
/**
 * \brief The getJobOutput function gets outputPath and errorPath of a job from its id
 * \param sessionKey : The session key
 * \param machineId : The Id of the machine
 * \param jobId : The Id of the job
 * \param outputInfo : The  Job object  containing the job output information (ex: outputPath and errorPath) of the job to submit
 * \param outDir : The output directory where the files will be stored (default is current directory)
 * \return int : an error code
 */
int
vishnu::getJobOutput(const std::string& sessionKey,
		const std::string& machineId,
		const std::string& jobId,
		JobResult& outputInfo,
		const std::string& outDir)
throw (UMSVishnuException, TMSVishnuException, UserException, SystemException) {

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

	if((outDir.size()!=0)&&(!boost::filesystem::exists(outDir))) {
		throw UMSVishnuException(ERRCODE_INVALID_PARAM, "The directory "+outDir+" does not exist");
	}

	SessionProxy sessionProxy(sessionKey);
	JobOutputProxy jobOutputProxy(sessionProxy, machineId, outDir);

	outputInfo = jobOutputProxy.getJobOutPut(jobId);

	return 0;
}
Exemplo n.º 27
0
  /**
   * \brief Function to treat the listSessionServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListSessionServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListSessionOptions_ptr& options, std::string& sqlRequest)
  {
    boost::posix_time::ptime pt;
    size_t userIdSize = options->getUserId().size();
    bool listAll = options->isAdminListOption();

    if ((!userServer.isAdmin()) && (userIdSize!=0 || listAll)) {
      UMSVishnuException e (ERRCODE_NO_ADMIN);
      throw e;
    }

    if(options->getMachineId().size()!=0) {
      //To check if the name of the machine is correct
      checkClientMachineName(options->getMachineId());

      sqlRequest = "SELECT vsessionid, userid, sessionkey, state, closepolicy, timeout, lastconnect,"
                   "creation, closure, authid from vsession, users, clmachine where vsession.users_numuserid=users.numuserid"
                   " and vsession.clmachine_numclmachineid=clmachine.numclmachineid";
      addOptionRequest("name", options->getMachineId(), sqlRequest);
    }

    if(userIdSize!=0) {
      //To check if the user id is correct
      checkUserId(options->getUserId());

      addOptionRequest("userid", options->getUserId(), sqlRequest);
    } else {
      if(!listAll) {
        addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
      }
    }

    int status = options->getStatus();
    if (status == vishnu::STATUS_UNDEFINED) {
      status = vishnu::STATUS_ACTIVE;
    }
    //To check the status value
    checkStatus(status);

    addIntegerOptionRequest("state", status, sqlRequest);

    int closePolicy = options->getSessionClosePolicy();
    //To check the closePolicy value
    checkClosePolicy(closePolicy);

    if(closePolicy) {
      addIntegerOptionRequest("closepolicy", closePolicy, sqlRequest);
    }

    int timeOut = options->getSessionInactivityDelay();
    if(timeOut < 0) {
      throw UMSVishnuException(ERRCODE_INCORRECT_TIMEOUT);
    }
    if(timeOut) {
      addIntegerOptionRequest("timeout", timeOut, sqlRequest);
    }

    if(options->getSessionId().size()!=0) {
      //To check if the session id is correct
      checkSessionId(options->getSessionId());

      addOptionRequest("vsessionid", options->getSessionId(), sqlRequest);
    }

    time_t startDate = static_cast<time_t>(options->getStartDateOption());
    if(startDate!=-1) {
      pt =  boost::posix_time::from_time_t(startDate);
      std::string startDateStr =  boost::posix_time::to_iso_string(pt);
      addTimeRequest("creation", startDateStr, sqlRequest, ">=");
    }

    time_t endDate = static_cast<time_t>(options->getEndDateOption());
    if(endDate!=-1) {
      pt =  boost::posix_time::from_time_t(endDate);
      std::string endDateStr =  boost::posix_time::to_iso_string(pt);
      addTimeRequest("closure", endDateStr, sqlRequest, "<=");
    }

  }
Exemplo n.º 28
0
int
LSFParser::parse_file(const char* pathTofile, struct submit* req) {

    std::vector<std::string>  tokensArgs=convertScriptIntoArgv(pathTofile);
    int argc = tokensArgs.size()+1;
    char* argv[argc];
    argv[0] = (char*) "vishnu_submit_job";
    for(int i=0; i < tokensArgs.size(); ++i) {
        argv[i+1] = strdup(tokensArgs[i].c_str());
    }

#define GETOPT_ARGS "J:q:m:n:i:o:e:xNBG:k:rw:R:E:L:P:u:U:KW:g:Hc:F:p:M:D:S:v:T:b:t:f:Q:s:"

    int option_index = 0;
    optind=0;
    int c;
    std::string host_list;
    std::vector<std::string> host_tokens;
    std::string procsStr;
    std::istringstream stream_procs;
    std::string min_proc_str;
    std::string max_proc_str;
    int min_proc;
    int max_proc;
    char separator=',';
    std::string chkpnt;
    std::vector<std::string> chkpnt_tokens;
    std::string timeStr;
    std::string wHostSpec;
    struct xFile *tmpXfile;
    std::string xFileStr;
    std::vector<std::string> xFile_tokens;
    int oldNxf;

    std::string errHead = "Error in your script: ";
    //set default values for jobName and job output and error path
    req->options |=SUB_JOB_NAME;
    req->jobName = (char*) "NoName";
    req->options |=SUB_OUT_FILE;
    req->outFile = (char*) "lsf-%J.out";
    req->options |=SUB_ERR_FILE;
    req->errFile = (char*) "lsf-%J.err";

    //Parse options in script file
    while ((c = getopt_long_only(argc, argv, GETOPT_ARGS, long_options, &option_index)) != -1) {
        switch (c) {
        case 'J':
            req->options |=SUB_JOB_NAME;
            req->jobName = strdup(optarg);
            break;
        case 'q':
            req->options |=SUB_QUEUE;
            req->queue = strdup(optarg);
            break;
        case 'm':
            req->options |=SUB_HOST;
            host_list = strdup(optarg);
            host_tokens=getStreamTokens(host_list);
            req->numAskedHosts = host_tokens.size();
            req->askedHosts = new char*[host_tokens.size()];
            for(int i=0; i < host_tokens.size(); i++) {
                req->askedHosts[i] = strdup(host_tokens[i].c_str());
            }
            break;
        case 'n':
            procsStr = strdup(optarg);
            if (procsStr.find(',')!=std::string::npos) {
                stream_procs.str(procsStr);
                stream_procs >> min_proc_str;
                min_proc_str = procsStr.substr(0,procsStr.find(separator));
                if (procsStr.find(separator)+1!=std::string::npos) {
                    max_proc_str = procsStr.substr(procsStr.find(separator)+1);
                }
                if (!isNumerical(min_proc_str) || !isNumerical(max_proc_str)) {
                    throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+std::string(optarg)+"is an invalid"
                                             " value for -n option. Correct format is -n min_processors[,max_processors]");
                }
                min_proc = vishnu::convertToInt(min_proc_str);
                max_proc = vishnu::convertToInt(max_proc_str);
            } else {
                if (isNumerical(procsStr)) {
                    min_proc = vishnu::convertToInt(procsStr);
                    max_proc = min_proc;
                } else {
                    throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+std::string(optarg)+" is an invalid"
                                             " value for -n option. Correct format is -n min_processors[,max_processors]");
                }
            }
            req->numProcessors=min_proc;
            req->maxNumProcessors=max_proc;
            break;
        case 'i':
            if ((req->options2 & SUB2_IN_FILE_SPOOL)==SUB2_IN_FILE_SPOOL) {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+" is|i options are exclusive");
            }
            req->options |=SUB_IN_FILE;
            req->inFile = strdup(optarg);
            break;
        case 'o':
            req->options |=SUB_OUT_FILE;
            req->outFile = strdup(optarg);
            break;
        case 'e':
            req->options |=SUB_ERR_FILE;
            req->errFile = strdup(optarg);
            break;
        case 'x':
            req->options |=SUB_EXCLUSIVE;
            break;
        case 'N':
            req->options |=SUB_NOTIFY_END;
            break;
        case 'B':
            req->options |=SUB_NOTIFY_BEGIN;
            break;
        case 'G':
            req->options |=SUB_USER_GROUP;
            req->userGroup = strdup(optarg);
            break;
        case 'k':
            req->options |=SUB_CHKPNT_DIR;
            chkpnt = strdup(optarg);
            chkpnt_tokens=getStreamTokens(chkpnt);
            req->chkpntDir = strdup(chkpnt_tokens[0].c_str());
            if (chkpnt_tokens.size() >=2) {
                if (boost::algorithm::starts_with(chkpnt_tokens[1], "init=")) {
                    chkpnt_tokens[1] = chkpnt_tokens[1].substr(std::string("init=").size());
                    if (isNumerical(chkpnt_tokens[1])) {
                        req->initChkpntPeriod = vishnu::convertToInt(chkpnt_tokens[1]);
                    } else {
                        throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+chkpnt_tokens[1]+" is an invalid"
                                                 " initial checkpoint period value for -k option.");
                    }
                } else {
                    if (isNumerical(chkpnt_tokens[1])) {
                        req->chkpntPeriod= vishnu::convertToInt(chkpnt_tokens[1]);
                    } else {
                        throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+chkpnt_tokens[1]+" is an invalid"
                                                 " checkpoint period value for -k option.");
                    }
                }
            }
            if (chkpnt_tokens.size() >=3) {
                if (!boost::algorithm::starts_with(chkpnt_tokens[2], "method=")) {
                    req->options |=SUB_CHKPNT_PERIOD;
                    if (isNumerical(chkpnt_tokens[2])) {
                        req->chkpntPeriod= vishnu::convertToInt(chkpnt_tokens[2]);
                    }  else {
                        throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+chkpnt_tokens[2]+" is an invalid"
                                                 " checkpoint period value for -k option.");
                    }
                }
            }
            break;
        case 'r':
            req->options |=SUB_RERUNNABLE;
            if ((req->options3 & SUB3_NOT_RERUNNABLE)==SUB3_NOT_RERUNNABLE) {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+" You cannot set a job to be rerunnable"
                                         "and not-rerunnable at the same time");
            }
            break;
        case 'w':
            req->options |=SUB_DEPEND_COND;
            req->dependCond = strdup(optarg);
            break;
        case 'R':
            req->options |=SUB_RES_REQ;
            req->resReq = strdup(optarg);
            break;
        case 'E':
            req->options |=SUB_PRE_EXEC;
            req->preExecCmd = strdup(optarg);
            break;
        case 'L':
            req->options |=SUB_LOGIN_SHELL;
            req->loginShell = strdup(optarg);
            break;
        case 'P':
            req->options |=SUB_PROJECT_NAME;
            req->projectName = strdup(optarg);
            break;
        case 'u':
            req->options |=SUB_MAIL_USER;
            req->mailUser = strdup(optarg);
            break;
        case 'U':
            req->options2 |=SUB2_USE_RSV;
            req->rsvId = strdup(optarg);
            break;
        case 'K':
            throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+" option -K is "
                                     " not treated by VISHNU.");
            break;
        case 'W':
            //-W run_limit[/host_spec]
            timeStr = std::string(strdup(optarg));
            if (timeStr.find("/")!=std::string::npos) {
                if ((timeStr.find("/")+1)!=std::string::npos) {
                    req->options |= SUB_HOST_SPEC;
                    req->rLimits[LSF_RLIMIT_RUN] = convertWallTimeToTime(timeStr.substr(0, timeStr.find("/")));
                    wHostSpec = timeStr.substr(timeStr.find("/")+1);
                    req->hostSpec = strdup(wHostSpec.c_str());
                }
            } else {
                req->rLimits[LSF_RLIMIT_RUN] = convertWallTimeToTime(timeStr);
            }
            break;
        case 'g':
            req->options2 |= SUB2_JOB_GROUP;
            req->jobGroup = strdup(optarg);
            break;
        case 'H':
            req->options2 |= SUB2_HOLD;
            break;
        case 'c':
            timeStr = std::string(strdup(optarg));
            if (timeStr.find("/")!=std::string::npos) {
                if ((timeStr.find("/")+1)!=std::string::npos) {
                    req->options |= SUB_HOST_SPEC;
                    req->rLimits[LSF_RLIMIT_CPU] = convertWallTimeToTime(timeStr.substr(0, timeStr.find("/")));
                    wHostSpec = timeStr.substr(timeStr.find("/")+1);
                    req->hostSpec = strdup(wHostSpec.c_str());
                }
            } else {
                req->rLimits[LSF_RLIMIT_CPU] = convertWallTimeToTime(timeStr);
            }
            break;
        case 'F':
            if (isNumerical(strdup(optarg))) {
                req->rLimits[LSF_RLIMIT_FSIZE]=vishnu::convertToInt(strdup(optarg));
            }  else {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+std::string(strdup(optarg))+" is an invalid"
                                         " file_limit value for -F option.");
            }
            break;
        case 'p':
            if (isNumerical(strdup(optarg))) {
                req->rLimits[LSF_RLIMIT_PROCESS]=vishnu::convertToInt(strdup(optarg));
            }  else {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+std::string(strdup(optarg))+" is an invalid"
                                         " process_limit value for -p option.");
            }
            break;
        case 'M':
            if (isNumerical(strdup(optarg))) {
                req->rLimits[LSF_RLIMIT_RSS]=vishnu::convertToInt(strdup(optarg));
            }  else {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+std::string(strdup(optarg))+" is an invalid"
                                         " mem_limit value for -M option.");
            }
            break;
        case 'D':
            if (isNumerical(strdup(optarg))) {
                req->rLimits[LSF_RLIMIT_DATA]=vishnu::convertToInt(strdup(optarg));
            }  else {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+std::string(strdup(optarg))+" is an invalid"
                                         " data_limit value for -D option.");
            }
            break;
        case 'S':
            if (isNumerical(strdup(optarg))) {
                req->rLimits[LSF_RLIMIT_STACK]=vishnu::convertToInt(strdup(optarg));
            }  else {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+std::string(strdup(optarg))+" is an invalid"
                                         " stack_limit value for -S option.");
            }
            break;
        case 'v':
            if (isNumerical(strdup(optarg))) {
                req->rLimits[LSF_RLIMIT_SWAP]=vishnu::convertToInt(strdup(optarg));
            }  else {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+std::string(strdup(optarg))+" is an invalid"
                                         " swap_limit value for -v option.");
            }
            break;
        case 'T':
            if (isNumerical(strdup(optarg))) {
                req->rLimits[LSF_RLIMIT_THREAD]=vishnu::convertToInt(strdup(optarg));
            }  else {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+std::string(strdup(optarg))+" is an invalid"
                                         " thread_limit value for -T option.");
            }
            break;
        case 'b':
            req->beginTime = convertDateToTime(strdup(optarg), " See LSF manual for -b option.");
            break;
        case 't':
            req->termTime = convertDateToTime(strdup(optarg), " See LSF manual for -t option.");
            break;
        case 'f':
            //-f "lfile op [rfile]"
            xFileStr = strdup(optarg);
            xFile_tokens = getStreamTokens(xFileStr);

            if (xFile_tokens.size() < 2) {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+xFileStr+" is an invalid"
                                         " file transfer value for -f option. This must be taken at least two arguments ");
            } else {

                if (req->nxf > 0) {
                    oldNxf=req->nxf;
                    tmpXfile = new xFile[req->nxf];
                    for(int i=0; i < oldNxf; ++i) {
                        tmpXfile[i]=req->xf[i];
                    }
                    delete [] req->xf;
                    req->nxf +=1;
                    req->xf = new xFile[req->nxf];
                    for(int i=0; i < oldNxf; ++i) {
                        req->xf[i]=tmpXfile[i];
                    }
                    delete [] tmpXfile;

                } else {
                    oldNxf=0;
                    req->nxf =1;
                    req->xf = new xFile[req->nxf];
                }

                req->xf[oldNxf].subFn = strdup(xFile_tokens[0].c_str());
                if (xFile_tokens[1]==">") {
                    req->xf[oldNxf].options = XF_OP_SUB2EXEC;
                }
                else if (xFile_tokens[1]=="<") {
                    req->xf[oldNxf].options = XF_OP_EXEC2SUB;
                }
                else if (xFile_tokens[1]=="<<") {
                    req->xf[oldNxf].options = XF_OP_EXEC2SUB_APPEND;
                }
                else if (xFile_tokens[1]=="><") {
                    req->xf[oldNxf].options = (XF_OP_SUB2EXEC | XF_OP_EXEC2SUB);
                }
                else if (xFile_tokens[1]=="<>") {
                    req->xf[oldNxf].options = (XF_OP_SUB2EXEC | XF_OP_EXEC2SUB);
                } else {
                    throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+xFile_tokens[1]+" is an invalid"
                                             " file transfer operator for -f option. See LSF manual.");
                }

                if (xFile_tokens.size() >=3) {
                    req->xf[oldNxf].execFn = strdup(xFile_tokens[2].c_str());
                }
            }
            break;
        case 'Q':
            req->options3 |= SUB3_JOB_REQUEUE;
            req->requeueEValues = strdup(optarg);
            break;
        case 's':
            if (isNumerical(strdup(optarg))) {
                req->sigValue = vishnu::convertToInt(strdup(optarg));
            } else {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+std::string(strdup(optarg))+" is an invalid"
                                         " job migration threshold value for -s option.");
            }
            break;
        case LONG_OPT_APP:
            req->options3 |= SUB3_APP;
            req->app= strdup(optarg);
            break;
        case LONG_OPT_CWD:
            req->options3 |= SUB3_CWD;
            req->cwd= strdup(optarg);
            break;
        case LONG_OPT_UL:
            req->options3 |= SUB3_USER_SHELL_LIMITS;
            break;
        case LONG_OPT_WE:
            req->options3 |= SUB3_RUNTIME_ESTIMATION;
            timeStr = strdup(optarg);
            if (timeStr.find("/")!=std::string::npos) {
                if ((timeStr.find("/")+1)!=std::string::npos) {
                    req->options |= SUB_HOST_SPEC;
                    req->runtimeEstimation = convertWallTimeToTime(timeStr.substr(0, timeStr.find("/")));
                    wHostSpec = timeStr.substr(timeStr.find("/")+1);
                    req->hostSpec = strdup(wHostSpec.c_str());
                }
            } else {
                req->runtimeEstimation = convertWallTimeToTime(timeStr);
            }
            break;
        case LONG_OPT_RN:
            req->options3 |= SUB3_NOT_RERUNNABLE;
            if ((req->options & SUB_RERUNNABLE)==SUB_RERUNNABLE) {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+" You cannot set a job to be rerunnable"
                                         "and not-rerunnable at the same time");
            }
            break;
        case LONG_OPT_JD:
            req->options3 |= SUB3_JOB_DESCRIPTION;
            req->jobDescription = strdup(optarg);
            break;
        case LONG_OPT_IS:
            if ((req->options & SUB_IN_FILE)==SUB_IN_FILE) {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+" is|i options are exclusive");
            }
            req->options |=SUB_IN_FILE;
            req->options2 |=SUB2_IN_FILE_SPOOL;
            req->inFile = strdup(optarg);
            break;
        case LONG_OPT_EO:
            req->options |=SUB_ERR_FILE;
            req->options2 |= SUB2_OVERWRITE_ERR_FILE;
            req->errFile = strdup(optarg);
            break;
        case LONG_OPT_OO:
            req->options |=SUB_OUT_FILE;
            req->options2 |= SUB2_OVERWRITE_OUT_FILE;
            req->outFile = strdup(optarg);
            break;
        case LONG_OPT_AR:
            req->options3 |= SUB3_AUTO_RESIZE;
            break;
        case LONG_OPT_WA:
            req->options2 |=SUB2_WARNING_ACTION;
            req->warningAction = strdup(optarg);
            break;
        case LONG_OPT_WT:
            req->options2 |= SUB2_WARNING_TIME_PERIOD;
            req->warningTimePeriod = convertWallTimeToTime(strdup(optarg), "Is an invalid"
                                     " job action warning time  value for -wt option.");
            break;
        case LONG_OPT_ZS:
            throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+" -Zs is not supported for VISHNU"
                                     " because LSF is unable to determine the first command"
                                     " to be spooled in an embedded job command"
                                     "(VISHNU job is considered by LSF as embedded job commands)");
            break;
        case LONG_OPT_EP:
            req->options3 |= SUB3_POST_EXEC;
            req->postExecCmd = strdup(optarg);
            break;
        case LONG_OPT_SP:
            req->options2 |= SUB2_JOB_PRIORITY;
            if (isNumerical(strdup(optarg))) {
                req->userPriority =  vishnu::convertToInt(strdup(optarg));
            } else {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+std::string(strdup(optarg))+" is an invalid"
                                         " job priority value for -sp option.");
            }
            break;
        case LONG_OPT_MIG:
            req->options3 |=SUB3_MIG_THRESHOLD;
            if (isNumerical(strdup(optarg))) {
                req->migThreshold = vishnu::convertToInt(strdup(optarg));
            } else {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+std::string(strdup(optarg))+" is an invalid"
                                         " job migration threshold value for -mig option.");
            }
            break;
        case LONG_OPT_SLA:
            req->options2 |=SUB2_SLA;
            req->sla = strdup(optarg);
            break;
        case LONG_OPT_EXT:
            req->options2 |=SUB2_EXTSCHED;
            req->extsched = strdup(optarg);
            break;
        case LONG_OPT_LP:
            req->options2 |=SUB2_LICENSE_PROJECT;
            req->licenseProject = strdup(optarg);
            break;
        case LONG_OPT_JSDL:
            if (req->jsdlFlag == 0) {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+" conflict: you cannot set jsdl"
                                         " and jsdl_strict at the same time");
            }
            req->jsdlFlag = 1;
            req->jsdlDoc = strdup(optarg);
            break;
        case LONG_OPT_JSDL_STRICT:
            if (req->jsdlFlag == 1) {
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+" conflict: you cannot set jsdl"
                                         " and jsdl_strict at the same time");
            }
            req->jsdlFlag = 0;
            req->jsdlDoc = strdup(optarg);
            break;
        case LONG_OPT_RNC:
            req->options3 |=SUB3_RESIZE_NOTIFY_CMD;
            req->notifyCmd = strdup(optarg);
            break;
        case LONG_OPT_XF:
            throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+" option -XF is "
                                     " not treated by VISHNU.");
            break;
        case LONG_OPT_I:
        case LONG_OPT_Ip:
        case LONG_OPT_Is:
        case LONG_OPT_IS2:
        case LONG_OPT_ISp:
        case LONG_OPT_ISs:
        case LONG_OPT_IX:
            throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+" LSF batch interactive job "
                                     "option "+std::string(argv[optind-1])+" is not supported by VISHNU");
            break;
        default:
            throw UMSVishnuException(ERRCODE_INVALID_PARAM, errHead+"Invalid option: "
                                     +std::string(argv[optind-1]));
            break;
        }
Exemplo n.º 29
0
std::vector<std::string>
LSFParser::convertScriptIntoArgv(const char* pathTofile,
                                 const std::string& BATCH_PREFIX) {
    std::ifstream fileStream;
    std::string line;

    fileStream.open (pathTofile);

    std::string cmd;
    std::vector<std::string> tokens;
    std::string tmpLine="";
    size_t escapePos;
    bool escapeFound = false;

    if (fileStream.is_open()) {
        while (!fileStream.eof()) {

            getline(fileStream, line);

            //Treating of the escape character int the script content
            if (boost::algorithm::ends_with(boost::algorithm::erase_all_copy(line, " "),"\\")) {
                escapePos = line.rfind("\\");
                if (escapePos!=std::string::npos) {
                    tmpLine += line.substr(0, escapePos);
                    escapeFound = true;
                    continue;
                }
            }

            if (escapeFound) {
                tmpLine +=line;
                line = tmpLine;
                escapeFound = false;
                tmpLine = "";
            }

            // erase all white space until # (excluded)
            while(boost::algorithm::starts_with(line, " ")) {
                line.erase(0,1);
            };

            /*search # character*/
            size_t pos = line.find('#');
            if (pos == std::string::npos) {
                continue;
            }

            if (boost::algorithm::starts_with(boost::algorithm::erase_all_copy(line," "), BATCH_PREFIX)) {

                pos = line.find(BATCH_PREFIX.substr(1));//skip the character # in  BATCH_PREFIX
                line = line.substr(pos+BATCH_PREFIX.size()-1);

                //To skip a comment on the line
                pos = line.find('#');
                if (pos != std::string::npos) {
                    if (pos-1 >=0) {
                        std::string tmp = line.substr(pos-1);
                        if (boost::algorithm::starts_with(boost::algorithm::erase_all_copy(tmp, " "), "#")) {
                            line = line.substr(0, pos);
                        }
                    } else {
                        line = line.substr(0, pos);
                    }
                }
                //verify quote characters in line
                verifyQuotaCharacter(line, '\"');
                verifyQuotaCharacter(line, '\'');
                //add line to cmd
                cmd = cmd+" "+line;
            }
        }
        fileStream.close();

        std::istringstream iss(cmd);
        std::copy(std::istream_iterator<std::string>(iss),
                  std::istream_iterator<std::string>(),
                  std::back_inserter<std::vector<std::string> >(tokens));

    }

    std::string argvStr;
    std::vector<std::string>::iterator iter;
    std::vector<std::string>::iterator end = tokens.end();
    std::vector<std::string> tokensArgs;
    char quote = '\0';
    for(iter=tokens.begin(); iter!=end; ++iter) {
        argvStr = *iter;
        if (isStartByQuote(argvStr, '\"')) {
            quote = '\"';
        } else if (isStartByQuote(argvStr, '\'')) {
            quote = '\'';
        }
        if (quote!='\0') {
            std::vector<std::string>::iterator found_iter;
            std::vector<std::string>::iterator beg_iter=iter;
            found_iter = std::find_if(beg_iter, end, IsEndByQuote(quote));
            if (found_iter!=end) {
                while(beg_iter!=found_iter) {
                    ++beg_iter;
                    argvStr = argvStr+" "+*beg_iter;
                }
                iter=beg_iter;
            } else {
                std::string errorMsg = "Error: invalid argument "+argvStr;
                errorMsg +=". It must be closed by the character quote character (\' or \")";
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errorMsg);
            }
        }
        quote='\0';
        if (!cleanString(argvStr, '\"')) {
            cleanString(argvStr, '\'');
        }
        tokensArgs.push_back(argvStr);
    }

    return tokensArgs;
}
Exemplo n.º 30
0
time_t
LSFParser::convertDateToTime(const std::string& date, const std::string& compErrMsg) {

    time_t totalTime;
    time_t timeNow;
    struct tm totalTimeTm;
    struct tm *timeNowTm;
    int minute = -1;
    int hour   = -1;
    int day    = -1;
    int month  = -1;
    int year   = -1;
    bool hasDayField   = false;
    bool hasMonthField = false;
    bool hasYearField  = false;

    std::string errMsg = "illegal date option value "+date+":";
    std::vector<std::string> tokens = getTimeToKens(date);
    for(std::vector<std::string>::iterator iter = tokens.begin(); iter!=tokens.end(); ++iter) {
        if (!isNumerical(*iter)) {
            errMsg += " The fields values must be intergers.";
            throw UMSVishnuException(ERRCODE_INVALID_PARAM, errMsg+" "+compErrMsg);
        }
    }

    if (tokens.size() < 2) {
        errMsg += " At least two fields must be specified.";
        throw UMSVishnuException(ERRCODE_INVALID_PARAM, errMsg+" "+compErrMsg);
    } else {

        //minute
        minute = vishnu::convertToInt(tokens[0]);
        if (minute < 0 || minute > 59) {
            errMsg += " minute number range must be 0-59.";
            throw UMSVishnuException(ERRCODE_INVALID_PARAM, errMsg+" "+compErrMsg);
        }
        //hour
        hour = vishnu::convertToInt(tokens[1]);
        if (hour < 0 || hour > 23) {
            errMsg += " hour number range must be 0-23.";
            throw UMSVishnuException(ERRCODE_INVALID_PARAM, errMsg+" "+compErrMsg);
        }
        //day
        if (tokens.size() >= 3) {
            day = vishnu::convertToInt(tokens[2]);
            if (day < 1 || day > 31) {
                errMsg += " day number range must be 1-31.";
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errMsg+" "+compErrMsg);
            }
            hasDayField = true;
        }
        //month
        if (tokens.size() >= 4) {
            month = vishnu::convertToInt(tokens[3]);
            if (month < 1 || month > 12) {
                errMsg += " month number range must be 1-31.";
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errMsg+" "+compErrMsg);
            }
            hasMonthField = true;
        }
        //year
        if (tokens.size() >= 5) {
            year = vishnu::convertToInt(tokens[4]);
            if (year < 1970) {
                errMsg += " year must after 1970.";
                throw UMSVishnuException(ERRCODE_INVALID_PARAM, errMsg+" "+compErrMsg);
            }
            hasYearField = true;
        }
    }

    timeNow = std::time(NULL);
    timeNowTm = std::localtime(&timeNow);

    totalTimeTm.tm_min = minute;
    totalTimeTm.tm_hour = hour;
    //day
    if (hasDayField) {
        totalTimeTm.tm_mday = day;
    } else {
        if ((hour < timeNowTm->tm_hour)|| (hour==timeNowTm->tm_hour && minute < timeNowTm->tm_min))
        {
            totalTimeTm.tm_mday = timeNowTm->tm_mday+1;
        } else {
            totalTimeTm.tm_mday = timeNowTm->tm_mday;
        }
    }
    //month
    if (hasMonthField) {
        totalTimeTm.tm_mon = month-1;
    } else {
        if ((day!=-1 && (day < timeNowTm->tm_mday))
                || (day==timeNowTm->tm_mday && hour < timeNowTm->tm_hour)
                || (day==timeNowTm->tm_mday && hour==timeNowTm->tm_hour && minute < timeNowTm->tm_min))
        {
            totalTimeTm.tm_mon = timeNowTm->tm_mon+1;
        } else {
            totalTimeTm.tm_mon = timeNowTm->tm_mon;
        }
    }
    //month
    if (hasYearField) {
        totalTimeTm.tm_year = year-1900;
    } else {
        if ((month!=-1 && ((month-1) < timeNowTm->tm_mon))
                ||((month-1)==timeNowTm->tm_mon && day < timeNowTm->tm_mday)
                || ((month-1)==timeNowTm->tm_mon && day==timeNowTm->tm_mday && hour < timeNowTm->tm_hour)
                || ((month-1)==timeNowTm->tm_mon && day==timeNowTm->tm_mday
                    && hour==timeNowTm->tm_hour && minute < timeNowTm->tm_min))
        {
            totalTimeTm.tm_year = timeNowTm->tm_year+1;
        } else {
            totalTimeTm.tm_year = timeNowTm->tm_year;
        }
    }

    totalTimeTm.tm_sec = 0;
    totalTimeTm.tm_isdst = -1;
    totalTime = std::mktime(&totalTimeTm);

    return totalTime;
}