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