{-# 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.EC2.Types.TargetCapacitySpecification
-- 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.EC2.Types.TargetCapacitySpecification where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.EC2.Internal
import Amazonka.EC2.Types.DefaultTargetCapacityType
import Amazonka.EC2.Types.TargetCapacityUnitType
import qualified Amazonka.Prelude as Prelude

-- | The number of units to request. You can choose to set the target
-- capacity in terms of instances or a performance characteristic that is
-- important to your application workload, such as vCPUs, memory, or I\/O.
-- If the request type is @maintain@, you can specify a target capacity of
-- 0 and add capacity later.
--
-- You can use the On-Demand Instance @MaxTotalPrice@ parameter, the Spot
-- Instance @MaxTotalPrice@, or both to ensure that your fleet cost does
-- not exceed your budget. If you set a maximum price per hour for the
-- On-Demand Instances and Spot Instances in your request, EC2 Fleet will
-- launch instances until it reaches the maximum amount that you\'re
-- willing to pay. When the maximum amount you\'re willing to pay is
-- reached, the fleet stops launching instances even if it hasn’t met the
-- target capacity. The @MaxTotalPrice@ parameters are located in
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_OnDemandOptions.html OnDemandOptions>
-- and
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_SpotOptions SpotOptions>.
--
-- /See:/ 'newTargetCapacitySpecification' smart constructor.
data TargetCapacitySpecification = TargetCapacitySpecification'
  { -- | The default @TotalTargetCapacity@, which is either @Spot@ or
    -- @On-Demand@.
    TargetCapacitySpecification -> Maybe DefaultTargetCapacityType
defaultTargetCapacityType :: Prelude.Maybe DefaultTargetCapacityType,
    -- | The number of On-Demand units to request. If you specify a target
    -- capacity for Spot units, you cannot specify a target capacity for
    -- On-Demand units.
    TargetCapacitySpecification -> Maybe Int
onDemandTargetCapacity :: Prelude.Maybe Prelude.Int,
    -- | The maximum number of Spot units to launch. If you specify a target
    -- capacity for On-Demand units, you cannot specify a target capacity for
    -- Spot units.
    TargetCapacitySpecification -> Maybe Int
spotTargetCapacity :: Prelude.Maybe Prelude.Int,
    -- | The unit for the target capacity.
    --
    -- Default: @units@ (translates to number of instances)
    TargetCapacitySpecification -> Maybe TargetCapacityUnitType
targetCapacityUnitType :: Prelude.Maybe TargetCapacityUnitType,
    -- | The number of units to request, filled using
    -- @DefaultTargetCapacityType@.
    TargetCapacitySpecification -> Maybe Int
totalTargetCapacity :: Prelude.Maybe Prelude.Int
  }
  deriving (TargetCapacitySpecification -> TargetCapacitySpecification -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TargetCapacitySpecification -> TargetCapacitySpecification -> Bool
$c/= :: TargetCapacitySpecification -> TargetCapacitySpecification -> Bool
== :: TargetCapacitySpecification -> TargetCapacitySpecification -> Bool
$c== :: TargetCapacitySpecification -> TargetCapacitySpecification -> Bool
Prelude.Eq, ReadPrec [TargetCapacitySpecification]
ReadPrec TargetCapacitySpecification
Int -> ReadS TargetCapacitySpecification
ReadS [TargetCapacitySpecification]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TargetCapacitySpecification]
$creadListPrec :: ReadPrec [TargetCapacitySpecification]
readPrec :: ReadPrec TargetCapacitySpecification
$creadPrec :: ReadPrec TargetCapacitySpecification
readList :: ReadS [TargetCapacitySpecification]
$creadList :: ReadS [TargetCapacitySpecification]
readsPrec :: Int -> ReadS TargetCapacitySpecification
$creadsPrec :: Int -> ReadS TargetCapacitySpecification
Prelude.Read, Int -> TargetCapacitySpecification -> ShowS
[TargetCapacitySpecification] -> ShowS
TargetCapacitySpecification -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TargetCapacitySpecification] -> ShowS
$cshowList :: [TargetCapacitySpecification] -> ShowS
show :: TargetCapacitySpecification -> String
$cshow :: TargetCapacitySpecification -> String
showsPrec :: Int -> TargetCapacitySpecification -> ShowS
$cshowsPrec :: Int -> TargetCapacitySpecification -> ShowS
Prelude.Show, forall x.
Rep TargetCapacitySpecification x -> TargetCapacitySpecification
forall x.
TargetCapacitySpecification -> Rep TargetCapacitySpecification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep TargetCapacitySpecification x -> TargetCapacitySpecification
$cfrom :: forall x.
TargetCapacitySpecification -> Rep TargetCapacitySpecification x
Prelude.Generic)

