Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ORNL Quantum Computing Institute
xacc
Commits
89da38ef
Commit
89da38ef
authored
Apr 10, 2018
by
Mccaskey, Alex
Browse files
improving http post mechanism in remoteaccelerator
Signed-off-by:
Alex McCaskey
<
mccaskeyaj@ornl.gov
>
parent
d85cbd97
Changes
2
Hide whitespace changes
Inline
Side-by-side
xacc/accelerator/remote/RemoteAccelerator.cpp
View file @
89da38ef
...
...
@@ -62,7 +62,7 @@ const std::string RestClient::get(const std::string& remoteUrl,
// get the result as a string
std
::
stringstream
z
;
z
<<
getResponse
.
get
().
extract_json
().
get
();
//
xacc::info("GET RESPONSE: " + z.str());
xacc
::
info
(
"GET RESPONSE: "
+
z
.
str
());
return
z
.
str
();
}
...
...
@@ -72,7 +72,7 @@ void RemoteAccelerator::execute(std::shared_ptr<AcceleratorBuffer> buffer,
auto
jsonPostStr
=
processInput
(
buffer
,
std
::
vector
<
std
::
shared_ptr
<
Function
>>
{
function
});
auto
responseStr
=
r
estClient
->
p
ost
(
remoteUrl
,
postPath
,
jsonPostStr
,
headers
);
auto
responseStr
=
handleExceptionR
estClient
P
ost
(
remoteUrl
,
postPath
,
jsonPostStr
,
headers
);
processResponse
(
buffer
,
responseStr
);
...
...
@@ -85,7 +85,7 @@ std::vector<std::shared_ptr<AcceleratorBuffer>> RemoteAccelerator::execute(
const
std
::
vector
<
std
::
shared_ptr
<
Function
>>
functions
)
{
auto
jsonPostStr
=
processInput
(
buffer
,
functions
);
auto
responseStr
=
r
estClient
->
p
ost
(
remoteUrl
,
postPath
,
jsonPostStr
,
headers
);
auto
responseStr
=
handleExceptionR
estClient
P
ost
(
remoteUrl
,
postPath
,
jsonPostStr
,
headers
);
return
processResponse
(
buffer
,
responseStr
);
}
...
...
xacc/accelerator/remote/RemoteAccelerator.hpp
View file @
89da38ef
...
...
@@ -105,6 +105,68 @@ protected:
std
::
shared_ptr
<
AcceleratorBuffer
>
buffer
,
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
;
}
};
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment