This commit is contained in:
Chenling Zhang 2017-09-11 17:39:42 +08:00
Родитель b3fcc87d75
Коммит 09dd23127b
3 изменённых файлов: 37 добавлений и 38 удалений

Просмотреть файл

@ -39,8 +39,7 @@ Process::Process(
workDirectory(workDir), userName(user.empty() ? "root" : user), dumpStdout(dumpStdoutToExecutionMessage),
affinity(cpuAffinity), environments(envi), callback(completed), processId(0)
{
this->streamOutput = boost::algorithm::starts_with(stdOutFile, "http://") ||
boost::algorithm::starts_with(stdOutFile, "https://");
this->streamOutput = StartWithHttpOrHttps(stdOutFile);
Logger::Debug(this->jobId, this->taskId, this->requeueCount, "{0}, stream ? {1}", stdOutFile, this->streamOutput);
}
@ -528,28 +527,15 @@ std::string Process::BuildScript()
std::ofstream fs(runDirInOut, std::ios::trunc);
fs << "#!/bin/bash" << std::endl << std::endl;
fs << "cd ";
Logger::Debug("{0}, {1}", this->taskFolder, this->workDirectory);
if (this->workDirectory.empty())
{
fs << this->taskFolder;
}
else
{
fs << this->workDirectory;
}
fs << " || exit $?";
fs << std::endl << std::endl;
std::string workDirectory = this->workDirectory.empty() ? this->taskFolder : this->workDirectory;
fs << "cd " << workDirectory << " || exit $?" << std::endl << std::endl;
if (!this->streamOutput)
{
if (this->stdOutFile.empty()) this->stdOutFile = this->taskFolder + "/stdout.txt";
else if (!boost::algorithm::starts_with(this->stdOutFile, "/") && !StartWithHttpOrHttps(this->stdOutFile)) this->stdOutFile = workDirectory + "/" + this->stdOutFile;
if (this->stdErrFile.empty()) this->stdErrFile = this->taskFolder + "/stderr.txt";
if (!boost::algorithm::starts_with(this->stdOutFile, "/")) this->stdOutFile = this->taskFolder + "/" + this->stdOutFile;
if (!boost::algorithm::starts_with(this->stdErrFile, "/")) this->stdErrFile = this->taskFolder + "/" + this->stdErrFile;
}
else if (!boost::algorithm::starts_with(this->stdErrFile, "/") && !StartWithHttpOrHttps(this->stdErrFile)) this->stdErrFile = workDirectory + "/" + this->stdErrFile;
// before
fs << "echo before >" << this->taskFolder << "/before1.txt 2>" << this->taskFolder << "/before2.txt";
@ -638,25 +624,33 @@ std::unique_ptr<const char* []> Process::PrepareEnvironment()
std::string Process::PeekOutput()
{
std::string output;
int ret = 0;
std::string stdout;
ret = System::ExecuteCommandOut(stdout, "2>&1 tail -c 5000", this->stdOutFile);
ret = System::ExecuteCommandOut(stdout, "tail -c 5000 2>&1", this->stdOutFile);
if (ret != 0)
{
stdout = "Reading " + this->stdOutFile + " failed: " + stdout;
std::ostringstream stream;
stream << "Reading " << this->stdOutFile << " failed with exitcode " << ret << ": " << stdout;
stdout = stream.str();
}
if (this->stdOutFile == this->stdErrFile)
output = stdout;
if (this->stdOutFile != this->stdErrFile)
{
return stdout;
}
std::string stderr;
ret = System::ExecuteCommandOut(stderr, "2>&1 tail -c 5000", this->stdErrFile);
ret = System::ExecuteCommandOut(stderr, "tail -c 5000 2>&1", this->stdErrFile);
if (ret != 0)
{
stderr = "Reading " + this->stdErrFile + " failed: " + stderr;
std::ostringstream stream;
stream << "Reading " << this->stdErrFile << " failed with exitcode " << ret << ": " << stderr;
stderr = stream.str();
}
return "STDOUT:\n" + stdout + "\nSTDERR:\n" + stderr;
output = String::Join("\n", "STDOUT:", stdout, "STDERR:", stderr);
}
return output;
}

Просмотреть файл

@ -70,6 +70,11 @@ namespace hpc
protected:
private:
static bool StartWithHttpOrHttps(const std::string& path)
{
return boost::algorithm::starts_with(path, "http://") || boost::algorithm::starts_with(path, "https://");
}
void SetExitCode(int exitCode)
{
this->exitCode = exitCode;

Просмотреть файл

@ -746,7 +746,7 @@ pplx::task<json::value> RemoteExecutor::PeekTaskOutput(hpc::arguments::PeekTaskO
catch (const std::exception& ex)
{
Logger::Warn(args.JobId, args.TaskId, this->UnknowId, "Exception when peeking task output: {0}", ex.what());
output = "Failed to get the output.";
output = "NodeManager: Failed to get the output.";
}
return pplx::task_from_result(json::value::string(output));