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

import qualified Amazonka.Core as Core
import Amazonka.EMR.Types.AutoScalingPolicyStatus
import Amazonka.EMR.Types.ScalingConstraints
import Amazonka.EMR.Types.ScalingRule
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An automatic scaling policy for a core instance group or task instance
-- group in an Amazon EMR cluster. The automatic scaling policy defines how
-- an instance group dynamically adds and terminates EC2 instances in
-- response to the value of a CloudWatch metric. See PutAutoScalingPolicy.
--
-- /See:/ 'newAutoScalingPolicyDescription' smart constructor.
data AutoScalingPolicyDescription = AutoScalingPolicyDescription'
  { -- | The status of an automatic scaling policy.
    AutoScalingPolicyDescription -> Maybe AutoScalingPolicyStatus
status :: Prelude.Maybe AutoScalingPolicyStatus,
    -- | The scale-in and scale-out rules that comprise the automatic scaling
    -- policy.
    AutoScalingPolicyDescription -> Maybe [ScalingRule]
rules :: Prelude.Maybe [ScalingRule],
    -- | The upper and lower EC2 instance limits for an automatic scaling policy.
    -- Automatic scaling activity will not cause an instance group to grow
    -- above or below these limits.
    AutoScalingPolicyDescription -> Maybe ScalingConstraints
constraints :: Prelude.Maybe ScalingConstraints
  }
  deriving (AutoScalingPolicyDescription
-> AutoScalingPolicyDescription -> Bool
(AutoScalingPolicyDescription
 -> AutoScalingPolicyDescription -> Bool)
-> (AutoScalingPolicyDescription
    -> AutoScalingPolicyDescription -> Bool)
-> Eq AutoScalingPolicyDescription
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AutoScalingPolicyDescription
-> AutoScalingPolicyDescription -> Bool
$c/= :: AutoScalingPolicyDescription
-> AutoScalingPolicyDescription -> Bool
== :: AutoScalingPolicyDescription
-> AutoScalingPolicyDescription -> Bool
$c== :: AutoScalingPolicyDescription
-> AutoScalingPolicyDescription -> Bool
Prelude.Eq, ReadPrec [AutoScalingPolicyDescription]
ReadPrec AutoScalingPolicyDescription
Int -> ReadS AutoScalingPolicyDescription
ReadS [AutoScalingPolicyDescription]
(Int -> ReadS AutoScalingPolicyDescription)
-> ReadS [AutoScalingPolicyDescription]
-> ReadPrec AutoScalingPolicyDescription
-> ReadPrec [AutoScalingPolicyDescription]
-> Read AutoScalingPolicyDescription
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AutoScalingPolicyDescription]
$creadListPrec :: ReadPrec [AutoScalingPolicyDescription]
readPrec :: ReadPrec AutoScalingPolicyDescription
$creadPrec :: ReadPrec AutoScalingPolicyDescription
readList :: ReadS [AutoScalingPolicyDescription]
$creadList :: ReadS [AutoScalingPolicyDescription]
readsPrec :: Int -> ReadS AutoScalingPolicyDescription
$creadsPrec :: Int -> ReadS AutoScalingPolicyDescription
Prelude.Read, Int -> AutoScalingPolicyDescription -> ShowS
[AutoScalingPolicyDescription] -> ShowS
AutoScalingPolicyDescription -> String
(Int -> AutoScalingPolicyDescription -> ShowS)
-> (AutoScalingPolicyDescription -> String)
-> ([AutoScalingPolicyDescription] -> ShowS)
-> Show AutoScalingPolicyDescription
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AutoScalingPolicyDescription] -> ShowS
$cshowList :: [AutoScalingPolicyDescription] -> ShowS
show :: AutoScalingPolicyDescription -> String
$cshow :: AutoScalingPolicyDescription -> String
showsPrec :: Int -> AutoScalingPolicyDescription -> ShowS
$cshowsPrec :: Int -> AutoScalingPolicyDescription -> ShowS
Prelude.Show, (forall x.
 AutoScalingPolicyDescription -> Rep AutoScalingPolicyDescription x)
-> (forall x.
    Rep AutoScalingPolicyDescription x -> AutoScalingPolicyDescription)
-> Generic AutoScalingPolicyDescription
forall x.
Rep AutoScalingPolicyDescription x -> AutoScalingPolicyDescription
forall x.
AutoScalingPolicyDescription -> Rep AutoScalingPolicyDescription x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AutoScalingPolicyDescription x -> AutoScalingPolicyDescription
$cfrom :: forall x.
AutoScalingPolicyDescription -> Rep AutoScalingPolicyDescription x
Prelude.Generic)

