use std::collections::HashMap;
use serde_derive::{Deserialize, Serialize};
use serde_json::Value;
use crate::models::duration::*;
use crate::models::event::*;
use crate::models::error::*;
use crate::models::map::*;
use crate::models::input::*;
use crate::models::resource::*;
use crate::models::retry::*;
use super::output::OutputDataModelDefinition;
use super::timeout::OneOfTimeoutDefinitionOrReference;
pub struct TaskType;
impl TaskType {
pub const CALL: &'static str = "call";
pub const DO: &'static str = "do";
pub const EMIT: &'static str = "emit";
pub const FOR: &'static str = "for";
pub const FORK: &'static str = "fork";
pub const LISTEN: &'static str = "listen";
pub const RAISE: &'static str = "raise";
pub const RUN: &'static str = "run";
pub const SET: &'static str = "set";
pub const SWITCH: &'static str = "switch";
pub const TRY: &'static str = "try";
pub const WAIT: &'static str = "wait";
}
pub struct ProcessType;
impl ProcessType {
pub const CONTAINER: &'static str = "container";
pub const SCRIPT: &'static str = "script";
pub const SHELL: &'static str = "shell";
pub const WORKFLOW: &'static str = "workflow";
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TaskDefinition{
Call(CallTaskDefinition),
Do(DoTaskDefinition),
Emit(EmitTaskDefinition),
For(ForTaskDefinition),
Fork(ForkTaskDefinition),
Listen(ListenTaskDefinition),
Raise(RaiseTaskDefinition),
Run(RunTaskDefinition),
Set(SetTaskDefinition),
Switch(SwitchTaskDefinition),
Try(TryTaskDefinition),
Wait(WaitTaskDefinition)
}
pub trait TaskDefinitionBase {
fn task_type(&self) -> &str;
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TaskDefinitionFields{
#[serde(rename = "if", skip_serializing_if = "Option::is_none")]
pub if_: Option<String>,
#[serde(rename = "input", skip_serializing_if = "Option::is_none")]
pub input: Option<InputDataModelDefinition>,
#[serde(rename = "output", skip_serializing_if = "Option::is_none")]
pub output: Option<OutputDataModelDefinition>,
#[serde(rename = "export", skip_serializing_if = "Option::is_none")]
pub export: Option<OutputDataModelDefinition>,
#[serde(rename = "timeout", skip_serializing_if = "Option::is_none")]
pub timeout: Option<OneOfTimeoutDefinitionOrReference>,
#[serde(rename = "then", skip_serializing_if = "Option::is_none")]
pub then: Option<String>,
#[serde(rename = "metadata", skip_serializing_if = "Option::is_none")]
pub metadata: Option<HashMap<String, Value>>
}
impl Default for TaskDefinitionFields{
fn default() -> Self {
TaskDefinitionFields::new()
}
}
impl TaskDefinitionFields{
pub fn new() -> Self{
Self {
if_: None,
input: None,
output: None,
export: None,
timeout: None,
then: None,
metadata: None
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct CallTaskDefinition{
#[serde(rename = "call")]
pub call: String,
#[serde(rename = "with", skip_serializing_if = "Option::is_none")]
pub with: Option<HashMap<String, Value>>,
#[serde(rename = "await", skip_serializing_if = "Option::is_none")]
pub await_: Option<bool>,
#[serde(flatten)]
pub common: TaskDefinitionFields
}
impl TaskDefinitionBase for CallTaskDefinition {
fn task_type(&self) -> &str {
TaskType::CALL
}
}
impl CallTaskDefinition {
pub fn new(call: &str, with: Option<HashMap<String, Value>>, await_: Option<bool>) -> Self{
Self {
call: call.to_string(),
with,
await_,
common: TaskDefinitionFields::new()
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct DoTaskDefinition{
#[serde(rename = "do")]
pub do_: Map<String, TaskDefinition>,
#[serde(flatten)]
pub common: TaskDefinitionFields
}
impl TaskDefinitionBase for DoTaskDefinition {
fn task_type(&self) -> &str {
TaskType::DO
}
}
impl DoTaskDefinition {
pub fn new(do_: Map<String, TaskDefinition>) -> Self{
Self {
do_,
common: TaskDefinitionFields::new()
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct EmitTaskDefinition{
#[serde(rename = "emit")]
pub emit: EventEmissionDefinition,
#[serde(flatten)]
pub common: TaskDefinitionFields,
}
impl TaskDefinitionBase for EmitTaskDefinition {
fn task_type(&self) -> &str {
TaskType::EMIT
}
}
impl EmitTaskDefinition {
pub fn new(emit: EventEmissionDefinition) -> Self{
Self {
emit,
common: TaskDefinitionFields::new()
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct EventEmissionDefinition{
#[serde(rename = "event")]
pub event: EventDefinition
}
impl EventEmissionDefinition {
pub fn new(event: EventDefinition) -> Self{
Self {
event
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ForTaskDefinition{
#[serde(rename = "for")]
pub for_: ForLoopDefinition,
#[serde(rename = "while", skip_serializing_if = "Option::is_none")]
pub while_: Option<String>,
#[serde(rename = "do")]
pub do_: Map<String, TaskDefinition>,
#[serde(flatten)]
pub common: TaskDefinitionFields
}
impl TaskDefinitionBase for ForTaskDefinition {
fn task_type(&self) -> &str {
TaskType::FOR
}
}
impl ForTaskDefinition {
pub fn new(for_: ForLoopDefinition, do_: Map<String, TaskDefinition>, while_: Option<String>) -> Self{
Self {
for_,
while_,
do_,
common: TaskDefinitionFields::new()
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ForLoopDefinition{
#[serde(rename = "emit")]
pub each: String,
#[serde(rename = "in")]
pub in_: String,
#[serde(rename = "at", skip_serializing_if = "Option::is_none")]
pub at: Option<String>,
#[serde(rename = "input", skip_serializing_if = "Option::is_none")]
pub input: Option<InputDataModelDefinition>,
}
impl ForLoopDefinition {
pub fn new(each: &str, in_: &str, at: Option<String>, input: Option<InputDataModelDefinition>) -> Self{
Self {
each: each.to_string(),
in_: in_.to_string(),
at,
input
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ForkTaskDefinition{
#[serde(rename = "fork")]
pub fork: BranchingDefinition,
#[serde(flatten)]
pub common: TaskDefinitionFields
}
impl TaskDefinitionBase for ForkTaskDefinition {
fn task_type(&self) -> &str {
TaskType::FORK
}
}
impl ForkTaskDefinition {
pub fn new(fork: BranchingDefinition) -> Self{
Self {
fork,
common: TaskDefinitionFields::new()
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct BranchingDefinition{
#[serde(rename = "branches")]
pub branches: Map<String, TaskDefinition>,
#[serde(rename = "compete")]
pub compete: bool
}
impl BranchingDefinition{
pub fn new(branches:Map<String, TaskDefinition>, compete: bool) -> Self{
Self {
branches,
compete
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ListenTaskDefinition{
#[serde(rename = "listen")]
pub listen: ListenerDefinition,
#[serde(rename = "foreach")]
pub foreach: Option<SubscriptionIteratorDefinition>,
#[serde(flatten)]
pub common: TaskDefinitionFields
}
impl TaskDefinitionBase for ListenTaskDefinition {
fn task_type(&self) -> &str {
TaskType::LISTEN
}
}
impl ListenTaskDefinition {
pub fn new(listen: ListenerDefinition) -> Self{
Self {
listen,
foreach: None,
common: TaskDefinitionFields::new()
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ListenerDefinition{
#[serde(rename = "to")]
pub to: EventConsumptionStrategyDefinition,
#[serde(rename = "read")]
pub read: Option<String>
}
impl ListenerDefinition {
pub fn new(to: EventConsumptionStrategyDefinition) -> Self{
Self{
to,
read: None
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct RaiseTaskDefinition{
#[serde(rename = "raise")]
pub raise: RaiseErrorDefinition,
#[serde(flatten)]
pub common: TaskDefinitionFields
}
impl TaskDefinitionBase for RaiseTaskDefinition {
fn task_type(&self) -> &str {
TaskType::RAISE
}
}
impl RaiseTaskDefinition {
pub fn new(raise: RaiseErrorDefinition) -> Self{
Self{
raise,
common: TaskDefinitionFields::new()
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct RaiseErrorDefinition{
#[serde(rename = "error")]
pub error: OneOfErrorDefinitionOrReference
}
impl RaiseErrorDefinition{
pub fn new(error: OneOfErrorDefinitionOrReference) -> Self{
Self { error }
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct RunTaskDefinition{
#[serde(rename = "run")]
pub run: ProcessTypeDefinition,
#[serde(flatten)]
pub common: TaskDefinitionFields
}
impl TaskDefinitionBase for RunTaskDefinition {
fn task_type(&self) -> &str {
TaskType::RUN
}
}
impl RunTaskDefinition {
pub fn new(run: ProcessTypeDefinition) -> Self{
Self {
run,
common: TaskDefinitionFields::new()
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ProcessTypeDefinition{
#[serde(rename = "container", skip_serializing_if = "Option::is_none")]
pub container: Option<ContainerProcessDefinition>,
#[serde(rename = "script", skip_serializing_if = "Option::is_none")]
pub script: Option<ScriptProcessDefinition>,
#[serde(rename = "shell", skip_serializing_if = "Option::is_none")]
pub shell: Option<ShellProcessDefinition>,
#[serde(rename = "workflow", skip_serializing_if = "Option::is_none")]
pub workflow: Option<WorkflowProcessDefinition>,
#[serde(rename = "await", skip_serializing_if = "Option::is_none")]
pub await_: Option<bool>
}
impl ProcessTypeDefinition {
pub fn using_container(container: ContainerProcessDefinition, await_: Option<bool>) -> Self{
Self {
container: Some(container),
await_,
shell: None,
script: None,
workflow: None
}
}
pub fn using_script(script: ScriptProcessDefinition, await_: Option<bool>) -> Self{
Self {
script: Some(script),
await_,
container: None,
shell: None,
workflow: None
}
}
pub fn using_shell(shell: ShellProcessDefinition, await_: Option<bool>) -> Self{
Self {
shell: Some(shell),
await_,
container: None,
script: None,
workflow: None
}
}
pub fn using_workflow(workflow: WorkflowProcessDefinition, await_: Option<bool>) -> Self{
Self {
workflow: Some(workflow),
await_,
container: None,
shell: None,
script: None
}
}
pub fn get_process_type(&self) -> &str{
if self.container.is_some(){
ProcessType::CONTAINER
}
else if self.script.is_some(){
ProcessType::SCRIPT
}
else if self.shell.is_some(){
ProcessType::SHELL
}
else{
ProcessType::WORKFLOW
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ContainerProcessDefinition{
#[serde(rename = "image")]
pub image: String,
#[serde(rename = "name")]
pub name: Option<String>,
#[serde(rename = "command", skip_serializing_if = "Option::is_none")]
pub command: Option<String>,
#[serde(rename = "ports", skip_serializing_if = "Option::is_none")]
pub ports: Option<HashMap<u16, u16>>,
#[serde(rename = "volumes", skip_serializing_if = "Option::is_none")]
pub volumes: Option<HashMap<String, String>>,
#[serde(rename = "environment", skip_serializing_if = "Option::is_none")]
pub environment: Option<HashMap<String, String>>,
}
impl ContainerProcessDefinition {
pub fn new(image: &str, name: Option<String>, command: Option<String>, ports: Option<HashMap<u16, u16>>, volumes: Option<HashMap<String, String>>, environment: Option<HashMap<String, String>>) -> Self{
Self {
image: image.to_string(),
name,
command,
ports,
volumes,
environment
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ScriptProcessDefinition{
#[serde(rename = "language")]
pub language: String,
#[serde(rename = "code", skip_serializing_if = "Option::is_none")]
pub code: Option<String>,
#[serde(rename = "source", skip_serializing_if = "Option::is_none")]
pub source: Option<ExternalResourceDefinition>,
#[serde(rename = "arguments", skip_serializing_if = "Option::is_none")]
pub arguments: Option<HashMap<String, String>>,
#[serde(rename = "environment", skip_serializing_if = "Option::is_none")]
pub environment: Option<HashMap<String, String>>,
}
impl ScriptProcessDefinition {
pub fn from_code(language: &str, code: String, arguments: Option<HashMap<String, String>>, environment: Option<HashMap<String, String>>) -> Self{
Self {
language: language.to_string(),
code: Some(code),
source: None,
arguments,
environment
}
}
pub fn from_source(language: &str, source: ExternalResourceDefinition, arguments: Option<HashMap<String, String>>, environment: Option<HashMap<String, String>>) -> Self{
Self {
language: language.to_string(),
code: None,
source: Some(source),
arguments,
environment
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ShellProcessDefinition{
#[serde(rename = "command")]
pub command: String,
#[serde(rename = "arguments", skip_serializing_if = "Option::is_none")]
pub arguments: Option<Vec<String>>,
#[serde(rename = "environment", skip_serializing_if = "Option::is_none")]
pub environment: Option<HashMap<String, String>>,
}
impl ShellProcessDefinition {
pub fn new(command: &str, arguments: Option<Vec<String>>, environment: Option<HashMap<String, String>>) -> Self{
Self {
command: command.to_string(),
arguments,
environment
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct WorkflowProcessDefinition{
#[serde(rename = "namespace")]
pub namespace: String,
#[serde(rename = "name")]
pub name: String,
#[serde(rename = "version")]
pub version: String,
#[serde(rename = "input", skip_serializing_if = "Option::is_none")]
pub input: Option<Value>
}
impl WorkflowProcessDefinition {
pub fn new(namespace: &str, name: &str, version: &str, input: Option<Value>) -> Self{
Self {
namespace: namespace.to_string(),
name: name.to_string(),
version: version.to_string(),
input
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct SetTaskDefinition{
#[serde(rename = "set")]
pub set: HashMap<String, Value>,
#[serde(flatten)]
pub common: TaskDefinitionFields
}
impl TaskDefinitionBase for SetTaskDefinition {
fn task_type(&self) -> &str {
TaskType::SET
}
}
impl SetTaskDefinition {
pub fn new() -> Self{
Self {
set: HashMap::new(),
common: TaskDefinitionFields::new()
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct SwitchTaskDefinition{
#[serde(rename = "switch")]
pub switch: Map<String, SwitchCaseDefinition>,
#[serde(flatten)]
pub common: TaskDefinitionFields
}
impl TaskDefinitionBase for SwitchTaskDefinition {
fn task_type(&self) -> &str {
TaskType::SWITCH
}
}
impl SwitchTaskDefinition {
pub fn new() -> Self{
Self {
switch: Map::new(),
common: TaskDefinitionFields::new()
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct SwitchCaseDefinition{
#[serde(rename = "when", skip_serializing_if = "Option::is_none")]
pub when: Option<String>,
#[serde(rename = "then", skip_serializing_if = "Option::is_none")]
pub then: Option<String>
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct TryTaskDefinition{
#[serde(rename = "try")]
pub try_: Map<String, TaskDefinition>,
#[serde(rename = "catch")]
pub catch: ErrorCatcherDefinition,
#[serde(flatten)]
pub common: TaskDefinitionFields
}
impl TaskDefinitionBase for TryTaskDefinition {
fn task_type(&self) -> &str {
TaskType::TRY
}
}
impl TryTaskDefinition {
pub fn new(try_: Map<String, TaskDefinition>, catch: ErrorCatcherDefinition) -> Self{
Self {
try_,
catch,
common: TaskDefinitionFields::new()
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ErrorCatcherDefinition{
#[serde(rename = "errors", skip_serializing_if = "Option::is_none")]
pub errors: Option<ErrorFilterDefinition>,
#[serde(rename = "as", skip_serializing_if = "Option::is_none")]
pub as_: Option<String>,
#[serde(rename = "when", skip_serializing_if = "Option::is_none")]
pub when: Option<String>,
#[serde(rename = "exceptWhen", skip_serializing_if = "Option::is_none")]
pub except_when: Option<String>,
#[serde(rename = "retry", skip_serializing_if = "Option::is_none")]
pub retry: Option<OneOfRetryPolicyDefinitionOrReference>,
#[serde(rename = "do", skip_serializing_if = "Option::is_none")]
pub do_: Option<Map<String, TaskDefinition>>
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct ErrorFilterDefinition{
#[serde(rename = "with", skip_serializing_if = "Option::is_none")]
pub with: Option<HashMap<String, Value>>
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct WaitTaskDefinition{
#[serde(rename = "duration")]
pub duration: OneOfDurationOrIso8601Expression,
#[serde(flatten)]
pub common: TaskDefinitionFields
}
impl TaskDefinitionBase for WaitTaskDefinition {
fn task_type(&self) -> &str {
TaskType::WAIT
}
}
impl WaitTaskDefinition {
pub fn new(duration: OneOfDurationOrIso8601Expression) -> Self{
Self {
duration,
common: TaskDefinitionFields::new()
}
}
}
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct SubscriptionIteratorDefinition{
#[serde(rename = "item")]
pub item: Option<String>,
#[serde(rename = "at")]
pub at: Option<String>,
#[serde(rename = "do")]
pub do_: Option<Map<String, TaskDefinition>>,
#[serde(rename = "output", skip_serializing_if = "Option::is_none")]
pub output: Option<OutputDataModelDefinition>,
#[serde(rename = "export", skip_serializing_if = "Option::is_none")]
pub export: Option<OutputDataModelDefinition>
}
impl SubscriptionIteratorDefinition{
pub fn new() -> Self{
SubscriptionIteratorDefinition::default()
}
}