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

import qualified Amazonka.Core as Core
import Amazonka.EMR.Types.ComputeLimits
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Managed scaling policy for an Amazon EMR cluster. The policy specifies
-- the limits for resources that can be added or terminated from a cluster.
-- The policy only applies to the core and task nodes. The master node
-- cannot be scaled after initial configuration.
--
-- /See:/ 'newManagedScalingPolicy' smart constructor.
data ManagedScalingPolicy = ManagedScalingPolicy'
  { -- | The EC2 unit limits for a managed scaling policy. The managed scaling
    -- activity of a cluster is not allowed to go above or below these limits.
    -- The limit only applies to the core and task nodes. The master node
    -- cannot be scaled after initial configuration.
    ManagedScalingPolicy -> Maybe ComputeLimits
computeLimits :: Prelude.Maybe ComputeLimits
  }
  deriving (ManagedScalingPolicy -> ManagedScalingPolicy -> Bool
(ManagedScalingPolicy -> ManagedScalingPolicy -> Bool)
-> (ManagedScalingPolicy -> ManagedScalingPolicy -> Bool)
-> Eq ManagedScalingPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ManagedScalingPolicy -> ManagedScalingPolicy -> Bool
$c/= :: ManagedScalingPolicy -> ManagedScalingPolicy -> Bool
== :: ManagedScalingPolicy -> ManagedScalingPolicy -> Bool
$c== :: ManagedScalingPolicy -> ManagedScalingPolicy -> Bool
Prelude.Eq, ReadPrec [ManagedScalingPolicy]
ReadPrec ManagedScalingPolicy
Int -> ReadS ManagedScalingPolicy
ReadS [ManagedScalingPolicy]
(Int -> ReadS ManagedScalingPolicy)
-> ReadS [ManagedScalingPolicy]
-> ReadPrec ManagedScalingPolicy
-> ReadPrec [ManagedScalingPolicy]
-> Read ManagedScalingPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ManagedScalingPolicy]
$creadListPrec :: ReadPrec [ManagedScalingPolicy]
readPrec :: ReadPrec ManagedScalingPolicy
$creadPrec :: ReadPrec ManagedScalingPolicy
readList :: ReadS [ManagedScalingPolicy]
$creadList :: ReadS [ManagedScalingPolicy]
readsPrec :: Int -> ReadS ManagedScalingPolicy
$creadsPrec :: Int -> ReadS ManagedScalingPolicy
Prelude.Read, Int -> ManagedScalingPolicy -> ShowS
[ManagedScalingPolicy] -> ShowS
ManagedScalingPolicy -> String
(Int -> ManagedScalingPolicy -> ShowS)
-> (ManagedScalingPolicy -> String)
-> ([ManagedScalingPolicy] -> ShowS)
-> Show ManagedScalingPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ManagedScalingPolicy] -> ShowS
$cshowList :: [ManagedScalingPolicy] -> ShowS
show :: ManagedScalingPolicy -> String
$cshow :: ManagedScalingPolicy -> String
showsPrec :: Int -> ManagedScalingPolicy -> ShowS
$cshowsPrec :: Int -> ManagedScalingPolicy -> ShowS
Prelude.Show, (forall x. ManagedScalingPolicy -> Rep ManagedScalingPolicy x)
-> (forall x. Rep ManagedScalingPolicy x -> ManagedScalingPolicy)
-> Generic ManagedScalingPolicy
forall x. Rep ManagedScalingPolicy x -> ManagedScalingPolicy
forall x. ManagedScalingPolicy -> Rep ManagedScalingPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ManagedScalingPolicy x -> ManagedScalingPolicy
$cfrom :: forall x. ManagedScalingPolicy -> Rep ManagedScalingPolicy x
Prelude.Generic)

-- |
-- Create a value of 'ManagedScalingPolicy' 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:
--
-- 'computeLimits', 'managedScalingPolicy_computeLimits' - The EC2 unit limits for a managed scaling policy. The managed scaling
-- activity of a cluster is not allowed to go above or below these limits.
-- The limit only applies to the core and task nodes. The master node
-- cannot be scaled after initial configuration.
newManagedScalingPolicy ::
  ManagedScalingPolicy
newManagedScalingPolicy :: ManagedScalingPolicy
newManagedScalingPolicy =
  ManagedScalingPolicy' :: Maybe ComputeLimits -> ManagedScalingPolicy
ManagedScalingPolicy'
    { $sel:computeLimits:ManagedScalingPolicy' :: Maybe ComputeLimits
computeLimits =
        Maybe ComputeLimits
forall a. Maybe a
Prelude.Nothing
    }

-- | The EC2 unit limits for a managed scaling policy. The managed scaling
-- activity of a cluster is not allowed to go above or below these limits.
-- The limit only applies to the core and task nodes. The master node
-- cannot be scaled after initial configuration.
managedScalingPolicy_computeLimits :: Lens.Lens' ManagedScalingPolicy (Prelude.Maybe ComputeLimits)
managedScalingPolicy_computeLimits :: (Maybe ComputeLimits -> f (Maybe ComputeLimits))
-> ManagedScalingPolicy -> f ManagedScalingPolicy
managedScalingPolicy_computeLimits = (ManagedScalingPolicy -> Maybe ComputeLimits)
-> (ManagedScalingPolicy
    -> Maybe ComputeLimits -> ManagedScalingPolicy)
-> Lens
     ManagedScalingPolicy
     ManagedScalingPolicy
     (Maybe ComputeLimits)
     (Maybe ComputeLimits)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ManagedScalingPolicy' {Maybe ComputeLimits
computeLimits :: Maybe ComputeLimits
$sel:computeLimits:ManagedScalingPolicy' :: ManagedScalingPolicy -> Maybe ComputeLimits
computeLimits} -> Maybe ComputeLimits
computeLimits) (\s :: ManagedScalingPolicy
s@ManagedScalingPolicy' {} Maybe ComputeLimits
a -> ManagedScalingPolicy
s {$sel:computeLimits:ManagedScalingPolicy' :: Maybe ComputeLimits
computeLimits = Maybe ComputeLimits
a} :: ManagedScalingPolicy)

instance Core.FromJSON ManagedScalingPolicy where
  parseJSON :: Value -> Parser ManagedScalingPolicy
parseJSON =
    String
-> (Object -> Parser ManagedScalingPolicy)
-> Value
-> Parser ManagedScalingPolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ManagedScalingPolicy"
      ( \Object
x ->
          Maybe ComputeLimits -> ManagedScalingPolicy
ManagedScalingPolicy'
            (Maybe ComputeLimits -> ManagedScalingPolicy)
-> Parser (Maybe ComputeLimits) -> Parser ManagedScalingPolicy
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ComputeLimits)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ComputeLimits")
      )

instance Prelude.Hashable ManagedScalingPolicy

instance Prelude.NFData ManagedScalingPolicy

instance Core.ToJSON ManagedScalingPolicy where
  toJSON :: ManagedScalingPolicy -> Value
toJSON ManagedScalingPolicy' {Maybe ComputeLimits
computeLimits :: Maybe ComputeLimits
$sel:computeLimits:ManagedScalingPolicy' :: ManagedScalingPolicy -> Maybe ComputeLimits
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ComputeLimits" Text -> ComputeLimits -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ComputeLimits -> Pair) -> Maybe ComputeLimits -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ComputeLimits
computeLimits
          ]
      )