-- |
-- Create a value of 'TargetCapacitySpecification' 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:
--
-- 'defaultTargetCapacityType', 'targetCapacitySpecification_defaultTargetCapacityType' - The default @TotalTargetCapacity@, which is either @Spot@ or
-- @On-Demand@.
--
-- 'onDemandTargetCapacity', 'targetCapacitySpecification_onDemandTargetCapacity' - The number of On-Demand units to request. If you specify a target
-- capacity for Spot units, you cannot specify a target capacity for
-- On-Demand units.
--
-- 'spotTargetCapacity', 'targetCapacitySpecification_spotTargetCapacity' - The maximum number of Spot units to launch. If you specify a target
-- capacity for On-Demand units, you cannot specify a target capacity for
-- Spot units.
--
-- 'targetCapacityUnitType', 'targetCapacitySpecification_targetCapacityUnitType' - The unit for the target capacity.
--
-- Default: @units@ (translates to number of instances)
--
-- 'totalTargetCapacity', 'targetCapacitySpecification_totalTargetCapacity' - The number of units to request, filled using
-- @DefaultTargetCapacityType@.
newTargetCapacitySpecification ::
  TargetCapacitySpecification
newTargetCapacitySpecification :: TargetCapacitySpecification
newTargetCapacitySpecification =
  TargetCapacitySpecification'
    { $sel:defaultTargetCapacityType:TargetCapacitySpecification' :: Maybe DefaultTargetCapacityType
defaultTargetCapacityType =
        forall a. Maybe a
Prelude.Nothing,
      $sel:onDemandTargetCapacity:TargetCapacitySpecification' :: Maybe Int
onDemandTargetCapacity = forall a. Maybe a
Prelude.Nothing,
      $sel:spotTargetCapacity:TargetCapacitySpecification' :: Maybe Int
spotTargetCapacity = forall a. Maybe a
Prelude.Nothing,
      $sel:targetCapacityUnitType:TargetCapacitySpecification' :: Maybe TargetCapacityUnitType
targetCapacityUnitType = forall a. Maybe a
Prelude.Nothing,
      $sel:totalTargetCapacity:TargetCapacitySpecification' :: Maybe Int
totalTargetCapacity = forall a. Maybe a
Prelude.Nothing
    }

-- | The default @TotalTargetCapacity@, which is either @Spot@ or
-- @On-Demand@.
targetCapacitySpecification_defaultTargetCapacityType :: Lens.Lens' TargetCapacitySpecification (Prelude.Maybe DefaultTargetCapacityType)
targetCapacitySpecification_defaultTargetCapacityType :: Lens' TargetCapacitySpecification (Maybe DefaultTargetCapacityType)
targetCapacitySpecification_defaultTargetCapacityType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetCapacitySpecification' {Maybe DefaultTargetCapacityType
defaultTargetCapacityType :: Maybe DefaultTargetCapacityType
$sel:defaultTargetCapacityType:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe DefaultTargetCapacityType
defaultTargetCapacityType} -> Maybe DefaultTargetCapacityType
defaultTargetCapacityType) (\s :: TargetCapacitySpecification
s@TargetCapacitySpecification' {} Maybe DefaultTargetCapacityType
a -> TargetCapacitySpecification
s {$sel:defaultTargetCapacityType:TargetCapacitySpecification' :: Maybe DefaultTargetCapacityType
defaultTargetCapacityType = Maybe DefaultTargetCapacityType
a} :: TargetCapacitySpecification)

-- | The number of On-Demand units to request. If you specify a target
-- capacity for Spot units, you cannot specify a target capacity for
-- On-Demand units.
targetCapacitySpecification_onDemandTargetCapacity :: Lens.Lens' TargetCapacitySpecification (Prelude.Maybe Prelude.Int)
targetCapacitySpecification_onDemandTargetCapacity :: Lens' TargetCapacitySpecification (Maybe Int)
targetCapacitySpecification_onDemandTargetCapacity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetCapacitySpecification' {Maybe Int
onDemandTargetCapacity :: Maybe Int
$sel:onDemandTargetCapacity:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe Int
onDemandTargetCapacity} -> Maybe Int
onDemandTargetCapacity) (\s :: TargetCapacitySpecification
s@TargetCapacitySpecification' {} Maybe Int
a -> TargetCapacitySpecification
s {$sel:onDemandTargetCapacity:TargetCapacitySpecification' :: Maybe Int
onDemandTargetCapacity = Maybe Int
a} :: TargetCapacitySpecification)

-- | The maximum number of Spot units to launch. If you specify a target
-- capacity for On-Demand units, you cannot specify a target capacity for
-- Spot units.
targetCapacitySpecification_spotTargetCapacity :: Lens.Lens' TargetCapacitySpecification (Prelude.Maybe Prelude.Int)
targetCapacitySpecification_spotTargetCapacity :: Lens' TargetCapacitySpecification (Maybe Int)
targetCapacitySpecification_spotTargetCapacity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetCapacitySpecification' {Maybe Int
spotTargetCapacity :: Maybe Int
$sel:spotTargetCapacity:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe Int
spotTargetCapacity} -> Maybe Int
spotTargetCapacity) (\s :: TargetCapacitySpecification
s@TargetCapacitySpecification' {} Maybe Int
a -> TargetCapacitySpecification
s {$sel:spotTargetCapacity:TargetCapacitySpecification' :: Maybe Int
spotTargetCapacity = Maybe Int
a} :: TargetCapacitySpecification)

