{-# 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.OnDemandCapacityReservationOptions
-- 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.EMR.Types.OnDemandCapacityReservationOptions where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.EMR.Types.OnDemandCapacityReservationPreference
import Amazonka.EMR.Types.OnDemandCapacityReservationUsageStrategy
import qualified Amazonka.Prelude as Prelude

-- | Describes the strategy for using unused Capacity Reservations for
-- fulfilling On-Demand capacity.
--
-- /See:/ 'newOnDemandCapacityReservationOptions' smart constructor.
data OnDemandCapacityReservationOptions = OnDemandCapacityReservationOptions'
  { -- | Indicates the instance\'s Capacity Reservation preferences. Possible
    -- preferences include:
    --
    -- -   @open@ - The instance can run in any open Capacity Reservation that
    --     has matching attributes (instance type, platform, Availability
    --     Zone).
    --
    -- -   @none@ - The instance avoids running in a Capacity Reservation even
    --     if one is available. The instance runs as an On-Demand Instance.
    OnDemandCapacityReservationOptions
-> Maybe OnDemandCapacityReservationPreference
capacityReservationPreference :: Prelude.Maybe OnDemandCapacityReservationPreference,
    -- | The ARN of the Capacity Reservation resource group in which to run the
    -- instance.
    OnDemandCapacityReservationOptions -> Maybe Text
capacityReservationResourceGroupArn :: Prelude.Maybe Prelude.Text,
    -- | Indicates whether to use unused Capacity Reservations for fulfilling
    -- On-Demand capacity.
    --
    -- If you specify @use-capacity-reservations-first@, the fleet uses unused
    -- Capacity Reservations to fulfill On-Demand capacity up to the target
    -- On-Demand capacity. If multiple instance pools have unused Capacity
    -- Reservations, the On-Demand allocation strategy (@lowest-price@) is
    -- applied. If the number of unused Capacity Reservations is less than the
    -- On-Demand target capacity, the remaining On-Demand target capacity is
    -- launched according to the On-Demand allocation strategy
    -- (@lowest-price@).
    --
    -- If you do not specify a value, the fleet fulfills the On-Demand capacity
    -- according to the chosen On-Demand allocation strategy.
    OnDemandCapacityReservationOptions
-> Maybe OnDemandCapacityReservationUsageStrategy
usageStrategy :: Prelude.Maybe OnDemandCapacityReservationUsageStrategy
  }
  deriving (OnDemandCapacityReservationOptions
-> OnDemandCapacityReservationOptions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OnDemandCapacityReservationOptions
-> OnDemandCapacityReservationOptions -> Bool
$c/= :: OnDemandCapacityReservationOptions
-> OnDemandCapacityReservationOptions -> Bool
== :: OnDemandCapacityReservationOptions
-> OnDemandCapacityReservationOptions -> Bool
$c== :: OnDemandCapacityReservationOptions
-> OnDemandCapacityReservationOptions -> Bool
Prelude.Eq, ReadPrec [OnDemandCapacityReservationOptions]
ReadPrec OnDemandCapacityReservationOptions
Int -> ReadS OnDemandCapacityReservationOptions
ReadS [OnDemandCapacityReservationOptions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OnDemandCapacityReservationOptions]
$creadListPrec :: ReadPrec [OnDemandCapacityReservationOptions]
readPrec :: ReadPrec OnDemandCapacityReservationOptions
$creadPrec :: ReadPrec OnDemandCapacityReservationOptions
readList :: ReadS [OnDemandCapacityReservationOptions]
$creadList :: ReadS [OnDemandCapacityReservationOptions]
readsPrec :: Int -> ReadS OnDemandCapacityReservationOptions
$creadsPrec :: Int -> ReadS OnDemandCapacityReservationOptions
Prelude.Read, Int -> OnDemandCapacityReservationOptions -> ShowS
[OnDemandCapacityReservationOptions] -> ShowS
OnDemandCapacityReservationOptions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OnDemandCapacityReservationOptions] -> ShowS
$cshowList :: [OnDemandCapacityReservationOptions] -> ShowS
show :: OnDemandCapacityReservationOptions -> String
$cshow :: OnDemandCapacityReservationOptions -> String
showsPrec :: Int -> OnDemandCapacityReservationOptions -> ShowS
$cshowsPrec :: Int -> OnDemandCapacityReservationOptions -> ShowS
Prelude.Show, forall x.
Rep OnDemandCapacityReservationOptions x
-> OnDemandCapacityReservationOptions
forall x.
OnDemandCapacityReservationOptions
-> Rep OnDemandCapacityReservationOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep OnDemandCapacityReservationOptions x
-> OnDemandCapacityReservationOptions
$cfrom :: forall x.
OnDemandCapacityReservationOptions
-> Rep OnDemandCapacityReservationOptions x
Prelude.Generic)

