{-# 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.SimpleScalingPolicyConfiguration
-- 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.SimpleScalingPolicyConfiguration 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.AdjustmentType
import qualified Amazonka.Prelude as Prelude

-- | An automatic scaling configuration, which describes how the policy adds
-- or removes instances, the cooldown period, and the number of EC2
-- instances that will be added each time the CloudWatch metric alarm
-- condition is satisfied.
--
-- /See:/ 'newSimpleScalingPolicyConfiguration' smart constructor.
data SimpleScalingPolicyConfiguration = SimpleScalingPolicyConfiguration'
  { -- | The way in which EC2 instances are added (if @ScalingAdjustment@ is a
    -- positive number) or terminated (if @ScalingAdjustment@ is a negative
    -- number) each time the scaling activity is triggered.
    -- @CHANGE_IN_CAPACITY@ is the default. @CHANGE_IN_CAPACITY@ indicates that
    -- the EC2 instance count increments or decrements by @ScalingAdjustment@,
    -- which should be expressed as an integer. @PERCENT_CHANGE_IN_CAPACITY@
    -- indicates the instance count increments or decrements by the percentage
    -- specified by @ScalingAdjustment@, which should be expressed as an
    -- integer. For example, 20 indicates an increase in 20% increments of
    -- cluster capacity. @EXACT_CAPACITY@ indicates the scaling activity
    -- results in an instance group with the number of EC2 instances specified
    -- by @ScalingAdjustment@, which should be expressed as a positive integer.
    SimpleScalingPolicyConfiguration -> Maybe AdjustmentType
adjustmentType :: Prelude.Maybe AdjustmentType,
    -- | The amount of time, in seconds, after a scaling activity completes
    -- before any further trigger-related scaling activities can start. The
    -- default value is 0.
    SimpleScalingPolicyConfiguration -> Maybe Int
coolDown :: Prelude.Maybe Prelude.Int,
    -- | The amount by which to scale in or scale out, based on the specified
    -- @AdjustmentType@. A positive value adds to the instance group\'s EC2
    -- instance count while a negative number removes instances. If
    -- @AdjustmentType@ is set to @EXACT_CAPACITY@, the number should only be a
    -- positive integer. If @AdjustmentType@ is set to
    -- @PERCENT_CHANGE_IN_CAPACITY@, the value should express the percentage as
    -- an integer. For example, -20 indicates a decrease in 20% increments of
    -- cluster capacity.
    SimpleScalingPolicyConfiguration -> Int
scalingAdjustment :: Prelude.Int
  }
  deriving (SimpleScalingPolicyConfiguration
-> SimpleScalingPolicyConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SimpleScalingPolicyConfiguration
-> SimpleScalingPolicyConfiguration -> Bool
$c/= :: SimpleScalingPolicyConfiguration
-> SimpleScalingPolicyConfiguration -> Bool
== :: SimpleScalingPolicyConfiguration
-> SimpleScalingPolicyConfiguration -> Bool
$c== :: SimpleScalingPolicyConfiguration
-> SimpleScalingPolicyConfiguration -> Bool
Prelude.Eq, ReadPrec [SimpleScalingPolicyConfiguration]
ReadPrec SimpleScalingPolicyConfiguration
Int -> ReadS SimpleScalingPolicyConfiguration
ReadS [SimpleScalingPolicyConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SimpleScalingPolicyConfiguration]
$creadListPrec :: ReadPrec [SimpleScalingPolicyConfiguration]
readPrec :: ReadPrec SimpleScalingPolicyConfiguration
$creadPrec :: ReadPrec SimpleScalingPolicyConfiguration
readList :: ReadS [SimpleScalingPolicyConfiguration]
$creadList :: ReadS [SimpleScalingPolicyConfiguration]
readsPrec :: Int -> ReadS SimpleScalingPolicyConfiguration
$creadsPrec :: Int -> ReadS SimpleScalingPolicyConfiguration
Prelude.Read, Int -> SimpleScalingPolicyConfiguration -> ShowS
[SimpleScalingPolicyConfiguration] -> ShowS
SimpleScalingPolicyConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SimpleScalingPolicyConfiguration] -> ShowS
$cshowList :: [SimpleScalingPolicyConfiguration] -> ShowS
show :: SimpleScalingPolicyConfiguration -> String
$cshow :: SimpleScalingPolicyConfiguration -> String
showsPrec :: Int -> SimpleScalingPolicyConfiguration -> ShowS
$cshowsPrec :: Int -> SimpleScalingPolicyConfiguration -> ShowS
Prelude.Show, forall x.
Rep SimpleScalingPolicyConfiguration x
-> SimpleScalingPolicyConfiguration
forall x.
SimpleScalingPolicyConfiguration
-> Rep SimpleScalingPolicyConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep SimpleScalingPolicyConfiguration x
-> SimpleScalingPolicyConfiguration
$cfrom :: forall x.
SimpleScalingPolicyConfiguration
-> Rep SimpleScalingPolicyConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'SimpleScalingPolicyConfiguration' 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:
--
-- 'adjustmentType', 'simpleScalingPolicyConfiguration_adjustmentType' - The way in which EC2 instances are added (if @ScalingAdjustment@ is a
-- positive number) or terminated (if @ScalingAdjustment@ is a negative
-- number) each time the scaling activity is triggered.
-- @CHANGE_IN_CAPACITY@ is the default. @CHANGE_IN_CAPACITY@ indicates that
-- the EC2 instance count increments or decrements by @ScalingAdjustment@,
-- which should be expressed as an integer. @PERCENT_CHANGE_IN_CAPACITY@
-- indicates the instance count increments or decrements by the percentage
-- specified by @ScalingAdjustment@, which should be expressed as an
-- integer. For example, 20 indicates an increase in 20% increments of
-- cluster capacity. @EXACT_CAPACITY@ indicates the scaling activity
-- results in an instance group with the number of EC2 instances specified
-- by @ScalingAdjustment@, which should be expressed as a positive integer.
--
-- 'coolDown', 'simpleScalingPolicyConfiguration_coolDown' - The amount of time, in seconds, after a scaling activity completes
-- before any further trigger-related scaling activities can start. The
-- default value is 0.
--
-- 'scalingAdjustment', 'simpleScalingPolicyConfiguration_scalingAdjustment' - The amount by which to scale in or scale out, based on the specified
-- @AdjustmentType@. A positive value adds to the instance group\'s EC2
-- instance count while a negative number removes instances. If
-- @AdjustmentType@ is set to @EXACT_CAPACITY@, the number should only be a
-- positive integer. If @AdjustmentType@ is set to
-- @PERCENT_CHANGE_IN_CAPACITY@, the value should express the percentage as
-- an integer. For example, -20 indicates a decrease in 20% increments of
-- cluster capacity.
newSimpleScalingPolicyConfiguration ::
  -- | 'scalingAdjustment'
  Prelude.Int ->
  SimpleScalingPolicyConfiguration
newSimpleScalingPolicyConfiguration :: Int -> SimpleScalingPolicyConfiguration
newSimpleScalingPolicyConfiguration
  Int
pScalingAdjustment_ =
    SimpleScalingPolicyConfiguration'
      { $sel:adjustmentType:SimpleScalingPolicyConfiguration' :: Maybe AdjustmentType
adjustmentType =
          forall a. Maybe a
Prelude.Nothing,
        $sel:coolDown:SimpleScalingPolicyConfiguration' :: Maybe Int
coolDown = forall a. Maybe a
Prelude.Nothing,
        $sel:scalingAdjustment:SimpleScalingPolicyConfiguration' :: Int
scalingAdjustment = Int
pScalingAdjustment_
      }

-- | The way in which EC2 instances are added (if @ScalingAdjustment@ is a
-- positive number) or terminated (if @ScalingAdjustment@ is a negative
-- number) each time the scaling activity is triggered.
-- @CHANGE_IN_CAPACITY@ is the default. @CHANGE_IN_CAPACITY@ indicates that
-- the EC2 instance count increments or decrements by @ScalingAdjustment@,
-- which should be expressed as an integer. @PERCENT_CHANGE_IN_CAPACITY@
-- indicates the instance count increments or decrements by the percentage
-- specified by @ScalingAdjustment@, which should be expressed as an
-- integer. For example, 20 indicates an increase in 20% increments of
-- cluster capacity. @EXACT_CAPACITY@ indicates the scaling activity
-- results in an instance group with the number of EC2 instances specified
-- by @ScalingAdjustment@, which should be expressed as a positive integer.
simpleScalingPolicyConfiguration_adjustmentType :: Lens.Lens' SimpleScalingPolicyConfiguration (Prelude.Maybe AdjustmentType)
simpleScalingPolicyConfiguration_adjustmentType :: Lens' SimpleScalingPolicyConfiguration (Maybe AdjustmentType)
simpleScalingPolicyConfiguration_adjustmentType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SimpleScalingPolicyConfiguration' {Maybe AdjustmentType
adjustmentType :: Maybe AdjustmentType
$sel:adjustmentType:SimpleScalingPolicyConfiguration' :: SimpleScalingPolicyConfiguration -> Maybe AdjustmentType
adjustmentType} -> Maybe AdjustmentType
adjustmentType) (\s :: SimpleScalingPolicyConfiguration
s@SimpleScalingPolicyConfiguration' {} Maybe AdjustmentType
a -> SimpleScalingPolicyConfiguration
s {$sel:adjustmentType:SimpleScalingPolicyConfiguration' :: Maybe AdjustmentType
adjustmentType = Maybe AdjustmentType
a} :: SimpleScalingPolicyConfiguration)

