{-# 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.AutoScaling.Types.TargetTrackingConfiguration
-- 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.AutoScaling.Types.TargetTrackingConfiguration where

import Amazonka.AutoScaling.Types.CustomizedMetricSpecification
import Amazonka.AutoScaling.Types.PredefinedMetricSpecification
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a target tracking scaling policy configuration to use with
-- Amazon EC2 Auto Scaling.
--
-- /See:/ 'newTargetTrackingConfiguration' smart constructor.
data TargetTrackingConfiguration = TargetTrackingConfiguration'
  { -- | A predefined metric. You must specify either a predefined metric or a
    -- customized metric.
    TargetTrackingConfiguration -> Maybe PredefinedMetricSpecification
predefinedMetricSpecification :: Prelude.Maybe PredefinedMetricSpecification,
    -- | A customized metric. You must specify either a predefined metric or a
    -- customized metric.
    TargetTrackingConfiguration -> Maybe CustomizedMetricSpecification
customizedMetricSpecification :: Prelude.Maybe CustomizedMetricSpecification,
    -- | Indicates whether scaling in by the target tracking scaling policy is
    -- disabled. If scaling in is disabled, the target tracking scaling policy
    -- doesn\'t remove instances from the Auto Scaling group. Otherwise, the
    -- target tracking scaling policy can remove instances from the Auto
    -- Scaling group. The default is @false@.
    TargetTrackingConfiguration -> Maybe Bool
disableScaleIn :: Prelude.Maybe Prelude.Bool,
    -- | The target value for the metric.
    TargetTrackingConfiguration -> Double
targetValue :: Prelude.Double
  }
  deriving (TargetTrackingConfiguration -> TargetTrackingConfiguration -> Bool
(TargetTrackingConfiguration
 -> TargetTrackingConfiguration -> Bool)
-> (TargetTrackingConfiguration
    -> TargetTrackingConfiguration -> Bool)
-> Eq TargetTrackingConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TargetTrackingConfiguration -> TargetTrackingConfiguration -> Bool
$c/= :: TargetTrackingConfiguration -> TargetTrackingConfiguration -> Bool
== :: TargetTrackingConfiguration -> TargetTrackingConfiguration -> Bool
$c== :: TargetTrackingConfiguration -> TargetTrackingConfiguration -> Bool
Prelude.Eq, ReadPrec [TargetTrackingConfiguration]
ReadPrec TargetTrackingConfiguration
Int -> ReadS TargetTrackingConfiguration
ReadS [TargetTrackingConfiguration]
(Int -> ReadS TargetTrackingConfiguration)
-> ReadS [TargetTrackingConfiguration]
-> ReadPrec TargetTrackingConfiguration
-> ReadPrec [TargetTrackingConfiguration]
-> Read TargetTrackingConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TargetTrackingConfiguration]
$creadListPrec :: ReadPrec [TargetTrackingConfiguration]
readPrec :: ReadPrec TargetTrackingConfiguration
$creadPrec :: ReadPrec TargetTrackingConfiguration
readList :: ReadS [TargetTrackingConfiguration]
$creadList :: ReadS [TargetTrackingConfiguration]
readsPrec :: Int -> ReadS TargetTrackingConfiguration
$creadsPrec :: Int -> ReadS TargetTrackingConfiguration
Prelude.Read, Int -> TargetTrackingConfiguration -> ShowS
[TargetTrackingConfiguration] -> ShowS
TargetTrackingConfiguration -> String
(Int -> TargetTrackingConfiguration -> ShowS)
-> (TargetTrackingConfiguration -> String)
-> ([TargetTrackingConfiguration] -> ShowS)
-> Show TargetTrackingConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TargetTrackingConfiguration] -> ShowS
$cshowList :: [TargetTrackingConfiguration] -> ShowS
show :: TargetTrackingConfiguration -> String
$cshow :: TargetTrackingConfiguration -> String
showsPrec :: Int -> TargetTrackingConfiguration -> ShowS
$cshowsPrec :: Int -> TargetTrackingConfiguration -> ShowS
Prelude.Show, (forall x.
 TargetTrackingConfiguration -> Rep TargetTrackingConfiguration x)
