예제 #1
0
def set_resource(resource_name, capacity, client_id=None):
    """ Set a resource to a specified capacity.

    This creates, updates or deletes a custom resource for a target NodeID.
    If the resource already exists, it's capacity is updated to the new value.
    If the capacity is set to 0, the resource is deleted.
    If NodeID is not specified or set to None,
    the resource is created on the local client where the actor is running.

    Args:
        resource_name (str): Name of the resource to be created
        capacity (int): Capacity of the new resource. Resource is deleted if
            capacity is 0.
        client_id (str): The NodeID of the node where the resource is to be
            set.

    Returns:
        None

    Raises:
          ValueError: This exception is raised when a non-negative capacity is
            specified.
    """
    if client_id is not None:
        client_id_obj = ray.NodeID(ray.utils.hex_to_binary(client_id))
    else:
        client_id_obj = ray.NodeID.nil()
    if (capacity < 0) or (capacity != int(capacity)):
        raise ValueError(
            "Capacity {} must be a non-negative integer.".format(capacity))
    return ray.worker.global_worker.core_worker.set_resource(
        resource_name, capacity, client_id_obj)
예제 #2
0
파일: state.py 프로젝트: zeta1999/ray
    def node_resource_table(self, node_id=None):
        """Fetch and parse the node resource table info for one.

        Args:
            node_id: An node ID to fetch information about.

        Returns:
            Information from the node resource table.
        """
        self._check_connected()

        node_id = ray.NodeID(hex_to_binary(node_id))
        node_resource_bytes = \
            self.global_state_accessor.get_node_resource_info(node_id)
        if node_resource_bytes is None:
            return {}
        else:
            node_resource_info = gcs_utils.ResourceMap.FromString(
                node_resource_bytes)
            return {
                key: value.resource_capacity
                for key, value in node_resource_info.items.items()
            }