| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
import logging |
| 4 |
import typing as t |
| 5 |
import uuid |
| 6 |
|
| 7 |
from globus_sdk import GlobusHTTPResponse, client |
| 8 |
from globus_sdk._internal.remarshal import strseq_listify |
| 9 |
from globus_sdk._missing import MISSING, MissingType |
| 10 |
from globus_sdk.scopes import ComputeScopes |
| 11 |
|
| 12 |
from .errors import ComputeAPIError |
| 13 |
|
| 14 |
log = logging.getLogger(__name__) |
| 15 |
|
| 16 |
|
| 17 |
class ComputeClientV2(client.BaseClient): |
| 18 |
r""" |
| 19 |
Client for the Globus Compute API, version 2. |
| 20 |
|
| 21 |
.. sdk-sphinx-copy-params:: BaseClient |
| 22 |
|
| 23 |
.. automethodlist:: globus_sdk.ComputeClientV2 |
| 24 |
""" |
| 25 |
|
| 26 |
error_class = ComputeAPIError |
| 27 |
service_name = "compute" |
| 28 |
scopes = ComputeScopes |
| 29 |
default_scope_requirements = [ComputeScopes.all] |
| 30 |
|
| 31 |
def get_version(self, service: str | MissingType = MISSING) -> GlobusHTTPResponse: |
| 32 |
"""Get the current version of the API and other services. |
| 33 |
|
| 34 |
:param service: Service for which to get version information. |
| 35 |
|
| 36 |
.. tab-set:: |
| 37 |
|
| 38 |
.. tab-item:: API Info |
| 39 |
|
| 40 |
.. extdoclink:: Get Version |
| 41 |
:service: compute |
| 42 |
:ref: Root/operation/get_version_v2_version_get |
| 43 |
""" |
| 44 |
query_params = {"service": service} |
| 45 |
return self.get("/v2/version", query_params=query_params) |
| 46 |
|
| 47 |
def get_result_amqp_url(self) -> GlobusHTTPResponse: |
| 48 |
"""Generate new credentials (in the form of a connection URL) for |
| 49 |
connecting to the AMQP service. |
| 50 |
|
| 51 |
.. tab-set:: |
| 52 |
|
| 53 |
.. tab-item:: API Info |
| 54 |
|
| 55 |
.. extdoclink:: Get Result AMQP URL |
| 56 |
:service: compute |
| 57 |
:ref: Root/operation/get_user_specific_result_amqp_url_v2_get_amqp_result_connection_url_get |
| 58 |
""" # noqa: E501 |
| 59 |
return self.get("/v2/get_amqp_result_connection_url") |
| 60 |
|
| 61 |
def register_endpoint(self, data: dict[str, t.Any]) -> GlobusHTTPResponse: |
| 62 |
"""Register a new endpoint. |
| 63 |
|
| 64 |
:param data: An endpoint registration document. |
| 65 |
|
| 66 |
.. tab-set:: |
| 67 |
|
| 68 |
.. tab-item:: API Info |
| 69 |
|
| 70 |
.. extdoclink:: Register Endpoint |
| 71 |
:service: compute |
| 72 |
:ref: Endpoints/operation/register_endpoint_v2_endpoints_post |
| 73 |
""" |
| 74 |
return self.post("/v2/endpoints", data=data) |
| 75 |
|
| 76 |
def get_endpoint(self, endpoint_id: uuid.UUID | str) -> GlobusHTTPResponse: |
| 77 |
"""Get information about a registered endpoint. |
| 78 |
|
| 79 |
:param endpoint_id: The ID of the Globus Compute endpoint. |
| 80 |
|
| 81 |
.. tab-set:: |
| 82 |
|
| 83 |
.. tab-item:: API Info |
| 84 |
|
| 85 |
.. extdoclink:: Get Endpoint |
| 86 |
:service: compute |
| 87 |
:ref: Endpoints/operation/get_endpoint_v2_endpoints__endpoint_uuid__get |
| 88 |
""" # noqa: E501 |
| 89 |
return self.get(f"/v2/endpoints/{endpoint_id}") |
| 90 |
|
| 91 |
def get_endpoint_status(self, endpoint_id: uuid.UUID | str) -> GlobusHTTPResponse: |
| 92 |
"""Get the status of a registered endpoint. |
| 93 |
|
| 94 |
:param endpoint_id: The ID of the Globus Compute endpoint. |
| 95 |
|
| 96 |
.. tab-set:: |
| 97 |
|
| 98 |
.. tab-item:: API Info |
| 99 |
|
| 100 |
.. extdoclink:: Get Endpoint Status |
| 101 |
:service: compute |
| 102 |
:ref: Endpoints/operation/get_endpoint_status_v2_endpoints__endpoint_uuid__status_get |
| 103 |
""" # noqa: E501 |
| 104 |
return self.get(f"/v2/endpoints/{endpoint_id}/status") |
| 105 |
|
| 106 |
def get_endpoints(self, role: str | MissingType = MISSING) -> GlobusHTTPResponse: |
| 107 |
"""Get a list of registered endpoints associated with the authenticated user. |
| 108 |
|
| 109 |
:param role: Role of the user in relation to endpoints. (e.g.: owner, any) |
| 110 |
|
| 111 |
.. tab-set:: |
| 112 |
|
| 113 |
.. tab-item:: API Info |
| 114 |
|
| 115 |
.. extdoclink:: Get Endpoints |
| 116 |
:service: compute |
| 117 |
:ref: Endpoints/operation/get_endpoints_v2_endpoints_get |
| 118 |
""" # noqa: E501 |
| 119 |
query_params = {"role": role} |
| 120 |
return self.get("/v2/endpoints", query_params=query_params) |
| 121 |
|
| 122 |
def delete_endpoint(self, endpoint_id: uuid.UUID | str) -> GlobusHTTPResponse: |
| 123 |
"""Delete a registered endpoint. |
| 124 |
|
| 125 |
:param endpoint_id: The ID of the Globus Compute endpoint. |
| 126 |
|
| 127 |
.. tab-set:: |
| 128 |
|
| 129 |
.. tab-item:: API Info |
| 130 |
|
| 131 |
.. extdoclink:: Delete Endpoint |
| 132 |
:service: compute |
| 133 |
:ref: Endpoints/operation/delete_endpoint_v2_endpoints__endpoint_uuid__delete |
| 134 |
""" # noqa: E501 |
| 135 |
return self.delete(f"/v2/endpoints/{endpoint_id}") |
| 136 |
|
| 137 |
def lock_endpoint(self, endpoint_id: uuid.UUID | str) -> GlobusHTTPResponse: |
| 138 |
"""Temporarily block registration requests for the endpoint. |
| 139 |
|
| 140 |
:param endpoint_id: The ID of the Globus Compute endpoint. |
| 141 |
|
| 142 |
.. tab-set:: |
| 143 |
|
| 144 |
.. tab-item:: API Info |
| 145 |
|
| 146 |
.. extdoclink:: Lock Endpoint |
| 147 |
:service: compute |
| 148 |
:ref: Endpoints/operation/lock_endpoint_v2_endpoints__endpoint_uuid__lock_post |
| 149 |
""" # noqa: E501 |
| 150 |
return self.post(f"/v2/endpoints/{endpoint_id}/lock") |
| 151 |
|
| 152 |
def register_function(self, data: dict[str, t.Any]) -> GlobusHTTPResponse: |
| 153 |
"""Register a new function. |
| 154 |
|
| 155 |
:param data: A function registration document. |
| 156 |
|
| 157 |
.. tab-set:: |
| 158 |
|
| 159 |
.. tab-item:: API Info |
| 160 |
|
| 161 |
.. extdoclink:: Register Function |
| 162 |
:service: compute |
| 163 |
:ref: Functions/operation/register_function_v2_functions_post |
| 164 |
""" # noqa: E501 |
| 165 |
return self.post("/v2/functions", data=data) |
| 166 |
|
| 167 |
def get_function(self, function_id: uuid.UUID | str) -> GlobusHTTPResponse: |
| 168 |
"""Get information about a registered function. |
| 169 |
|
| 170 |
:param function_id: The ID of the function. |
| 171 |
|
| 172 |
.. tab-set:: |
| 173 |
|
| 174 |
.. tab-item:: API Info |
| 175 |
|
| 176 |
.. extdoclink:: Get Function |
| 177 |
:service: compute |
| 178 |
:ref: Functions/operation/get_function_v2_functions__function_uuid__get |
| 179 |
""" # noqa: E501 |
| 180 |
return self.get(f"/v2/functions/{function_id}") |
| 181 |
|
| 182 |
def delete_function(self, function_id: uuid.UUID | str) -> GlobusHTTPResponse: |
| 183 |
"""Delete a registered function. |
| 184 |
|
| 185 |
:param function_id: The ID of the function. |
| 186 |
|
| 187 |
.. tab-set:: |
| 188 |
|
| 189 |
.. tab-item:: API Info |
| 190 |
|
| 191 |
.. extdoclink:: Delete Function |
| 192 |
:service: compute |
| 193 |
:ref: Functions/operation/delete_function_v2_functions__function_uuid__delete |
| 194 |
""" # noqa: E501 |
| 195 |
return self.delete(f"/v2/functions/{function_id}") |
| 196 |
|
| 197 |
def get_task(self, task_id: uuid.UUID | str) -> GlobusHTTPResponse: |
| 198 |
"""Get information about a task. |
| 199 |
|
| 200 |
:param task_id: The ID of the task. |
| 201 |
|
| 202 |
.. tab-set:: |
| 203 |
|
| 204 |
.. tab-item:: API Info |
| 205 |
|
| 206 |
.. extdoclink:: Get Task |
| 207 |
:service: compute |
| 208 |
:ref: Tasks/operation/get_task_status_and_result_v2_tasks__task_uuid__get |
| 209 |
""" # noqa: E501 |
| 210 |
return self.get(f"/v2/tasks/{task_id}") |
| 211 |
|
| 212 |
def get_task_batch( |
| 213 |
self, task_ids: uuid.UUID | str | t.Iterable[uuid.UUID | str] |
| 214 |
) -> GlobusHTTPResponse: |
| 215 |
"""Get information about a batch of tasks. |
| 216 |
|
| 217 |
:param task_ids: The IDs of the tasks. |
| 218 |
|
| 219 |
.. tab-set:: |
| 220 |
|
| 221 |
.. tab-item:: API Info |
| 222 |
|
| 223 |
.. extdoclink:: Get Task Batch |
| 224 |
:service: compute |
| 225 |
:ref: Root/operation/get_batch_status_v2_batch_status_post |
| 226 |
""" |
| 227 |
return self.post( |
| 228 |
"/v2/batch_status", data={"task_ids": strseq_listify(task_ids)} |
| 229 |
) |
| 230 |
|
| 231 |
def get_task_group(self, task_group_id: uuid.UUID | str) -> GlobusHTTPResponse: |
| 232 |
"""Get a list of task IDs associated with a task group. |
| 233 |
|
| 234 |
:param task_group_id: The ID of the task group. |
| 235 |
|
| 236 |
.. tab-set:: |
| 237 |
|
| 238 |
.. tab-item:: API Info |
| 239 |
|
| 240 |
.. extdoclink:: Get Task Group Tasks |
| 241 |
:service: compute |
| 242 |
:ref: TaskGroup/operation/get_task_group_tasks_v2_taskgroup__task_group_uuid__get |
| 243 |
""" # noqa: E501 |
| 244 |
return self.get(f"/v2/taskgroup/{task_group_id}") |
| 245 |
|
| 246 |
def submit(self, data: dict[str, t.Any]) -> GlobusHTTPResponse: |
| 247 |
"""Submit a batch of tasks to a Globus Compute endpoint. |
| 248 |
|
| 249 |
:param data: The task batch document. |
| 250 |
|
| 251 |
.. tab-set:: |
| 252 |
|
| 253 |
.. tab-item:: API Info |
| 254 |
|
| 255 |
.. extdoclink:: Submit Batch |
| 256 |
:service: compute |
| 257 |
:ref: Root/operation/submit_batch_v2_submit_post |
| 258 |
""" # noqa: E501 |
| 259 |
return self.post("/v2/submit", data=data) |
| 260 |
|
| 261 |
|
| 262 |
class ComputeClientV3(client.BaseClient): |
| 263 |
r""" |
| 264 |
Client for the Globus Compute API, version 3. |
| 265 |
|
| 266 |
.. automethodlist:: globus_sdk.ComputeClientV3 |
| 267 |
""" |
| 268 |
|
| 269 |
error_class = ComputeAPIError |
| 270 |
service_name = "compute" |
| 271 |
scopes = ComputeScopes |
| 272 |
default_scope_requirements = [ComputeScopes.all] |
| 273 |
|
| 274 |
def register_endpoint(self, data: dict[str, t.Any]) -> GlobusHTTPResponse: |
| 275 |
"""Register a new endpoint. |
| 276 |
|
| 277 |
:param data: An endpoint registration document. |
| 278 |
|
| 279 |
.. tab-set:: |
| 280 |
|
| 281 |
.. tab-item:: API Info |
| 282 |
|
| 283 |
.. extdoclink:: Register Endpoint |
| 284 |
:service: compute |
| 285 |
:ref: Endpoints/operation/register_endpoint_v3_endpoints_post |
| 286 |
""" |
| 287 |
return self.post("/v3/endpoints", data=data) |
| 288 |
|
| 289 |
def update_endpoint( |
| 290 |
self, endpoint_id: uuid.UUID | str, data: dict[str, t.Any] |
| 291 |
) -> GlobusHTTPResponse: |
| 292 |
"""Update an endpoint. |
| 293 |
|
| 294 |
:param endpoint_id: The ID of the endpoint. |
| 295 |
:param data: An endpoint update document. |
| 296 |
|
| 297 |
.. tab-set:: |
| 298 |
|
| 299 |
.. tab-item:: API Info |
| 300 |
|
| 301 |
.. extdoclink:: Update Endpoint |
| 302 |
:service: compute |
| 303 |
:ref: Endpoints/operation/update_endpoint_v3_endpoints__endpoint_uuid__put |
| 304 |
""" # noqa: E501 |
| 305 |
return self.put(f"/v3/endpoints/{endpoint_id}", data=data) |
| 306 |
|
| 307 |
def lock_endpoint(self, endpoint_id: uuid.UUID | str) -> GlobusHTTPResponse: |
| 308 |
"""Temporarily block registration requests for the endpoint. |
| 309 |
|
| 310 |
:param endpoint_id: The ID of the Globus Compute endpoint. |
| 311 |
|
| 312 |
.. tab-set:: |
| 313 |
|
| 314 |
.. tab-item:: API Info |
| 315 |
|
| 316 |
.. extdoclink:: Lock Endpoint |
| 317 |
:service: compute |
| 318 |
:ref: Endpoints/operation/lock_endpoint_v3_endpoints__endpoint_uuid__lock_post |
| 319 |
""" # noqa: E501 |
| 320 |
return self.post(f"/v3/endpoints/{endpoint_id}/lock") |
| 321 |
|
| 322 |
def get_endpoint_allowlist( |
| 323 |
self, endpoint_id: uuid.UUID | str |
| 324 |
) -> GlobusHTTPResponse: |
| 325 |
"""Get a list of IDs for functions allowed to run on an endpoint. |
| 326 |
|
| 327 |
:param endpoint_id: The ID of the Globus Compute endpoint. |
| 328 |
|
| 329 |
.. tab-set:: |
| 330 |
|
| 331 |
.. tab-item:: API Info |
| 332 |
|
| 333 |
.. extdoclink:: Get Endpoint Allowlist |
| 334 |
:service: compute |
| 335 |
:ref: Endpoints/operation/get_endpoint_allowlist_v3_endpoints__endpoint_uuid__allowed_functions_get |
| 336 |
""" # noqa: E501 |
| 337 |
return self.get(f"/v3/endpoints/{endpoint_id}/allowed_functions") |
| 338 |
|
| 339 |
def register_function(self, data: dict[str, t.Any]) -> GlobusHTTPResponse: |
| 340 |
"""Register a new function. |
| 341 |
|
| 342 |
:param data: A function registration document. |
| 343 |
|
| 344 |
.. tab-set:: |
| 345 |
|
| 346 |
.. tab-item:: API Info |
| 347 |
|
| 348 |
.. extdoclink:: Register Function |
| 349 |
:service: compute |
| 350 |
:ref: Functions/operation/register_function_v3_functions_post |
| 351 |
""" |
| 352 |
return self.post("/v3/functions", data=data) |
| 353 |
|
| 354 |
def submit( |
| 355 |
self, endpoint_id: uuid.UUID | str, data: dict[str, t.Any] |
| 356 |
) -> GlobusHTTPResponse: |
| 357 |
"""Submit a batch of tasks to a Globus Compute endpoint. |
| 358 |
|
| 359 |
:param endpoint_id: The ID of the Globus Compute endpoint. |
| 360 |
:param data: The task batch document. |
| 361 |
|
| 362 |
.. tab-set:: |
| 363 |
|
| 364 |
.. tab-item:: API Info |
| 365 |
|
| 366 |
.. extdoclink:: Submit Batch |
| 367 |
:service: compute |
| 368 |
:ref: Endpoints/operation/submit_batch_v3_endpoints__endpoint_uuid__submit_post |
| 369 |
""" # noqa: E501 |
| 370 |
return self.post(f"/v3/endpoints/{endpoint_id}/submit", data=data) |