{-# 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.SpotProvisioningSpecification
-- 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.SpotProvisioningSpecification where

import qualified Amazonka.Core as Core
import Amazonka.EMR.Types.SpotProvisioningAllocationStrategy
import Amazonka.EMR.Types.SpotProvisioningTimeoutAction
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The launch specification for Spot Instances in the instance fleet, which
-- determines the defined duration, provisioning timeout behavior, and
-- allocation strategy.
--
-- The instance fleet configuration is available only in Amazon EMR
-- versions 4.8.0 and later, excluding 5.0.x versions. Spot Instance
-- allocation strategy is available in Amazon EMR version 5.12.1 and later.
--
-- /See:/ 'newSpotProvisioningSpecification' smart constructor.
data SpotProvisioningSpecification = SpotProvisioningSpecification'
  { -- | The defined duration for Spot Instances (also known as Spot blocks) in
    -- minutes. When specified, the Spot Instance does not terminate before the
    -- defined duration expires, and defined duration pricing for Spot
    -- Instances applies. Valid values are 60, 120, 180, 240, 300, or 360. The
    -- duration period starts as soon as a Spot Instance receives its instance
    -- ID. At the end of the duration, Amazon EC2 marks the Spot Instance for
    -- termination and provides a Spot Instance termination notice, which gives
    -- the instance a two-minute warning before it terminates.
    SpotProvisioningSpecification -> Maybe Natural
blockDurationMinutes :: Prelude.Maybe Prelude.Natural,
    -- | Specifies the strategy to use in launching Spot Instance fleets.
    -- Currently, the only option is capacity-optimized (the default), which
    -- launches instances from Spot Instance pools with optimal capacity for
    -- the number of instances that are launching.
    SpotProvisioningSpecification
-> Maybe SpotProvisioningAllocationStrategy
allocationStrategy :: Prelude.Maybe SpotProvisioningAllocationStrategy,
    -- | The spot provisioning timeout period in minutes. If Spot Instances are
    -- not provisioned within this time period, the @TimeOutAction@ is taken.
    -- Minimum value is 5 and maximum value is 1440. The timeout applies only
    -- during initial provisioning, when the cluster is first created.
    SpotProvisioningSpecification -> Natural
timeoutDurationMinutes :: Prelude.Natural,
    -- | The action to take when @TargetSpotCapacity@ has not been fulfilled when
    -- the @TimeoutDurationMinutes@ has expired; that is, when all Spot
    -- Instances could not be provisioned within the Spot provisioning timeout.
    -- Valid values are @TERMINATE_CLUSTER@ and @SWITCH_TO_ON_DEMAND@.
    -- SWITCH_TO_ON_DEMAND specifies that if no Spot Instances are available,
    -- On-Demand Instances should be provisioned to fulfill any remaining Spot
    -- capacity.
    SpotProvisioningSpecification -> SpotProvisioningTimeoutAction
timeoutAction :: SpotProvisioningTimeoutAction
  }
  deriving (SpotProvisioningSpecification
-> SpotProvisioningSpecification -> Bool
(SpotProvisioningSpecification
 -> SpotProvisioningSpecification -> Bool)
-> (SpotProvisioningSpecification
    -> SpotProvisioningSpecification -> Bool)
-> Eq SpotProvisioningSpecification
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SpotProvisioningSpecification
-> SpotProvisioningSpecification -> Bool
$c/= :: SpotProvisioningSpecification
-> SpotProvisioningSpecification -> Bool
== :: SpotProvisioningSpecification
-> SpotProvisioningSpecification -> Bool
$c== :: SpotProvisioningSpecification
-> SpotProvisioningSpecification -> Bool
Prelude.Eq, ReadPrec [SpotProvisioningSpecification]
ReadPrec SpotProvisioningSpecification
Int -> ReadS SpotProvisioningSpecification
ReadS [SpotProvisioningSpecification]
(Int -> ReadS SpotProvisioningSpecification)
-> ReadS [SpotProvisioningSpecification]
-> ReadPrec SpotProvisioningSpecification
-> ReadPrec [SpotProvisioningSpecification]
-> Read SpotProvisioningSpecification
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SpotProvisioningSpecification]
$creadListPrec :: ReadPrec [SpotProvisioningSpecification]
readPrec :: ReadPrec SpotProvisioningSpecification
$creadPrec :: ReadPrec SpotProvisioningSpecification
readList :: ReadS [SpotProvisioningSpecification]
$creadList :: ReadS [SpotProvisioningSpecification]
readsPrec :: Int -> ReadS SpotProvisioningSpecification
$creadsPrec :: Int -> ReadS SpotProvisioningSpecification
Prelude.Read, Int -> SpotProvisioningSpecification -> ShowS
[SpotProvisioningSpecification] -> ShowS
SpotProvisioningSpecification -> String
(Int -> SpotProvisioningSpecification -> ShowS)
-> (SpotProvisioningSpecification -> String)
-> ([SpotProvisioningSpecification] -> ShowS)
-> Show SpotProvisioningSpecification
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SpotProvisioningSpecification] -> ShowS
$cshowList :: [SpotProvisioningSpecification] -> ShowS
show :: SpotProvisioningSpecification -> String
$cshow :: SpotProvisioningSpecification -> String
showsPrec :: Int -> SpotProvisioningSpecification -> ShowS
$cshowsPrec :: Int -> SpotProvisioningSpecification -> ShowS
Prelude.Show, (forall x.
 SpotProvisioningSpecification
 -> Rep SpotProvisioningSpecification x)
