{-# 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.ScalingRule
-- 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.ScalingRule where

import qualified Amazonka.Core as Core
import Amazonka.EMR.Types.ScalingAction
import Amazonka.EMR.Types.ScalingTrigger
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A scale-in or scale-out rule that defines scaling activity, including
-- the CloudWatch metric alarm that triggers activity, how EC2 instances
-- are added or removed, and the periodicity of adjustments. The automatic
-- scaling policy for an instance group can comprise one or more automatic
-- scaling rules.
--
-- /See:/ 'newScalingRule' smart constructor.
data ScalingRule = ScalingRule'
  { -- | A friendly, more verbose description of the automatic scaling rule.
    ScalingRule -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The name used to identify an automatic scaling rule. Rule names must be
    -- unique within a scaling policy.
    ScalingRule -> Text
name :: Prelude.Text,
    -- | The conditions that trigger an automatic scaling activity.
    ScalingRule -> ScalingAction
action :: ScalingAction,
    -- | The CloudWatch alarm definition that determines when automatic scaling
    -- activity is triggered.
    ScalingRule -> ScalingTrigger
trigger :: ScalingTrigger
  }
  deriving (ScalingRule -> ScalingRule -> Bool
(ScalingRule -> ScalingRule -> Bool)
-> (ScalingRule -> ScalingRule -> Bool) -> Eq ScalingRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScalingRule -> ScalingRule -> Bool
$c/= :: ScalingRule -> ScalingRule -> Bool
== :: ScalingRule -> ScalingRule -> Bool
$c== :: ScalingRule -> ScalingRule -> Bool
Prelude.Eq, ReadPrec [ScalingRule]
ReadPrec ScalingRule
Int -> ReadS ScalingRule
ReadS [ScalingRule]
(Int -> ReadS ScalingRule)
-> ReadS [ScalingRule]
-> ReadPrec ScalingRule
-> ReadPrec [ScalingRule]
-> Read ScalingRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ScalingRule]
$creadListPrec :: ReadPrec [ScalingRule]
readPrec :: ReadPrec ScalingRule
$creadPrec :: ReadPrec ScalingRule
readList :: ReadS [ScalingRule]
$creadList :: ReadS [ScalingRule]
readsPrec :: Int -> ReadS ScalingRule
$creadsPrec :: Int -> ReadS ScalingRule
Prelude.Read, Int -> ScalingRule -> ShowS
[ScalingRule] -> ShowS
ScalingRule -> String
(Int -> ScalingRule -> ShowS)
-> (ScalingRule -> String)
-> ([ScalingRule] -> ShowS)
-> Show ScalingRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScalingRule] -> ShowS
$cshowList :: [ScalingRule] -> ShowS
show :: ScalingRule -> String
$cshow :: ScalingRule -> String
showsPrec :: Int -> ScalingRule -> ShowS
$cshowsPrec :: Int -> ScalingRule -> ShowS
Prelude.Show, (forall x. ScalingRule -> Rep ScalingRule x)
-> (forall x. Rep ScalingRule x -> ScalingRule)
-> Generic ScalingRule
forall x. Rep ScalingRule x -> ScalingRule
forall x. ScalingRule -> Rep ScalingRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ScalingRule x -> ScalingRule
$cfrom :: forall x. ScalingRule -> Rep ScalingRule x
Prelude.Generic)

-- |
-- Create a value of 'ScalingRule' 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:
--
-- 'description', 'scalingRule_description' - A friendly, more verbose description of the automatic scaling rule.
--
-- 'name', 'scalingRule_name' - The name used to identify an automatic scaling rule. Rule names must be
-- unique within a scaling policy.
--
-- 'action', 'scalingRule_action' - The conditions that trigger an automatic scaling activity.
--
-- 'trigger', 'scalingRule_trigger' - The CloudWatch alarm definition that determines when automatic scaling
-- activity is triggered.
newScalingRule ::
  -- | 'name'
  Prelude.Text ->
  -- | 'action'
  ScalingAction ->
  -- | 'trigger'
  ScalingTrigger ->
  ScalingRule
newScalingRule :: Text -> ScalingAction -> ScalingTrigger -> ScalingRule
newScalingRule Text
pName_ ScalingAction
pAction_ ScalingTrigger
pTrigger_ =
  ScalingRule' :: Maybe Text
-> Text -> ScalingAction -> ScalingTrigger -> ScalingRule
ScalingRule'
    { $sel:description:ScalingRule' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:ScalingRule' :: Text
name = Text
pName_,
      $sel:action:ScalingRule' :: ScalingAction
action = ScalingAction
pAction_,
      $sel:trigger:ScalingRule' :: ScalingTrigger
trigger = ScalingTrigger
pTrigger_
    }

