Beispiel #1
0
 def _options_from_req(self, req) -> ListApiOptions:
     """Obtain `ListApiOptions` from the aiohttp request."""
     limit = int(req.query.get("limit"))
     # Only apply 80% of the timeout so that
     # the API will reply before client times out if query to the source fails.
     timeout = int(req.query.get("timeout"))
     return ListApiOptions(limit=limit, timeout=timeout)
Beispiel #2
0
Datei: api.py Projekt: smorad/ray
def list_runtime_envs(api_server_url: str = None,
                      limit: int = 1000,
                      timeout: int = 30):
    return _list(
        "runtime_envs",
        ListApiOptions(limit=limit, timeout=timeout),
        api_server_url=api_server_url,
    )
Beispiel #3
0
Datei: api.py Projekt: smorad/ray
def list_workers(
    api_server_url: str = None,
    limit: int = DEFAULT_LIMIT,
    timeout: int = DEFAULT_RPC_TIMEOUT,
):
    return _list(
        "workers",
        ListApiOptions(limit=limit, timeout=timeout),
        api_server_url=api_server_url,
    )
Beispiel #4
0
Datei: api.py Projekt: smorad/ray
def list_placement_groups(
    api_server_url: str = None,
    limit: int = DEFAULT_LIMIT,
    timeout: int = DEFAULT_RPC_TIMEOUT,
):
    return _list(
        "placement_groups",
        ListApiOptions(limit=limit, timeout=timeout),
        api_server_url=api_server_url,
    )
Beispiel #5
0
def test_dashboard_requests_fail_on_missing_deps(ray_start_with_dashboard):
    """Check that requests from client fail with minimal installation"""
    response = None

    with pytest.raises(ServerUnavailable):
        client = StateApiClient(address=DEFAULT_DASHBOARD_ADDRESS)
        response = client.list(StateResource.NODES, options=ListApiOptions())

    # Response should not be populated
    assert response is None
Beispiel #6
0
 def _options_from_req(self, req) -> ListApiOptions:
     """Obtain `ListApiOptions` from the aiohttp request."""
     limit = int(req.query.get("limit"))
     timeout = int(req.query.get("timeout"))
     filter_keys = req.query.getall("filter_keys", [])
     filter_values = req.query.getall("filter_values", [])
     assert len(filter_keys) == len(filter_values)
     filters = []
     for key, val in zip(filter_keys, filter_values):
         filters.append((key, val))
     return ListApiOptions(limit=limit, timeout=timeout, filters=filters)
Beispiel #7
0
def create_api_options(
    timeout: int = DEFAULT_RPC_TIMEOUT,
    limit: int = DEFAULT_LIMIT,
    filters: List[Tuple[str, SupportedFilterType]] = None,
):
    if not filters:
        filters = []
    return ListApiOptions(limit=limit,
                          timeout=timeout,
                          filters=filters,
                          _server_timeout_multiplier=1.0)
Beispiel #8
0
def list_runtime_envs(
    address: Optional[str] = None,
    filters: Optional[List[Tuple[str, SupportedFilterType]]] = None,
    limit: int = DEFAULT_LIMIT,
    timeout: int = DEFAULT_RPC_TIMEOUT,
    _explain: bool = False,
):
    return StateApiClient(api_server_address=address).list(
        StateResource.RUNTIME_ENVS,
        options=ListApiOptions(limit=limit, timeout=timeout, filters=filters),
        _explain=_explain,
    )
Beispiel #9
0
def list_nodes(
    api_server_url: str = None,
    limit: int = DEFAULT_LIMIT,
    timeout: int = DEFAULT_RPC_TIMEOUT,
    _explain: bool = False,
):
    return _list(
        "nodes",
        ListApiOptions(limit=limit, timeout=timeout),
        api_server_url=api_server_url,
        _explain=_explain,
    )
Beispiel #10
0
 async def summarize_objects(
         self, option: SummaryApiOptions) -> SummaryApiResponse:
     # For summary, try getting as many entries as possible to minimze data loss.
     result = await self.list_objects(option=ListApiOptions(
         timeout=option.timeout, limit=MAX_LIMIT, filters=[]))
     summary = StateSummary(
         node_id_to_summary={
             "cluster": ObjectSummaries.to_summary(objects=result.result)
         })
     return SummaryApiResponse(
         result=summary,
         partial_failure_warning=result.partial_failure_warning)
Beispiel #11
0
def list_placement_groups(
    api_server_url: str = None,
    filters: List[Tuple[str, SupportedFilterType]] = None,
    limit: int = DEFAULT_LIMIT,
    timeout: int = DEFAULT_RPC_TIMEOUT,
    _explain: bool = False,
):
    return _list(
        "placement_groups",
        ListApiOptions(limit=limit, timeout=timeout, filters=filters),
        api_server_url=api_server_url,
        _explain=_explain,
    )
