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

import qualified Amazonka.Core as Core
import Amazonka.EMR.Types.InstanceResizePolicy
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Policy for customizing shrink operations. Allows configuration of
-- decommissioning timeout and targeted instance shrinking.
--
-- /See:/ 'newShrinkPolicy' smart constructor.
data ShrinkPolicy = ShrinkPolicy'
  { -- | The desired timeout for decommissioning an instance. Overrides the
    -- default YARN decommissioning timeout.
    ShrinkPolicy -> Maybe Int
decommissionTimeout :: Prelude.Maybe Prelude.Int,
    -- | Custom policy for requesting termination protection or termination of
    -- specific instances when shrinking an instance group.
    ShrinkPolicy -> Maybe InstanceResizePolicy
instanceResizePolicy :: Prelude.Maybe InstanceResizePolicy
  }
  deriving (ShrinkPolicy -> ShrinkPolicy -> Bool
(ShrinkPolicy -> ShrinkPolicy -> Bool)
-> (ShrinkPolicy -> ShrinkPolicy -> Bool) -> Eq ShrinkPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ShrinkPolicy -> ShrinkPolicy -> Bool
$c/= :: ShrinkPolicy -> ShrinkPolicy -> Bool
== :: ShrinkPolicy -> ShrinkPolicy -> Bool
$c== :: ShrinkPolicy -> ShrinkPolicy -> Bool
Prelude.Eq, ReadPrec [ShrinkPolicy]
ReadPrec ShrinkPolicy
Int -> ReadS ShrinkPolicy
ReadS [ShrinkPolicy]
(Int -> ReadS ShrinkPolicy)
-> ReadS [ShrinkPolicy]
-> ReadPrec ShrinkPolicy
-> ReadPrec [ShrinkPolicy]
-> Read ShrinkPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ShrinkPolicy]
$creadListPrec :: ReadPrec [ShrinkPolicy]
readPrec :: ReadPrec ShrinkPolicy
$creadPrec :: ReadPrec ShrinkPolicy
readList :: ReadS [ShrinkPolicy]
$creadList :: ReadS [ShrinkPolicy]
readsPrec :: Int -> ReadS ShrinkPolicy
$creadsPrec :: Int -> ReadS ShrinkPolicy
Prelude.Read, Int -> ShrinkPolicy -> ShowS
[ShrinkPolicy] -> ShowS
ShrinkPolicy -> String
(Int -> ShrinkPolicy -> ShowS)
-> (ShrinkPolicy -> String)
-> ([ShrinkPolicy] -> ShowS)
-> Show ShrinkPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ShrinkPolicy] -> ShowS
$cshowList :: [ShrinkPolicy] -> ShowS
show :: ShrinkPolicy -> String
$cshow :: ShrinkPolicy -> String
showsPrec :: Int -> ShrinkPolicy -> ShowS
$cshowsPrec :: Int -> ShrinkPolicy -> ShowS
Prelude.Show, (forall x. ShrinkPolicy -> Rep ShrinkPolicy x)
-> (forall x. Rep ShrinkPolicy x -> ShrinkPolicy)
-> Generic ShrinkPolicy
forall x. Rep ShrinkPolicy x -> ShrinkPolicy
forall x. ShrinkPolicy -> Rep ShrinkPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ShrinkPolicy x -> ShrinkPolicy
$cfrom :: forall x. ShrinkPolicy -> Rep ShrinkPolicy x
Prelude.Generic)

-- |
-- Create a value of 'ShrinkPolicy' 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:
--
-- 'decommissionTimeout', 'shrinkPolicy_decommissionTimeout' - The desired timeout for decommissioning an instance. Overrides the
-- default YARN decommissioning timeout.
--
-- 'instanceResizePolicy', 'shrinkPolicy_instanceResizePolicy' - Custom policy for requesting termination protection or termination of
-- specific instances when shrinking an instance group.
newShrinkPolicy ::
  ShrinkPolicy
newShrinkPolicy :: ShrinkPolicy
newShrinkPolicy =
  ShrinkPolicy' :: Maybe Int -> Maybe InstanceResizePolicy -> ShrinkPolicy
ShrinkPolicy'
    { $sel:decommissionTimeout:ShrinkPolicy' :: Maybe Int
decommissionTimeout =
        Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:instanceResizePolicy:ShrinkPolicy' :: Maybe InstanceResizePolicy
instanceResizePolicy = Maybe InstanceResizePolicy
forall a. Maybe a
Prelude.Nothing
    }

