{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.EMR.Types.Step
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.EMR.Types.Step where

import qualified Amazonka.Core as Core
import Amazonka.EMR.Types.ActionOnFailure
import Amazonka.EMR.Types.HadoopStepConfig
import Amazonka.EMR.Types.StepStatus
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | This represents a step in a cluster.
--
-- /See:/ 'newStep' smart constructor.
data Step = Step'
  { -- | The current execution status details of the cluster step.
    Step -> Maybe StepStatus
status :: Prelude.Maybe StepStatus,
    -- | The action to take when the cluster step fails. Possible values are
    -- @TERMINATE_CLUSTER@, @CANCEL_AND_WAIT@, and @CONTINUE@.
    -- @TERMINATE_JOB_FLOW@ is provided for backward compatibility. We
    -- recommend using @TERMINATE_CLUSTER@ instead.
    --
    -- If a cluster\'s @StepConcurrencyLevel@ is greater than @1@, do not use
    -- @AddJobFlowSteps@ to submit a step with this parameter set to
    -- @CANCEL_AND_WAIT@ or @TERMINATE_CLUSTER@. The step is not submitted and
    -- the action fails with a message that the @ActionOnFailure@ setting is
    -- not valid.
    --
    -- If you change a cluster\'s @StepConcurrencyLevel@ to be greater than 1
    -- while a step is running, the @ActionOnFailure@ parameter may not behave
    -- as you expect. In this case, for a step that fails with this parameter
    -- set to @CANCEL_AND_WAIT@, pending steps and the running step are not
    -- canceled; for a step that fails with this parameter set to
    -- @TERMINATE_CLUSTER@, the cluster does not terminate.
    Step -> Maybe ActionOnFailure
actionOnFailure :: Prelude.Maybe ActionOnFailure,
    -- | The Hadoop job configuration of the cluster step.
    Step -> Maybe HadoopStepConfig
config :: Prelude.Maybe HadoopStepConfig,
    -- | The name of the cluster step.
    Step -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The identifier of the cluster step.
    Step -> Maybe Text
id :: Prelude.Maybe Prelude.Text
  }
  deriving (Step -> Step -> Bool
(Step -> Step -> Bool) -> (Step -> Step -> Bool) -> Eq Step
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Step -> Step -> Bool
$c/= :: Step -> Step -> Bool
== :: Step -> Step -> Bool
$c== :: Step -> Step -> Bool
Prelude.Eq, ReadPrec [Step]
ReadPrec Step
Int -> ReadS Step
ReadS [Step]
(Int -> ReadS Step)
-> ReadS [Step] -> ReadPrec Step -> ReadPrec [Step] -> Read Step
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Step]
$creadListPrec :: ReadPrec [Step]
readPrec :: ReadPrec Step
$creadPrec :: ReadPrec Step
readList :: ReadS [Step]
$creadList :: ReadS [Step]
readsPrec :: Int -> ReadS Step
$creadsPrec :: Int -> ReadS Step
Prelude.Read, Int -> Step -> ShowS
[Step] -> ShowS
Step -> String
(Int -> Step -> ShowS)
-> (Step -> String) -> ([Step] -> ShowS) -> Show Step
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Step] -> ShowS
$cshowList :: [Step] -> ShowS
show :: Step -> String
$cshow :: Step -> String
showsPrec :: Int -> Step -> ShowS
$cshowsPrec :: Int -> Step -> ShowS
Prelude.Show, (forall x. Step -> Rep Step x)
-> (forall x. Rep Step x -> Step) -> Generic Step
forall x. Rep Step x -> Step
forall x. Step -> Rep Step x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Step x -> Step
$cfrom :: forall x. Step -> Rep Step x
Prelude.Generic)

