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

import qualified Amazonka.Core as Core
import Amazonka.EMR.Types.OnDemandCapacityReservationPreference
import Amazonka.EMR.Types.OnDemandCapacityReservationUsageStrategy
import qualified Amazonka.Lens as Lens
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 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,
    -- | The ARN of the Capacity Reservation resource group in which to run the
    -- instance.
    OnDemandCapacityReservationOptions -> Maybe Text
capacityReservationResourceGroupArn :: Prelude.Maybe Prelude.Text,
    -- | 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
  }
  deriving (OnDemandCapacityReservationOptions
-> OnDemandCapacityReservationOptions -> Bool
(OnDemandCapacityReservationOptions
 -> OnDemandCapacityReservationOptions -> Bool)
-> (OnDemandCapacityReservationOptions
    -> OnDemandCapacityReservationOptions -> Bool)
-> Eq OnDemandCapacityReservationOptions
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]
(Int -> ReadS OnDemandCapacityReservationOptions)
-> ReadS [OnDemandCapacityReservationOptions]
-> ReadPrec OnDemandCapacityReservationOptions
-> ReadPrec [OnDemandCapacityReservationOptions]
-> Read 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
(Int -> OnDemandCapacityReservationOptions -> ShowS)
-> (OnDemandCapacityReservationOptions -> String)
-> ([OnDemandCapacityReservationOptions] -> ShowS)
-> Show OnDemandCapacityReservationOptions
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.
 OnDemandCapacityReservationOptions
 -> Rep OnDemandCapacityReservationOptions x)
-> (forall x.
    Rep OnDemandCapacityReservationOptions x
    -> OnDemandCapacityReservationOptions)
-> Generic OnDemandCapacityReservationOptions
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:
--
-- '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.
--
-- 'capacityReservationResourceGroupArn', 'onDemandCapacityReservationOptions_capacityReservationResourceGroupArn' - The ARN of the Capacity Reservation resource group in which to run the
-- instance.
--
-- '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.
newOnDemandCapacityReservationOptions ::
  OnDemandCapacityReservationOptions
newOnDemandCapacityReservationOptions :: OnDemandCapacityReservationOptions
newOnDemandCapacityReservationOptions =
  OnDemandCapacityReservationOptions' :: Maybe OnDemandCapacityReservationUsageStrategy
-> Maybe Text
-> Maybe OnDemandCapacityReservationPreference
-> OnDemandCapacityReservationOptions
OnDemandCapacityReservationOptions'
    { $sel:usageStrategy:OnDemandCapacityReservationOptions' :: Maybe OnDemandCapacityReservationUsageStrategy
usageStrategy =
        Maybe OnDemandCapacityReservationUsageStrategy
forall a. Maybe a
Prelude.Nothing,
      $sel:capacityReservationResourceGroupArn:OnDemandCapacityReservationOptions' :: Maybe Text
capacityReservationResourceGroupArn =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:capacityReservationPreference:OnDemandCapacityReservationOptions' :: Maybe OnDemandCapacityReservationPreference
capacityReservationPreference =
        Maybe OnDemandCapacityReservationPreference
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe OnDemandCapacityReservationUsageStrategy
 -> f (Maybe OnDemandCapacityReservationUsageStrategy))
-> OnDemandCapacityReservationOptions
-> f OnDemandCapacityReservationOptions
onDemandCapacityReservationOptions_usageStrategy = (OnDemandCapacityReservationOptions
 -> Maybe OnDemandCapacityReservationUsageStrategy)
-> (OnDemandCapacityReservationOptions
    -> Maybe OnDemandCapacityReservationUsageStrategy
    -> OnDemandCapacityReservationOptions)
-> Lens
     OnDemandCapacityReservationOptions
     OnDemandCapacityReservationOptions
     (Maybe OnDemandCapacityReservationUsageStrategy)
     (Maybe OnDemandCapacityReservationUsageStrategy)
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)

-- | 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 :: (Maybe Text -> f (Maybe Text))
-> OnDemandCapacityReservationOptions
-> f OnDemandCapacityReservationOptions
onDemandCapacityReservationOptions_capacityReservationResourceGroupArn = (OnDemandCapacityReservationOptions -> Maybe Text)
-> (OnDemandCapacityReservationOptions
    -> Maybe Text -> OnDemandCapacityReservationOptions)