-- |
-- Create a value of 'OnDemandCapacityReservationOptions' 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:
--
-- 'capacityReservationPreference', 'onDemandCapacityReservationOptions_capacityReservationPreference' - Indicates the instance\'s Capacity Reservation preferences. Possible
-- preferences include:
--
-- -   @open@ - The instance can run in any open Capacity Reservation that
--     has matching attributes (instance type, platform, Availability
--     Zone).
--
-- -   @none@ - The instance avoids running in a Capacity Reservation even
--     if one is available. The instance runs as an On-Demand Instance.
--
-- 'capacityReservationResourceGroupArn', 'onDemandCapacityReservationOptions_capacityReservationResourceGroupArn' - The ARN of the Capacity Reservation resource group in which to run the
-- instance.
--
-- 'usageStrategy', 'onDemandCapacityReservationOptions_usageStrategy' - Indicates whether to use unused Capacity Reservations for fulfilling
-- On-Demand capacity.
--
-- If you specify @use-capacity-reservations-first@, the fleet uses unused
-- Capacity Reservations to fulfill On-Demand capacity up to the target
-- On-Demand capacity. If multiple instance pools have unused Capacity
-- Reservations, the On-Demand allocation strategy (@lowest-price@) is
-- applied. If the number of unused Capacity Reservations is less than the
-- On-Demand target capacity, the remaining On-Demand target capacity is
-- launched according to the On-Demand allocation strategy
-- (@lowest-price@).
--
-- If you do not specify a value, the fleet fulfills the On-Demand capacity
-- according to the chosen On-Demand allocation strategy.
newOnDemandCapacityReservationOptions ::
  OnDemandCapacityReservationOptions
newOnDemandCapacityReservationOptions :: OnDemandCapacityReservationOptions
newOnDemandCapacityReservationOptions =
  OnDemandCapacityReservationOptions'
    { $sel:capacityReservationPreference:OnDemandCapacityReservationOptions' :: Maybe OnDemandCapacityReservationPreference
capacityReservationPreference =
        forall a. Maybe a
Prelude.Nothing,
      $sel:capacityReservationResourceGroupArn:OnDemandCapacityReservationOptions' :: Maybe Text
capacityReservationResourceGroupArn =
        forall a. Maybe a
Prelude.Nothing,
      $sel:usageStrategy:OnDemandCapacityReservationOptions' :: Maybe OnDemandCapacityReservationUsageStrategy
usageStrategy = forall a. Maybe a
Prelude.Nothing
    }

-- | Indicates the instance\'s Capacity Reservation preferences. Possible
-- preferences include:
--
-- -   @open@ - The instance can run in any open Capacity Reservation that
--     has matching attributes (instance type, platform, Availability
--     Zone).
--
-- -   @none@ - The instance avoids running in a Capacity Reservation even
--     if one is available. The instance runs as an On-Demand Instance.
onDemandCapacityReservationOptions_capacityReservationPreference :: Lens.Lens' OnDemandCapacityReservationOptions (Prelude.Maybe OnDemandCapacityReservationPreference)
onDemandCapacityReservationOptions_capacityReservationPreference :: Lens'
  OnDemandCapacityReservationOptions
  (Maybe OnDemandCapacityReservationPreference)
