{-# 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.SpotCapacityRebalance
-- 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.SpotCapacityRebalance 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.ReplacementStrategy
import qualified Amazonka.Prelude as Prelude

-- | The Spot Instance replacement strategy to use when Amazon EC2 emits a
-- signal that your Spot Instance is at an elevated risk of being
-- interrupted. For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-fleet-capacity-rebalance.html Capacity rebalancing>
-- in the /Amazon EC2 User Guide for Linux Instances/.
--
-- /See:/ 'newSpotCapacityRebalance' smart constructor.
data SpotCapacityRebalance = SpotCapacityRebalance'
  { -- | The replacement strategy to use. Only available for fleets of type
    -- @maintain@.
    --
    -- @launch@ - Spot Fleet launches a new replacement Spot Instance when a
    -- rebalance notification is emitted for an existing Spot Instance in the
    -- fleet. Spot Fleet does not terminate the instances that receive a
    -- rebalance notification. You can terminate the old instances, or you can
    -- leave them running. You are charged for all instances while they are
    -- running.
    --
    -- @launch-before-terminate@ - Spot Fleet launches a new replacement Spot
    -- Instance when a rebalance notification is emitted for an existing Spot
    -- Instance in the fleet, and then, after a delay that you specify (in
    -- @TerminationDelay@), terminates the instances that received a rebalance
    -- notification.
    SpotCapacityRebalance -> Maybe ReplacementStrategy
replacementStrategy :: Prelude.Maybe ReplacementStrategy,
    -- | The amount of time (in seconds) that Amazon EC2 waits before terminating
    -- the old Spot Instance after launching a new replacement Spot Instance.
    --
    -- Required when @ReplacementStrategy@ is set to @launch-before-terminate@.
    --
    -- Not valid when @ReplacementStrategy@ is set to @launch@.
    --
    -- Valid values: Minimum value of @120@ seconds. Maximum value of @7200@
    -- seconds.
    SpotCapacityRebalance -> Maybe Int
terminationDelay :: Prelude.Maybe Prelude.Int
  }
  deriving (SpotCapacityRebalance -> SpotCapacityRebalance -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SpotCapacityRebalance -> SpotCapacityRebalance -> Bool
$c/= :: SpotCapacityRebalance -> SpotCapacityRebalance -> Bool
== :: SpotCapacityRebalance -> SpotCapacityRebalance -> Bool
$c== :: SpotCapacityRebalance -> SpotCapacityRebalance -> Bool
Prelude.Eq, ReadPrec [SpotCapacityRebalance]
ReadPrec SpotCapacityRebalance
Int -> ReadS SpotCapacityRebalance
ReadS [SpotCapacityRebalance]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SpotCapacityRebalance]
$creadListPrec :: ReadPrec [SpotCapacityRebalance]
readPrec :: ReadPrec SpotCapacityRebalance
$creadPrec :: ReadPrec SpotCapacityRebalance
readList :: ReadS [SpotCapacityRebalance]
$creadList :: ReadS [SpotCapacityRebalance]
readsPrec :: Int -> ReadS SpotCapacityRebalance
$creadsPrec :: Int -> ReadS SpotCapacityRebalance
Prelude.Read, Int -> SpotCapacityRebalance -> ShowS
[SpotCapacityRebalance] -> ShowS
SpotCapacityRebalance -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SpotCapacityRebalance] -> ShowS
$cshowList :: [SpotCapacityRebalance] -> ShowS
show :: SpotCapacityRebalance -> String
$cshow :: SpotCapacityRebalance -> String
showsPrec :: Int -> SpotCapacityRebalance -> ShowS
$cshowsPrec :: Int -> SpotCapacityRebalance -> ShowS
Prelude.Show, forall x. Rep SpotCapacityRebalance x -> SpotCapacityRebalance
forall x. SpotCapacityRebalance -> Rep SpotCapacityRebalance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SpotCapacityRebalance x -> SpotCapacityRebalance
$cfrom :: forall x. SpotCapacityRebalance -> Rep SpotCapacityRebalance x
Prelude.Generic)

-- |
-- Create a value of 'SpotCapacityRebalance' 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:
--
-- 'replacementStrategy', 'spotCapacityRebalance_replacementStrategy' - The replacement strategy to use. Only available for fleets of type
-- @maintain@.
--
-- @launch@ - Spot Fleet launches a new replacement Spot Instance when a
-- rebalance notification is emitted for an existing Spot Instance in the
-- fleet. Spot Fleet does not terminate the instances that receive a
-- rebalance notification. You can terminate the old instances, or you can
-- leave them running. You are charged for all instances while they are
-- running.
--
-- @launch-before-terminate@ - Spot Fleet launches a new replacement Spot
-- Instance when a rebalance notification is emitted for an existing Spot
-- Instance in the fleet, and then, after a delay that you specify (in
-- @TerminationDelay@), terminates the instances that received a rebalance
-- notification.
--
-- 'terminationDelay', 'spotCapacityRebalance_terminationDelay' - The amount of time (in seconds) that Amazon EC2 waits before terminating
-- the old Spot Instance after launching a new replacement Spot Instance.
--
-- Required when @ReplacementStrategy@ is set to @launch-before-terminate@.
--
-- Not valid when @ReplacementStrategy@ is set to @launch@.
--
-- Valid values: Minimum value of @120@ seconds. Maximum value of @7200@
-- seconds.
newSpotCapacityRebalance ::
  SpotCapacityRebalance
