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(
26///    parent: &str,
27/// ) -> anyhow::Result<()> {
28///     let client = MigrationService::builder().build().await?;
29///     let mut list = client.list_migration_workflows()
30///         .set_parent(parent)
31///         .by_item();
32///     while let Some(item) = list.next().await.transpose()? {
33///         println!("{:?}", item);
34///     }
35///     Ok(())
36/// }
37/// ```
38///
39/// # Service Description
40///
41/// Service to handle EDW migrations.
42///
43/// # Configuration
44///
45/// To configure `MigrationService` use the `with_*` methods in the type returned
46/// by [builder()][MigrationService::builder]. The default configuration should
47/// work for most applications. Common configuration changes include
48///
49/// * [with_endpoint()]: by default this client uses the global default endpoint
50///   (`https://bigquerymigration.googleapis.com`). Applications using regional
51///   endpoints or running in restricted networks (e.g. a network configured
52//    with [Private Google Access with VPC Service Controls]) may want to
53///   override this default.
54/// * [with_credentials()]: by default this client uses
55///   [Application Default Credentials]. Applications using custom
56///   authentication may need to override this default.
57///
58/// [with_endpoint()]: super::builder::migration_service::ClientBuilder::with_endpoint
59/// [with_credentials()]: super::builder::migration_service::ClientBuilder::with_credentials
60/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
61/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
62///
63/// # Pooling and Cloning
64///
65/// `MigrationService` holds a connection pool internally, it is advised to
66/// create one and reuse it. You do not need to wrap `MigrationService` in
67/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
68/// already uses an `Arc` internally.
69#[derive(Clone, Debug)]
70pub struct MigrationService {
71    inner: std::sync::Arc<dyn super::stub::dynamic::MigrationService>,
72}
73
74impl MigrationService {
75    /// Returns a builder for [MigrationService].
76    ///
77    /// ```
78    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
79    /// # use google_cloud_bigquery_migration_v2::client::MigrationService;
80    /// let client = MigrationService::builder().build().await?;
81    /// # Ok(()) }
82    /// ```
83    pub fn builder() -> super::builder::migration_service::ClientBuilder {
84        crate::new_client_builder(super::builder::migration_service::client::Factory)
85    }
86
87    /// Creates a new client from the provided stub.
88    ///
89    /// The most common case for calling this function is in tests mocking the
90    /// client's behavior.
91    pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
92    where
93        T: super::stub::MigrationService + 'static,
94    {
95        Self { inner: stub.into() }
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, project_id: &str, location_id: &str, workflow_id: &str
163    /// ) -> Result<()> {
164    ///     let response = client.get_migration_workflow()
165    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/workflows/{workflow_id}"))
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, project_id: &str, location_id: &str, workflow_id: &str
210    /// ) -> Result<()> {
211    ///     client.delete_migration_workflow()
212    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/workflows/{workflow_id}"))
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, project_id: &str, location_id: &str, workflow_id: &str, subtask_id: &str
255    /// ) -> Result<()> {
256    ///     let response = client.get_migration_subtask()
257    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/workflows/{workflow_id}/subtasks/{subtask_id}"))
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, project_id: &str, location_id: &str, workflow_id: &str
276    /// ) -> Result<()> {
277    ///     let mut list = client.list_migration_subtasks()
278    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}/workflows/{workflow_id}"))
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}