-- | The amount of time, in seconds, after a scaling activity completes
-- before any further trigger-related scaling activities can start. The
-- default value is 0.
simpleScalingPolicyConfiguration_coolDown :: Lens.Lens' SimpleScalingPolicyConfiguration (Prelude.Maybe Prelude.Int)
simpleScalingPolicyConfiguration_coolDown :: Lens' SimpleScalingPolicyConfiguration (Maybe Int)
simpleScalingPolicyConfiguration_coolDown = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SimpleScalingPolicyConfiguration' {Maybe Int
coolDown :: Maybe Int
$sel:coolDown:SimpleScalingPolicyConfiguration' :: SimpleScalingPolicyConfiguration -> Maybe Int
coolDown} -> Maybe Int
coolDown) (\s :: SimpleScalingPolicyConfiguration
s@SimpleScalingPolicyConfiguration' {} Maybe Int
a -> SimpleScalingPolicyConfiguration
s {$sel:coolDown:SimpleScalingPolicyConfiguration' :: Maybe Int
coolDown = Maybe Int
a} :: SimpleScalingPolicyConfiguration)

-- | The amount by which to scale in or scale out, based on the specified
-- @AdjustmentType@. A positive value adds to the instance group\'s EC2
-- instance count while a negative number removes instances. If
-- @AdjustmentType@ is set to @EXACT_CAPACITY@, the number should only be a
-- positive integer. If @AdjustmentType@ is set to
-- @PERCENT_CHANGE_IN_CAPACITY@, the value should express the percentage as
-- an integer. For example, -20 indicates a decrease in 20% increments of
-- cluster capacity.
simpleScalingPolicyConfiguration_scalingAdjustment :: Lens.Lens' SimpleScalingPolicyConfiguration Prelude.Int
simpleScalingPolicyConfiguration_scalingAdjustment :: Lens' SimpleScalingPolicyConfiguration Int
simpleScalingPolicyConfiguration_scalingAdjustment = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SimpleScalingPolicyConfiguration' {Int
scalingAdjustment :: Int
$sel:scalingAdjustment:SimpleScalingPolicyConfiguration' :: SimpleScalingPolicyConfiguration -> Int
scalingAdjustment} -> Int
scalingAdjustment) (\s :: SimpleScalingPolicyConfiguration
s@SimpleScalingPolicyConfiguration' {} Int
a -> SimpleScalingPolicyConfiguration
s {$sel:scalingAdjustment:SimpleScalingPolicyConfiguration' :: Int
scalingAdjustment = Int
a} :: SimpleScalingPolicyConfiguration)