newSpotCapacityRebalance :: SpotCapacityRebalance
newSpotCapacityRebalance =
  SpotCapacityRebalance'
    { $sel:replacementStrategy:SpotCapacityRebalance' :: Maybe ReplacementStrategy
replacementStrategy =
        forall a. Maybe a
Prelude.Nothing,
      $sel:terminationDelay:SpotCapacityRebalance' :: Maybe Int
terminationDelay = forall a. Maybe a
Prelude.Nothing
    }

-- | The replacement strategy to use. Only available for fleets of type
-- @maintain@.
--
-- @launch@ - Spot Fleet launches a new replacement Spot Instance when a
-- rebalance notification is emitted for an existing Spot Instance in the
-- fleet. Spot Fleet does not terminate the instances that receive a
-- rebalance notification. You can terminate the old instances, or you can
-- leave them running. You are charged for all instances while they are
-- running.
--
-- @launch-before-terminate@ - Spot Fleet launches a new replacement Spot
-- Instance when a rebalance notification is emitted for an existing Spot
-- Instance in the fleet, and then, after a delay that you specify (in
-- @TerminationDelay@), terminates the instances that received a rebalance
-- notification.
spotCapacityRebalance_replacementStrategy :: Lens.Lens' SpotCapacityRebalance (Prelude.Maybe ReplacementStrategy)
spotCapacityRebalance_replacementStrategy :: Lens' SpotCapacityRebalance (Maybe ReplacementStrategy)
spotCapacityRebalance_replacementStrategy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SpotCapacityRebalance' {Maybe ReplacementStrategy
replacementStrategy :: Maybe ReplacementStrategy
$sel:replacementStrategy:SpotCapacityRebalance' :: SpotCapacityRebalance -> Maybe ReplacementStrategy
replacementStrategy} -> Maybe ReplacementStrategy
replacementStrategy) (\s :: SpotCapacityRebalance
s@SpotCapacityRebalance' {} Maybe ReplacementStrategy
a -> SpotCapacityRebalance
s {$sel:replacementStrategy:SpotCapacityRebalance' :: Maybe ReplacementStrategy
replacementStrategy = Maybe ReplacementStrategy
a} :: SpotCapacityRebalance)

-- | The amount of time (in seconds) that Amazon EC2 waits before terminating
-- the old Spot Instance after launching a new replacement Spot Instance.
--
-- Required when @ReplacementStrategy@ is set to @launch-before-terminate@.
--
-- Not valid when @ReplacementStrategy@ is set to @launch@.
--
-- Valid values: Minimum value of @120@ seconds. Maximum value of @7200@
-- seconds.
spotCapacityRebalance_terminationDelay :: Lens.Lens' SpotCapacityRebalance (Prelude.Maybe Prelude.Int)
spotCapacityRebalance_terminationDelay :: Lens' SpotCapacityRebalance (Maybe Int)
spotCapacityRebalance_terminationDelay = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SpotCapacityRebalance' {Maybe Int
terminationDelay :: Maybe Int
$sel:terminationDelay:SpotCapacityRebalance' :: SpotCapacityRebalance -> Maybe Int
terminationDelay} -> Maybe Int
terminationDelay) (\s :: SpotCapacityRebalance
s@SpotCapacityRebalance' {} Maybe Int
a -> SpotCapacityRebalance
s {$sel:terminationDelay:SpotCapacityRebalance' :: Maybe Int
terminationDelay = Maybe Int
a} :: SpotCapacityRebalance)

instance Data.FromXML SpotCapacityRebalance where
  parseXML :: [Node] -> Either String SpotCapacityRebalance
parseXML [Node]
x =
    Maybe ReplacementStrategy -> Maybe Int -> SpotCapacityRebalance
SpotCapacityRebalance'
      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
"replacementStrategy")
      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
"terminationDelay")

instance Prelude.Hashable SpotCapacityRebalance where
  hashWithSalt :: Int -> SpotCapacityRebalance -> Int
hashWithSalt Int
_salt SpotCapacityRebalance' {Maybe Int
Maybe ReplacementStrategy
terminationDelay :: Maybe Int
replacementStrategy :: Maybe ReplacementStrategy
$sel:terminationDelay:SpotCapacityRebalance' :: SpotCapacityRebalance -> Maybe Int
$sel:replacementStrategy:SpotCapacityRebalance' :: SpotCapacityRebalance -> Maybe ReplacementStrategy
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ReplacementStrategy
replacementStrategy
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
terminationDelay

instance Prelude.NFData SpotCapacityRebalance where
  rnf :: SpotCapacityRebalance -> ()
rnf SpotCapacityRebalance' {Maybe Int
Maybe ReplacementStrategy
terminationDelay :: Maybe Int
replacementStrategy :: Maybe ReplacementStrategy
$sel:terminationDelay:SpotCapacityRebalance' :: SpotCapacityRebalance -> Maybe Int
$sel:replacementStrategy:SpotCapacityRebalance' :: SpotCapacityRebalance -> Maybe ReplacementStrategy
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ReplacementStrategy
replacementStrategy
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
terminationDelay

instance Data.ToQuery SpotCapacityRebalance where
  toQuery :: SpotCapacityRebalance -> QueryString
toQuery SpotCapacityRebalance' {Maybe Int
Maybe ReplacementStrategy
terminationDelay :: Maybe Int
replacementStrategy :: Maybe ReplacementStrategy
$sel:terminationDelay:SpotCapacityRebalance' :: SpotCapacityRebalance -> Maybe Int
$sel:replacementStrategy:SpotCapacityRebalance' :: SpotCapacityRebalance -> Maybe ReplacementStrategy
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"ReplacementStrategy" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe ReplacementStrategy
replacementStrategy,
        ByteString
"TerminationDelay" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Int
terminationDelay
      ]