Commit 89da38ef authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

improving http post mechanism in remoteaccelerator


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent d85cbd97
...@@ -62,7 +62,7 @@ const std::string RestClient::get(const std::string& remoteUrl, ...@@ -62,7 +62,7 @@ const std::string RestClient::get(const std::string& remoteUrl,
// get the result as a string // get the result as a string
std::stringstream z; std::stringstream z;
z << getResponse.get().extract_json().get(); z << getResponse.get().extract_json().get();
// xacc::info("GET RESPONSE: " + z.str()); xacc::info("GET RESPONSE: " + z.str());
return z.str(); return z.str();
} }
...@@ -72,7 +72,7 @@ void RemoteAccelerator::execute(std::shared_ptr<AcceleratorBuffer> buffer, ...@@ -72,7 +72,7 @@ void RemoteAccelerator::execute(std::shared_ptr<AcceleratorBuffer> buffer,
auto jsonPostStr = processInput(buffer, std::vector<std::shared_ptr<Function>> { auto jsonPostStr = processInput(buffer, std::vector<std::shared_ptr<Function>> {
function }); function });
auto responseStr = restClient->post(remoteUrl, postPath, jsonPostStr, headers); auto responseStr = handleExceptionRestClientPost(remoteUrl, postPath, jsonPostStr, headers);
processResponse(buffer, responseStr); processResponse(buffer, responseStr);
...@@ -85,7 +85,7 @@ std::vector<std::shared_ptr<AcceleratorBuffer>> RemoteAccelerator::execute( ...@@ -85,7 +85,7 @@ std::vector<std::shared_ptr<AcceleratorBuffer>> RemoteAccelerator::execute(
const std::vector<std::shared_ptr<Function>> functions) { const std::vector<std::shared_ptr<Function>> functions) {
auto jsonPostStr = processInput(buffer, functions); auto jsonPostStr = processInput(buffer, functions);
auto responseStr = restClient->post(remoteUrl, postPath, jsonPostStr, headers); auto responseStr = handleExceptionRestClientPost(remoteUrl, postPath, jsonPostStr, headers);
return processResponse(buffer, responseStr); return processResponse(buffer, responseStr);
} }
......
...@@ -105,6 +105,68 @@ protected: ...@@ -105,6 +105,68 @@ protected:
std::shared_ptr<AcceleratorBuffer> buffer, std::shared_ptr<AcceleratorBuffer> buffer,
const std::string& response) = 0; const std::string& response) = 0;
std::string handleExceptionRestClientPost(const std::string& _url, const std::string& path, const std::string& postStr,
std::map<std::string, std::string> headers) {
std::string postResponse;
int retries = 10;
std::exception ex;
bool succeeded = false;
// Execute HTTP Post
do {
try {
postResponse = restClient->post(_url, path, postStr, headers);
succeeded = true;
break;
} catch (std::exception& e) {
ex = e;
xacc::info("Remote Accelerator " + name() + " caught exception while calling restClient->post() "
"- " + std::string(e.what()));
retries--;
if (retries > 0) {
xacc::info("Retrying HTTP Get.");
}
}
} while (retries > 0);
if (!succeeded) {
xacc::error("Remote Accelerator " + name() + " failed HTTP Post for Job Response - " + std::string(ex.what()));
}
return postResponse;
}
std::string handleExceptionRestClientGet(const std::string& _url, const std::string& path) {
std::string getResponse;
int retries = 10;
std::exception ex;
bool succeeded = false;
// Execute HTTP Get
do {
try {
getResponse = restClient->get(_url, path);
succeeded = true;
break;
} catch (std::exception& e) {
ex = e;
xacc::info("Remote Accelerator " + name() + " caught exception while calling restClient->get() "
"- " + std::string(e.what()));
retries--;
if (retries > 0) {
xacc::info("Retrying HTTP Get.");
}
}
} while (retries > 0);
if (!succeeded) {
xacc::error("Remote Accelerator " + name() + " failed HTTP Get for Job Response - " + std::string(ex.what()));
}
return getResponse;
}
}; };
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment