Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/cuopt_self_hosted/cuopt_sh_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
mime_type,
set_log_level,
)
from .cuopt_web_hosted_client import (
CuOptServiceWebHostedClient,
create_client,
)
from .thin_client_solution import ThinClientSolution
from .thin_client_solver_settings import (
PDLPSolverMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,35 @@ def _handle_request_exception(self, response, reqId=None):
if reqId:
err += f"\nreqId: {reqId}"
return err, complete

def _make_http_request(self, method: str, url: str, **kwargs):
"""
Make HTTP request. Can be overridden by subclasses for authentication.

Parameters
----------
method : str
HTTP method (GET, POST, DELETE, etc.)
url : str
Request URL
**kwargs
Additional arguments passed to requests.request()

Returns
-------
requests.Response
HTTP response object
"""
return requests.request(method, url, **kwargs)

def _get_logs(self, reqId, logging_callback):
if logging_callback is None or not callable(logging_callback):
return
try:
headers = {"Accept": self.accept_type.value}
params = {"frombyte": self.loggedbytes}
response = requests.get(
response = self._make_http_request(
"GET",
self.log_url + f"/{reqId}",
verify=self.verify,
headers=headers,
Expand Down Expand Up @@ -415,7 +436,8 @@ def _get_incumbents(self, reqId, incumbent_callback):
return
try:
headers = {"Accept": self.accept_type.value}
response = requests.get(
response = self._make_http_request(
"GET",
self.solution_url + f"/{reqId}/incumbents",
verify=self.verify,
headers=headers,
Expand Down Expand Up @@ -524,7 +546,8 @@ def stop_threads(log_t, inc_t, done):
try:
log.debug(f"GET {self.solution_url}/{reqId}")
headers = {"Accept": self.accept_type.value}
response = requests.get(
response = self._make_http_request(
"GET",
self.solution_url + f"/{reqId}",
verify=self.verify,
headers=headers,
Expand Down Expand Up @@ -613,7 +636,8 @@ def serialize(cuopt_problem_data):
headers["CUOPT-RESULT-FILE"] = output
headers["Content-Type"] = content_type
headers["Accept"] = self.accept_type.value
response = requests.post(
response = self._make_http_request(
"POST",
self.request_url,
params=params,
data=data,
Expand Down Expand Up @@ -869,7 +893,8 @@ def delete(self, id, running=None, queued=None, cached=None):
'running' and 'queued' are unspecified, otherwise False.
"""
try:
response = requests.delete(
response = self._make_http_request(
"DELETE",
self.request_url + f"/{id}",
headers={"Accept": self.accept_type.value},
params={
Expand Down Expand Up @@ -908,7 +933,8 @@ def delete_solution(self, id):
id = id["reqId"]
try:
headers = {"Accept": self.accept_type.value}
response = requests.delete(
response = self._make_http_request(
"DELETE",
self.solution_url + f"/{id}",
headers=headers,
verify=self.verify,
Expand All @@ -920,7 +946,8 @@ def delete_solution(self, id):
# Get rid of a log if it exists.
# It may not so just squash exceptions.
try:
response = requests.delete(
response = self._make_http_request(
"DELETE",
self.log_url + f"/{id}",
verify=self.verify,
timeout=self.http_general_timeout,
Expand Down Expand Up @@ -959,7 +986,8 @@ def repoll(self, data, response_type="obj", delete_solution=True):
data = data["reqId"]
headers = {"Accept": self.accept_type.value}
try:
response = requests.get(
response = self._make_http_request(
"GET",
self.solution_url + f"/{data}",
verify=self.verify,
headers=headers,
Expand Down Expand Up @@ -997,7 +1025,8 @@ def status(self, id):
id = id["reqId"]
headers = {"Accept": self.accept_type.value}
try:
response = requests.get(
response = self._make_http_request(
"GET",
self.request_url + f"/{id}?status",
verify=self.verify,
headers=headers,
Expand Down Expand Up @@ -1034,7 +1063,8 @@ def upload_solution(self, solution):
"Content-Type": content_type,
}
try:
response = requests.post(
response = self._make_http_request(
"POST",
self.solution_url,
verify=self.verify,
data=data,
Expand Down
Loading