-> (forall x.
    Rep SpotProvisioningSpecification x
    -> SpotProvisioningSpecification)
-> Generic SpotProvisioningSpecification
forall x.
Rep SpotProvisioningSpecification x
-> SpotProvisioningSpecification
forall x.
SpotProvisioningSpecification
-> Rep SpotProvisioningSpecification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep SpotProvisioningSpecification x
-> SpotProvisioningSpecification
$cfrom :: forall x.
SpotProvisioningSpecification
-> Rep SpotProvisioningSpecification x
Prelude.Generic)

-- |
-- Create a value of 'SpotProvisioningSpecification' 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:
--
-- 'blockDurationMinutes', 'spotProvisioningSpecification_blockDurationMinutes' - The defined duration for Spot Instances (also known as Spot blocks) in
-- minutes. When specified, the Spot Instance does not terminate before the
-- defined duration expires, and defined duration pricing for Spot
-- Instances applies. Valid values are 60, 120, 180, 240, 300, or 360. The
-- duration period starts as soon as a Spot Instance receives its instance
-- ID. At the end of the duration, Amazon EC2 marks the Spot Instance for
-- termination and provides a Spot Instance termination notice, which gives
-- the instance a two-minute warning before it terminates.
--
-- 'allocationStrategy', 'spotProvisioningSpecification_allocationStrategy' - Specifies the strategy to use in launching Spot Instance fleets.
-- Currently, the only option is capacity-optimized (the default), which
-- launches instances from Spot Instance pools with optimal capacity for
-- the number of instances that are launching.
--
-- 'timeoutDurationMinutes', 'spotProvisioningSpecification_timeoutDurationMinutes' - The spot provisioning timeout period in minutes. If Spot Instances are
-- not provisioned within this time period, the @TimeOutAction@ is taken.
-- Minimum value is 5 and maximum value is 1440. The timeout applies only
-- during initial provisioning, when the cluster is first created.
--
-- 'timeoutAction', 'spotProvisioningSpecification_timeoutAction' - The action to take when @TargetSpotCapacity@ has not been fulfilled when
-- the @TimeoutDurationMinutes@ has expired; that is, when all Spot
-- Instances could not be provisioned within the Spot provisioning timeout.
-- Valid values are @TERMINATE_CLUSTER@ and @SWITCH_TO_ON_DEMAND@.
-- SWITCH_TO_ON_DEMAND specifies that if no Spot Instances are available,
-- On-Demand Instances should be provisioned to fulfill any remaining Spot
-- capacity.
newSpotProvisioningSpecification ::
  -- | 'timeoutDurationMinutes'
  Prelude.Natural ->
  -- | 'timeoutAction'
  SpotProvisioningTimeoutAction ->
  SpotProvisioningSpecification