instance
  Data.FromJSON
    SimpleScalingPolicyConfiguration
  where
  parseJSON :: Value -> Parser SimpleScalingPolicyConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SimpleScalingPolicyConfiguration"
      ( \Object
x ->
          Maybe AdjustmentType
-> Maybe Int -> Int -> SimpleScalingPolicyConfiguration
SimpleScalingPolicyConfiguration'
            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
"AdjustmentType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"CoolDown")
            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
"ScalingAdjustment")
      )

instance
  Prelude.Hashable
    SimpleScalingPolicyConfiguration
  where
  hashWithSalt :: Int -> SimpleScalingPolicyConfiguration -> Int
hashWithSalt
    Int
_salt
    SimpleScalingPolicyConfiguration' {Int
Maybe Int
Maybe AdjustmentType
scalingAdjustment :: Int
coolDown :: Maybe Int
adjustmentType :: Maybe AdjustmentType
$sel:scalingAdjustment:SimpleScalingPolicyConfiguration' :: SimpleScalingPolicyConfiguration -> Int
$sel:coolDown:SimpleScalingPolicyConfiguration' :: SimpleScalingPolicyConfiguration -> Maybe Int
$sel:adjustmentType:SimpleScalingPolicyConfiguration' :: SimpleScalingPolicyConfiguration -> Maybe AdjustmentType
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AdjustmentType
adjustmentType
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
coolDown
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
scalingAdjustment