-- |
-- Create a value of 'AutoScalingPolicyDescription' 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', 'autoScalingPolicyDescription_status' - The status of an automatic scaling policy.
--
-- 'rules', 'autoScalingPolicyDescription_rules' - The scale-in and scale-out rules that comprise the automatic scaling
-- policy.
--
-- 'constraints', 'autoScalingPolicyDescription_constraints' - The upper and lower EC2 instance limits for an automatic scaling policy.
-- Automatic scaling activity will not cause an instance group to grow
-- above or below these limits.
newAutoScalingPolicyDescription ::
  AutoScalingPolicyDescription
newAutoScalingPolicyDescription :: AutoScalingPolicyDescription
newAutoScalingPolicyDescription =
  AutoScalingPolicyDescription' :: Maybe AutoScalingPolicyStatus
-> Maybe [ScalingRule]
-> Maybe ScalingConstraints
-> AutoScalingPolicyDescription
AutoScalingPolicyDescription'
    { $sel:status:AutoScalingPolicyDescription' :: Maybe AutoScalingPolicyStatus
status =
        Maybe AutoScalingPolicyStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:rules:AutoScalingPolicyDescription' :: Maybe [ScalingRule]
rules = Maybe [ScalingRule]
forall a. Maybe a
Prelude.Nothing,
      $sel:constraints:AutoScalingPolicyDescription' :: Maybe ScalingConstraints
constraints = Maybe ScalingConstraints
forall a. Maybe a
Prelude.Nothing
    }

-- | The status of an automatic scaling policy.
autoScalingPolicyDescription_status :: Lens.Lens' AutoScalingPolicyDescription (Prelude.Maybe AutoScalingPolicyStatus)
autoScalingPolicyDescription_status :: (Maybe AutoScalingPolicyStatus
 -> f (Maybe AutoScalingPolicyStatus))
-> AutoScalingPolicyDescription -> f AutoScalingPolicyDescription
autoScalingPolicyDescription_status = (AutoScalingPolicyDescription -> Maybe AutoScalingPolicyStatus)
-> (AutoScalingPolicyDescription
    -> Maybe AutoScalingPolicyStatus -> AutoScalingPolicyDescription)
-> Lens
     AutoScalingPolicyDescription
     AutoScalingPolicyDescription
     (Maybe AutoScalingPolicyStatus)
     (Maybe AutoScalingPolicyStatus)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutoScalingPolicyDescription' {Maybe AutoScalingPolicyStatus
status :: Maybe AutoScalingPolicyStatus
$sel:status:AutoScalingPolicyDescription' :: AutoScalingPolicyDescription -> Maybe AutoScalingPolicyStatus
status} -> Maybe AutoScalingPolicyStatus
status) (\s :: AutoScalingPolicyDescription
s@AutoScalingPolicyDescription' {} Maybe AutoScalingPolicyStatus
a -> AutoScalingPolicyDescription
s {$sel:status:AutoScalingPolicyDescription' :: Maybe AutoScalingPolicyStatus
status = Maybe AutoScalingPolicyStatus
a} :: AutoScalingPolicyDescription)

-- | The scale-in and scale-out rules that comprise the automatic scaling
-- policy.
autoScalingPolicyDescription_rules :: Lens.Lens' AutoScalingPolicyDescription (Prelude.Maybe [ScalingRule])
autoScalingPolicyDescription_rules :: (Maybe [ScalingRule] -> f (Maybe [ScalingRule]))
-> AutoScalingPolicyDescription -> f AutoScalingPolicyDescription
autoScalingPolicyDescription_rules = (AutoScalingPolicyDescription -> Maybe [ScalingRule])
-> (AutoScalingPolicyDescription
    -> Maybe [ScalingRule] -> AutoScalingPolicyDescription)
-> Lens
     AutoScalingPolicyDescription
     AutoScalingPolicyDescription
     (Maybe [ScalingRule])
     (Maybe [ScalingRule])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutoScalingPolicyDescription' {Maybe [ScalingRule]