onDemandCapacityReservationOptions_capacityReservationPreference = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OnDemandCapacityReservationOptions' {Maybe OnDemandCapacityReservationPreference
capacityReservationPreference :: Maybe OnDemandCapacityReservationPreference
$sel:capacityReservationPreference:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions
-> Maybe OnDemandCapacityReservationPreference
capacityReservationPreference} -> Maybe OnDemandCapacityReservationPreference
capacityReservationPreference) (\s :: OnDemandCapacityReservationOptions
s@OnDemandCapacityReservationOptions' {} Maybe OnDemandCapacityReservationPreference
a -> OnDemandCapacityReservationOptions
s {$sel:capacityReservationPreference:OnDemandCapacityReservationOptions' :: Maybe OnDemandCapacityReservationPreference
capacityReservationPreference = Maybe OnDemandCapacityReservationPreference
a} :: OnDemandCapacityReservationOptions)

-- | The ARN of the Capacity Reservation resource group in which to run the
-- instance.
onDemandCapacityReservationOptions_capacityReservationResourceGroupArn :: Lens.Lens' OnDemandCapacityReservationOptions (Prelude.Maybe Prelude.Text)
onDemandCapacityReservationOptions_capacityReservationResourceGroupArn :: Lens' OnDemandCapacityReservationOptions (Maybe Text)
onDemandCapacityReservationOptions_capacityReservationResourceGroupArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OnDemandCapacityReservationOptions' {Maybe Text
capacityReservationResourceGroupArn :: Maybe Text
$sel:capacityReservationResourceGroupArn:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions -> Maybe Text
capacityReservationResourceGroupArn} -> Maybe Text
capacityReservationResourceGroupArn) (\s :: OnDemandCapacityReservationOptions
s@OnDemandCapacityReservationOptions' {} Maybe Text
a -> OnDemandCapacityReservationOptions
s {$sel:capacityReservationResourceGroupArn:OnDemandCapacityReservationOptions' :: Maybe Text
capacityReservationResourceGroupArn = Maybe Text
a} :: OnDemandCapacityReservationOptions)

-- | Indicates whether to use unused Capacity Reservations for fulfilling
-- On-Demand capacity.
--
-- If you specify @use-capacity-reservations-first@, the fleet uses unused
-- Capacity Reservations to fulfill On-Demand capacity up to the target
-- On-Demand capacity. If multiple instance pools have unused Capacity
-- Reservations, the On-Demand allocation strategy (@lowest-price@) is
-- applied. If the number of unused Capacity Reservations is less than the
-- On-Demand target capacity, the remaining On-Demand target capacity is
-- launched according to the On-Demand allocation strategy
-- (@lowest-price@).
--
-- If you do not specify a value, the fleet fulfills the On-Demand capacity
-- according to the chosen On-Demand allocation strategy.
onDemandCapacityReservationOptions_usageStrategy :: Lens.Lens' OnDemandCapacityReservationOptions (Prelude.Maybe OnDemandCapacityReservationUsageStrategy)
onDemandCapacityReservationOptions_usageStrategy :: Lens'
  OnDemandCapacityReservationOptions
  (Maybe OnDemandCapacityReservationUsageStrategy)
onDemandCapacityReservationOptions_usageStrategy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OnDemandCapacityReservationOptions' {Maybe OnDemandCapacityReservationUsageStrategy
usageStrategy :: Maybe OnDemandCapacityReservationUsageStrategy
$sel:usageStrategy:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions
-> Maybe OnDemandCapacityReservationUsageStrategy
usageStrategy} -> Maybe OnDemandCapacityReservationUsageStrategy
usageStrategy) (\s :: OnDemandCapacityReservationOptions
s@OnDemandCapacityReservationOptions' {} Maybe OnDemandCapacityReservationUsageStrategy
a -> OnDemandCapacityReservationOptions
s {$sel:usageStrategy:OnDemandCapacityReservationOptions' :: Maybe OnDemandCapacityReservationUsageStrategy
usageStrategy = Maybe OnDemandCapacityReservationUsageStrategy
a} :: OnDemandCapacityReservationOptions)

