|
41 | 41 | ) |
42 | 42 | from urllib3.response import HTTPResponse |
43 | 43 |
|
| 44 | +from groundlight.edge.api import EdgeAPI |
44 | 45 | from groundlight.edge.config import EdgeEndpointConfig |
45 | 46 | from groundlight.images import parse_supported_image_types |
46 | 47 | from groundlight.internalapi import _generate_request_id |
@@ -105,6 +106,14 @@ def __init__( |
105 | 106 | self.detector_reset_api = DetectorResetApi(self.api_client) |
106 | 107 |
|
107 | 108 | self.edge_api = EdgeApi(self.api_client) |
| 109 | + self._edge: EdgeAPI | None = None |
| 110 | + |
| 111 | + @property |
| 112 | + def edge(self) -> "EdgeAPI": |
| 113 | + """Access edge-endpoint operations (e.g. ``gl.edge.get_config()``).""" |
| 114 | + if self._edge is None: |
| 115 | + self._edge = EdgeAPI(self) |
| 116 | + return self._edge |
108 | 117 |
|
109 | 118 | ITEMS_PER_PAGE = 100 |
110 | 119 |
|
@@ -828,66 +837,17 @@ def _edge_base_url(self) -> str: |
828 | 837 | return urlunparse((parsed.scheme, parsed.netloc, "", "", "", "")) |
829 | 838 |
|
830 | 839 | def get_edge_config(self) -> EdgeEndpointConfig: |
831 | | - """Retrieve the active edge endpoint configuration. |
832 | | -
|
833 | | - Only works when the client is pointed at an edge endpoint |
834 | | - (via GROUNDLIGHT_ENDPOINT or the endpoint constructor arg). |
835 | | - """ |
836 | | - url = f"{self._edge_base_url()}/edge-config" |
837 | | - headers = self.get_raw_headers() |
838 | | - response = requests.get(url, headers=headers, verify=self.configuration.verify_ssl) |
839 | | - response.raise_for_status() |
840 | | - return EdgeEndpointConfig.from_payload(response.json()) |
| 840 | + """Deprecated: use ``gl.edge.get_config()`` instead.""" |
| 841 | + return self.edge.get_config() |
841 | 842 |
|
842 | 843 | def get_edge_detector_readiness(self) -> dict[str, bool]: |
843 | | - """Check which configured detectors have inference pods ready to serve. |
844 | | -
|
845 | | - Only works when the client is pointed at an edge endpoint. |
846 | | -
|
847 | | - :return: Dict mapping detector_id to readiness (True/False). |
848 | | - """ |
849 | | - url = f"{self._edge_base_url()}/edge-detector-readiness" |
850 | | - headers = self.get_raw_headers() |
851 | | - response = requests.get(url, headers=headers, verify=self.configuration.verify_ssl) |
852 | | - response.raise_for_status() |
853 | | - return {det_id: info["ready"] for det_id, info in response.json().items()} |
| 844 | + """Deprecated: use ``gl.edge.get_detector_readiness()`` instead.""" |
| 845 | + return self.edge.get_detector_readiness() |
854 | 846 |
|
855 | 847 | def set_edge_config( |
856 | 848 | self, |
857 | 849 | config: EdgeEndpointConfig, |
858 | | - mode: str = "REPLACE", |
859 | 850 | timeout_sec: float = 300, |
860 | | - poll_interval_sec: float = 1, |
861 | 851 | ) -> EdgeEndpointConfig: |
862 | | - """Send a new edge endpoint configuration and wait until all detectors are ready. |
863 | | -
|
864 | | - Only works when the client is pointed at an edge endpoint. |
865 | | -
|
866 | | - :param config: The new configuration to apply. |
867 | | - :param mode: Currently only "REPLACE" is supported. |
868 | | - :param timeout_sec: Max seconds to wait for all detectors to become ready. |
869 | | - :param poll_interval_sec: How often to poll readiness while waiting. |
870 | | - :return: The applied configuration as reported by the edge endpoint. |
871 | | - """ |
872 | | - if mode != "REPLACE": |
873 | | - raise ValueError(f"Unsupported mode: {mode!r}. Currently only 'REPLACE' is supported.") |
874 | | - |
875 | | - url = f"{self._edge_base_url()}/edge-config" |
876 | | - headers = self.get_raw_headers() |
877 | | - response = requests.put( |
878 | | - url, json=config.to_payload(), headers=headers, verify=self.configuration.verify_ssl |
879 | | - ) |
880 | | - response.raise_for_status() |
881 | | - |
882 | | - desired_ids = {d.detector_id for d in config.detectors if d.detector_id} |
883 | | - deadline = time.time() + timeout_sec |
884 | | - while time.time() < deadline: |
885 | | - readiness = self.get_edge_detector_readiness() |
886 | | - if desired_ids and all(readiness.get(did, False) for did in desired_ids): |
887 | | - return self.get_edge_config() |
888 | | - time.sleep(poll_interval_sec) |
889 | | - |
890 | | - raise TimeoutError( |
891 | | - f"Edge detectors were not all ready within {timeout_sec}s. " |
892 | | - "The edge endpoint may still be converging." |
893 | | - ) |
| 852 | + """Deprecated: use ``gl.edge.set_config()`` instead.""" |
| 853 | + return self.edge.set_config(config, timeout_sec=timeout_sec) |
0 commit comments