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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The upper and lower EC2 instance limits for an automatic scaling policy.
-- Automatic scaling activities triggered by automatic scaling rules will
-- not cause an instance group to grow above or below these limits.
--
-- /See:/ 'newScalingConstraints' smart constructor.
data ScalingConstraints = ScalingConstraints'
  { -- | The lower boundary of EC2 instances in an instance group below which
    -- scaling activities are not allowed to shrink. Scale-in activities will
    -- not terminate instances below this boundary.
    ScalingConstraints -> Int
minCapacity :: Prelude.Int,
    -- | The upper boundary of EC2 instances in an instance group beyond which
    -- scaling activities are not allowed to grow. Scale-out activities will
    -- not add instances beyond this boundary.
    ScalingConstraints -> Int
maxCapacity :: Prelude.Int
  }
  deriving (ScalingConstraints -> ScalingConstraints -> Bool
(ScalingConstraints -> ScalingConstraints -> Bool)
-> (ScalingConstraints -> ScalingConstraints -> Bool)
-> Eq ScalingConstraints
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ScalingConstraints -> ScalingConstraints -> Bool
$c/= :: ScalingConstraints -> ScalingConstraints -> Bool
== :: ScalingConstraints -> ScalingConstraints -> Bool
$c== :: ScalingConstraints -> ScalingConstraints -> Bool
Prelude.Eq, ReadPrec [ScalingConstraints]
ReadPrec ScalingConstraints
Int -> ReadS ScalingConstraints
ReadS [ScalingConstraints]
(Int -> ReadS ScalingConstraints)
-> ReadS [ScalingConstraints]
-> ReadPrec ScalingConstraints
-> ReadPrec [ScalingConstraints]
-> Read ScalingConstraints
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ScalingConstraints]
$creadListPrec :: ReadPrec [ScalingConstraints]
readPrec :: ReadPrec ScalingConstraints
$creadPrec :: ReadPrec ScalingConstraints
readList :: ReadS [ScalingConstraints]
$creadList :: ReadS [ScalingConstraints]
readsPrec :: Int -> ReadS ScalingConstraints
$creadsPrec :: Int -> ReadS ScalingConstraints
Prelude.Read, Int -> ScalingConstraints -> ShowS
[ScalingConstraints] -> ShowS
ScalingConstraints -> String
(Int -> ScalingConstraints -> ShowS)
-> (ScalingConstraints -> String)
-> ([ScalingConstraints] -> ShowS)
-> Show ScalingConstraints
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ScalingConstraints] -> ShowS
$cshowList :: [ScalingConstraints] -> ShowS
show :: ScalingConstraints -> String
$cshow :: ScalingConstraints -> String
showsPrec :: Int -> ScalingConstraints -> ShowS
$cshowsPrec :: Int -> ScalingConstraints -> ShowS
Prelude.Show, (forall x. ScalingConstraints -> Rep ScalingConstraints x)
-> (forall x. Rep ScalingConstraints x -> ScalingConstraints)
-> Generic ScalingConstraints
forall x. Rep ScalingConstraints x -> ScalingConstraints
forall x. ScalingConstraints -> Rep ScalingConstraints x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ScalingConstraints x -> ScalingConstraints
$cfrom :: forall x. ScalingConstraints -> Rep ScalingConstraints x
Prelude.Generic)

-- |
-- Create a value of 'ScalingConstraints' 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:
--
-- 'minCapacity', 'scalingConstraints_minCapacity' - The lower boundary of EC2 instances in an instance group below which
-- scaling activities are not allowed to shrink. Scale-in activities will
-- not terminate instances below this boundary.
--
-- 'maxCapacity', 'scalingConstraints_maxCapacity' - The upper boundary of EC2 instances in an instance group beyond which
-- scaling activities are not allowed to grow. Scale-out activities will
-- not add instances beyond this boundary.
newScalingConstraints ::
  -- | 'minCapacity'
  Prelude.Int ->
  -- | 'maxCapacity'
  Prelude.Int ->
  ScalingConstraints
newScalingConstraints :: Int -> Int -> ScalingConstraints
newScalingConstraints Int
pMinCapacity_ Int
pMaxCapacity_ =
  ScalingConstraints' :: Int -> Int -> ScalingConstraints
ScalingConstraints'
    { $sel:minCapacity:ScalingConstraints' :: Int
minCapacity = Int
pMinCapacity_,
      $sel:maxCapacity:ScalingConstraints' :: Int
maxCapacity = Int
pMaxCapacity_
    }

-- | The lower boundary of EC2 instances in an instance group below which
-- scaling activities are not allowed to shrink. Scale-in activities will
-- not terminate instances below this boundary.
scalingConstraints_minCapacity :: Lens.Lens' ScalingConstraints Prelude.Int
scalingConstraints_minCapacity :: (Int -> f Int) -> ScalingConstraints -> f ScalingConstraints
scalingConstraints_minCapacity = (ScalingConstraints -> Int)
-> (ScalingConstraints -> Int -> ScalingConstraints)
-> Lens ScalingConstraints ScalingConstraints Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ScalingConstraints' {Int
minCapacity :: Int
$sel:minCapacity:ScalingConstraints' :: ScalingConstraints -> Int
minCapacity} -> Int
minCapacity) (\s :: ScalingConstraints
s@ScalingConstraints' {} Int
a -> ScalingConstraints
s {$sel:minCapacity:ScalingConstraints' :: Int
minCapacity = Int
a} :: ScalingConstraints)

-- | The upper boundary of EC2 instances in an instance group beyond which
-- scaling activities are not allowed to grow. Scale-out activities will
-- not add instances beyond this boundary.
scalingConstraints_maxCapacity :: Lens.Lens' ScalingConstraints Prelude.Int
scalingConstraints_maxCapacity :: (Int -> f Int) -> ScalingConstraints -> f ScalingConstraints
scalingConstraints_maxCapacity = (ScalingConstraints -> Int)
-> (ScalingConstraints -> Int -> ScalingConstraints)
-> Lens ScalingConstraints ScalingConstraints Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ScalingConstraints' {Int
maxCapacity :: Int
$sel:maxCapacity:ScalingConstraints' :: ScalingConstraints -> Int
maxCapacity} -> Int
maxCapacity) (\s :: ScalingConstraints
s@ScalingConstraints' {} Int
a -> ScalingConstraints
s {$sel:maxCapacity:ScalingConstraints' :: Int
maxCapacity = Int
a} :: ScalingConstraints)

instance Core.FromJSON ScalingConstraints where
  parseJSON :: Value -> Parser ScalingConstraints
parseJSON =
    String
-> (Object -> Parser ScalingConstraints)
-> Value
-> Parser ScalingConstraints
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ScalingConstraints"
      ( \Object
x ->
          Int -> Int -> ScalingConstraints
ScalingConstraints'
            (Int -> Int -> ScalingConstraints)
-> Parser Int -> Parser (Int -> ScalingConstraints)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"MinCapacity")
            Parser (Int -> ScalingConstraints)
-> Parser Int -> Parser ScalingConstraints
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"MaxCapacity")
      )

instance Prelude.Hashable ScalingConstraints

instance Prelude.NFData ScalingConstraints

instance Core.ToJSON ScalingConstraints where
  toJSON :: ScalingConstraints -> Value
toJSON ScalingConstraints' {Int
maxCapacity :: Int
minCapacity :: Int
$sel:maxCapacity:ScalingConstraints' :: ScalingConstraints -> Int
$sel:minCapacity:ScalingConstraints' :: ScalingConstraints -> Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"MinCapacity" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
minCapacity),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"MaxCapacity" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
maxCapacity)
          ]
      )