aws_sdk_fsx/operation/
restore_volume_from_snapshot.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Orchestration and serialization glue logic for `RestoreVolumeFromSnapshot`.
3#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug)]
4#[non_exhaustive]
5pub struct RestoreVolumeFromSnapshot;
6impl RestoreVolumeFromSnapshot {
7    /// Creates a new `RestoreVolumeFromSnapshot`
8    pub fn new() -> Self {
9        Self
10    }
11    pub(crate) async fn orchestrate(
12        runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
13        input: crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotInput,
14    ) -> ::std::result::Result<
15        crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotOutput,
16        ::aws_smithy_runtime_api::client::result::SdkError<
17            crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotError,
18            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
19        >,
20    > {
21        let map_err = |err: ::aws_smithy_runtime_api::client::result::SdkError<
22            ::aws_smithy_runtime_api::client::interceptors::context::Error,
23            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
24        >| {
25            err.map_service_error(|err| {
26                err.downcast::<crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotError>()
27                    .expect("correct error type")
28            })
29        };
30        let context = Self::orchestrate_with_stop_point(runtime_plugins, input, ::aws_smithy_runtime::client::orchestrator::StopPoint::None)
31            .await
32            .map_err(map_err)?;
33        let output = context.finalize().map_err(map_err)?;
34        ::std::result::Result::Ok(
35            output
36                .downcast::<crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotOutput>()
37                .expect("correct output type"),
38        )
39    }
40
41    pub(crate) async fn orchestrate_with_stop_point(
42        runtime_plugins: &::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
43        input: crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotInput,
44        stop_point: ::aws_smithy_runtime::client::orchestrator::StopPoint,
45    ) -> ::std::result::Result<
46        ::aws_smithy_runtime_api::client::interceptors::context::InterceptorContext,
47        ::aws_smithy_runtime_api::client::result::SdkError<
48            ::aws_smithy_runtime_api::client::interceptors::context::Error,
49            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
50        >,
51    > {
52        let input = ::aws_smithy_runtime_api::client::interceptors::context::Input::erase(input);
53        use ::tracing::Instrument;
54        ::aws_smithy_runtime::client::orchestrator::invoke_with_stop_point("FSx", "RestoreVolumeFromSnapshot", input, runtime_plugins, stop_point)
55            // Create a parent span for the entire operation. Includes a random, internal-only,
56            // seven-digit ID for the operation orchestration so that it can be correlated in the logs.
57            .instrument(::tracing::debug_span!(
58                "FSx.RestoreVolumeFromSnapshot",
59                "rpc.service" = "FSx",
60                "rpc.method" = "RestoreVolumeFromSnapshot",
61                "sdk_invocation_id" = ::fastrand::u32(1_000_000..10_000_000),
62                "rpc.system" = "aws-api",
63            ))
64            .await
65    }
66
67    pub(crate) fn operation_runtime_plugins(
68        client_runtime_plugins: ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
69        client_config: &crate::config::Config,
70        config_override: ::std::option::Option<crate::config::Builder>,
71    ) -> ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins {
72        let mut runtime_plugins = client_runtime_plugins.with_operation_plugin(Self::new());
73        runtime_plugins = runtime_plugins.with_operation_plugin(crate::client_idempotency_token::IdempotencyTokenRuntimePlugin::new(
74            |token_provider, input| {
75                let input: &mut crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotInput =
76                    input.downcast_mut().expect("correct type");
77                if input.client_request_token.is_none() {
78                    input.client_request_token = ::std::option::Option::Some(token_provider.make_idempotency_token());
79                }
80            },
81        ));
82        if let ::std::option::Option::Some(config_override) = config_override {
83            for plugin in config_override.runtime_plugins.iter().cloned() {
84                runtime_plugins = runtime_plugins.with_operation_plugin(plugin);
85            }
86            runtime_plugins = runtime_plugins.with_operation_plugin(crate::config::ConfigOverrideRuntimePlugin::new(
87                config_override,
88                client_config.config.clone(),
89                &client_config.runtime_components,
90            ));
91        }
92        runtime_plugins
93    }
94}
95impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for RestoreVolumeFromSnapshot {
96    fn config(&self) -> ::std::option::Option<::aws_smithy_types::config_bag::FrozenLayer> {
97        let mut cfg = ::aws_smithy_types::config_bag::Layer::new("RestoreVolumeFromSnapshot");
98
99        cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedRequestSerializer::new(
100            RestoreVolumeFromSnapshotRequestSerializer,
101        ));
102        cfg.store_put(::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer::new(
103            RestoreVolumeFromSnapshotResponseDeserializer,
104        ));
105
106        cfg.store_put(::aws_smithy_runtime_api::client::auth::AuthSchemeOptionResolverParams::new(
107            crate::config::auth::Params::builder()
108                .operation_name("RestoreVolumeFromSnapshot")
109                .build()
110                .expect("required fields set"),
111        ));
112
113        cfg.store_put(::aws_smithy_runtime_api::client::orchestrator::SensitiveOutput);
114        cfg.store_put(::aws_smithy_runtime_api::client::orchestrator::Metadata::new(
115            "RestoreVolumeFromSnapshot",
116            "FSx",
117        ));
118        let mut signing_options = ::aws_runtime::auth::SigningOptions::default();
119        signing_options.double_uri_encode = true;
120        signing_options.content_sha256_header = false;
121        signing_options.normalize_uri_path = true;
122        signing_options.payload_override = None;
123
124        cfg.store_put(::aws_runtime::auth::SigV4OperationSigningConfig {
125            signing_options,
126            ..::std::default::Default::default()
127        });
128
129        ::std::option::Option::Some(cfg.freeze())
130    }
131
132    fn runtime_components(
133        &self,
134        _: &::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder,
135    ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
136        #[allow(unused_mut)]
137        let mut rcb = ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("RestoreVolumeFromSnapshot")
138            .with_interceptor(::aws_smithy_runtime::client::stalled_stream_protection::StalledStreamProtectionInterceptor::default())
139            .with_interceptor(RestoreVolumeFromSnapshotEndpointParamsInterceptor)
140            .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::TransientErrorClassifier::<
141                crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotError,
142            >::new())
143            .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::ModeledAsRetryableClassifier::<
144                crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotError,
145            >::new())
146            .with_retry_classifier(::aws_runtime::retries::classifiers::AwsErrorCodeClassifier::<
147                crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotError,
148            >::new());
149
150        ::std::borrow::Cow::Owned(rcb)
151    }
152}
153
154#[derive(Debug)]
155struct RestoreVolumeFromSnapshotResponseDeserializer;
156impl ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse for RestoreVolumeFromSnapshotResponseDeserializer {
157    fn deserialize_nonstreaming(
158        &self,
159        response: &::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
160    ) -> ::aws_smithy_runtime_api::client::interceptors::context::OutputOrError {
161        let (success, status) = (response.status().is_success(), response.status().as_u16());
162        let headers = response.headers();
163        let body = response.body().bytes().expect("body loaded");
164        #[allow(unused_mut)]
165        let mut force_error = false;
166        ::tracing::debug!(request_id = ?::aws_types::request_id::RequestId::request_id(response));
167        let parse_result = if !success && status != 200 || force_error {
168            crate::protocol_serde::shape_restore_volume_from_snapshot::de_restore_volume_from_snapshot_http_error(status, headers, body)
169        } else {
170            crate::protocol_serde::shape_restore_volume_from_snapshot::de_restore_volume_from_snapshot_http_response(status, headers, body)
171        };
172        crate::protocol_serde::type_erase_result(parse_result)
173    }
174}
175#[derive(Debug)]
176struct RestoreVolumeFromSnapshotRequestSerializer;
177impl ::aws_smithy_runtime_api::client::ser_de::SerializeRequest for RestoreVolumeFromSnapshotRequestSerializer {
178    #[allow(unused_mut, clippy::let_and_return, clippy::needless_borrow, clippy::useless_conversion)]
179    fn serialize_input(
180        &self,
181        input: ::aws_smithy_runtime_api::client::interceptors::context::Input,
182        _cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
183    ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, ::aws_smithy_runtime_api::box_error::BoxError> {
184        let input = input
185            .downcast::<crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotInput>()
186            .expect("correct type");
187        let _header_serialization_settings = _cfg
188            .load::<crate::serialization_settings::HeaderSerializationSettings>()
189            .cloned()
190            .unwrap_or_default();
191        let mut request_builder = {
192            #[allow(clippy::uninlined_format_args)]
193            fn uri_base(
194                _input: &crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotInput,
195                output: &mut ::std::string::String,
196            ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
197                use ::std::fmt::Write as _;
198                ::std::write!(output, "/").expect("formatting should succeed");
199                ::std::result::Result::Ok(())
200            }
201            #[allow(clippy::unnecessary_wraps)]
202            fn update_http_builder(
203                input: &crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotInput,
204                builder: ::http::request::Builder,
205            ) -> ::std::result::Result<::http::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
206                let mut uri = ::std::string::String::new();
207                uri_base(input, &mut uri)?;
208                ::std::result::Result::Ok(builder.method("POST").uri(uri))
209            }
210            let mut builder = update_http_builder(&input, ::http::request::Builder::new())?;
211            builder = _header_serialization_settings.set_default_header(builder, ::http::header::CONTENT_TYPE, "application/x-amz-json-1.1");
212            builder = _header_serialization_settings.set_default_header(
213                builder,
214                ::http::header::HeaderName::from_static("x-amz-target"),
215                "AWSSimbaAPIService_v20180301.RestoreVolumeFromSnapshot",
216            );
217            builder
218        };
219        let body = ::aws_smithy_types::body::SdkBody::from(
220            crate::protocol_serde::shape_restore_volume_from_snapshot::ser_restore_volume_from_snapshot_input(&input)?,
221        );
222        if let Some(content_length) = body.content_length() {
223            let content_length = content_length.to_string();
224            request_builder = _header_serialization_settings.set_default_header(request_builder, ::http::header::CONTENT_LENGTH, &content_length);
225        }
226        ::std::result::Result::Ok(request_builder.body(body).expect("valid request").try_into().unwrap())
227    }
228}
229#[derive(Debug)]
230struct RestoreVolumeFromSnapshotEndpointParamsInterceptor;
231
232impl ::aws_smithy_runtime_api::client::interceptors::Intercept for RestoreVolumeFromSnapshotEndpointParamsInterceptor {
233    fn name(&self) -> &'static str {
234        "RestoreVolumeFromSnapshotEndpointParamsInterceptor"
235    }
236
237    fn read_before_execution(
238        &self,
239        context: &::aws_smithy_runtime_api::client::interceptors::context::BeforeSerializationInterceptorContextRef<
240            '_,
241            ::aws_smithy_runtime_api::client::interceptors::context::Input,
242            ::aws_smithy_runtime_api::client::interceptors::context::Output,
243            ::aws_smithy_runtime_api::client::interceptors::context::Error,
244        >,
245        cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
246    ) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
247        let _input = context
248            .input()
249            .downcast_ref::<RestoreVolumeFromSnapshotInput>()
250            .ok_or("failed to downcast to RestoreVolumeFromSnapshotInput")?;
251
252        let params = crate::config::endpoint::Params::builder()
253            .set_region(cfg.load::<::aws_types::region::Region>().map(|r| r.as_ref().to_owned()))
254            .set_use_dual_stack(cfg.load::<::aws_types::endpoint_config::UseDualStack>().map(|ty| ty.0))
255            .set_use_fips(cfg.load::<::aws_types::endpoint_config::UseFips>().map(|ty| ty.0))
256            .set_endpoint(cfg.load::<::aws_types::endpoint_config::EndpointUrl>().map(|ty| ty.0.clone()))
257            .build()
258            .map_err(|err| {
259                ::aws_smithy_runtime_api::client::interceptors::error::ContextAttachedError::new("endpoint params could not be built", err)
260            })?;
261        cfg.interceptor_state()
262            .store_put(::aws_smithy_runtime_api::client::endpoint::EndpointResolverParams::new(params));
263        ::std::result::Result::Ok(())
264    }
265}
266
267// The get_* functions below are generated from JMESPath expressions in the
268// operationContextParams trait. They target the operation's input shape.
269
270/// Error type for the `RestoreVolumeFromSnapshotError` operation.
271#[non_exhaustive]
272#[derive(::std::fmt::Debug)]
273pub enum RestoreVolumeFromSnapshotError {
274    /// <p>A generic error indicating a failure with a client request.</p>
275    BadRequest(crate::types::error::BadRequest),
276    /// <p>A generic error indicating a server-side failure.</p>
277    InternalServerError(crate::types::error::InternalServerError),
278    /// <p>No Amazon FSx volumes were found based upon the supplied parameters.</p>
279    VolumeNotFound(crate::types::error::VolumeNotFound),
280    /// An unexpected error occurred (e.g., invalid JSON returned by the service or an unknown error code).
281    #[deprecated(note = "Matching `Unhandled` directly is not forwards compatible. Instead, match using a \
282    variable wildcard pattern and check `.code()`:
283     \
284    &nbsp;&nbsp;&nbsp;`err if err.code() == Some(\"SpecificExceptionCode\") => { /* handle the error */ }`
285     \
286    See [`ProvideErrorMetadata`](#impl-ProvideErrorMetadata-for-RestoreVolumeFromSnapshotError) for what information is available for the error.")]
287    Unhandled(crate::error::sealed_unhandled::Unhandled),
288}
289impl RestoreVolumeFromSnapshotError {
290    /// Creates the `RestoreVolumeFromSnapshotError::Unhandled` variant from any error type.
291    pub fn unhandled(
292        err: impl ::std::convert::Into<::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>>,
293    ) -> Self {
294        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
295            source: err.into(),
296            meta: ::std::default::Default::default(),
297        })
298    }
299
300    /// Creates the `RestoreVolumeFromSnapshotError::Unhandled` variant from an [`ErrorMetadata`](::aws_smithy_types::error::ErrorMetadata).
301    pub fn generic(err: ::aws_smithy_types::error::ErrorMetadata) -> Self {
302        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
303            source: err.clone().into(),
304            meta: err,
305        })
306    }
307    ///
308    /// Returns error metadata, which includes the error code, message,
309    /// request ID, and potentially additional information.
310    ///
311    pub fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
312        match self {
313            Self::BadRequest(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
314            Self::InternalServerError(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
315            Self::VolumeNotFound(e) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(e),
316            Self::Unhandled(e) => &e.meta,
317        }
318    }
319    /// Returns `true` if the error kind is `RestoreVolumeFromSnapshotError::BadRequest`.
320    pub fn is_bad_request(&self) -> bool {
321        matches!(self, Self::BadRequest(_))
322    }
323    /// Returns `true` if the error kind is `RestoreVolumeFromSnapshotError::InternalServerError`.
324    pub fn is_internal_server_error(&self) -> bool {
325        matches!(self, Self::InternalServerError(_))
326    }
327    /// Returns `true` if the error kind is `RestoreVolumeFromSnapshotError::VolumeNotFound`.
328    pub fn is_volume_not_found(&self) -> bool {
329        matches!(self, Self::VolumeNotFound(_))
330    }
331}
332impl ::std::error::Error for RestoreVolumeFromSnapshotError {
333    fn source(&self) -> ::std::option::Option<&(dyn ::std::error::Error + 'static)> {
334        match self {
335            Self::BadRequest(_inner) => ::std::option::Option::Some(_inner),
336            Self::InternalServerError(_inner) => ::std::option::Option::Some(_inner),
337            Self::VolumeNotFound(_inner) => ::std::option::Option::Some(_inner),
338            Self::Unhandled(_inner) => ::std::option::Option::Some(&*_inner.source),
339        }
340    }
341}
342impl ::std::fmt::Display for RestoreVolumeFromSnapshotError {
343    fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
344        match self {
345            Self::BadRequest(_inner) => _inner.fmt(f),
346            Self::InternalServerError(_inner) => _inner.fmt(f),
347            Self::VolumeNotFound(_inner) => _inner.fmt(f),
348            Self::Unhandled(_inner) => {
349                if let ::std::option::Option::Some(code) = ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self) {
350                    write!(f, "unhandled error ({code})")
351                } else {
352                    f.write_str("unhandled error")
353                }
354            }
355        }
356    }
357}
358impl ::aws_smithy_types::retry::ProvideErrorKind for RestoreVolumeFromSnapshotError {
359    fn code(&self) -> ::std::option::Option<&str> {
360        ::aws_smithy_types::error::metadata::ProvideErrorMetadata::code(self)
361    }
362    fn retryable_error_kind(&self) -> ::std::option::Option<::aws_smithy_types::retry::ErrorKind> {
363        ::std::option::Option::None
364    }
365}
366impl ::aws_smithy_types::error::metadata::ProvideErrorMetadata for RestoreVolumeFromSnapshotError {
367    fn meta(&self) -> &::aws_smithy_types::error::ErrorMetadata {
368        match self {
369            Self::BadRequest(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
370            Self::InternalServerError(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
371            Self::VolumeNotFound(_inner) => ::aws_smithy_types::error::metadata::ProvideErrorMetadata::meta(_inner),
372            Self::Unhandled(_inner) => &_inner.meta,
373        }
374    }
375}
376impl ::aws_smithy_runtime_api::client::result::CreateUnhandledError for RestoreVolumeFromSnapshotError {
377    fn create_unhandled_error(
378        source: ::std::boxed::Box<dyn ::std::error::Error + ::std::marker::Send + ::std::marker::Sync + 'static>,
379        meta: ::std::option::Option<::aws_smithy_types::error::ErrorMetadata>,
380    ) -> Self {
381        Self::Unhandled(crate::error::sealed_unhandled::Unhandled {
382            source,
383            meta: meta.unwrap_or_default(),
384        })
385    }
386}
387impl ::aws_types::request_id::RequestId for crate::operation::restore_volume_from_snapshot::RestoreVolumeFromSnapshotError {
388    fn request_id(&self) -> Option<&str> {
389        self.meta().request_id()
390    }
391}
392
393pub use crate::operation::restore_volume_from_snapshot::_restore_volume_from_snapshot_output::RestoreVolumeFromSnapshotOutput;
394
395pub use crate::operation::restore_volume_from_snapshot::_restore_volume_from_snapshot_input::RestoreVolumeFromSnapshotInput;
396
397mod _restore_volume_from_snapshot_input;
398
399mod _restore_volume_from_snapshot_output;
400
401/// Builders
402pub mod builders;