Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

A connection to one YTsaurus cluster.

Implementations§

Source§

impl Client

Source

pub fn new(proxy: &str) -> Self

Connects to proxy, with no token.

proxy may be a bare host (cluster.example.com, assumed HTTPS) or carry a scheme (http://localhost:8000).

Source

pub fn with_token(proxy: &str, token: impl Into<String>) -> Self

Connects to proxy using token for authentication.

Source

pub fn from_env() -> Result<Self>

Connects using YT_PROXY and, if set, YT_TOKEN.

§Errors

Returns ClientError::Config if YT_PROXY is not set.

Source

pub fn with_poll_interval(self, interval: Duration) -> Self

Overrides how often Client::wait_for_operation polls.

Source

pub fn heavy_proxy(&self) -> Result<Option<String>>

Returns the least-loaded heavy proxy the cluster reports, if any.

Large installations separate light and heavy proxies and answer heavy commands on a light proxy with 503. Point a second Client at this address to do uploads there. A local cluster returns nothing useful, and none of this is needed for it.

§Errors

Returns ClientError if the request fails.

Source

pub fn exists(&self, path: &str) -> Result<bool>

Whether a Cypress node exists.

§Errors

Returns ClientError if the request fails.

Source

pub fn create(&self, node_type: &str, path: &str) -> Result<()>

Creates a Cypress node, e.g. table, file or map_node.

Creates missing parents and succeeds if the node already exists.

§Errors

Returns ClientError if the request fails.

Source

pub fn remove(&self, path: &str) -> Result<()>

Removes a Cypress node. Succeeds if it is already absent.

§Errors

Returns ClientError if the request fails.

Source

pub fn get(&self, path: &str) -> Result<YsonValue>

Reads a node attribute, such as @row_count.

§Errors

Returns ClientError if the request fails.

Source

pub fn row_count(&self, path: &str) -> Result<i64>

Number of rows in a table.

§Errors

Returns ClientError if the request fails or the attribute is absent.

Source

pub fn upload_worker(&self, local: impl AsRef<Path>, remote: &str) -> Result<()>

Uploads a local file to Cypress, marking it executable.

This is what makes a worker runnable on a node: without the executable attribute YTsaurus copies the binary but refuses to exec it, and the job fails with a permission error that does not mention the attribute.

§Errors

Returns ClientError if the file cannot be read or the upload fails.

Source

pub fn write_file(&self, path: &str, contents: &[u8]) -> Result<()>

Writes raw bytes to a Cypress file, replacing its contents.

§Errors

Returns ClientError if the request fails.

Source

pub fn set_attribute( &self, path: &str, name: &str, value: YsonValue, ) -> Result<()>

Sets a node attribute.

§Errors

Returns ClientError if the request fails.

Source

pub fn write_table(&self, path: &str, rows: &[u8]) -> Result<()>

Writes rows to a table, replacing its contents.

rows must be a binary YSON list fragment — exactly what a ytsaurus-job worker writes.

§Errors

Returns ClientError if the request fails.

Source

pub fn read_table(&self, path: &str) -> Result<Vec<u8>>

Reads a whole table as a binary YSON list fragment.

Reads it into memory: this is for results a launcher inspects, not for bulk export.

The result is checked to be a complete list fragment. That is not pedantry — the proxy reports a mid-stream failure in a trailer this client cannot see (see the http module), so a truncated body is the symptom that is detectable, and returning it as success would hand the caller a silently short table.

§Errors

Returns ClientError if the request fails or the stream is truncated.

Source

pub fn start_map(&self, spec: &MapSpec) -> Result<String>

Starts a map operation, returning its ID.

§Errors

Returns ClientError if the request fails.

Source

pub fn start_map_reduce(&self, spec: &MapReduceSpec) -> Result<String>

Starts a map-reduce operation, returning its ID.

§Errors

Returns ClientError if the request fails.

Source

pub fn start_operation( &self, kind: OperationType, spec: &YsonValue, ) -> Result<String>

Starts an operation from a spec built by hand.

The escape hatch for anything MapSpec and MapReduceSpec do not model; build the spec with yson_build.

§Errors

Returns ClientError if the request fails.

Source

pub fn operation_state(&self, id: &str) -> Result<String>

Fetches an operation’s current state, e.g. running or completed.

§Errors

Returns ClientError if the request fails.

Source

pub fn wait_for_operation(&self, id: &str) -> Result<()>

Polls until the operation reaches a terminal state.

§Errors

Returns ClientError::OperationFailed if it ends as anything other than completed, or ClientError if polling itself fails.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.