Skip to main content

google_cloud_bigquery_migration_v2/
client.rs

1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the BigQuery Migration API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_bigquery_migration_v2::client::MigrationService;
24/// use google_cloud_gax::paginator::ItemPaginator as _;
25/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
26///     let client = MigrationService::builder().build().await?;
27///     let parent = "parent_value";
28///     let mut list = client.list_migration_workflows()
29///         .set_parent(parent)
30///         .by_item();
31///     while let Some(item) = list.next().await.transpose()? {
32///         println!("{:?}", item);
33///     }
34/// # Ok(()) }
35/// ```
36///
37/// # Service Description
38///
39/// Service to handle EDW migrations.
40///
41/// # Configuration
42///
43/// To configure `MigrationService` use the `with_*` methods in the type returned
44/// by [builder()][MigrationService::builder]. The default configuration should
45/// work for most applications. Common configuration changes include
46///
47/// * [with_endpoint()]: by default this client uses the global default endpoint
48///   (`https://bigquerymigration.googleapis.com`). Applications using regional
49///   endpoints or running in restricted networks (e.g. a network configured
50//    with [Private Google Access with VPC Service Controls]) may want to
51///   override this default.
52/// * [with_credentials()]: by default this client uses
53///   [Application Default Credentials]. Applications using custom
54///   authentication may need to override this default.
55///
56/// [with_endpoint()]: super::builder::migration_service::ClientBuilder::with_endpoint
57/// [with_credentials()]: super::builder::migration_service::ClientBuilder::with_credentials
58/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
59/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
60///
61/// # Pooling and Cloning
62///
63/// `MigrationService` holds a connection pool internally, it is advised to
64/// create one and reuse it. You do not need to wrap `MigrationService` in
65/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
66/// already uses an `Arc` internally.
67#[derive(Clone, Debug)]
68pub struct MigrationService {
69    inner: std::sync::Arc<dyn super::stub::dynamic::MigrationService>,
70}
71
72impl MigrationService {
73    /// Returns a builder for [MigrationService].
74    ///
75    /// ```
76    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
77    /// # use google_cloud_bigquery_migration_v2::client::MigrationService;
78    /// let client = MigrationService::builder().build().await?;
79    /// # Ok(()) }
80    /// ```
81    pub fn builder() -> super::builder::migration_service::ClientBuilder {
82        crate::new_client_builder(super::builder::migration_service::client::Factory)
83    }
84
85    /// Creates a new client from the provided stub.
86    ///
87    /// The most common case for calling this function is in tests mocking the
88    /// client's behavior.
89    pub fn from_stub<T>(stub: T) -> Self
90    where
91        T: super::stub::MigrationService + 'static,
92    {
93        Self {
94            inner: std::sync::Arc::new(stub),
95        }
96    }
97
98    pub(crate) async fn new(
99        config: gaxi::options::ClientConfig,
100    ) -> crate::ClientBuilderResult<Self> {
101        let inner = Self::build_inner(config).await?;
102        Ok(Self { inner })
103    }
104
105    async fn build_inner(
106        conf: gaxi::options::ClientConfig,
107    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::MigrationService>>
108    {
109        if gaxi::options::tracing_enabled(&conf) {
110            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
111        }
112        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
113    }
114
115    async fn build_transport(
116        conf: gaxi::options::ClientConfig,
117    ) -> crate::ClientBuilderResult<impl super::stub::MigrationService> {
118        super::transport::MigrationService::new(conf).await
119    }
120
121    async fn build_with_tracing(
122        conf: gaxi::options::ClientConfig,
123    ) -> crate::ClientBuilderResult<impl super::stub::MigrationService> {
124        Self::build_transport(conf)
125            .await
126            .map(super::tracing::MigrationService::new)
127    }
128
129    /// Creates a migration workflow.
130    ///
131    /// # Example
132    /// ```
133    /// # use google_cloud_bigquery_migration_v2::client::MigrationService;
134    /// use google_cloud_bigquery_migration_v2::model::MigrationWorkflow;
135    /// use google_cloud_bigquery_migration_v2::Result;
136    /// async fn sample(
137    ///    client: &MigrationService, parent: &str
138    /// ) -> Result<()> {
139    ///     let response = client.create_migration_workflow()
140    ///         .set_parent(parent)
141    ///         .set_migration_workflow(
142    ///             MigrationWorkflow::new()/* set fields */
143    ///         )
144    ///         .send().await?;
145    ///     println!("response {:?}", response);
146    ///     Ok(())
147    /// }
148    /// ```
149    pub fn create_migration_workflow(
150        &self,
151    ) -> super::builder::migration_service::CreateMigrationWorkflow {
152        super::builder::migration_service::CreateMigrationWorkflow::new(self.inner.clone())
153    }
154
155    /// Gets a previously created migration workflow.
156    ///
157    /// # Example
158    /// ```
159    /// # use google_cloud_bigquery_migration_v2::client::MigrationService;
160    /// use google_cloud_bigquery_migration_v2::Result;
161    /// async fn sample(
162    ///    client: &MigrationService, name: &str
163    /// ) -> Result<()> {
164    ///     let response = client.get_migration_workflow()
165    ///         .set_name(name)
166    ///         .send().await?;
167    ///     println!("response {:?}", response);
168    ///     Ok(())
169    /// }
170    /// ```
171    pub fn get_migration_workflow(
172        &self,
173    ) -> super::builder::migration_service::GetMigrationWorkflow {
174        super::builder::migration_service::GetMigrationWorkflow::new(self.inner.clone())
175    }
176
177    /// Lists previously created migration workflow.
178    ///
179    /// # Example
180    /// ```
181    /// # use google_cloud_bigquery_migration_v2::client::MigrationService;
182    /// use google_cloud_gax::paginator::ItemPaginator as _;
183    /// use google_cloud_bigquery_migration_v2::Result;
184    /// async fn sample(
185    ///    client: &MigrationService, parent: &str
186    /// ) -> Result<()> {
187    ///     let mut list = client.list_migration_workflows()
188    ///         .set_parent(parent)
189    ///         .by_item();
190    ///     while let Some(item) = list.next().await.transpose()? {
191    ///         println!("{:?}", item);
192    ///     }
193    ///     Ok(())
194    /// }
195    /// ```
196    pub fn list_migration_workflows(
197        &self,
198    ) -> super::builder::migration_service::ListMigrationWorkflows {
199        super::builder::migration_service::ListMigrationWorkflows::new(self.inner.clone())
200    }
201
202    /// Deletes a migration workflow by name.
203    ///
204    /// # Example
205    /// ```
206    /// # use google_cloud_bigquery_migration_v2::client::MigrationService;
207    /// use google_cloud_bigquery_migration_v2::Result;
208    /// async fn sample(
209    ///    client: &MigrationService, name: &str
210    /// ) -> Result<()> {
211    ///     client.delete_migration_workflow()
212    ///         .set_name(name)
213    ///         .send().await?;
214    ///     Ok(())
215    /// }
216    /// ```
217    pub fn delete_migration_workflow(
218        &self,
219    ) -> super::builder::migration_service::DeleteMigrationWorkflow {
220        super::builder::migration_service::DeleteMigrationWorkflow::new(self.inner.clone())
221    }
222
223    /// Starts a previously created migration workflow. I.e., the state transitions
224    /// from DRAFT to RUNNING. This is a no-op if the state is already RUNNING.
225    /// An error will be signaled if the state is anything other than DRAFT or
226    /// RUNNING.
227    ///
228    /// # Example
229    /// ```
230    /// # use google_cloud_bigquery_migration_v2::client::MigrationService;
231    /// use google_cloud_bigquery_migration_v2::Result;
232    /// async fn sample(
233    ///    client: &MigrationService
234    /// ) -> Result<()> {
235    ///     client.start_migration_workflow()
236    ///         /* set fields */
237    ///         .send().await?;
238    ///     Ok(())
239    /// }
240    /// ```
241    pub fn start_migration_workflow(
242        &self,
243    ) -> super::builder::migration_service::StartMigrationWorkflow {
244        super::builder::migration_service::StartMigrationWorkflow::new(self.inner.clone())
245    }
246
247    /// Gets a previously created migration subtask.
248    ///
249    /// # Example
250    /// ```
251    /// # use google_cloud_bigquery_migration_v2::client::MigrationService;
252    /// use google_cloud_bigquery_migration_v2::Result;
253    /// async fn sample(
254    ///    client: &MigrationService, name: &str
255    /// ) -> Result<()> {
256    ///     let response = client.get_migration_subtask()
257    ///         .set_name(name)
258    ///         .send().await?;
259    ///     println!("response {:?}", response);
260    ///     Ok(())
261    /// }
262    /// ```
263    pub fn get_migration_subtask(&self) -> super::builder::migration_service::GetMigrationSubtask {
264        super::builder::migration_service::GetMigrationSubtask::new(self.inner.clone())
265    }
266
267    /// Lists previously created migration subtasks.
268    ///
269    /// # Example
270    /// ```
271    /// # use google_cloud_bigquery_migration_v2::client::MigrationService;
272    /// use google_cloud_gax::paginator::ItemPaginator as _;
273    /// use google_cloud_bigquery_migration_v2::Result;
274    /// async fn sample(
275    ///    client: &MigrationService, parent: &str
276    /// ) -> Result<()> {
277    ///     let mut list = client.list_migration_subtasks()
278    ///         .set_parent(parent)
279    ///         .by_item();
280    ///     while let Some(item) = list.next().await.transpose()? {
281    ///         println!("{:?}", item);
282    ///     }
283    ///     Ok(())
284    /// }
285    /// ```
286    pub fn list_migration_subtasks(
287        &self,
288    ) -> super::builder::migration_service::ListMigrationSubtasks {
289        super::builder::migration_service::ListMigrationSubtasks::new(self.inner.clone())
290    }
291}