-> (forall x.
    Rep TargetTrackingConfiguration x -> TargetTrackingConfiguration)
-> Generic TargetTrackingConfiguration
forall x.
Rep TargetTrackingConfiguration x -> TargetTrackingConfiguration
forall x.
TargetTrackingConfiguration -> Rep TargetTrackingConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep TargetTrackingConfiguration x -> TargetTrackingConfiguration
$cfrom :: forall x.
TargetTrackingConfiguration -> Rep TargetTrackingConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'TargetTrackingConfiguration' 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:
--
-- 'predefinedMetricSpecification', 'targetTrackingConfiguration_predefinedMetricSpecification' - A predefined metric. You must specify either a predefined metric or a
-- customized metric.
--
-- 'customizedMetricSpecification', 'targetTrackingConfiguration_customizedMetricSpecification' - A customized metric. You must specify either a predefined metric or a
-- customized metric.
--
-- 'disableScaleIn', 'targetTrackingConfiguration_disableScaleIn' - Indicates whether scaling in by the target tracking scaling policy is
-- disabled. If scaling in is disabled, the target tracking scaling policy
-- doesn\'t remove instances from the Auto Scaling group. Otherwise, the
-- target tracking scaling policy can remove instances from the Auto
-- Scaling group. The default is @false@.
--
-- 'targetValue', 'targetTrackingConfiguration_targetValue' - The target value for the metric.
newTargetTrackingConfiguration ::
  -- | 'targetValue'
  Prelude.Double ->
  TargetTrackingConfiguration
newTargetTrackingConfiguration :: Double -> TargetTrackingConfiguration
newTargetTrackingConfiguration Double
pTargetValue_ =
  TargetTrackingConfiguration' :: Maybe PredefinedMetricSpecification
-> Maybe CustomizedMetricSpecification
-> Maybe Bool
-> Double
-> TargetTrackingConfiguration
TargetTrackingConfiguration'
    { $sel:predefinedMetricSpecification:TargetTrackingConfiguration' :: Maybe PredefinedMetricSpecification
predefinedMetricSpecification =
        Maybe PredefinedMetricSpecification
forall a. Maybe a
Prelude.Nothing,
      $sel:customizedMetricSpecification:TargetTrackingConfiguration' :: Maybe CustomizedMetricSpecification
customizedMetricSpecification =
        Maybe CustomizedMetricSpecification
forall a. Maybe a
Prelude.Nothing,
      $sel:disableScaleIn:TargetTrackingConfiguration' :: Maybe Bool
disableScaleIn = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:targetValue:TargetTrackingConfiguration' :: Double
targetValue = Double
pTargetValue_
    }

-- | A predefined metric. You must specify either a predefined metric or a
-- customized metric.
targetTrackingConfiguration_predefinedMetricSpecification :: Lens.Lens' TargetTrackingConfiguration (Prelude.Maybe PredefinedMetricSpecification)
targetTrackingConfiguration_predefinedMetricSpecification :: (Maybe PredefinedMetricSpecification
 -> f (Maybe PredefinedMetricSpecification))
-> TargetTrackingConfiguration -> f TargetTrackingConfiguration
targetTrackingConfiguration_predefinedMetricSpecification = (TargetTrackingConfiguration
 -> Maybe PredefinedMetricSpecification)
-> (TargetTrackingConfiguration
    -> Maybe PredefinedMetricSpecification
    -> TargetTrackingConfiguration)
-> Lens
     TargetTrackingConfiguration
     TargetTrackingConfiguration
     (Maybe PredefinedMetricSpecification)
     (Maybe PredefinedMetricSpecification)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetTrackingConfiguration' {Maybe PredefinedMetricSpecification
