Example #1
0
/**
 * \brief Function to parse textual or file parameters
 * \param IN opt A structure containing the set of submitted options
 * \param OUT paramsStr a string containing all of parameters
 * \param IN paramOptName the name of the option for a single parameter
 * \param IN paramsVector a vector of parameters
 * \return true if all parameters are syntaxicaly valid
 */
int
vishnu::validateParameters(const boost::shared_ptr<Options> & opt,
                           std::string & paramsStr,
                           const std::string & paramOptName,
                           const ListStrings & paramsVector){

  if( opt->count(paramOptName) ){
    paramsStr = opt->get< std::string >(paramOptName) ;
  }

  // Append other parameters in paramStr
  for(ListStrings::const_iterator it = paramsVector.begin(); it != paramsVector.end() ; it++) {
    paramsStr += " " + *it ;
  }

  //Now check the syntax of parameters and set them suitable for VISHNU
  ListStrings paramsVecBuffer ;
  boost::trim(paramsStr) ; boost::split(paramsVecBuffer, paramsStr, boost::is_any_of(" "), boost::token_compress_on);

  paramsStr = "" ; // Reinitialization for outpout
  for(ListStrings::iterator it = paramsVecBuffer.begin(); it != paramsVecBuffer.end() ; it++) {

    size_t pos = (*it).find("=") ;
    if( pos == 0 || pos == std::string::npos || pos == (*it).size() - 1 ){
      std::cerr << "Uncompleted definition for the parameter : '" << *it << "'"<< std::endl ;
      return CLI_ERROR_INVALID_PARAMETER;
    }

    std::string paramName = (*it).substr(0, pos) ; // Keep the parameter name in upper case
    std::string paramValue = (*it).substr(pos+1, std::string::npos) ;

    // Check whether the parameter is duplicate
    if( paramsStr.size() != 0) {
      size_t start = 0 ;
      while( pos = paramsStr.find(paramName+"=", start), pos != std::string::npos ){
        if( pos == 0 || paramsStr[pos-1] == char(' ') ) {
          std::cerr << "Duplicate parameter : '" << paramName << "'"<< std::endl ;
          return CLI_ERROR_INVALID_PARAMETER ;
        }
        start = pos + paramName.size() ;
      }
      paramsStr += " " ;
    }
    // Append the parameter
    paramsStr += paramName + "=" + paramValue ;
  }
  return 0 ;
}
Example #2
0
/**
 * \brief Function to create temporary file
 * \param fileName The name of the file to create
 * \param missingDesc The content of the file
 */
void
vishnu::recordMissingFiles(const std::string & fileName,
                           const std::string& missingDesc) {

  std::ofstream file;
  file.open(fileName.c_str());
  if (file.good()) {
    ListStrings missingFiles;
    boost::split(missingFiles, missingDesc, boost::is_space());
    int count = missingFiles.size();
    for(int i = 1; i < count; i++) {
      file << missingFiles[i] << "\n";
      //std::cout << missingFiles[i] << "\n";
    }
  }
  file.close();

}
Example #3
0
/**
 * \brief function to set parameters appearing in a script
 * \param scriptContent The string to modify
 * \param \param params a list of parameters in the form of PARAM1=value1  PARAM2=value2 ...
 */
void
vishnu::setParams(std::string& scriptContent,
                  const std::string & params) {
  std::string paramName;
  std::string paramValue;
  size_t pos;
  ListStrings paramsVec;

  std::string& refParams = const_cast<std::string&>(params);
  boost::trim(refParams);
  boost::split(paramsVec, refParams, boost::is_any_of(" "));
  for (ListStrings::iterator it = paramsVec.begin(); it != paramsVec.end(); ++it) {
    pos = it->find("=");
    if (pos != std::string::npos) {
      paramName = it->substr(0, pos);
      paramValue = it->substr(pos+1, std::string::npos);
      replaceAllOccurences(scriptContent, "$" + paramName, paramValue);
      replaceAllOccurences(scriptContent, "${" + paramName + "}", paramValue);
    }
  }
}
Example #4
0
/**
 * \brief Function to list file containing in a directory. Recursivity is not taken into account
 * \param lFiles a vector containing the set of files
 * \param fileNames the names of files containing in the directory
 * \param dirPath The path of the directory
 * Throw exception on error
 * */