newSpotProvisioningSpecification :: Natural
-> SpotProvisioningTimeoutAction -> SpotProvisioningSpecification
newSpotProvisioningSpecification
  Natural
pTimeoutDurationMinutes_
  SpotProvisioningTimeoutAction
pTimeoutAction_ =
    SpotProvisioningSpecification' :: Maybe Natural
-> Maybe SpotProvisioningAllocationStrategy
-> Natural
-> SpotProvisioningTimeoutAction
-> SpotProvisioningSpecification
SpotProvisioningSpecification'
      { $sel:blockDurationMinutes:SpotProvisioningSpecification' :: Maybe Natural
blockDurationMinutes =
          Maybe Natural
forall a. Maybe a
Prelude.Nothing,
        $sel:allocationStrategy:SpotProvisioningSpecification' :: Maybe SpotProvisioningAllocationStrategy
allocationStrategy = Maybe SpotProvisioningAllocationStrategy
forall a. Maybe a
Prelude.Nothing,
        $sel:timeoutDurationMinutes:SpotProvisioningSpecification' :: Natural
timeoutDurationMinutes =
          Natural
pTimeoutDurationMinutes_,
        $sel:timeoutAction:SpotProvisioningSpecification' :: SpotProvisioningTimeoutAction
timeoutAction = SpotProvisioningTimeoutAction
pTimeoutAction_
      }

-- | The defined duration for Spot Instances (also known as Spot blocks) in
-- minutes. When specified, the Spot Instance does not terminate before the
-- defined duration expires, and defined duration pricing for Spot
-- Instances applies. Valid values are 60, 120, 180, 240, 300, or 360. The
-- duration period starts as soon as a Spot Instance receives its instance
-- ID. At the end of the duration, Amazon EC2 marks the Spot Instance for
-- termination and provides a Spot Instance termination notice, which gives
-- the instance a two-minute warning before it terminates.
spotProvisioningSpecification_blockDurationMinutes :: Lens.Lens' SpotProvisioningSpecification (Prelude.Maybe Prelude.Natural)
spotProvisioningSpecification_blockDurationMinutes :: (Maybe Natural -> f (Maybe Natural))
-> SpotProvisioningSpecification -> f SpotProvisioningSpecification
spotProvisioningSpecification_blockDurationMinutes = (SpotProvisioningSpecification -> Maybe Natural)
-> (SpotProvisioningSpecification
    -> Maybe Natural -> SpotProvisioningSpecification)
-> Lens
     SpotProvisioningSpecification
     SpotProvisioningSpecification
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SpotProvisioningSpecification' {Maybe Natural
blockDurationMinutes :: Maybe Natural
$sel:blockDurationMinutes:SpotProvisioningSpecification' :: SpotProvisioningSpecification -> Maybe Natural
blockDurationMinutes} -> Maybe Natural
blockDurationMinutes) (\s :: SpotProvisioningSpecification
s@SpotProvisioningSpecification' {} Maybe Natural
a -> SpotProvisioningSpecification
s {$sel:blockDurationMinutes:SpotProvisioningSpecification' :: Maybe Natural
blockDurationMinutes = Maybe Natural
a} :: SpotProvisioningSpecification)

-- | Specifies the strategy to use in launching Spot Instance fleets.
-- Currently, the only option is capacity-optimized (the default), which
-- launches instances from Spot Instance pools with optimal capacity for
-- the number of instances that are launching.
spotProvisioningSpecification_allocationStrategy :: Lens.Lens' SpotProvisioningSpecification (Prelude.Maybe SpotProvisioningAllocationStrategy)
spotProvisioningSpecification_allocationStrategy :: (Maybe SpotProvisioningAllocationStrategy
 -> f (Maybe SpotProvisioningAllocationStrategy))
-> SpotProvisioningSpecification -> f SpotProvisioningSpecification
spotProvisioningSpecification_allocationStrategy = (SpotProvisioningSpecification
 -> Maybe SpotProvisioningAllocationStrategy)
-> (SpotProvisioningSpecification
    -> Maybe SpotProvisioningAllocationStrategy
    -> SpotProvisioningSpecification)
