Commit 669796e0 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

work to switch to restclient-cpp


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 89da38ef
......@@ -74,33 +74,41 @@ ExternalProject_Add(cppmicroservices
# Make it so you don't always have to
# specify openssl dir on mac
if(APPLE AND NOT OPENSSL_ROOT_DIR)
if (EXISTS /usr/local/opt/openssl)
message(STATUS "${BoldGreen}[OSX] Searching for OpenSSL from /usr/local/opt/openssl. Override with -DOPENSSL_ROOT_DIR=...${ColorReset}")
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)
endif()
elseif(EXISTS /etc/redhat-release AND NOT OPENSSL_ROOT_DIR)
#if(APPLE AND NOT OPENSSL_ROOT_DIR)
# if (EXISTS /usr/local/opt/openssl)
# message(STATUS "${BoldGreen}[OSX] Searching for OpenSSL from /usr/local/opt/openssl. Override with -DOPENSSL_ROOT_DIR=...${ColorReset}")
# set(OPENSSL_ROOT_DIR /usr/local/opt/openssl)
# endif()
#elseif(EXISTS /etc/redhat-release AND NOT OPENSSL_ROOT_DIR)
# we are on fedora... check for custom openssl install
# in /usr/local/ssl
if (EXISTS /usr/local/ssl)
message(STATUS "${BoldGreen}[Fedora] Searching for OpenSSL from /usr/local/ssl. Override with -DOPENSSL_ROOT_DIR=...${ColorReset}")
set(OPENSSL_ROOT_DIR /usr/local/ssl)
endif()
endif()
find_package(OpenSSL 1.0.2 REQUIRED)
message(STATUS "${BoldGreen}Found OpenSSL version ${OPENSSL_VERSION}${ColorReset} at ${OPENSSL_ROOT_DIR}")
ExternalProject_Add(cpprestsdk
# if (EXISTS /usr/local/ssl)
# message(STATUS "${BoldGreen}[Fedora] Searching for OpenSSL from /usr/local/ssl. Override with -DOPENSSL_ROOT_DIR=...${ColorReset}")
# set(OPENSSL_ROOT_DIR /usr/local/ssl)
# endif()
#endif()
#find_package(OpenSSL 1.0.2 REQUIRED)
#message(STATUS "${BoldGreen}Found OpenSSL version ${OPENSSL_VERSION}${ColorReset} at ${OPENSSL_ROOT_DIR}")
#ExternalProject_Add(cpprestsdk
# DEPENDS cppmicroservices
# GIT_REPOSITORY https://github.com/Microsoft/cpprestsdk
# GIT_TAG master
# CONFIGURE_COMMAND ${CMAKE_COMMAND} ../cpprestsdk/Release/ -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
# -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
# -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
# -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
# -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
# -DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR}
# -DBUILD_TESTS=OFF
# INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install
#)
ExternalProject_Add(restclient-cpp
DEPENDS cppmicroservices
GIT_REPOSITORY https://github.com/Microsoft/cpprestsdk
GIT_REPOSITORY https://github.com/mrtazz/restclient-cpp
GIT_TAG master
CONFIGURE_COMMAND ${CMAKE_COMMAND} ../cpprestsdk/Release/ -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR}
-DBUILD_TESTS=OFF
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND sh autogen.sh && sh ./configure CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} --prefix=${CMAKE_INSTALL_PREFIX}
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install
)
......@@ -122,7 +130,7 @@ if(PYTHONLIBS_FOUND)
endif()
ExternalProject_Add(xacc-core
DEPENDS cppmicroservices cpprestsdk
DEPENDS cppmicroservices restclient-cpp
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xacc
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
......@@ -137,10 +145,10 @@ ExternalProject_Add(xacc-core
-DXACC_PYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR}
-DXACC_PYTHON_LIBRARIES=${PYTHON_LIBRARIES}
-DPYBIND11_DIR=${CMAKE_SOURCE_DIR}/python/pybind11
-DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR}
-DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
-DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES}
-DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
# -DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR}
# -DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
# -DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES}
# -DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
BUILD_ALWAYS 1
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install # DESTDIR=${CMAKE_BINARY_DIR}/stage
......@@ -166,10 +174,10 @@ ExternalProject_Add(xacc-quantum
-DCPPUS_LIBRARY_DIR=${CppMicroServices_LIBRARY_DIR}
-DXACC_INCLUDE_DIR=${CMAKE_INSTALL_PREFIX}/include/xacc
-DXACC_LIBRARY_DIR=${CMAKE_INSTALL_PREFIX}/lib
-DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR}
-DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
-DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES}
-DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
# -DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR}
# -DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
# -DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES}
# -DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
BUILD_ALWAYS 1
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install #DESTDIR=${CMAKE_BINARY_DIR}/stage
......@@ -193,10 +201,10 @@ ExternalProject_Add(xacc-python
-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
-DFROM_SETUP_PY=${FROM_SETUP_PY}
-DXACC_PYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIR}
-DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR}
-DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
-DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES}
-DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
# -DCppRSDK_INCLUDE_DIR=${CppRSDK_INCLUDE_DIR}
# -DOPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}
# -DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES}
# -DOPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
CMAKE_CACHE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
BUILD_ALWAYS 1
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install #DESTDIR=${CMAKE_BINARY_DIR}/stage
......
......@@ -13,4 +13,4 @@ set (XACC_INCLUDE_DIRS "${XACC_ROOT}/include/cppmicroservices3;${XACC_ROOT}/incl
set (XACC_LIBRARY_DIR "${XACC_ROOT}/lib")
set(CppUsLib CppMicroServicesd)
link_directories("${XACC_ROOT}/lib")
set (XACC_LIBRARIES "xacc;CppMicroServices;cpprest;@OPENSSL_LIBRARIES@")
set (XACC_LIBRARIES "xacc;CppMicroServices;restclient-cpp")
......@@ -51,7 +51,7 @@ link_directories(${Boost_LIBRARY_DIR})
#if (NOT cppus_has_d_suffix)
# set(CppUsLib CppMicroServices)
#endif()
target_link_libraries(pyxacc ${PYTHON_LIBRARY} xacc xacc-quantum-gate xacc-quantum-aqc CppMicroServices ${Boost_LIBRARIES} cpprest ${OPENSSL_LIBRARIES})
target_link_libraries(pyxacc ${PYTHON_LIBRARY} xacc xacc-quantum-gate xacc-quantum-aqc CppMicroServices ${Boost_LIBRARIES} restclient-cpp) #cpprest ${OPENSSL_LIBRARIES})
if(APPLE)
set_target_properties(pyxacc PROPERTIES INSTALL_RPATH "@loader_path/lib")
......
......@@ -45,8 +45,8 @@ include_directories(${CMAKE_BINARY_DIR})
link_directories(${XACC_LIBRARY_DIR})
link_directories(${CPPUS_LIBRARY_DIR})
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${CppRSDK_INCLUDE_DIR})
#include_directories(${OPENSSL_INCLUDE_DIR})
#include_directories(${CppRSDK_INCLUDE_DIR})
add_subdirectory(gate)
add_subdirectory(aqc)
......@@ -60,7 +60,7 @@ find_library(cppus_has_d_suffix CppMicroServicesd)
if (NOT cppus_has_d_suffix)
set(CppUsLib CppMicroServices)
endif()
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} ${CppUsLib} xacc cpprest ${OPENSSL_LIBRARIES})
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} ${CppUsLib} xacc restclient-cpp) #cpprest ${OPENSSL_LIBRARIES})
add_subdirectory(ir)
add_subdirectory(compiler)
......
......@@ -12,5 +12,5 @@
# *******************************************************************************/
# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};${Boost_LIBRARIES};dl;pthread;xacc-quantum-aqc;xacc;cpprest;${OPENSSL_LIBRARIES}")
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};${Boost_LIBRARIES};dl;pthread;xacc-quantum-aqc;xacc;restclient-cpp")#rest;${OPENSSL_LIBRARIES}")
......@@ -12,5 +12,5 @@
# *******************************************************************************/
# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${Boost_LIBRARIES};xacc;cpprest;${OPENSSL_LIBRARIES}")
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${Boost_LIBRARIES};xacc;restclient-cpp")#rest;${OPENSSL_LIBRARIES}")
......@@ -64,7 +64,7 @@ find_library(cppus_has_d_suffix CppMicroServicesd)
if (NOT cppus_has_d_suffix)
set(CppUsLib CppMicroServices)
endif()
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} xacc ${CppUsLib} cpprest ${OPENSSL_LIBRARIES})
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} xacc ${CppUsLib} restclient-cpp) #cpprest ${OPENSSL_LIBRARIES})
add_subdirectory(compiler)
add_subdirectory(ir)
......
......@@ -12,5 +12,5 @@
# *******************************************************************************/
# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${Boost_LIBRARIES};xacc-quantum-gate;xacc;cpprest;${OPENSSL_LIBRARIES}")
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${Boost_LIBRARIES};xacc-quantum-gate;xacc;restclient-cpp")#rest;${OPENSSL_LIBRARIES}")
......@@ -13,5 +13,5 @@
# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};${Boost_LIBRARIES};xacc;xacc-quantum-gate;cpprest;${OPENSSL_LIBRARIES}")
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};${Boost_LIBRARIES};xacc;xacc-quantum-gate;restclient-cpp")#rest;${OPENSSL_LIBRARIES}")
......@@ -14,6 +14,6 @@ include_directories(${CMAKE_SOURCE_DIR}/tpls/eigen)
# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${Boost_LIBRARIES};xacc;xacc-quantum-gate;cpprest;${OPENSSL_LIBRARIES}")
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${Boost_LIBRARIES};xacc;xacc-quantum-gate;restclient-cpp")#rest;${OPENSSL_LIBRARIES}")
......@@ -77,9 +77,9 @@ if (APPLE)
endif()
if(PythonLibs_FOUND)
target_link_libraries(${LIBRARY_NAME} ${PYTHON_LIBRARY} ${Boost_LIBRARIES} ${CppUsLib} ${OPENSSL_LIBRARIES} cpprest)
target_link_libraries(${LIBRARY_NAME} ${PYTHON_LIBRARY} ${Boost_LIBRARIES} ${CppUsLib} restclient-cpp)
else()
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} ${CppUsLib} ${OPENSSL_LIBRARIES} cpprest)
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} ${CppUsLib} restclient-cpp)
endif()
# Get the test files
......
......@@ -13,57 +13,37 @@
#include "RemoteAccelerator.hpp"
namespace xacc {
const std::string RestClient::post(const std::string& remoteUrl,
const std::string Client::post(const std::string& remoteUrl,
const std::string& path, const std::string& postStr,
std::map<std::string, std::string> headers) {
using namespace RestClient;
init();
Connection* conn = new Connection(remoteUrl);
HeaderFields _headers;
if (headers.empty()) {
headers.insert(std::make_pair("Content-type", "application/json"));
headers.insert(std::make_pair("Connection", "keep-alive"));
headers.insert(std::make_pair("Accept", "*/*"));
}
http::uri uri = http::uri(remoteUrl);
http_client_config config;
config.set_validate_certificates(false);
http_client postClient(
http::uri_builder(uri).append_path(U(path)).to_uri(), config);
http_request postRequest(methods::POST);
for (auto& kv : headers) {
postRequest.headers().add(kv.first, kv.second);
_headers[kv.first] = kv.second;
}
postRequest.set_body(postStr);
// xacc::info("POSTING: " + postStr + " to " + remoteUrl + ", " + path);// << "\n";
// Post the problem, get the response as json
auto postResponse = postClient.request(postRequest);
auto respJson = postResponse.get().extract_string().get();
// Map that response to a string
std::stringstream ss;
ss << respJson;
// xacc::info("post response was " + ss.str());// << "\n";
return ss.str();
conn->SetHeaders(headers);
Response r = conn->post(path, postStr);
if (r.code != 200) throw std::runtime_error("HTTP POST Error");
delete conn;
disable();
return r.body;
}
const std::string RestClient::get(const std::string& remoteUrl,
const std::string Client::get(const std::string& remoteUrl,
const std::string& path, std::map<std::string, std::string> headers) {
http_client_config config;
config.set_validate_certificates(false);
http_client getClient(
http::uri_builder(http::uri(remoteUrl)).append_path(U(path)).to_uri(), config);
http_request getRequest(methods::GET);
for (auto& kv : headers) {
getRequest.headers().add(kv.first, kv.second);
}
// xacc::info("Getting IBM at " + remoteUrl + ", " + path);
auto getResponse = getClient.request(getRequest);
// get the result as a string
std::stringstream z;
z << getResponse.get().extract_json().get();
xacc::info("GET RESPONSE: " + z.str());
return z.str();
using namespace RestClient;
Response r = RestClient::get(remoteUrl+path);
if (r.code != 200) throw std::runtime_error("HTTP GET Error");
return r.body;
}
void RemoteAccelerator::execute(std::shared_ptr<AcceleratorBuffer> buffer,
......
......@@ -15,19 +15,12 @@
#include "Accelerator.hpp"
#include "XACC.hpp"
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
using namespace utility;
using namespace web;
using namespace web::http;
using namespace web::http::client;
using namespace concurrency::streams;
#include "restclient-cpp/connection.h"
#include "restclient-cpp/restclient.h"
namespace xacc {
class RestClient {
class Client {
public:
......@@ -41,7 +34,7 @@ public:
std::map<std::string, std::string> headers = std::map<std::string,
std::string> { });
virtual ~RestClient() {}
virtual ~Client() {}
};
......@@ -50,9 +43,9 @@ class RemoteAccelerator : public Accelerator {
public:
RemoteAccelerator() : Accelerator(), restClient(std::make_shared<RestClient>()) {}
RemoteAccelerator() : Accelerator(), restClient(std::make_shared<Client>()) {}
RemoteAccelerator(std::shared_ptr<RestClient> client) : restClient(client) {}
RemoteAccelerator(std::shared_ptr<Client> client) : restClient(client) {}
/**
......@@ -84,7 +77,7 @@ public:
protected:
std::shared_ptr<RestClient> restClient;
std::shared_ptr<Client> restClient;
std::string postPath;
......
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