-- |
-- Create a value of 'Step' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'status', 'step_status' - The current execution status details of the cluster step.
--
-- 'actionOnFailure', 'step_actionOnFailure' - The action to take when the cluster step fails. Possible values are
-- @TERMINATE_CLUSTER@, @CANCEL_AND_WAIT@, and @CONTINUE@.
-- @TERMINATE_JOB_FLOW@ is provided for backward compatibility. We
-- recommend using @TERMINATE_CLUSTER@ instead.
--
-- If a cluster\'s @StepConcurrencyLevel@ is greater than @1@, do not use
-- @AddJobFlowSteps@ to submit a step with this parameter set to
-- @CANCEL_AND_WAIT@ or @TERMINATE_CLUSTER@. The step is not submitted and
-- the action fails with a message that the @ActionOnFailure@ setting is
-- not valid.
--
-- If you change a cluster\'s @StepConcurrencyLevel@ to be greater than 1
-- while a step is running, the @ActionOnFailure@ parameter may not behave
-- as you expect. In this case, for a step that fails with this parameter
-- set to @CANCEL_AND_WAIT@, pending steps and the running step are not
-- canceled; for a step that fails with this parameter set to
-- @TERMINATE_CLUSTER@, the cluster does not terminate.
--
-- 'config', 'step_config' - The Hadoop job configuration of the cluster step.
--
-- 'name', 'step_name' - The name of the cluster step.
--
-- 'id', 'step_id' - The identifier of the cluster step.
newStep ::
  Step
newStep :: Step
newStep =
  Step' :: Maybe StepStatus
-> Maybe ActionOnFailure
-> Maybe HadoopStepConfig
-> Maybe Text
-> Maybe Text
-> Step
Step'
    { $sel:status:Step' :: Maybe StepStatus
status = Maybe StepStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:actionOnFailure:Step' :: Maybe ActionOnFailure
actionOnFailure = Maybe ActionOnFailure
forall a. Maybe a
Prelude.Nothing,
      $sel:config:Step' :: Maybe HadoopStepConfig
config = Maybe HadoopStepConfig
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Step' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:id:Step' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The current execution status details of the cluster step.
step_status :: Lens.Lens' Step (Prelude.Maybe StepStatus)
step_status :: (Maybe StepStatus -> f (Maybe StepStatus)) -> Step -> f Step
step_status = (Step -> Maybe StepStatus)
-> (Step -> Maybe StepStatus -> Step)
-> Lens Step Step (Maybe StepStatus) (Maybe StepStatus)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Step' {Maybe StepStatus
status :: Maybe StepStatus
$sel:status:Step' :: Step -> Maybe StepStatus
status} -> Maybe StepStatus
status) (\s :: Step
s@Step' {} Maybe StepStatus
a -> Step
s {$sel:status:Step' :: Maybe StepStatus
status = Maybe StepStatus
a} :: Step)

-- | The action to take when the cluster step fails. Possible values are
-- @TERMINATE_CLUSTER@, @CANCEL_AND_WAIT@, and @CONTINUE@.
-- @TERMINATE_JOB_FLOW@ is provided for backward compatibility. We
-- recommend using @TERMINATE_CLUSTER@ instead.
--
-- If a cluster\'s @StepConcurrencyLevel@ is greater than @1@, do not use
-- @AddJobFlowSteps@ to submit a step with this parameter set to
-- @CANCEL_AND_WAIT@ or @TERMINATE_CLUSTER@. The step is not submitted and
-- the action fails with a message that the @ActionOnFailure@ setting is
-- not valid.
--
-- If you change a cluster\'s @StepConcurrencyLevel@ to be greater than 1
-- while a step is running, the @ActionOnFailure@ parameter may not behave
-- as you expect. In this case, for a step that fails with this parameter
-- set to @CANCEL_AND_WAIT@, pending steps and the running step are not
-- canceled; for a step that fails with this parameter set to
-- @TERMINATE_CLUSTER@, the cluster does not terminate.
step_actionOnFailure :: Lens.Lens' Step (Prelude.Maybe ActionOnFailure)
step_actionOnFailure :: (Maybe ActionOnFailure -> f (Maybe ActionOnFailure))
-> Step -> f Step
step_actionOnFailure = (Step -> Maybe ActionOnFailure)
-> (Step -> Maybe ActionOnFailure -> Step)
-> Lens Step Step (Maybe ActionOnFailure) (Maybe ActionOnFailure)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Step' {Maybe ActionOnFailure
actionOnFailure :: Maybe ActionOnFailure
$sel:actionOnFailure:Step' :: Step -> Maybe ActionOnFailure
actionOnFailure} -> Maybe ActionOnFailure
actionOnFailure) (\s :: Step
s@Step' {} Maybe ActionOnFailure
a -> Step
s {$sel:actionOnFailure:Step' :: Maybe ActionOnFailure
actionOnFailure = Maybe ActionOnFailure
a} :: Step)

