{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.EMR.Types.ScalingRule where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.EMR.Types.ScalingAction
import Amazonka.EMR.Types.ScalingTrigger
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
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]
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
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. 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'
    { $sel:description:ScalingRule' :: Maybe Text
description = 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 :: Lens' ScalingRule (Maybe Text)
scalingRule_description = 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 :: Lens' ScalingRule Text
scalingRule_name = 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 :: Lens' ScalingRule ScalingAction
scalingRule_action = 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 :: Lens' ScalingRule ScalingTrigger
scalingRule_trigger = 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 Data.FromJSON ScalingRule where
  parseJSON :: Value -> Parser ScalingRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ScalingRule"
      ( \Object
x ->
          Maybe Text
-> Text -> ScalingAction -> ScalingTrigger -> ScalingRule
ScalingRule'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Description")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Action")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Trigger")
      )

instance Prelude.Hashable ScalingRule where
  hashWithSalt :: Int -> ScalingRule -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ScalingAction
action
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ScalingTrigger
trigger

instance Prelude.NFData ScalingRule where
  rnf :: ScalingRule -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ScalingAction
action
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ScalingTrigger
trigger

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Description" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description,
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"Action" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ScalingAction
action),
            forall a. a -> Maybe a
Prelude.Just (Key
"Trigger" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ScalingTrigger
trigger)
          ]
      )