Skip to content

Overview

Overview API

The Overview API provides information about the availability of the CANFAR Science Platform.

Bases: HTTPClient

Overview of the CANFAR Server.

Parameters:

Name Type Description Default
HTTPClient HTTPClient

Configured HTTP Client.

required
Source code in canfar/overview.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class Overview(HTTPClient):
    """Overview of the CANFAR Server.

    Args:
        HTTPClient (canfar.client.HTTPClient): Configured HTTP Client.
    """

    @model_validator(mode="after")
    def _update_base_url(self) -> Self:
        """Update base URL for the server.

        Returns:
            Self: The current object.
        """
        url: str = str(self.client.base_url)
        base: str = url.split("/v", maxsplit=1)[0]
        # The overview endpoint is not versioned, so need to remove it
        self.client.base_url = URL(base)
        self.asynclient.base_url = URL(base)
        return self

    def availability(self) -> bool:
        """Check if the server backend is available.

        Returns:
            bool: True if the server is available, False otherwise.
        """
        response: Response = self.client.get("availability")
        data: str = response.text
        if not data:
            log.error("No data returned from availability endpoint.")
            return False
        root = ElementTree.fromstring(data)
        available = root.find(
            ".//{http://www.ivoa.net/xml/VOSIAvailability/v1.0}available",
        )
        availaibility: str | None = available.text if available is not None else None

        note = root.find(
            ".//{http://www.ivoa.net/xml/VOSIAvailability/v1.0}note",
        )
        notify: str | None = note.text if note is not None else None
        if availaibility is None:
            log.error("No availability information found in the response.")
            return False
        log.info(notify if notify else "No additional information provided.")
        return availaibility == "true"

availability()

Check if the server backend is available.

Returns:

Name Type Description
bool bool

True if the server is available, False otherwise.

Source code in canfar/overview.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def availability(self) -> bool:
    """Check if the server backend is available.

    Returns:
        bool: True if the server is available, False otherwise.
    """
    response: Response = self.client.get("availability")
    data: str = response.text
    if not data:
        log.error("No data returned from availability endpoint.")
        return False
    root = ElementTree.fromstring(data)
    available = root.find(
        ".//{http://www.ivoa.net/xml/VOSIAvailability/v1.0}available",
    )
    availaibility: str | None = available.text if available is not None else None

    note = root.find(
        ".//{http://www.ivoa.net/xml/VOSIAvailability/v1.0}note",
    )
    notify: str | None = note.text if note is not None else None
    if availaibility is None:
        log.error("No availability information found in the response.")
        return False
    log.info(notify if notify else "No additional information provided.")
    return availaibility == "true"