-- | The Hadoop job configuration of the cluster step.
step_config :: Lens.Lens' Step (Prelude.Maybe HadoopStepConfig)
step_config :: (Maybe HadoopStepConfig -> f (Maybe HadoopStepConfig))
-> Step -> f Step
step_config = (Step -> Maybe HadoopStepConfig)
-> (Step -> Maybe HadoopStepConfig -> Step)
-> Lens Step Step (Maybe HadoopStepConfig) (Maybe HadoopStepConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Step' {Maybe HadoopStepConfig
config :: Maybe HadoopStepConfig
$sel:config:Step' :: Step -> Maybe HadoopStepConfig
config} -> Maybe HadoopStepConfig
config) (\s :: Step
s@Step' {} Maybe HadoopStepConfig
a -> Step
s {$sel:config:Step' :: Maybe HadoopStepConfig
config = Maybe HadoopStepConfig
a} :: Step)

-- | The name of the cluster step.
step_name :: Lens.Lens' Step (Prelude.Maybe Prelude.Text)
step_name :: (Maybe Text -> f (Maybe Text)) -> Step -> f Step
step_name = (Step -> Maybe Text)
-> (Step -> Maybe Text -> Step)
-> Lens Step Step (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Step' {Maybe Text
name :: Maybe Text
$sel:name:Step' :: Step -> Maybe Text
name} -> Maybe Text
name) (\s :: Step
s@Step' {} Maybe Text
a -> Step
s {$sel:name:Step' :: Maybe Text
name = Maybe Text
a} :: Step)

-- | The identifier of the cluster step.
step_id :: Lens.Lens' Step (Prelude.Maybe Prelude.Text)
step_id :: (Maybe Text -> f (Maybe Text)) -> Step -> f Step
step_id = (Step -> Maybe Text)
-> (Step -> Maybe Text -> Step)
-> Lens Step Step (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Step' {Maybe Text
id :: Maybe Text
$sel:id:Step' :: Step -> Maybe Text
id} -> Maybe Text
id) (\s :: Step
s@Step' {} Maybe Text
a -> Step
s {$sel:id:Step' :: Maybe Text
id = Maybe Text
a} :: Step)

instance Core.FromJSON Step where
  parseJSON :: Value -> Parser Step
parseJSON =
    String -> (Object -> Parser Step) -> Value -> Parser Step
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Step"
      ( \Object
x ->
          Maybe StepStatus
-> Maybe ActionOnFailure
-> Maybe HadoopStepConfig
-> Maybe Text
-> Maybe Text
-> Step
Step'
            (Maybe StepStatus
 -> Maybe ActionOnFailure
 -> Maybe HadoopStepConfig
 -> Maybe Text
 -> Maybe Text
 -> Step)
-> Parser (Maybe StepStatus)
-> Parser
     (Maybe ActionOnFailure
      -> Maybe HadoopStepConfig -> Maybe Text -> Maybe Text -> Step)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe StepStatus)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Status")
            Parser
  (Maybe ActionOnFailure
   -> Maybe HadoopStepConfig -> Maybe Text -> Maybe Text -> Step)
-> Parser (Maybe ActionOnFailure)
-> Parser
     (Maybe HadoopStepConfig -> Maybe Text -> Maybe Text -> Step)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ActionOnFailure)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ActionOnFailure")
            Parser (Maybe HadoopStepConfig -> Maybe Text -> Maybe Text -> Step)
-> Parser (Maybe HadoopStepConfig)
-> Parser (Maybe Text -> Maybe Text -> Step)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe HadoopStepConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Config")
            Parser (Maybe Text -> Maybe Text -> Step)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Step)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Name")
            Parser (Maybe Text -> Step) -> Parser (Maybe Text) -> Parser Step
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Id")
      )

instance Prelude.Hashable Step

instance Prelude.NFData Step