-> Lens
     SpotProvisioningSpecification
     SpotProvisioningSpecification
     (Maybe SpotProvisioningAllocationStrategy)
     (Maybe SpotProvisioningAllocationStrategy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SpotProvisioningSpecification' {Maybe SpotProvisioningAllocationStrategy
allocationStrategy :: Maybe SpotProvisioningAllocationStrategy
$sel:allocationStrategy:SpotProvisioningSpecification' :: SpotProvisioningSpecification
-> Maybe SpotProvisioningAllocationStrategy
allocationStrategy} -> Maybe SpotProvisioningAllocationStrategy
allocationStrategy) (\s :: SpotProvisioningSpecification
s@SpotProvisioningSpecification' {} Maybe SpotProvisioningAllocationStrategy
a -> SpotProvisioningSpecification
s {$sel:allocationStrategy:SpotProvisioningSpecification' :: Maybe SpotProvisioningAllocationStrategy
allocationStrategy = Maybe SpotProvisioningAllocationStrategy
a} :: SpotProvisioningSpecification)

-- | The spot provisioning timeout period in minutes. If Spot Instances are
-- not provisioned within this time period, the @TimeOutAction@ is taken.
-- Minimum value is 5 and maximum value is 1440. The timeout applies only
-- during initial provisioning, when the cluster is first created.
spotProvisioningSpecification_timeoutDurationMinutes :: Lens.Lens' SpotProvisioningSpecification Prelude.Natural
spotProvisioningSpecification_timeoutDurationMinutes :: (Natural -> f Natural)
-> SpotProvisioningSpecification -> f SpotProvisioningSpecification
spotProvisioningSpecification_timeoutDurationMinutes = (SpotProvisioningSpecification -> Natural)
-> (SpotProvisioningSpecification
    -> Natural -> SpotProvisioningSpecification)
-> Lens
     SpotProvisioningSpecification
     SpotProvisioningSpecification
     Natural
     Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SpotProvisioningSpecification' {Natural
timeoutDurationMinutes :: Natural
$sel:timeoutDurationMinutes:SpotProvisioningSpecification' :: SpotProvisioningSpecification -> Natural
timeoutDurationMinutes} -> Natural
timeoutDurationMinutes) (\s :: SpotProvisioningSpecification
s@SpotProvisioningSpecification' {} Natural
a -> SpotProvisioningSpecification
s {$sel:timeoutDurationMinutes:SpotProvisioningSpecification' :: Natural
timeoutDurationMinutes = Natural
a} :: SpotProvisioningSpecification)

-- | The action to take when @TargetSpotCapacity@ has not been fulfilled when
-- the @TimeoutDurationMinutes@ has expired; that is, when all Spot
-- Instances could not be provisioned within the Spot provisioning timeout.
-- Valid values are @TERMINATE_CLUSTER@ and @SWITCH_TO_ON_DEMAND@.
-- SWITCH_TO_ON_DEMAND specifies that if no Spot Instances are available,
-- On-Demand Instances should be provisioned to fulfill any remaining Spot
-- capacity.
spotProvisioningSpecification_timeoutAction :: Lens.Lens' SpotProvisioningSpecification SpotProvisioningTimeoutAction
spotProvisioningSpecification_timeoutAction :: (SpotProvisioningTimeoutAction -> f SpotProvisioningTimeoutAction)
-> SpotProvisioningSpecification -> f SpotProvisioningSpecification
spotProvisioningSpecification_timeoutAction = (SpotProvisioningSpecification -> SpotProvisioningTimeoutAction)
-> (SpotProvisioningSpecification
    -> SpotProvisioningTimeoutAction -> SpotProvisioningSpecification)
-> Lens
     SpotProvisioningSpecification
     SpotProvisioningSpecification
     SpotProvisioningTimeoutAction
     SpotProvisioningTimeoutAction
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SpotProvisioningSpecification' {SpotProvisioningTimeoutAction
timeoutAction :: SpotProvisioningTimeoutAction
$sel:timeoutAction:SpotProvisioningSpecification' :: SpotProvisioningSpecification -> SpotProvisioningTimeoutAction
timeoutAction} -> SpotProvisioningTimeoutAction
timeoutAction) (\s :: SpotProvisioningSpecification
s@SpotProvisioningSpecification' {} SpotProvisioningTimeoutAction
a -> SpotProvisioningSpecification
s {$sel:timeoutAction:SpotProvisioningSpecification' :: SpotProvisioningTimeoutAction
timeoutAction = SpotProvisioningTimeoutAction
a} :: SpotProvisioningSpecification)