predefinedMetricSpecification :: Maybe PredefinedMetricSpecification
$sel:predefinedMetricSpecification:TargetTrackingConfiguration' :: TargetTrackingConfiguration -> Maybe PredefinedMetricSpecification
predefinedMetricSpecification} -> Maybe PredefinedMetricSpecification
predefinedMetricSpecification) (\s :: TargetTrackingConfiguration
s@TargetTrackingConfiguration' {} Maybe PredefinedMetricSpecification
a -> TargetTrackingConfiguration
s {$sel:predefinedMetricSpecification:TargetTrackingConfiguration' :: Maybe PredefinedMetricSpecification
predefinedMetricSpecification = Maybe PredefinedMetricSpecification
a} :: TargetTrackingConfiguration)

-- | A customized metric. You must specify either a predefined metric or a
-- customized metric.
targetTrackingConfiguration_customizedMetricSpecification :: Lens.Lens' TargetTrackingConfiguration (Prelude.Maybe CustomizedMetricSpecification)
targetTrackingConfiguration_customizedMetricSpecification :: (Maybe CustomizedMetricSpecification
 -> f (Maybe CustomizedMetricSpecification))
-> TargetTrackingConfiguration -> f TargetTrackingConfiguration
targetTrackingConfiguration_customizedMetricSpecification = (TargetTrackingConfiguration
 -> Maybe CustomizedMetricSpecification)
-> (TargetTrackingConfiguration
    -> Maybe CustomizedMetricSpecification
    -> TargetTrackingConfiguration)
-> Lens
     TargetTrackingConfiguration
     TargetTrackingConfiguration
     (Maybe CustomizedMetricSpecification)
     (Maybe CustomizedMetricSpecification)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetTrackingConfiguration' {Maybe CustomizedMetricSpecification
customizedMetricSpecification :: Maybe CustomizedMetricSpecification
$sel:customizedMetricSpecification:TargetTrackingConfiguration' :: TargetTrackingConfiguration -> Maybe CustomizedMetricSpecification
customizedMetricSpecification} -> Maybe CustomizedMetricSpecification
customizedMetricSpecification) (\s :: TargetTrackingConfiguration
s@TargetTrackingConfiguration' {} Maybe CustomizedMetricSpecification
a -> TargetTrackingConfiguration
s {$sel:customizedMetricSpecification:TargetTrackingConfiguration' :: Maybe CustomizedMetricSpecification
customizedMetricSpecification = Maybe CustomizedMetricSpecification
a} :: TargetTrackingConfiguration)

-- | Indicates whether scaling in by the target tracking scaling policy is
-- disabled. If scaling in is disabled, the target tracking scaling policy
-- doesn\'t remove instances from the Auto Scaling group. Otherwise, the
-- target tracking scaling policy can remove instances from the Auto
-- Scaling group. The default is @false@.
targetTrackingConfiguration_disableScaleIn :: Lens.Lens' TargetTrackingConfiguration (Prelude.Maybe Prelude.Bool)
targetTrackingConfiguration_disableScaleIn :: (Maybe Bool -> f (Maybe Bool))
-> TargetTrackingConfiguration -> f TargetTrackingConfiguration
targetTrackingConfiguration_disableScaleIn = (TargetTrackingConfiguration -> Maybe Bool)
-> (TargetTrackingConfiguration
    -> Maybe Bool -> TargetTrackingConfiguration)
-> Lens
     TargetTrackingConfiguration
     TargetTrackingConfiguration
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetTrackingConfiguration' {Maybe Bool
disableScaleIn :: Maybe Bool
$sel:disableScaleIn:TargetTrackingConfiguration' :: TargetTrackingConfiguration -> Maybe Bool
disableScaleIn} -> Maybe Bool
disableScaleIn) (\s :: TargetTrackingConfiguration
s@TargetTrackingConfiguration' {} Maybe Bool
a -> TargetTrackingConfiguration
s {$sel:disableScaleIn:TargetTrackingConfiguration' :: Maybe Bool
disableScaleIn = Maybe Bool
a} :: TargetTrackingConfiguration)

-- | The target value for the metric.
targetTrackingConfiguration_targetValue :: Lens.Lens' TargetTrackingConfiguration Prelude.Double
targetTrackingConfiguration_targetValue :: (Double -> f Double)
-> TargetTrackingConfiguration -> f TargetTrackingConfiguration
targetTrackingConfiguration_targetValue = (TargetTrackingConfiguration -> Double)
-> (TargetTrackingConfiguration
    -> Double -> TargetTrackingConfiguration)