Beispiel #12
0
 async def summarize_objects(self, option: SummaryApiOptions) -> SummaryApiResponse:
     result = await self.list_objects(
         option=ListApiOptions(
             timeout=option.timeout, limit=DEFAULT_LIMIT, filters=[]
         )
     )
     summary = StateSummary(
         node_id_to_summary={
             "cluster": ObjectSummaries.to_summary(objects=result.result)
         }
     )
     return SummaryApiResponse(
         result=summary, partial_failure_warning=result.partial_failure_warning
     )
Beispiel #13
0
def list_objects(
    address: Optional[str] = None,
    filters: Optional[List[Tuple[str, PredicateType,
                                 SupportedFilterType]]] = None,
    limit: int = DEFAULT_LIMIT,
    timeout: int = DEFAULT_RPC_TIMEOUT,
    detail: bool = False,
    _explain: bool = False,
):
    return StateApiClient(api_server_address=address).list(
        StateResource.OBJECTS,
        options=ListApiOptions(limit=limit,
                               timeout=timeout,
                               filters=filters,
                               detail=detail),
        _explain=_explain,
    )
Beispiel #14
0
Datei: api.py Projekt: parasj/ray
def list_placement_groups(
    address: Optional[str] = None,
    filters: Optional[List[Tuple[str, PredicateType,
                                 SupportedFilterType]]] = None,
    limit: int = DEFAULT_LIMIT,
    timeout: int = DEFAULT_RPC_TIMEOUT,
    detail: bool = False,
    _explain: bool = False,
):
    return StateApiClient(address=address).list(
        StateResource.PLACEMENT_GROUPS,
        options=ListApiOptions(limit=limit,
                               timeout=timeout,
                               filters=filters,
                               detail=detail),
        _explain=_explain,
    )
Beispiel #15
0
def list(
    resource: str,
    format: str,
    detail: bool,
    filter: List[str],
    timeout: float,
    address: str,
):
    """
    List RESOURCE used by Ray.

    RESOURCE is the name of the possible resources from `StateResource`,
    i.e. 'jobs', 'actors', 'nodes', ...

    """
    # All resource names use '_' rather than '-'. But users options have '-'
    resource = StateResource(resource.replace("-", "_"))
    format = AvailableFormat(format)

    # Get the state API server address from ray if not provided by user
    api_server_address = address if address else get_api_server_url()

    # Create the State API server and put it into context
    logger.debug(f"Create StateApiClient at {api_server_address}...")
    client = StateApiClient(api_server_address=api_server_address, )

    filter = [_parse_filter(f) for f in filter]

    options = ListApiOptions(
        limit=
        DEFAULT_LIMIT,  # TODO(rickyyx): parameters discussion to be finalized
        timeout=timeout,
        filters=filter,
        detail=detail,
    )

    # If errors occur, exceptions will be thrown. Empty data indicate successful query.
    data = client.list(resource,
                       options=options,
                       _explain=_should_explain(format))

    # Print data to console.
    print(format_list_api_output(
        state_data=data,
        format=format,
    ))
Beispiel #16
0
    def _options_from_req(self, req: aiohttp.web.Request) -> ListApiOptions:
        """Obtain `ListApiOptions` from the aiohttp request."""
        limit = int(
            req.query.get("limit") if req.query.
            get("limit") is not None else DEFAULT_LIMIT)
        timeout = int(req.query.get("timeout"))
        filter_keys = req.query.getall("filter_keys", [])
        filter_predicates = req.query.getall("filter_predicates", [])
        filter_values = req.query.getall("filter_values", [])
        assert len(filter_keys) == len(filter_values)
        filters = []
        for key, predicate, val in zip(filter_keys, filter_predicates,
                                       filter_values):
            filters.append((key, predicate, val))
        detail = convert_string_to_type(req.query.get("detail", False), bool)

        return ListApiOptions(limit=limit,
                              timeout=timeout,
                              filters=filters,
                              detail=detail)
Beispiel #17
0
def list_api_options(timeout: int = DEFAULT_RPC_TIMEOUT,
                     limit: int = DEFAULT_LIMIT):
    return ListApiOptions(limit=limit, timeout=timeout)
Beispiel #18
0
 def _options_from_req(self, req) -> ListApiOptions:
     """Obtain `ListApiOptions` from the aiohttp request."""
     limit = int(req.query.get("limit"))
     timeout = int(req.query.get("timeout"))
     return ListApiOptions(limit=limit, timeout=timeout)
Beispiel #19
0
def list_api_options(timeout: int = DEFAULT_RPC_TIMEOUT,
                     limit: int = DEFAULT_LIMIT):
    return ListApiOptions(limit=limit,
                          timeout=timeout,
                          _server_timeout_multiplier=1.0)