|
2 | 2 |
|
3 | 3 | import threading |
4 | 4 | from dataclasses import dataclass |
5 | | -from typing import Callable, List, Optional |
| 5 | +from typing import Callable, Optional |
6 | 6 | from urllib import parse |
7 | 7 |
|
8 | 8 | from databricks.sdk import oauth |
@@ -88,61 +88,3 @@ class DataPlaneDetails: |
88 | 88 | """URL used to query the endpoint through the DataPlane.""" |
89 | 89 | token: Token |
90 | 90 | """Token to query the DataPlane endpoint.""" |
91 | | - |
92 | | - |
93 | | -## Old implementation. #TODO: Remove after the new implementation is used |
94 | | - |
95 | | - |
96 | | -class DataPlaneService: |
97 | | - """Helper class to fetch and manage DataPlane details.""" |
98 | | - |
99 | | - from .service.serving import DataPlaneInfo |
100 | | - |
101 | | - def __init__(self): |
102 | | - self._data_plane_info = {} |
103 | | - self._tokens = {} |
104 | | - self._lock = threading.Lock() |
105 | | - |
106 | | - def get_data_plane_details( |
107 | | - self, |
108 | | - method: str, |
109 | | - params: List[str], |
110 | | - info_getter: Callable[[], DataPlaneInfo], |
111 | | - refresh: Callable[[str], Token], |
112 | | - ): |
113 | | - """Get and cache information required to query a Data Plane endpoint using the provided methods. |
114 | | -
|
115 | | - Returns a cached DataPlaneDetails if the details have already been fetched previously and are still valid. |
116 | | - If not, it uses the provided functions to fetch the details. |
117 | | -
|
118 | | - :param method: method name. Used to construct a unique key for the cache. |
119 | | - :param params: path params used in the "get" operation which uniquely determine the object. Used to construct a unique key for the cache. |
120 | | - :param info_getter: function which returns the DataPlaneInfo. It will only be called if the information is not already present in the cache. |
121 | | - :param refresh: function to refresh the token. It will only be called if the token is missing or expired. |
122 | | - """ |
123 | | - all_elements = params.copy() |
124 | | - all_elements.insert(0, method) |
125 | | - map_key = "/".join(all_elements) |
126 | | - info = self._data_plane_info.get(map_key) |
127 | | - if not info: |
128 | | - self._lock.acquire() |
129 | | - try: |
130 | | - info = self._data_plane_info.get(map_key) |
131 | | - if not info: |
132 | | - info = info_getter() |
133 | | - self._data_plane_info[map_key] = info |
134 | | - finally: |
135 | | - self._lock.release() |
136 | | - |
137 | | - token = self._tokens.get(map_key) |
138 | | - if not token or not token.valid: |
139 | | - self._lock.acquire() |
140 | | - token = self._tokens.get(map_key) |
141 | | - try: |
142 | | - if not token or not token.valid: |
143 | | - token = refresh(info.authorization_details) |
144 | | - self._tokens[map_key] = token |
145 | | - finally: |
146 | | - self._lock.release() |
147 | | - |
148 | | - return DataPlaneDetails(endpoint_url=info.endpoint_url, token=token) |
0 commit comments