{-# 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.ECS.Types.ManagedScaling
-- 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.ECS.Types.ManagedScaling where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ECS.Types.ManagedScalingStatus
import qualified Amazonka.Prelude as Prelude

-- | The managed scaling settings for the Auto Scaling group capacity
-- provider.
--
-- When managed scaling is enabled, Amazon ECS manages the scale-in and
-- scale-out actions of the Auto Scaling group. Amazon ECS manages a target
-- tracking scaling policy using an Amazon ECS managed CloudWatch metric
-- with the specified @targetCapacity@ value as the target value for the
-- metric. For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/asg-capacity-providers.html#asg-capacity-providers-managed-scaling Using managed scaling>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- If managed scaling is disabled, the user must manage the scaling of the
-- Auto Scaling group.
--
-- /See:/ 'newManagedScaling' smart constructor.
data ManagedScaling = ManagedScaling'
  { -- | The period of time, in seconds, after a newly launched Amazon EC2
    -- instance can contribute to CloudWatch metrics for Auto Scaling group. If
    -- this parameter is omitted, the default value of @300@ seconds is used.
    ManagedScaling -> Maybe Natural
instanceWarmupPeriod :: Prelude.Maybe Prelude.Natural,
    -- | The maximum number of Amazon EC2 instances that Amazon ECS will scale
    -- out at one time. The scale in process is not affected by this parameter.
    -- If this parameter is omitted, the default value of @1@ is used.
    ManagedScaling -> Maybe Natural
maximumScalingStepSize :: Prelude.Maybe Prelude.Natural,
    -- | The minimum number of Amazon EC2 instances that Amazon ECS will scale
    -- out at one time. The scale in process is not affected by this parameter
    -- If this parameter is omitted, the default value of @1@ is used.
    --
    -- When additional capacity is required, Amazon ECS will scale up the
    -- minimum scaling step size even if the actual demand is less than the
    -- minimum scaling step size.
    --
    -- If you use a capacity provider with an Auto Scaling group configured
    -- with more than one Amazon EC2 instance type or Availability Zone, Amazon
    -- ECS will scale up by the exact minimum scaling step size value and will
    -- ignore both the maximum scaling step size as well as the capacity
    -- demand.
    ManagedScaling -> Maybe Natural
minimumScalingStepSize :: Prelude.Maybe Prelude.Natural,
    -- | Determines whether to use managed scaling for the capacity provider.
    ManagedScaling -> Maybe ManagedScalingStatus
status :: Prelude.Maybe ManagedScalingStatus,
    -- | The target capacity value for the capacity provider. The specified value
    -- must be greater than @0@ and less than or equal to @100@. A value of
    -- @100@ results in the Amazon EC2 instances in your Auto Scaling group
    -- being completely used.
    ManagedScaling -> Maybe Natural
targetCapacity :: Prelude.Maybe Prelude.Natural
  }
  deriving (ManagedScaling -> ManagedScaling -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ManagedScaling -> ManagedScaling -> Bool
$c/= :: ManagedScaling -> ManagedScaling -> Bool
== :: ManagedScaling -> ManagedScaling -> Bool
$c== :: ManagedScaling -> ManagedScaling -> Bool
Prelude.Eq, ReadPrec [ManagedScaling]
ReadPrec ManagedScaling
Int -> ReadS ManagedScaling
ReadS [ManagedScaling]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ManagedScaling]
$creadListPrec :: ReadPrec [ManagedScaling]
readPrec :: ReadPrec ManagedScaling
$creadPrec :: ReadPrec ManagedScaling
readList :: ReadS [ManagedScaling]
$creadList :: ReadS [ManagedScaling]
readsPrec :: Int -> ReadS ManagedScaling
$creadsPrec :: Int -> ReadS ManagedScaling
Prelude.Read, Int -> ManagedScaling -> ShowS
[ManagedScaling] -> ShowS
ManagedScaling -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ManagedScaling] -> ShowS
$cshowList :: [ManagedScaling] -> ShowS
show :: ManagedScaling -> String
$cshow :: ManagedScaling -> String
showsPrec :: Int -> ManagedScaling -> ShowS
$cshowsPrec :: Int -> ManagedScaling -> ShowS
Prelude.Show, forall x. Rep ManagedScaling x -> ManagedScaling
forall x. ManagedScaling -> Rep ManagedScaling x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ManagedScaling x -> ManagedScaling
$cfrom :: forall x. ManagedScaling -> Rep ManagedScaling x
Prelude.Generic)

