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

import qualified Amazonka.Core as Core
import Amazonka.EMR.Types.AdjustmentType
import qualified Amazonka.Lens as Lens
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
(SimpleScalingPolicyConfiguration
 -> SimpleScalingPolicyConfiguration -> Bool)
-> (SimpleScalingPolicyConfiguration
    -> SimpleScalingPolicyConfiguration -> Bool)
-> Eq SimpleScalingPolicyConfiguration
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]
(Int -> ReadS SimpleScalingPolicyConfiguration)
-> ReadS [SimpleScalingPolicyConfiguration]
-> ReadPrec SimpleScalingPolicyConfiguration
-> ReadPrec [SimpleScalingPolicyConfiguration]
-> Read 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
(Int -> SimpleScalingPolicyConfiguration -> ShowS)
-> (SimpleScalingPolicyConfiguration -> String)
-> ([SimpleScalingPolicyConfiguration] -> ShowS)
-> Show SimpleScalingPolicyConfiguration
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.
 SimpleScalingPolicyConfiguration
 -> Rep SimpleScalingPolicyConfiguration x)
-> (forall x.
    Rep SimpleScalingPolicyConfiguration x
    -> SimpleScalingPolicyConfiguration)
-> Generic SimpleScalingPolicyConfiguration
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' :: Maybe AdjustmentType
-> Maybe Int -> Int -> SimpleScalingPolicyConfiguration
SimpleScalingPolicyConfiguration'
      { $sel:adjustmentType:SimpleScalingPolicyConfiguration' :: Maybe AdjustmentType
adjustmentType =
          Maybe AdjustmentType
forall a. Maybe a
Prelude.Nothing,
        $sel:coolDown:SimpleScalingPolicyConfiguration' :: Maybe Int
coolDown = Maybe Int
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 :: (Maybe AdjustmentType -> f (Maybe AdjustmentType))
-> SimpleScalingPolicyConfiguration
-> f SimpleScalingPolicyConfiguration
simpleScalingPolicyConfiguration_adjustmentType = (SimpleScalingPolicyConfiguration -> Maybe AdjustmentType)
-> (SimpleScalingPolicyConfiguration
    -> Maybe AdjustmentType -> SimpleScalingPolicyConfiguration)
-> Lens
     SimpleScalingPolicyConfiguration
     SimpleScalingPolicyConfiguration
     (Maybe AdjustmentType)
     (Maybe 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 :: (Maybe Int -> f (Maybe Int))
-> SimpleScalingPolicyConfiguration
-> f SimpleScalingPolicyConfiguration
simpleScalingPolicyConfiguration_coolDown = (SimpleScalingPolicyConfiguration -> Maybe Int)
-> (SimpleScalingPolicyConfiguration
    -> Maybe Int -> SimpleScalingPolicyConfiguration)
-> Lens
     SimpleScalingPolicyConfiguration
     SimpleScalingPolicyConfiguration
     (Maybe Int)
     (Maybe Int)
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 :: (Int -> f Int)
-> SimpleScalingPolicyConfiguration
-> f SimpleScalingPolicyConfiguration
simpleScalingPolicyConfiguration_scalingAdjustment = (SimpleScalingPolicyConfiguration -> Int)
-> (SimpleScalingPolicyConfiguration
    -> Int -> SimpleScalingPolicyConfiguration)
-> Lens
     SimpleScalingPolicyConfiguration
     SimpleScalingPolicyConfiguration
     Int
     Int
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
  Core.FromJSON
    SimpleScalingPolicyConfiguration
  where
  parseJSON :: Value -> Parser SimpleScalingPolicyConfiguration
parseJSON =
    String
-> (Object -> Parser SimpleScalingPolicyConfiguration)
-> Value
-> Parser SimpleScalingPolicyConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SimpleScalingPolicyConfiguration"
      ( \Object
x ->
          Maybe AdjustmentType
-> Maybe Int -> Int -> SimpleScalingPolicyConfiguration
SimpleScalingPolicyConfiguration'
            (Maybe AdjustmentType
 -> Maybe Int -> Int -> SimpleScalingPolicyConfiguration)
-> Parser (Maybe AdjustmentType)
-> Parser (Maybe Int -> Int -> SimpleScalingPolicyConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe AdjustmentType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AdjustmentType")
            Parser (Maybe Int -> Int -> SimpleScalingPolicyConfiguration)
-> Parser (Maybe Int)
-> Parser (Int -> SimpleScalingPolicyConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CoolDown")
            Parser (Int -> SimpleScalingPolicyConfiguration)
-> Parser Int -> Parser SimpleScalingPolicyConfiguration
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
"ScalingAdjustment")
      )

instance
  Prelude.Hashable
    SimpleScalingPolicyConfiguration

instance
  Prelude.NFData
    SimpleScalingPolicyConfiguration

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"AdjustmentType" Text -> AdjustmentType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (AdjustmentType -> Pair) -> Maybe AdjustmentType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AdjustmentType
adjustmentType,
            (Text
"CoolDown" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
coolDown,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ScalingAdjustment" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
scalingAdjustment)
          ]
      )