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

import qualified Amazonka.Core as Core
import Amazonka.ECS.Types.ManagedScalingStatus
import qualified Amazonka.Lens as Lens
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'
  { -- | Whether or not to enable managed scaling for the capacity provider.
    ManagedScaling -> Maybe ManagedScalingStatus
status :: Prelude.Maybe ManagedScalingStatus,
    -- | The maximum number of container instances that Amazon ECS will scale in
    -- or scale out at one time. If this parameter is omitted, the default
    -- value of @10000@ is used.
    ManagedScaling -> Maybe Natural
maximumScalingStepSize :: Prelude.Maybe Prelude.Natural,
    -- | 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@ will result in the Amazon EC2 instances in your Auto Scaling group
    -- being completely utilized.
    ManagedScaling -> Maybe Natural
targetCapacity :: Prelude.Maybe Prelude.Natural,
    -- | The minimum number of container instances that Amazon ECS will scale in
    -- or scale out at one time. If this parameter is omitted, the default
    -- value of @1@ is used.
    ManagedScaling -> Maybe Natural
minimumScalingStepSize :: Prelude.Maybe Prelude.Natural,
    -- | 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
  }
  deriving (ManagedScaling -> ManagedScaling -> Bool
(ManagedScaling -> ManagedScaling -> Bool)
-> (ManagedScaling -> ManagedScaling -> Bool) -> Eq ManagedScaling
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]
(Int -> ReadS ManagedScaling)
-> ReadS [ManagedScaling]
-> ReadPrec ManagedScaling
-> ReadPrec [ManagedScaling]
-> Read 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
(Int -> ManagedScaling -> ShowS)
-> (ManagedScaling -> String)
-> ([ManagedScaling] -> ShowS)
-> Show ManagedScaling
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. ManagedScaling -> Rep ManagedScaling x)
-> (forall x. Rep ManagedScaling x -> ManagedScaling)
-> Generic ManagedScaling
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:
--
-- 'status', 'managedScaling_status' - Whether or not to enable managed scaling for the capacity provider.
--
-- 'maximumScalingStepSize', 'managedScaling_maximumScalingStepSize' - The maximum number of container instances that Amazon ECS will scale in
-- or scale out at one time. If this parameter is omitted, the default
-- value of @10000@ is used.
--
-- '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@ will result in the Amazon EC2 instances in your Auto Scaling group
-- being completely utilized.
--
-- 'minimumScalingStepSize', 'managedScaling_minimumScalingStepSize' - The minimum number of container instances that Amazon ECS will scale in
-- or scale out at one time. If this parameter is omitted, the default
-- value of @1@ is used.
--
-- '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.
newManagedScaling ::
  ManagedScaling
newManagedScaling :: ManagedScaling
newManagedScaling =
  ManagedScaling' :: Maybe ManagedScalingStatus
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> ManagedScaling
ManagedScaling'
    { $sel:status:ManagedScaling' :: Maybe ManagedScalingStatus
status = Maybe ManagedScalingStatus
forall a. Maybe a
Prelude.Nothing,
      $sel:maximumScalingStepSize:ManagedScaling' :: Maybe Natural
maximumScalingStepSize = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:targetCapacity:ManagedScaling' :: Maybe Natural
targetCapacity = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:minimumScalingStepSize:ManagedScaling' :: Maybe Natural
minimumScalingStepSize = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:instanceWarmupPeriod:ManagedScaling' :: Maybe Natural
instanceWarmupPeriod = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | Whether or not to enable managed scaling for the capacity provider.
managedScaling_status :: Lens.Lens' ManagedScaling (Prelude.Maybe ManagedScalingStatus)
managedScaling_status :: (Maybe ManagedScalingStatus -> f (Maybe ManagedScalingStatus))
-> ManagedScaling -> f ManagedScaling
managedScaling_status = (ManagedScaling -> Maybe ManagedScalingStatus)
-> (ManagedScaling -> Maybe ManagedScalingStatus -> ManagedScaling)
-> Lens
     ManagedScaling
     ManagedScaling
     (Maybe ManagedScalingStatus)
     (Maybe ManagedScalingStatus)
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 maximum number of container instances that Amazon ECS will scale in
-- or scale out at one time. If this parameter is omitted, the default
-- value of @10000@ is used.
managedScaling_maximumScalingStepSize :: Lens.Lens' ManagedScaling (Prelude.Maybe Prelude.Natural)
managedScaling_maximumScalingStepSize :: (Maybe Natural -> f (Maybe Natural))
-> ManagedScaling -> f ManagedScaling
managedScaling_maximumScalingStepSize = (ManagedScaling -> Maybe Natural)
-> (ManagedScaling -> Maybe Natural -> ManagedScaling)
-> Lens
     ManagedScaling ManagedScaling (Maybe Natural) (Maybe Natural)
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 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@ will result in the Amazon EC2 instances in your Auto Scaling group
-- being completely utilized.
managedScaling_targetCapacity :: Lens.Lens' ManagedScaling (Prelude.Maybe Prelude.Natural)
managedScaling_targetCapacity :: (Maybe Natural -> f (Maybe Natural))
-> ManagedScaling -> f ManagedScaling
managedScaling_targetCapacity = (ManagedScaling -> Maybe Natural)
-> (ManagedScaling -> Maybe Natural -> ManagedScaling)
-> Lens
     ManagedScaling ManagedScaling (Maybe Natural) (Maybe Natural)
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)