-- |
-- Create a value of 'ManagedScaling' 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:
--
-- 'instanceWarmupPeriod', 'managedScaling_instanceWarmupPeriod' - The period of time, in seconds, after a newly launched Amazon EC2
-- instance can contribute to CloudWatch metrics for Auto Scaling group. If
-- this parameter is omitted, the default value of @300@ seconds is used.
--
-- 'maximumScalingStepSize', 'managedScaling_maximumScalingStepSize' - The maximum number of Amazon EC2 instances that Amazon ECS will scale
-- out at one time. The scale in process is not affected by this parameter.
-- If this parameter is omitted, the default value of @1@ is used.
--
-- 'minimumScalingStepSize', 'managedScaling_minimumScalingStepSize' - The minimum number of Amazon EC2 instances that Amazon ECS will scale
-- out at one time. The scale in process is not affected by this parameter
-- If this parameter is omitted, the default value of @1@ is used.
--
-- When additional capacity is required, Amazon ECS will scale up the
-- minimum scaling step size even if the actual demand is less than the
-- minimum scaling step size.
--
-- If you use a capacity provider with an Auto Scaling group configured
-- with more than one Amazon EC2 instance type or Availability Zone, Amazon
-- ECS will scale up by the exact minimum scaling step size value and will
-- ignore both the maximum scaling step size as well as the capacity
-- demand.
--
-- 'status', 'managedScaling_status' - Determines whether to use managed scaling for the capacity provider.
--
-- 'targetCapacity', 'managedScaling_targetCapacity' - The target capacity value for the capacity provider. The specified value
-- must be greater than @0@ and less than or equal to @100@. A value of
-- @100@ results in the Amazon EC2 instances in your Auto Scaling group
-- being completely used.
newManagedScaling ::
  ManagedScaling
newManagedScaling :: ManagedScaling
newManagedScaling =
  ManagedScaling'
    { $sel:instanceWarmupPeriod:ManagedScaling' :: Maybe Natural
instanceWarmupPeriod =
        forall a. Maybe a
Prelude.Nothing,
      $sel:maximumScalingStepSize:ManagedScaling' :: Maybe Natural
maximumScalingStepSize = forall a. Maybe a
Prelude.Nothing,
      $sel:minimumScalingStepSize:ManagedScaling' :: Maybe Natural
minimumScalingStepSize = forall a. Maybe a
Prelude.Nothing,
      $sel:status:ManagedScaling' :: Maybe ManagedScalingStatus
status = forall a. Maybe a
Prelude.Nothing,
      $sel:targetCapacity:ManagedScaling' :: Maybe Natural
targetCapacity = forall a. Maybe a
Prelude.Nothing
    }

-- | The period of time, in seconds, after a newly launched Amazon EC2
-- instance can contribute to CloudWatch metrics for Auto Scaling group. If
-- this parameter is omitted, the default value of @300@ seconds is used.
managedScaling_instanceWarmupPeriod :: Lens.Lens' ManagedScaling (Prelude.Maybe Prelude.Natural)
managedScaling_instanceWarmupPeriod :: Lens' ManagedScaling (Maybe Natural)
managedScaling_instanceWarmupPeriod = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ManagedScaling' {Maybe Natural
instanceWarmupPeriod :: Maybe Natural
$sel:instanceWarmupPeriod:ManagedScaling' :: ManagedScaling -> Maybe Natural
instanceWarmupPeriod} -> Maybe Natural
instanceWarmupPeriod) (\s :: ManagedScaling
s@ManagedScaling' {} Maybe Natural
a -> ManagedScaling
s {$sel:instanceWarmupPeriod:ManagedScaling' :: Maybe Natural
instanceWarmupPeriod = Maybe Natural
a} :: ManagedScaling)