-> Lens
     TargetTrackingConfiguration
     TargetTrackingConfiguration
     Double
     Double
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetTrackingConfiguration' {Double
targetValue :: Double
$sel:targetValue:TargetTrackingConfiguration' :: TargetTrackingConfiguration -> Double
targetValue} -> Double
targetValue) (\s :: TargetTrackingConfiguration
s@TargetTrackingConfiguration' {} Double
a -> TargetTrackingConfiguration
s {$sel:targetValue:TargetTrackingConfiguration' :: Double
targetValue = Double
a} :: TargetTrackingConfiguration)

instance Core.FromXML TargetTrackingConfiguration where
  parseXML :: [Node] -> Either String TargetTrackingConfiguration
parseXML [Node]
x =
    Maybe PredefinedMetricSpecification
-> Maybe CustomizedMetricSpecification
-> Maybe Bool
-> Double
-> TargetTrackingConfiguration
TargetTrackingConfiguration'
      (Maybe PredefinedMetricSpecification
 -> Maybe CustomizedMetricSpecification
 -> Maybe Bool
 -> Double
 -> TargetTrackingConfiguration)
-> Either String (Maybe PredefinedMetricSpecification)
-> Either
     String
     (Maybe CustomizedMetricSpecification
      -> Maybe Bool -> Double -> TargetTrackingConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node]
-> Text -> Either String (Maybe PredefinedMetricSpecification)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"PredefinedMetricSpecification")
      Either
  String
  (Maybe CustomizedMetricSpecification
   -> Maybe Bool -> Double -> TargetTrackingConfiguration)
-> Either String (Maybe CustomizedMetricSpecification)
-> Either
     String (Maybe Bool -> Double -> TargetTrackingConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node]
-> Text -> Either String (Maybe CustomizedMetricSpecification)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"CustomizedMetricSpecification")
      Either String (Maybe Bool -> Double -> TargetTrackingConfiguration)
-> Either String (Maybe Bool)
-> Either String (Double -> TargetTrackingConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Bool)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"DisableScaleIn")
      Either String (Double -> TargetTrackingConfiguration)
-> Either String Double
-> Either String TargetTrackingConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Double
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"TargetValue")

instance Prelude.Hashable TargetTrackingConfiguration

instance Prelude.NFData TargetTrackingConfiguration

instance Core.ToQuery TargetTrackingConfiguration where
  toQuery :: TargetTrackingConfiguration -> QueryString
toQuery TargetTrackingConfiguration' {Double
Maybe Bool
Maybe CustomizedMetricSpecification
Maybe PredefinedMetricSpecification
targetValue :: Double
disableScaleIn :: Maybe Bool
customizedMetricSpecification :: Maybe CustomizedMetricSpecification
predefinedMetricSpecification :: Maybe PredefinedMetricSpecification
$sel:targetValue:TargetTrackingConfiguration' :: TargetTrackingConfiguration -> Double
$sel:disableScaleIn:TargetTrackingConfiguration' :: TargetTrackingConfiguration -> Maybe Bool
$sel:customizedMetricSpecification:TargetTrackingConfiguration' :: TargetTrackingConfiguration -> Maybe CustomizedMetricSpecification
$sel:predefinedMetricSpecification:TargetTrackingConfiguration' :: TargetTrackingConfiguration -> Maybe PredefinedMetricSpecification
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"PredefinedMetricSpecification"
          ByteString -> Maybe PredefinedMetricSpecification -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe PredefinedMetricSpecification
predefinedMetricSpecification,
        ByteString
"CustomizedMetricSpecification"
          ByteString -> Maybe CustomizedMetricSpecification -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe CustomizedMetricSpecification
customizedMetricSpecification,
        ByteString
"DisableScaleIn" ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
disableScaleIn,
        ByteString
"TargetValue" ByteString -> Double -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Double
targetValue
      ]