instance Core.FromJSON SpotProvisioningSpecification where
  parseJSON :: Value -> Parser SpotProvisioningSpecification
parseJSON =
    String
-> (Object -> Parser SpotProvisioningSpecification)
-> Value
-> Parser SpotProvisioningSpecification
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SpotProvisioningSpecification"
      ( \Object
x ->
          Maybe Natural
-> Maybe SpotProvisioningAllocationStrategy
-> Natural
-> SpotProvisioningTimeoutAction
-> SpotProvisioningSpecification
SpotProvisioningSpecification'
            (Maybe Natural
 -> Maybe SpotProvisioningAllocationStrategy
 -> Natural
 -> SpotProvisioningTimeoutAction
 -> SpotProvisioningSpecification)
-> Parser (Maybe Natural)
-> Parser
     (Maybe SpotProvisioningAllocationStrategy
      -> Natural
      -> SpotProvisioningTimeoutAction
      -> SpotProvisioningSpecification)
forall (f :: * -> *) a b. Functor 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
"BlockDurationMinutes")
            Parser
  (Maybe SpotProvisioningAllocationStrategy
   -> Natural
   -> SpotProvisioningTimeoutAction
   -> SpotProvisioningSpecification)
-> Parser (Maybe SpotProvisioningAllocationStrategy)
-> Parser
     (Natural
      -> SpotProvisioningTimeoutAction -> SpotProvisioningSpecification)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe SpotProvisioningAllocationStrategy)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AllocationStrategy")
            Parser
  (Natural
   -> SpotProvisioningTimeoutAction -> SpotProvisioningSpecification)
-> Parser Natural
-> Parser
     (SpotProvisioningTimeoutAction -> SpotProvisioningSpecification)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"TimeoutDurationMinutes")
            Parser
  (SpotProvisioningTimeoutAction -> SpotProvisioningSpecification)
-> Parser SpotProvisioningTimeoutAction
-> Parser SpotProvisioningSpecification
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser SpotProvisioningTimeoutAction
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"TimeoutAction")
      )

instance
  Prelude.Hashable
    SpotProvisioningSpecification

instance Prelude.NFData SpotProvisioningSpecification

instance Core.ToJSON SpotProvisioningSpecification where
  toJSON :: SpotProvisioningSpecification -> Value
toJSON SpotProvisioningSpecification' {Natural
Maybe Natural
Maybe SpotProvisioningAllocationStrategy
SpotProvisioningTimeoutAction
timeoutAction :: SpotProvisioningTimeoutAction
timeoutDurationMinutes :: Natural
allocationStrategy :: Maybe SpotProvisioningAllocationStrategy
blockDurationMinutes :: Maybe Natural
$sel:timeoutAction:SpotProvisioningSpecification' :: SpotProvisioningSpecification -> SpotProvisioningTimeoutAction
$sel:timeoutDurationMinutes:SpotProvisioningSpecification' :: SpotProvisioningSpecification -> Natural
$sel:allocationStrategy:SpotProvisioningSpecification' :: SpotProvisioningSpecification
-> Maybe SpotProvisioningAllocationStrategy
$sel:blockDurationMinutes:SpotProvisioningSpecification' :: SpotProvisioningSpecification -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"BlockDurationMinutes" 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
blockDurationMinutes,
            (Text
"AllocationStrategy" Text -> SpotProvisioningAllocationStrategy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (SpotProvisioningAllocationStrategy -> Pair)
-> Maybe SpotProvisioningAllocationStrategy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SpotProvisioningAllocationStrategy
allocationStrategy,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"TimeoutDurationMinutes"
                  Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
timeoutDurationMinutes
              ),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"TimeoutAction" Text -> SpotProvisioningTimeoutAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= SpotProvisioningTimeoutAction
timeoutAction)
          ]
      )