instance
  Data.FromJSON
    OnDemandCapacityReservationOptions
  where
  parseJSON :: Value -> Parser OnDemandCapacityReservationOptions
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"OnDemandCapacityReservationOptions"
      ( \Object
x ->
          Maybe OnDemandCapacityReservationPreference
-> Maybe Text
-> Maybe OnDemandCapacityReservationUsageStrategy
-> OnDemandCapacityReservationOptions
OnDemandCapacityReservationOptions'
            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
"CapacityReservationPreference")
            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
"CapacityReservationResourceGroupArn")
            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
"UsageStrategy")
      )

instance
  Prelude.Hashable
    OnDemandCapacityReservationOptions
  where
  hashWithSalt :: Int -> OnDemandCapacityReservationOptions -> Int
hashWithSalt
    Int
_salt
    OnDemandCapacityReservationOptions' {Maybe Text
Maybe OnDemandCapacityReservationPreference
Maybe OnDemandCapacityReservationUsageStrategy
usageStrategy :: Maybe OnDemandCapacityReservationUsageStrategy
capacityReservationResourceGroupArn :: Maybe Text
capacityReservationPreference :: Maybe OnDemandCapacityReservationPreference
$sel:usageStrategy:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions
-> Maybe OnDemandCapacityReservationUsageStrategy
$sel:capacityReservationResourceGroupArn:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions -> Maybe Text
$sel:capacityReservationPreference:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions
-> Maybe OnDemandCapacityReservationPreference
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe OnDemandCapacityReservationPreference
capacityReservationPreference
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
capacityReservationResourceGroupArn
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe OnDemandCapacityReservationUsageStrategy
usageStrategy

instance
  Prelude.NFData
    OnDemandCapacityReservationOptions
  where
  rnf :: OnDemandCapacityReservationOptions -> ()
rnf OnDemandCapacityReservationOptions' {Maybe Text
Maybe OnDemandCapacityReservationPreference
Maybe OnDemandCapacityReservationUsageStrategy
usageStrategy :: Maybe OnDemandCapacityReservationUsageStrategy
capacityReservationResourceGroupArn :: Maybe Text
capacityReservationPreference :: Maybe OnDemandCapacityReservationPreference
$sel:usageStrategy:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions
-> Maybe OnDemandCapacityReservationUsageStrategy
$sel:capacityReservationResourceGroupArn:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions -> Maybe Text
$sel:capacityReservationPreference:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions
-> Maybe OnDemandCapacityReservationPreference
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe OnDemandCapacityReservationPreference
capacityReservationPreference
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
capacityReservationResourceGroupArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe OnDemandCapacityReservationUsageStrategy
usageStrategy

instance
  Data.ToJSON
    OnDemandCapacityReservationOptions
  where
  toJSON :: OnDemandCapacityReservationOptions -> Value
toJSON OnDemandCapacityReservationOptions' {Maybe Text
Maybe OnDemandCapacityReservationPreference
Maybe OnDemandCapacityReservationUsageStrategy
usageStrategy :: Maybe OnDemandCapacityReservationUsageStrategy
capacityReservationResourceGroupArn :: Maybe Text
capacityReservationPreference :: Maybe OnDemandCapacityReservationPreference
$sel:usageStrategy:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions
-> Maybe OnDemandCapacityReservationUsageStrategy
$sel:capacityReservationResourceGroupArn:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions -> Maybe Text
$sel:capacityReservationPreference:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions
-> Maybe OnDemandCapacityReservationPreference
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CapacityReservationPreference" 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 OnDemandCapacityReservationPreference
capacityReservationPreference,
            (Key
"CapacityReservationResourceGroupArn" 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 Text
capacityReservationResourceGroupArn,
            (Key
"UsageStrategy" 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 OnDemandCapacityReservationUsageStrategy
usageStrategy
          ]
      )