-- | The maximum number of Amazon EC2 instances that Amazon ECS will scale
-- out at one time. The scale in process is not affected by this parameter.
-- If this parameter is omitted, the default value of @1@ is used.
managedScaling_maximumScalingStepSize :: Lens.Lens' ManagedScaling (Prelude.Maybe Prelude.Natural)
managedScaling_maximumScalingStepSize :: Lens' ManagedScaling (Maybe Natural)
managedScaling_maximumScalingStepSize = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ManagedScaling' {Maybe Natural
maximumScalingStepSize :: Maybe Natural
$sel:maximumScalingStepSize:ManagedScaling' :: ManagedScaling -> Maybe Natural
maximumScalingStepSize} -> Maybe Natural
maximumScalingStepSize) (\s :: ManagedScaling
s@ManagedScaling' {} Maybe Natural
a -> ManagedScaling
s {$sel:maximumScalingStepSize:ManagedScaling' :: Maybe Natural
maximumScalingStepSize = Maybe Natural
a} :: ManagedScaling)

-- | The minimum number of Amazon EC2 instances that Amazon ECS will scale
-- out at one time. The scale in process is not affected by this parameter
-- If this parameter is omitted, the default value of @1@ is used.
--
-- When additional capacity is required, Amazon ECS will scale up the
-- minimum scaling step size even if the actual demand is less than the
-- minimum scaling step size.
--
-- If you use a capacity provider with an Auto Scaling group configured
-- with more than one Amazon EC2 instance type or Availability Zone, Amazon
-- ECS will scale up by the exact minimum scaling step size value and will
-- ignore both the maximum scaling step size as well as the capacity
-- demand.
managedScaling_minimumScalingStepSize :: Lens.Lens' ManagedScaling (Prelude.Maybe Prelude.Natural)
managedScaling_minimumScalingStepSize :: Lens' ManagedScaling (Maybe Natural)
managedScaling_minimumScalingStepSize = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ManagedScaling' {Maybe Natural
minimumScalingStepSize :: Maybe Natural
$sel:minimumScalingStepSize:ManagedScaling' :: ManagedScaling -> Maybe Natural
minimumScalingStepSize} -> Maybe Natural
minimumScalingStepSize) (\s :: ManagedScaling
s@ManagedScaling' {} Maybe Natural
a -> ManagedScaling
s {$sel:minimumScalingStepSize:ManagedScaling' :: Maybe Natural
minimumScalingStepSize = Maybe Natural
a} :: ManagedScaling)

-- | Determines whether to use managed scaling for the capacity provider.
managedScaling_status :: Lens.Lens' ManagedScaling (Prelude.Maybe ManagedScalingStatus)
managedScaling_status :: Lens' ManagedScaling (Maybe ManagedScalingStatus)
managedScaling_status = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ManagedScaling' {Maybe ManagedScalingStatus
status :: Maybe ManagedScalingStatus
$sel:status:ManagedScaling' :: ManagedScaling -> Maybe ManagedScalingStatus
status} -> Maybe ManagedScalingStatus
status) (\s :: ManagedScaling
s@ManagedScaling' {} Maybe ManagedScalingStatus
a -> ManagedScaling
s {$sel:status:ManagedScaling' :: Maybe ManagedScalingStatus
status = Maybe ManagedScalingStatus
a} :: ManagedScaling)

-- | The target capacity value for the capacity provider. The specified value
-- must be greater than @0@ and less than or equal to @100@. A value of
-- @100@ results in the Amazon EC2 instances in your Auto Scaling group
-- being completely used.
managedScaling_targetCapacity :: Lens.Lens' ManagedScaling (Prelude.Maybe Prelude.Natural)
managedScaling_targetCapacity :: Lens' ManagedScaling (Maybe Natural)
managedScaling_targetCapacity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ManagedScaling' {Maybe Natural
targetCapacity :: Maybe Natural
$sel:targetCapacity:ManagedScaling' :: ManagedScaling -> Maybe Natural
targetCapacity} -> Maybe Natural
targetCapacity) (\s :: ManagedScaling
s@ManagedScaling' {} Maybe Natural
a -> ManagedScaling
s {$sel:targetCapacity:ManagedScaling' :: Maybe Natural
targetCapacity = Maybe Natural
a} :: ManagedScaling)

