Ejemplo n.º 1
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();

}
Ejemplo n.º 2
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;
}