-> Lens
     OnDemandCapacityReservationOptions
     OnDemandCapacityReservationOptions
     (Maybe Text)
     (Maybe Text)
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 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 :: (Maybe OnDemandCapacityReservationPreference
 -> f (Maybe OnDemandCapacityReservationPreference))
-> OnDemandCapacityReservationOptions
-> f OnDemandCapacityReservationOptions
onDemandCapacityReservationOptions_capacityReservationPreference = (OnDemandCapacityReservationOptions
 -> Maybe OnDemandCapacityReservationPreference)
-> (OnDemandCapacityReservationOptions
    -> Maybe OnDemandCapacityReservationPreference
    -> OnDemandCapacityReservationOptions)
-> Lens
     OnDemandCapacityReservationOptions
     OnDemandCapacityReservationOptions
     (Maybe OnDemandCapacityReservationPreference)
     (Maybe OnDemandCapacityReservationPreference)
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)

instance
  Core.FromJSON
    OnDemandCapacityReservationOptions
  where
  parseJSON :: Value -> Parser OnDemandCapacityReservationOptions
parseJSON =
    String
-> (Object -> Parser OnDemandCapacityReservationOptions)
-> Value
-> Parser OnDemandCapacityReservationOptions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"OnDemandCapacityReservationOptions"
      ( \Object
x ->
          Maybe OnDemandCapacityReservationUsageStrategy
-> Maybe Text
-> Maybe OnDemandCapacityReservationPreference
-> OnDemandCapacityReservationOptions
OnDemandCapacityReservationOptions'
            (Maybe OnDemandCapacityReservationUsageStrategy
 -> Maybe Text
 -> Maybe OnDemandCapacityReservationPreference
 -> OnDemandCapacityReservationOptions)
-> Parser (Maybe OnDemandCapacityReservationUsageStrategy)
-> Parser
     (Maybe Text
      -> Maybe OnDemandCapacityReservationPreference
      -> OnDemandCapacityReservationOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object
-> Text -> Parser (Maybe OnDemandCapacityReservationUsageStrategy)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"UsageStrategy")
            Parser
  (Maybe Text
   -> Maybe OnDemandCapacityReservationPreference
   -> OnDemandCapacityReservationOptions)
-> Parser (Maybe Text)
-> Parser
     (Maybe OnDemandCapacityReservationPreference
      -> OnDemandCapacityReservationOptions)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CapacityReservationResourceGroupArn")
            Parser
  (Maybe OnDemandCapacityReservationPreference
   -> OnDemandCapacityReservationOptions)
-> Parser (Maybe OnDemandCapacityReservationPreference)
-> Parser OnDemandCapacityReservationOptions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object
-> Text -> Parser (Maybe OnDemandCapacityReservationPreference)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CapacityReservationPreference")
      )

instance
  Prelude.Hashable
    OnDemandCapacityReservationOptions

instance
  Prelude.NFData
    OnDemandCapacityReservationOptions

instance
  Core.ToJSON
    OnDemandCapacityReservationOptions
  where
  toJSON :: OnDemandCapacityReservationOptions -> Value
toJSON OnDemandCapacityReservationOptions' {Maybe Text
Maybe OnDemandCapacityReservationPreference
Maybe OnDemandCapacityReservationUsageStrategy
capacityReservationPreference :: Maybe OnDemandCapacityReservationPreference
capacityReservationResourceGroupArn :: Maybe Text
usageStrategy :: Maybe OnDemandCapacityReservationUsageStrategy
$sel:capacityReservationPreference:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions
-> Maybe OnDemandCapacityReservationPreference
$sel:capacityReservationResourceGroupArn:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions -> Maybe Text
$sel:usageStrategy:OnDemandCapacityReservationOptions' :: OnDemandCapacityReservationOptions
-> Maybe OnDemandCapacityReservationUsageStrategy
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"UsageStrategy" Text -> OnDemandCapacityReservationUsageStrategy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (OnDemandCapacityReservationUsageStrategy -> Pair)
-> Maybe OnDemandCapacityReservationUsageStrategy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe OnDemandCapacityReservationUsageStrategy
usageStrategy,
            (Text
"CapacityReservationResourceGroupArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
capacityReservationResourceGroupArn,
            (Text
"CapacityReservationPreference" Text -> OnDemandCapacityReservationPreference -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (OnDemandCapacityReservationPreference -> Pair)
-> Maybe OnDemandCapacityReservationPreference -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe OnDemandCapacityReservationPreference
capacityReservationPreference
          ]
      )