instance Data.FromJSON ManagedScaling where
  parseJSON :: Value -> Parser ManagedScaling
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ManagedScaling"
      ( \Object
x ->
          Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe ManagedScalingStatus
-> Maybe Natural
-> ManagedScaling
ManagedScaling'
            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
"instanceWarmupPeriod")
            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
"maximumScalingStepSize")
            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
"minimumScalingStepSize")
            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
"status")
            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
"targetCapacity")
      )

instance Prelude.Hashable ManagedScaling where
  hashWithSalt :: Int -> ManagedScaling -> Int
hashWithSalt Int
_salt ManagedScaling' {Maybe Natural
Maybe ManagedScalingStatus
targetCapacity :: Maybe Natural
status :: Maybe ManagedScalingStatus
minimumScalingStepSize :: Maybe Natural
maximumScalingStepSize :: Maybe Natural
instanceWarmupPeriod :: Maybe Natural
$sel:targetCapacity:ManagedScaling' :: ManagedScaling -> Maybe Natural
$sel:status:ManagedScaling' :: ManagedScaling -> Maybe ManagedScalingStatus
$sel:minimumScalingStepSize:ManagedScaling' :: ManagedScaling -> Maybe Natural
$sel:maximumScalingStepSize:ManagedScaling' :: ManagedScaling -> Maybe Natural
$sel:instanceWarmupPeriod:ManagedScaling' :: ManagedScaling -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
instanceWarmupPeriod
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maximumScalingStepSize
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
minimumScalingStepSize
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ManagedScalingStatus
status
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
targetCapacity

instance Prelude.NFData ManagedScaling where
  rnf :: ManagedScaling -> ()
rnf ManagedScaling' {Maybe Natural
Maybe ManagedScalingStatus
targetCapacity :: Maybe Natural
status :: Maybe ManagedScalingStatus
minimumScalingStepSize :: Maybe Natural
maximumScalingStepSize :: Maybe Natural
instanceWarmupPeriod :: Maybe Natural
$sel:targetCapacity:ManagedScaling' :: ManagedScaling -> Maybe Natural
$sel:status:ManagedScaling' :: ManagedScaling -> Maybe ManagedScalingStatus
$sel:minimumScalingStepSize:ManagedScaling' :: ManagedScaling -> Maybe Natural
$sel:maximumScalingStepSize:ManagedScaling' :: ManagedScaling -> Maybe Natural
$sel:instanceWarmupPeriod:ManagedScaling' :: ManagedScaling -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
instanceWarmupPeriod
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maximumScalingStepSize
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
minimumScalingStepSize
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ManagedScalingStatus
status
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
targetCapacity

instance Data.ToJSON ManagedScaling where
  toJSON :: ManagedScaling -> Value
toJSON ManagedScaling' {Maybe Natural
Maybe ManagedScalingStatus
targetCapacity :: Maybe Natural
status :: Maybe ManagedScalingStatus
minimumScalingStepSize :: Maybe Natural
maximumScalingStepSize :: Maybe Natural
instanceWarmupPeriod :: Maybe Natural
$sel:targetCapacity:ManagedScaling' :: ManagedScaling -> Maybe Natural
$sel:status:ManagedScaling' :: ManagedScaling -> Maybe ManagedScalingStatus
$sel:minimumScalingStepSize:ManagedScaling' :: ManagedScaling -> Maybe Natural
$sel:maximumScalingStepSize:ManagedScaling' :: ManagedScaling -> Maybe Natural
$sel:instanceWarmupPeriod:ManagedScaling' :: ManagedScaling -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"instanceWarmupPeriod" 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 Natural
instanceWarmupPeriod,
            (Key
"maximumScalingStepSize" 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 Natural
maximumScalingStepSize,
            (Key
"minimumScalingStepSize" 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 Natural
minimumScalingStepSize,
            (Key
"status" 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 ManagedScalingStatus
status,
            (Key
"targetCapacity" 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 Natural
targetCapacity
          ]
      )