instance
  Prelude.NFData
    SimpleScalingPolicyConfiguration
  where
  rnf :: SimpleScalingPolicyConfiguration -> ()
rnf SimpleScalingPolicyConfiguration' {Int
Maybe Int
Maybe AdjustmentType
scalingAdjustment :: Int
coolDown :: Maybe Int
adjustmentType :: Maybe AdjustmentType
$sel:scalingAdjustment:SimpleScalingPolicyConfiguration' :: SimpleScalingPolicyConfiguration -> Int
$sel:coolDown:SimpleScalingPolicyConfiguration' :: SimpleScalingPolicyConfiguration -> Maybe Int
$sel:adjustmentType:SimpleScalingPolicyConfiguration' :: SimpleScalingPolicyConfiguration -> Maybe AdjustmentType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe AdjustmentType
adjustmentType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
coolDown
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
scalingAdjustment

instance Data.ToJSON SimpleScalingPolicyConfiguration where
  toJSON :: SimpleScalingPolicyConfiguration -> Value
toJSON SimpleScalingPolicyConfiguration' {Int
Maybe Int
Maybe AdjustmentType
scalingAdjustment :: Int
coolDown :: Maybe Int
adjustmentType :: Maybe AdjustmentType
$sel:scalingAdjustment:SimpleScalingPolicyConfiguration' :: SimpleScalingPolicyConfiguration -> Int
$sel:coolDown:SimpleScalingPolicyConfiguration' :: SimpleScalingPolicyConfiguration -> Maybe Int
$sel:adjustmentType:SimpleScalingPolicyConfiguration' :: SimpleScalingPolicyConfiguration -> Maybe AdjustmentType
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"AdjustmentType" 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 AdjustmentType
adjustmentType,
            (Key
"CoolDown" 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 Int
coolDown,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ScalingAdjustment" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Int
scalingAdjustment)
          ]
      )