-- | The minimum number of container instances that Amazon ECS will scale in
-- or scale out at one time. If this parameter is omitted, the default
-- value of @1@ is used.
managedScaling_minimumScalingStepSize :: Lens.Lens' ManagedScaling (Prelude.Maybe Prelude.Natural)
managedScaling_minimumScalingStepSize :: (Maybe Natural -> f (Maybe Natural))
-> ManagedScaling -> f ManagedScaling
managedScaling_minimumScalingStepSize = (ManagedScaling -> Maybe Natural)
-> (ManagedScaling -> Maybe Natural -> ManagedScaling)
-> Lens
     ManagedScaling ManagedScaling (Maybe Natural) (Maybe Natural)
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)

-- | 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 :: (Maybe Natural -> f (Maybe Natural))
-> ManagedScaling -> f ManagedScaling
managedScaling_instanceWarmupPeriod = (ManagedScaling -> Maybe Natural)
-> (ManagedScaling -> Maybe Natural -> ManagedScaling)
-> Lens
     ManagedScaling ManagedScaling (Maybe Natural) (Maybe Natural)
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)

instance Core.FromJSON ManagedScaling where
  parseJSON :: Value -> Parser ManagedScaling
parseJSON =
    String
-> (Object -> Parser ManagedScaling)
-> Value
-> Parser ManagedScaling
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ManagedScaling"
      ( \Object
x ->
          Maybe ManagedScalingStatus
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> ManagedScaling
ManagedScaling'
            (Maybe ManagedScalingStatus
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe Natural
 -> ManagedScaling)
-> Parser (Maybe ManagedScalingStatus)
-> Parser
     (Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> ManagedScaling)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ManagedScalingStatus)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"status")
            Parser
  (Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> ManagedScaling)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Natural -> Maybe Natural -> Maybe Natural -> ManagedScaling)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"maximumScalingStepSize")
            Parser
  (Maybe Natural -> Maybe Natural -> Maybe Natural -> ManagedScaling)
-> Parser (Maybe Natural)
-> Parser (Maybe Natural -> Maybe Natural -> ManagedScaling)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"targetCapacity")
            Parser (Maybe Natural -> Maybe Natural -> ManagedScaling)
-> Parser (Maybe Natural)
-> Parser (Maybe Natural -> ManagedScaling)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"minimumScalingStepSize")
            Parser (Maybe Natural -> ManagedScaling)
-> Parser (Maybe Natural) -> Parser ManagedScaling
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"instanceWarmupPeriod")
      )

instance Prelude.Hashable ManagedScaling

instance Prelude.NFData ManagedScaling

instance Core.ToJSON ManagedScaling where
  toJSON :: ManagedScaling -> Value
toJSON ManagedScaling' {Maybe Natural
Maybe ManagedScalingStatus
instanceWarmupPeriod :: Maybe Natural
minimumScalingStepSize :: Maybe Natural
targetCapacity :: Maybe Natural
maximumScalingStepSize :: Maybe Natural
status :: Maybe ManagedScalingStatus
$sel:instanceWarmupPeriod:ManagedScaling' :: ManagedScaling -> Maybe Natural
$sel:minimumScalingStepSize:ManagedScaling' :: ManagedScaling -> Maybe Natural
$sel:targetCapacity:ManagedScaling' :: ManagedScaling -> Maybe Natural
$sel:maximumScalingStepSize:ManagedScaling' :: ManagedScaling -> Maybe Natural
$sel:status:ManagedScaling' :: ManagedScaling -> Maybe ManagedScalingStatus
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"status" Text -> ManagedScalingStatus -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ManagedScalingStatus -> Pair)
-> Maybe ManagedScalingStatus -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ManagedScalingStatus
status,
            (Text
"maximumScalingStepSize" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maximumScalingStepSize,
            (Text
"targetCapacity" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
targetCapacity,
            (Text
"minimumScalingStepSize" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
minimumScalingStepSize,
            (Text
"instanceWarmupPeriod" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
instanceWarmupPeriod
          ]
      )