void
vishnu::appendFilesFromDir(ListStrings& lFiles, std::ostringstream & fileNames, const std::string & dirPath) {

  if(dirPath.size() == 0 ||
		  ! bfs::exists(dirPath)) {
	  return ;
  }
  for( bfs::directory_iterator it(dirPath) ; it != bfs::directory_iterator() ; ++it ) {

    if ( bfs::is_directory( *it ) ) continue ;
    lFiles.push_back( it->path().string() ) ;
    fileNames << ((fileNames.str().size() != 0)? " " : "") + it->path().string() ;   //TODO Check if it's a absolute or a relative path
  }
}
Example #5
0
/**
 * \brief Function to get the job results
 * \param jobId The Id of the
 * \param options Object containing the user-provided options
 * \return The job results data structure
 */
TMS_Data::JobResult
JobOutputProxy::getJobOutPut(const std::string& jobId, const TMS_Data::JobOutputOptions& options) {

  std::string serviceName = boost::str(boost::format("%1%@%2%") % SERVICES_TMS[JOBOUTPUTGETRESULT]  %mmachineId);

  diet_profile_t* profile = diet_profile_alloc(serviceName, 4);
  string sessionKey = msessionProxy.getSessionKey();

  //IN Parameters
  TMS_Data::JobResult jobResult; jobResult.setJobId(jobId);
  std::string outputDir = options.getOutputDir();
  JsonObject optionsData(options);

  diet_string_set(profile,0, sessionKey);
  diet_string_set(profile,1, mmachineId);
  diet_string_set(profile,2, optionsData.encode());
  diet_string_set(profile, 3, jobId);

  //Call the Server
  if (diet_call(profile)) {
    raiseCommunicationMsgException("RPC call failed");
  }
  raiseExceptionOnErrorResult(profile);

  std::string remoteOutputInfo;
  diet_string_get(profile,1, remoteOutputInfo);

  if (remoteOutputInfo.empty()) {
    throw TMSVishnuException(ERRCODE_INVDATA, "Weird behavior: no output to retrieve");
  }

  if (! boost::starts_with(remoteOutputInfo, "/") ) {
    raiseExceptionIfNotEmptyMsg(remoteOutputInfo);
  }
  if (outputDir.empty()) {
    outputDir = boost::str(boost::format("%1%/VISHNU_DOWNLOAD_%2%")
                           % bfs::path(bfs::current_path()).string()
                           % vishnu::generatedUniquePatternFromCurTime(jobId));
    vishnu::createOutputDir(outputDir);
  }

  jobResult.setOutputDir(outputDir);

  FMS_Data::CpFileOptions copts;
  copts.setIsRecursive(true);
  copts.setTrCommand(0); // for using scp
  try {
    std::string downloadInfoFile = boost::str(boost::format("%1%/%2%")
                                              % outputDir
                                              % boost::filesystem::unique_path("vishnu-%%%%%%.dinfo").string());
    vishnu::genericFileCopier(sessionKey, mmachineId, remoteOutputInfo, "", downloadInfoFile, copts);
    istringstream fdescStream(vishnu::get_file_content(downloadInfoFile, false));
    string line;
    if(! getline(fdescStream, line)) {
      line = "";
    }
    boost::trim(line);
    ListStrings lineVec;
    boost::split(lineVec, line, boost::is_any_of(" "));
    int nbFiles = lineVec.size();

    std::string missingFileContent = "";
    if (! line.empty() && nbFiles > 0) {
      vishnu::copyFiles(sessionKey, mmachineId, lineVec, outputDir, copts, missingFileContent, 0);
      std::string fileName = bfs::basename(lineVec[0]) + bfs::extension(lineVec[0]);
      jobResult.setOutputPath(outputDir+"/"+fileName);
      std::string fileName2 = bfs::basename(lineVec[1]) + bfs::extension(lineVec[1]);
      jobResult.setErrorPath(outputDir+"/"+fileName2);
    }
    if (! missingFileContent.empty()) {
      std::string missingFileName = (boost::format("%1%/MISSINGFILES_%2%") % outputDir % jobId).str();
      vishnu::saveInFile(missingFileName, missingFileContent);
    }
  } catch (VishnuException &ex) {
    std::string errorFileName = (boost::format("%1%/ERROR_%2%") % outputDir % jobId).str();
    vishnu::saveInFile(errorFileName, ex.what());
  }

  diet_profile_free(profile);
  return jobResult;
}