-- | A friendly, more verbose description of the automatic scaling rule.
scalingRule_description :: Lens.Lens' ScalingRule (Prelude.Maybe Prelude.Text)
scalingRule_description :: (Maybe Text -> f (Maybe Text)) -> ScalingRule -> f ScalingRule
scalingRule_description = (ScalingRule -> Maybe Text)
-> (ScalingRule -> Maybe Text -> ScalingRule)
-> Lens ScalingRule ScalingRule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ScalingRule' {Maybe Text
description :: Maybe Text
$sel:description:ScalingRule' :: ScalingRule -> Maybe Text
description} -> Maybe Text
description) (\s :: ScalingRule
s@ScalingRule' {} Maybe Text
a -> ScalingRule
s {$sel:description:ScalingRule' :: Maybe Text
description = Maybe Text
a} :: ScalingRule)

-- | The name used to identify an automatic scaling rule. Rule names must be
-- unique within a scaling policy.
scalingRule_name :: Lens.Lens' ScalingRule Prelude.Text
scalingRule_name :: (Text -> f Text) -> ScalingRule -> f ScalingRule
scalingRule_name = (ScalingRule -> Text)
-> (ScalingRule -> Text -> ScalingRule)
-> Lens ScalingRule ScalingRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ScalingRule' {Text
name :: Text
$sel:name:ScalingRule' :: ScalingRule -> Text
name} -> Text
name) (\s :: ScalingRule
s@ScalingRule' {} Text
a -> ScalingRule
s {$sel:name:ScalingRule' :: Text
name = Text
a} :: ScalingRule)

-- | The conditions that trigger an automatic scaling activity.
scalingRule_action :: Lens.Lens' ScalingRule ScalingAction
scalingRule_action :: (ScalingAction -> f ScalingAction) -> ScalingRule -> f ScalingRule
scalingRule_action = (ScalingRule -> ScalingAction)
-> (ScalingRule -> ScalingAction -> ScalingRule)
-> Lens ScalingRule ScalingRule ScalingAction ScalingAction
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ScalingRule' {ScalingAction
action :: ScalingAction
$sel:action:ScalingRule' :: ScalingRule -> ScalingAction
action} -> ScalingAction
action) (\s :: ScalingRule
s@ScalingRule' {} ScalingAction
a -> ScalingRule
s {$sel:action:ScalingRule' :: ScalingAction
action = ScalingAction
a} :: ScalingRule)

-- | The CloudWatch alarm definition that determines when automatic scaling
-- activity is triggered.
scalingRule_trigger :: Lens.Lens' ScalingRule ScalingTrigger
scalingRule_trigger :: (ScalingTrigger -> f ScalingTrigger)
-> ScalingRule -> f ScalingRule
scalingRule_trigger = (ScalingRule -> ScalingTrigger)
-> (ScalingRule -> ScalingTrigger -> ScalingRule)
-> Lens ScalingRule ScalingRule ScalingTrigger ScalingTrigger
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ScalingRule' {ScalingTrigger
trigger :: ScalingTrigger
$sel:trigger:ScalingRule' :: ScalingRule -> ScalingTrigger
trigger} -> ScalingTrigger
trigger) (\s :: ScalingRule
s@ScalingRule' {} ScalingTrigger
a -> ScalingRule
s {$sel:trigger:ScalingRule' :: ScalingTrigger
trigger = ScalingTrigger
a} :: ScalingRule)

instance Core.FromJSON ScalingRule where
  parseJSON :: Value -> Parser ScalingRule
parseJSON =
    String
-> (Object -> Parser ScalingRule) -> Value -> Parser ScalingRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ScalingRule"
      ( \Object
x ->
          Maybe Text
-> Text -> ScalingAction -> ScalingTrigger -> ScalingRule
ScalingRule'
            (Maybe Text
 -> Text -> ScalingAction -> ScalingTrigger -> ScalingRule)
-> Parser (Maybe Text)
-> Parser (Text -> ScalingAction -> ScalingTrigger -> ScalingRule)
forall (f :: * -> *) a b. Functor 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
"Description")
            Parser (Text -> ScalingAction -> ScalingTrigger -> ScalingRule)
-> Parser Text
-> Parser (ScalingAction -> ScalingTrigger -> ScalingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Name")
            Parser (ScalingAction -> ScalingTrigger -> ScalingRule)
-> Parser ScalingAction -> Parser (ScalingTrigger -> ScalingRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ScalingAction
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Action")
            Parser (ScalingTrigger -> ScalingRule)
-> Parser ScalingTrigger -> Parser ScalingRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ScalingTrigger
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Trigger")
      )

instance Prelude.Hashable ScalingRule

instance Prelude.NFData ScalingRule

instance Core.ToJSON ScalingRule where
  toJSON :: ScalingRule -> Value
toJSON ScalingRule' {Maybe Text
Text
ScalingAction
ScalingTrigger
trigger :: ScalingTrigger
action :: ScalingAction
name :: Text
description :: Maybe Text
$sel:trigger:ScalingRule' :: ScalingRule -> ScalingTrigger
$sel:action:ScalingRule' :: ScalingRule -> ScalingAction
$sel:name:ScalingRule' :: ScalingRule -> Text
$sel:description:ScalingRule' :: ScalingRule -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Description" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Action" Text -> ScalingAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ScalingAction
action),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Trigger" Text -> ScalingTrigger -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ScalingTrigger
trigger)
          ]
      )