rules :: Maybe [ScalingRule]
$sel:rules:AutoScalingPolicyDescription' :: AutoScalingPolicyDescription -> Maybe [ScalingRule]
rules} -> Maybe [ScalingRule]
rules) (\s :: AutoScalingPolicyDescription
s@AutoScalingPolicyDescription' {} Maybe [ScalingRule]
a -> AutoScalingPolicyDescription
s {$sel:rules:AutoScalingPolicyDescription' :: Maybe [ScalingRule]
rules = Maybe [ScalingRule]
a} :: AutoScalingPolicyDescription) ((Maybe [ScalingRule] -> f (Maybe [ScalingRule]))
 -> AutoScalingPolicyDescription -> f AutoScalingPolicyDescription)
-> ((Maybe [ScalingRule] -> f (Maybe [ScalingRule]))
    -> Maybe [ScalingRule] -> f (Maybe [ScalingRule]))
-> (Maybe [ScalingRule] -> f (Maybe [ScalingRule]))
-> AutoScalingPolicyDescription
-> f AutoScalingPolicyDescription
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [ScalingRule] [ScalingRule] [ScalingRule] [ScalingRule]
-> Iso
     (Maybe [ScalingRule])
     (Maybe [ScalingRule])
     (Maybe [ScalingRule])
     (Maybe [ScalingRule])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [ScalingRule] [ScalingRule] [ScalingRule] [ScalingRule]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The upper and lower EC2 instance limits for an automatic scaling policy.
-- Automatic scaling activity will not cause an instance group to grow
-- above or below these limits.
autoScalingPolicyDescription_constraints :: Lens.Lens' AutoScalingPolicyDescription (Prelude.Maybe ScalingConstraints)
autoScalingPolicyDescription_constraints :: (Maybe ScalingConstraints -> f (Maybe ScalingConstraints))
-> AutoScalingPolicyDescription -> f AutoScalingPolicyDescription
autoScalingPolicyDescription_constraints = (AutoScalingPolicyDescription -> Maybe ScalingConstraints)
-> (AutoScalingPolicyDescription
    -> Maybe ScalingConstraints -> AutoScalingPolicyDescription)
-> Lens
     AutoScalingPolicyDescription
     AutoScalingPolicyDescription
     (Maybe ScalingConstraints)
     (Maybe ScalingConstraints)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AutoScalingPolicyDescription' {Maybe ScalingConstraints
constraints :: Maybe ScalingConstraints
$sel:constraints:AutoScalingPolicyDescription' :: AutoScalingPolicyDescription -> Maybe ScalingConstraints
constraints} -> Maybe ScalingConstraints
constraints) (\s :: AutoScalingPolicyDescription
s@AutoScalingPolicyDescription' {} Maybe ScalingConstraints
a -> AutoScalingPolicyDescription
s {$sel:constraints:AutoScalingPolicyDescription' :: Maybe ScalingConstraints
constraints = Maybe ScalingConstraints
a} :: AutoScalingPolicyDescription)

instance Core.FromJSON AutoScalingPolicyDescription where
  parseJSON :: Value -> Parser AutoScalingPolicyDescription
parseJSON =
    String
-> (Object -> Parser AutoScalingPolicyDescription)
-> Value
-> Parser AutoScalingPolicyDescription
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AutoScalingPolicyDescription"
      ( \Object
x ->
          Maybe AutoScalingPolicyStatus
-> Maybe [ScalingRule]
-> Maybe ScalingConstraints
-> AutoScalingPolicyDescription
AutoScalingPolicyDescription'
            (Maybe AutoScalingPolicyStatus
 -> Maybe [ScalingRule]
 -> Maybe ScalingConstraints
 -> AutoScalingPolicyDescription)
-> Parser (Maybe AutoScalingPolicyStatus)
-> Parser
     (Maybe [ScalingRule]
      -> Maybe ScalingConstraints -> AutoScalingPolicyDescription)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe AutoScalingPolicyStatus)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Status")
            Parser
  (Maybe [ScalingRule]
   -> Maybe ScalingConstraints -> AutoScalingPolicyDescription)
-> Parser (Maybe [ScalingRule])
-> Parser
     (Maybe ScalingConstraints -> AutoScalingPolicyDescription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [ScalingRule]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Rules" Parser (Maybe (Maybe [ScalingRule]))
-> Maybe [ScalingRule] -> Parser (Maybe [ScalingRule])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [ScalingRule]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe ScalingConstraints -> AutoScalingPolicyDescription)
-> Parser (Maybe ScalingConstraints)
-> Parser AutoScalingPolicyDescription
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ScalingConstraints)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Constraints")
      )

instance
  Prelude.Hashable
    AutoScalingPolicyDescription

instance Prelude.NFData AutoScalingPolicyDescription