-- | The unit for the target capacity.
--
-- Default: @units@ (translates to number of instances)
targetCapacitySpecification_targetCapacityUnitType :: Lens.Lens' TargetCapacitySpecification (Prelude.Maybe TargetCapacityUnitType)
targetCapacitySpecification_targetCapacityUnitType :: Lens' TargetCapacitySpecification (Maybe TargetCapacityUnitType)
targetCapacitySpecification_targetCapacityUnitType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetCapacitySpecification' {Maybe TargetCapacityUnitType
targetCapacityUnitType :: Maybe TargetCapacityUnitType
$sel:targetCapacityUnitType:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe TargetCapacityUnitType
targetCapacityUnitType} -> Maybe TargetCapacityUnitType
targetCapacityUnitType) (\s :: TargetCapacitySpecification
s@TargetCapacitySpecification' {} Maybe TargetCapacityUnitType
a -> TargetCapacitySpecification
s {$sel:targetCapacityUnitType:TargetCapacitySpecification' :: Maybe TargetCapacityUnitType
targetCapacityUnitType = Maybe TargetCapacityUnitType
a} :: TargetCapacitySpecification)

-- | The number of units to request, filled using
-- @DefaultTargetCapacityType@.
targetCapacitySpecification_totalTargetCapacity :: Lens.Lens' TargetCapacitySpecification (Prelude.Maybe Prelude.Int)
targetCapacitySpecification_totalTargetCapacity :: Lens' TargetCapacitySpecification (Maybe Int)
targetCapacitySpecification_totalTargetCapacity = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetCapacitySpecification' {Maybe Int
totalTargetCapacity :: Maybe Int
$sel:totalTargetCapacity:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe Int
totalTargetCapacity} -> Maybe Int
totalTargetCapacity) (\s :: TargetCapacitySpecification
s@TargetCapacitySpecification' {} Maybe Int
a -> TargetCapacitySpecification
s {$sel:totalTargetCapacity:TargetCapacitySpecification' :: Maybe Int
totalTargetCapacity = Maybe Int
a} :: TargetCapacitySpecification)

instance Data.FromXML TargetCapacitySpecification where
  parseXML :: [Node] -> Either String TargetCapacitySpecification
parseXML [Node]
x =
    Maybe DefaultTargetCapacityType
-> Maybe Int
-> Maybe Int
-> Maybe TargetCapacityUnitType
-> Maybe Int
-> TargetCapacitySpecification
TargetCapacitySpecification'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"defaultTargetCapacityType")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"onDemandTargetCapacity")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"spotTargetCapacity")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"targetCapacityUnitType")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"totalTargetCapacity")

instance Prelude.Hashable TargetCapacitySpecification where
  hashWithSalt :: Int -> TargetCapacitySpecification -> Int
hashWithSalt Int
_salt TargetCapacitySpecification' {Maybe Int
Maybe DefaultTargetCapacityType
Maybe TargetCapacityUnitType
totalTargetCapacity :: Maybe Int
targetCapacityUnitType :: Maybe TargetCapacityUnitType
spotTargetCapacity :: Maybe Int
onDemandTargetCapacity :: Maybe Int
defaultTargetCapacityType :: Maybe DefaultTargetCapacityType
$sel:totalTargetCapacity:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe Int
$sel:targetCapacityUnitType:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe TargetCapacityUnitType
$sel:spotTargetCapacity:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe Int
$sel:onDemandTargetCapacity:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe Int
$sel:defaultTargetCapacityType:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe DefaultTargetCapacityType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DefaultTargetCapacityType
defaultTargetCapacityType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
onDemandTargetCapacity
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
spotTargetCapacity
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe TargetCapacityUnitType
targetCapacityUnitType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
totalTargetCapacity

instance Prelude.NFData TargetCapacitySpecification where
  rnf :: TargetCapacitySpecification -> ()
rnf TargetCapacitySpecification' {Maybe Int
Maybe DefaultTargetCapacityType
Maybe TargetCapacityUnitType
totalTargetCapacity :: Maybe Int
targetCapacityUnitType :: Maybe TargetCapacityUnitType
spotTargetCapacity :: Maybe Int
onDemandTargetCapacity :: Maybe Int
defaultTargetCapacityType :: Maybe DefaultTargetCapacityType
$sel:totalTargetCapacity:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe Int
$sel:targetCapacityUnitType:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe TargetCapacityUnitType
$sel:spotTargetCapacity:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe Int
$sel:onDemandTargetCapacity:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe Int
$sel:defaultTargetCapacityType:TargetCapacitySpecification' :: TargetCapacitySpecification -> Maybe DefaultTargetCapacityType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe DefaultTargetCapacityType
defaultTargetCapacityType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
onDemandTargetCapacity
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
spotTargetCapacity
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe TargetCapacityUnitType
targetCapacityUnitType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
totalTargetCapacity