use std::error::Error;
use std::fmt;
use async_trait::async_trait;
use rusoto_core::credential::ProvideAwsCredentials;
use rusoto_core::region;
use rusoto_core::request::{BufferedHttpResponse, DispatchSignedRequest};
use rusoto_core::{Client, RusotoError};
use rusoto_core::param::{Params, ServiceParams};
use rusoto_core::proto;
use rusoto_core::signature::SignedRequest;
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
use serde_json;
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct DeleteHumanLoopRequest {
#[serde(rename = "HumanLoopName")]
pub human_loop_name: String,
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct DeleteHumanLoopResponse {}
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct DescribeHumanLoopRequest {
#[serde(rename = "HumanLoopName")]
pub human_loop_name: String,
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct DescribeHumanLoopResponse {
#[serde(rename = "CreationTime")]
pub creation_time: f64,
#[serde(rename = "FailureCode")]
#[serde(skip_serializing_if = "Option::is_none")]
pub failure_code: Option<String>,
#[serde(rename = "FailureReason")]
#[serde(skip_serializing_if = "Option::is_none")]
pub failure_reason: Option<String>,
#[serde(rename = "FlowDefinitionArn")]
pub flow_definition_arn: String,
#[serde(rename = "HumanLoopArn")]
pub human_loop_arn: String,
#[serde(rename = "HumanLoopName")]
pub human_loop_name: String,
#[serde(rename = "HumanLoopOutput")]
#[serde(skip_serializing_if = "Option::is_none")]
pub human_loop_output: Option<HumanLoopOutput>,
#[serde(rename = "HumanLoopStatus")]
pub human_loop_status: String,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct HumanLoopDataAttributes {
#[serde(rename = "ContentClassifiers")]
pub content_classifiers: Vec<String>,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct HumanLoopInput {
#[serde(rename = "InputContent")]
pub input_content: String,
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct HumanLoopOutput {
#[serde(rename = "OutputS3Uri")]
pub output_s3_uri: String,
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct HumanLoopSummary {
#[serde(rename = "CreationTime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub creation_time: Option<f64>,
#[serde(rename = "FailureReason")]
#[serde(skip_serializing_if = "Option::is_none")]
pub failure_reason: Option<String>,
#[serde(rename = "FlowDefinitionArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub flow_definition_arn: Option<String>,
#[serde(rename = "HumanLoopName")]
#[serde(skip_serializing_if = "Option::is_none")]
pub human_loop_name: Option<String>,
#[serde(rename = "HumanLoopStatus")]
#[serde(skip_serializing_if = "Option::is_none")]
pub human_loop_status: Option<String>,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct ListHumanLoopsRequest {
#[serde(rename = "CreationTimeAfter")]
#[serde(skip_serializing_if = "Option::is_none")]
pub creation_time_after: Option<f64>,
#[serde(rename = "CreationTimeBefore")]
#[serde(skip_serializing_if = "Option::is_none")]
pub creation_time_before: Option<f64>,
#[serde(rename = "FlowDefinitionArn")]
pub flow_definition_arn: String,
#[serde(rename = "MaxResults")]
#[serde(skip_serializing_if = "Option::is_none")]
pub max_results: Option<i64>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
#[serde(rename = "SortOrder")]
#[serde(skip_serializing_if = "Option::is_none")]
pub sort_order: Option<String>,
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct ListHumanLoopsResponse {
#[serde(rename = "HumanLoopSummaries")]
pub human_loop_summaries: Vec<HumanLoopSummary>,
#[serde(rename = "NextToken")]
#[serde(skip_serializing_if = "Option::is_none")]
pub next_token: Option<String>,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct StartHumanLoopRequest {
#[serde(rename = "DataAttributes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub data_attributes: Option<HumanLoopDataAttributes>,
#[serde(rename = "FlowDefinitionArn")]
pub flow_definition_arn: String,
#[serde(rename = "HumanLoopInput")]
pub human_loop_input: HumanLoopInput,
#[serde(rename = "HumanLoopName")]
pub human_loop_name: String,
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct StartHumanLoopResponse {
#[serde(rename = "HumanLoopArn")]
#[serde(skip_serializing_if = "Option::is_none")]
pub human_loop_arn: Option<String>,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
#[cfg_attr(feature = "deserialize_structs", derive(Deserialize))]
pub struct StopHumanLoopRequest {
#[serde(rename = "HumanLoopName")]
pub human_loop_name: String,
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
#[cfg_attr(any(test, feature = "serialize_structs"), derive(Serialize))]
pub struct StopHumanLoopResponse {}
#[derive(Debug, PartialEq)]
pub enum DeleteHumanLoopError {
InternalServer(String),
ResourceNotFound(String),
Throttling(String),
}
impl DeleteHumanLoopError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<DeleteHumanLoopError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"InternalServerException" => {
return RusotoError::Service(DeleteHumanLoopError::InternalServer(err.msg))
}
"ResourceNotFoundException" => {
return RusotoError::Service(DeleteHumanLoopError::ResourceNotFound(err.msg))
}
"ThrottlingException" => {
return RusotoError::Service(DeleteHumanLoopError::Throttling(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
RusotoError::Unknown(res)
}
}
impl fmt::Display for DeleteHumanLoopError {
#[allow(unused_variables)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
DeleteHumanLoopError::InternalServer(ref cause) => write!(f, "{}", cause),
DeleteHumanLoopError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
DeleteHumanLoopError::Throttling(ref cause) => write!(f, "{}", cause),
}
}
}
impl Error for DeleteHumanLoopError {}
#[derive(Debug, PartialEq)]
pub enum DescribeHumanLoopError {
InternalServer(String),
ResourceNotFound(String),
Throttling(String),
}
impl DescribeHumanLoopError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<DescribeHumanLoopError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"InternalServerException" => {
return RusotoError::Service(DescribeHumanLoopError::InternalServer(err.msg))
}
"ResourceNotFoundException" => {
return RusotoError::Service(DescribeHumanLoopError::ResourceNotFound(err.msg))
}
"ThrottlingException" => {
return RusotoError::Service(DescribeHumanLoopError::Throttling(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
RusotoError::Unknown(res)
}
}
impl fmt::Display for DescribeHumanLoopError {
#[allow(unused_variables)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
DescribeHumanLoopError::InternalServer(ref cause) => write!(f, "{}", cause),
DescribeHumanLoopError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
DescribeHumanLoopError::Throttling(ref cause) => write!(f, "{}", cause),
}
}
}
impl Error for DescribeHumanLoopError {}
#[derive(Debug, PartialEq)]
pub enum ListHumanLoopsError {
InternalServer(String),
ResourceNotFound(String),
Throttling(String),
}
impl ListHumanLoopsError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<ListHumanLoopsError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"InternalServerException" => {
return RusotoError::Service(ListHumanLoopsError::InternalServer(err.msg))
}
"ResourceNotFoundException" => {
return RusotoError::Service(ListHumanLoopsError::ResourceNotFound(err.msg))
}
"ThrottlingException" => {
return RusotoError::Service(ListHumanLoopsError::Throttling(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
RusotoError::Unknown(res)
}
}
impl fmt::Display for ListHumanLoopsError {
#[allow(unused_variables)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ListHumanLoopsError::InternalServer(ref cause) => write!(f, "{}", cause),
ListHumanLoopsError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
ListHumanLoopsError::Throttling(ref cause) => write!(f, "{}", cause),
}
}
}
impl Error for ListHumanLoopsError {}
#[derive(Debug, PartialEq)]
pub enum StartHumanLoopError {
Conflict(String),
InternalServer(String),
ServiceQuotaExceeded(String),
Throttling(String),
}
impl StartHumanLoopError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<StartHumanLoopError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"ConflictException" => {
return RusotoError::Service(StartHumanLoopError::Conflict(err.msg))
}
"InternalServerException" => {
return RusotoError::Service(StartHumanLoopError::InternalServer(err.msg))
}
"ServiceQuotaExceededException" => {
return RusotoError::Service(StartHumanLoopError::ServiceQuotaExceeded(err.msg))
}
"ThrottlingException" => {
return RusotoError::Service(StartHumanLoopError::Throttling(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
RusotoError::Unknown(res)
}
}
impl fmt::Display for StartHumanLoopError {
#[allow(unused_variables)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
StartHumanLoopError::Conflict(ref cause) => write!(f, "{}", cause),
StartHumanLoopError::InternalServer(ref cause) => write!(f, "{}", cause),
StartHumanLoopError::ServiceQuotaExceeded(ref cause) => write!(f, "{}", cause),
StartHumanLoopError::Throttling(ref cause) => write!(f, "{}", cause),
}
}
}
impl Error for StartHumanLoopError {}
#[derive(Debug, PartialEq)]
pub enum StopHumanLoopError {
InternalServer(String),
ResourceNotFound(String),
Throttling(String),
}
impl StopHumanLoopError {
pub fn from_response(res: BufferedHttpResponse) -> RusotoError<StopHumanLoopError> {
if let Some(err) = proto::json::Error::parse_rest(&res) {
match err.typ.as_str() {
"InternalServerException" => {
return RusotoError::Service(StopHumanLoopError::InternalServer(err.msg))
}
"ResourceNotFoundException" => {
return RusotoError::Service(StopHumanLoopError::ResourceNotFound(err.msg))
}
"ThrottlingException" => {
return RusotoError::Service(StopHumanLoopError::Throttling(err.msg))
}
"ValidationException" => return RusotoError::Validation(err.msg),
_ => {}
}
}
RusotoError::Unknown(res)
}
}
impl fmt::Display for StopHumanLoopError {
#[allow(unused_variables)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
StopHumanLoopError::InternalServer(ref cause) => write!(f, "{}", cause),
StopHumanLoopError::ResourceNotFound(ref cause) => write!(f, "{}", cause),
StopHumanLoopError::Throttling(ref cause) => write!(f, "{}", cause),
}
}
}
impl Error for StopHumanLoopError {}
#[async_trait]
pub trait SagemakerA2iRuntime {
async fn delete_human_loop(
&self,
input: DeleteHumanLoopRequest,
) -> Result<DeleteHumanLoopResponse, RusotoError<DeleteHumanLoopError>>;
async fn describe_human_loop(
&self,
input: DescribeHumanLoopRequest,
) -> Result<DescribeHumanLoopResponse, RusotoError<DescribeHumanLoopError>>;
async fn list_human_loops(
&self,
input: ListHumanLoopsRequest,
) -> Result<ListHumanLoopsResponse, RusotoError<ListHumanLoopsError>>;
async fn start_human_loop(
&self,
input: StartHumanLoopRequest,
) -> Result<StartHumanLoopResponse, RusotoError<StartHumanLoopError>>;
async fn stop_human_loop(
&self,
input: StopHumanLoopRequest,
) -> Result<StopHumanLoopResponse, RusotoError<StopHumanLoopError>>;
}
#[derive(Clone)]
pub struct SagemakerA2iRuntimeClient {
client: Client,
region: region::Region,
}
impl SagemakerA2iRuntimeClient {
pub fn new(region: region::Region) -> SagemakerA2iRuntimeClient {
SagemakerA2iRuntimeClient {
client: Client::shared(),
region,
}
}
pub fn new_with<P, D>(
request_dispatcher: D,
credentials_provider: P,
region: region::Region,
) -> SagemakerA2iRuntimeClient
where
P: ProvideAwsCredentials + Send + Sync + 'static,
D: DispatchSignedRequest + Send + Sync + 'static,
{
SagemakerA2iRuntimeClient {
client: Client::new_with(credentials_provider, request_dispatcher),
region,
}
}
pub fn new_with_client(client: Client, region: region::Region) -> SagemakerA2iRuntimeClient {
SagemakerA2iRuntimeClient { client, region }
}
}
#[async_trait]
impl SagemakerA2iRuntime for SagemakerA2iRuntimeClient {
#[allow(unused_mut)]
async fn delete_human_loop(
&self,
input: DeleteHumanLoopRequest,
) -> Result<DeleteHumanLoopResponse, RusotoError<DeleteHumanLoopError>> {
let request_uri = format!(
"/human-loops/{human_loop_name}",
human_loop_name = input.human_loop_name
);
let mut request = SignedRequest::new("DELETE", "sagemaker", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.set_endpoint_prefix("a2i-runtime.sagemaker".to_string());
let mut response = self
.client
.sign_and_dispatch(request)
.await
.map_err(RusotoError::from)?;
if response.status.is_success() {
let mut response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
let result = proto::json::ResponsePayload::new(&response)
.deserialize::<DeleteHumanLoopResponse, _>()?;
Ok(result)
} else {
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
Err(DeleteHumanLoopError::from_response(response))
}
}
#[allow(unused_mut)]
async fn describe_human_loop(
&self,
input: DescribeHumanLoopRequest,
) -> Result<DescribeHumanLoopResponse, RusotoError<DescribeHumanLoopError>> {
let request_uri = format!(
"/human-loops/{human_loop_name}",
human_loop_name = input.human_loop_name
);
let mut request = SignedRequest::new("GET", "sagemaker", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.set_endpoint_prefix("a2i-runtime.sagemaker".to_string());
let mut response = self
.client
.sign_and_dispatch(request)
.await
.map_err(RusotoError::from)?;
if response.status.is_success() {
let mut response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
let result = proto::json::ResponsePayload::new(&response)
.deserialize::<DescribeHumanLoopResponse, _>()?;
Ok(result)
} else {
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
Err(DescribeHumanLoopError::from_response(response))
}
}
#[allow(unused_mut)]
async fn list_human_loops(
&self,
input: ListHumanLoopsRequest,
) -> Result<ListHumanLoopsResponse, RusotoError<ListHumanLoopsError>> {
let request_uri = "/human-loops";
let mut request = SignedRequest::new("GET", "sagemaker", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.set_endpoint_prefix("a2i-runtime.sagemaker".to_string());
let mut params = Params::new();
if let Some(ref x) = input.creation_time_after {
params.put("CreationTimeAfter", x);
}
if let Some(ref x) = input.creation_time_before {
params.put("CreationTimeBefore", x);
}
params.put("FlowDefinitionArn", &input.flow_definition_arn);
if let Some(ref x) = input.max_results {
params.put("MaxResults", x);
}
if let Some(ref x) = input.next_token {
params.put("NextToken", x);
}
if let Some(ref x) = input.sort_order {
params.put("SortOrder", x);
}
request.set_params(params);
let mut response = self
.client
.sign_and_dispatch(request)
.await
.map_err(RusotoError::from)?;
if response.status.is_success() {
let mut response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
let result = proto::json::ResponsePayload::new(&response)
.deserialize::<ListHumanLoopsResponse, _>()?;
Ok(result)
} else {
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
Err(ListHumanLoopsError::from_response(response))
}
}
#[allow(unused_mut)]
async fn start_human_loop(
&self,
input: StartHumanLoopRequest,
) -> Result<StartHumanLoopResponse, RusotoError<StartHumanLoopError>> {
let request_uri = "/human-loops";
let mut request = SignedRequest::new("POST", "sagemaker", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.set_endpoint_prefix("a2i-runtime.sagemaker".to_string());
let encoded = Some(serde_json::to_vec(&input).unwrap());
request.set_payload(encoded);
let mut response = self
.client
.sign_and_dispatch(request)
.await
.map_err(RusotoError::from)?;
if response.status.is_success() {
let mut response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
let result = proto::json::ResponsePayload::new(&response)
.deserialize::<StartHumanLoopResponse, _>()?;
Ok(result)
} else {
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
Err(StartHumanLoopError::from_response(response))
}
}
#[allow(unused_mut)]
async fn stop_human_loop(
&self,
input: StopHumanLoopRequest,
) -> Result<StopHumanLoopResponse, RusotoError<StopHumanLoopError>> {
let request_uri = "/human-loops/stop";
let mut request = SignedRequest::new("POST", "sagemaker", &self.region, &request_uri);
request.set_content_type("application/x-amz-json-1.1".to_owned());
request.set_endpoint_prefix("a2i-runtime.sagemaker".to_string());
let encoded = Some(serde_json::to_vec(&input).unwrap());
request.set_payload(encoded);
let mut response = self
.client
.sign_and_dispatch(request)
.await
.map_err(RusotoError::from)?;
if response.status.is_success() {
let mut response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
let result = proto::json::ResponsePayload::new(&response)
.deserialize::<StopHumanLoopResponse, _>()?;
Ok(result)
} else {
let response = response.buffer().await.map_err(RusotoError::HttpDispatch)?;
Err(StopHumanLoopError::from_response(response))
}
}
}