-- | The desired timeout for decommissioning an instance. Overrides the
-- default YARN decommissioning timeout.
shrinkPolicy_decommissionTimeout :: Lens.Lens' ShrinkPolicy (Prelude.Maybe Prelude.Int)
shrinkPolicy_decommissionTimeout :: (Maybe Int -> f (Maybe Int)) -> ShrinkPolicy -> f ShrinkPolicy
shrinkPolicy_decommissionTimeout = (ShrinkPolicy -> Maybe Int)
-> (ShrinkPolicy -> Maybe Int -> ShrinkPolicy)
-> Lens ShrinkPolicy ShrinkPolicy (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ShrinkPolicy' {Maybe Int
decommissionTimeout :: Maybe Int
$sel:decommissionTimeout:ShrinkPolicy' :: ShrinkPolicy -> Maybe Int
decommissionTimeout} -> Maybe Int
decommissionTimeout) (\s :: ShrinkPolicy
s@ShrinkPolicy' {} Maybe Int
a -> ShrinkPolicy
s {$sel:decommissionTimeout:ShrinkPolicy' :: Maybe Int
decommissionTimeout = Maybe Int
a} :: ShrinkPolicy)

-- | Custom policy for requesting termination protection or termination of
-- specific instances when shrinking an instance group.
shrinkPolicy_instanceResizePolicy :: Lens.Lens' ShrinkPolicy (Prelude.Maybe InstanceResizePolicy)
shrinkPolicy_instanceResizePolicy :: (Maybe InstanceResizePolicy -> f (Maybe InstanceResizePolicy))
-> ShrinkPolicy -> f ShrinkPolicy
shrinkPolicy_instanceResizePolicy = (ShrinkPolicy -> Maybe InstanceResizePolicy)
-> (ShrinkPolicy -> Maybe InstanceResizePolicy -> ShrinkPolicy)
-> Lens
     ShrinkPolicy
     ShrinkPolicy
     (Maybe InstanceResizePolicy)
     (Maybe InstanceResizePolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ShrinkPolicy' {Maybe InstanceResizePolicy
instanceResizePolicy :: Maybe InstanceResizePolicy
$sel:instanceResizePolicy:ShrinkPolicy' :: ShrinkPolicy -> Maybe InstanceResizePolicy
instanceResizePolicy} -> Maybe InstanceResizePolicy
instanceResizePolicy) (\s :: ShrinkPolicy
s@ShrinkPolicy' {} Maybe InstanceResizePolicy
a -> ShrinkPolicy
s {$sel:instanceResizePolicy:ShrinkPolicy' :: Maybe InstanceResizePolicy
instanceResizePolicy = Maybe InstanceResizePolicy
a} :: ShrinkPolicy)

instance Core.FromJSON ShrinkPolicy where
  parseJSON :: Value -> Parser ShrinkPolicy
parseJSON =
    String
-> (Object -> Parser ShrinkPolicy) -> Value -> Parser ShrinkPolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ShrinkPolicy"
      ( \Object
x ->
          Maybe Int -> Maybe InstanceResizePolicy -> ShrinkPolicy
ShrinkPolicy'
            (Maybe Int -> Maybe InstanceResizePolicy -> ShrinkPolicy)
-> Parser (Maybe Int)
-> Parser (Maybe InstanceResizePolicy -> ShrinkPolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DecommissionTimeout")
            Parser (Maybe InstanceResizePolicy -> ShrinkPolicy)
-> Parser (Maybe InstanceResizePolicy) -> Parser ShrinkPolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe InstanceResizePolicy)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"InstanceResizePolicy")
      )

instance Prelude.Hashable ShrinkPolicy

instance Prelude.NFData ShrinkPolicy

instance Core.ToJSON ShrinkPolicy where
  toJSON :: ShrinkPolicy -> Value
toJSON ShrinkPolicy' {Maybe Int
Maybe InstanceResizePolicy
instanceResizePolicy :: Maybe InstanceResizePolicy
decommissionTimeout :: Maybe Int
$sel:instanceResizePolicy:ShrinkPolicy' :: ShrinkPolicy -> Maybe InstanceResizePolicy
$sel:decommissionTimeout:ShrinkPolicy' :: ShrinkPolicy -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"DecommissionTimeout" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
decommissionTimeout,
            (Text
"InstanceResizePolicy" Text -> InstanceResizePolicy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (InstanceResizePolicy -> Pair)
-> Maybe InstanceResizePolicy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe InstanceResizePolicy
instanceResizePolicy
          ]
      )