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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Custom policy for requesting termination protection or termination of
-- specific instances when shrinking an instance group.
--
-- /See:/ 'newInstanceResizePolicy' smart constructor.
data InstanceResizePolicy = InstanceResizePolicy'
  { -- | Specific list of instances to be protected when shrinking an instance
    -- group.
    InstanceResizePolicy -> Maybe [Text]
instancesToProtect :: Prelude.Maybe [Prelude.Text],
    -- | Specific list of instances to be terminated when shrinking an instance
    -- group.
    InstanceResizePolicy -> Maybe [Text]
instancesToTerminate :: Prelude.Maybe [Prelude.Text],
    -- | Decommissioning timeout override for the specific list of instances to
    -- be terminated.
    InstanceResizePolicy -> Maybe Int
instanceTerminationTimeout :: Prelude.Maybe Prelude.Int
  }
  deriving (InstanceResizePolicy -> InstanceResizePolicy -> Bool
(InstanceResizePolicy -> InstanceResizePolicy -> Bool)
-> (InstanceResizePolicy -> InstanceResizePolicy -> Bool)
-> Eq InstanceResizePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InstanceResizePolicy -> InstanceResizePolicy -> Bool
$c/= :: InstanceResizePolicy -> InstanceResizePolicy -> Bool
== :: InstanceResizePolicy -> InstanceResizePolicy -> Bool
$c== :: InstanceResizePolicy -> InstanceResizePolicy -> Bool
Prelude.Eq, ReadPrec [InstanceResizePolicy]
ReadPrec InstanceResizePolicy
Int -> ReadS InstanceResizePolicy
ReadS [InstanceResizePolicy]
(Int -> ReadS InstanceResizePolicy)
-> ReadS [InstanceResizePolicy]
-> ReadPrec InstanceResizePolicy
-> ReadPrec [InstanceResizePolicy]
-> Read InstanceResizePolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InstanceResizePolicy]
$creadListPrec :: ReadPrec [InstanceResizePolicy]
readPrec :: ReadPrec InstanceResizePolicy
$creadPrec :: ReadPrec InstanceResizePolicy
readList :: ReadS [InstanceResizePolicy]
$creadList :: ReadS [InstanceResizePolicy]
readsPrec :: Int -> ReadS InstanceResizePolicy
$creadsPrec :: Int -> ReadS InstanceResizePolicy
Prelude.Read, Int -> InstanceResizePolicy -> ShowS
[InstanceResizePolicy] -> ShowS
InstanceResizePolicy -> String
(Int -> InstanceResizePolicy -> ShowS)
-> (InstanceResizePolicy -> String)
-> ([InstanceResizePolicy] -> ShowS)
-> Show InstanceResizePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InstanceResizePolicy] -> ShowS
$cshowList :: [InstanceResizePolicy] -> ShowS
show :: InstanceResizePolicy -> String
$cshow :: InstanceResizePolicy -> String
showsPrec :: Int -> InstanceResizePolicy -> ShowS
$cshowsPrec :: Int -> InstanceResizePolicy -> ShowS
Prelude.Show, (forall x. InstanceResizePolicy -> Rep InstanceResizePolicy x)
-> (forall x. Rep InstanceResizePolicy x -> InstanceResizePolicy)
-> Generic InstanceResizePolicy
forall x. Rep InstanceResizePolicy x -> InstanceResizePolicy
forall x. InstanceResizePolicy -> Rep InstanceResizePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InstanceResizePolicy x -> InstanceResizePolicy
$cfrom :: forall x. InstanceResizePolicy -> Rep InstanceResizePolicy x
Prelude.Generic)

-- |
-- Create a value of 'InstanceResizePolicy' 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:
--
-- 'instancesToProtect', 'instanceResizePolicy_instancesToProtect' - Specific list of instances to be protected when shrinking an instance
-- group.
--
-- 'instancesToTerminate', 'instanceResizePolicy_instancesToTerminate' - Specific list of instances to be terminated when shrinking an instance
-- group.
--
-- 'instanceTerminationTimeout', 'instanceResizePolicy_instanceTerminationTimeout' - Decommissioning timeout override for the specific list of instances to
-- be terminated.
newInstanceResizePolicy ::
  InstanceResizePolicy
newInstanceResizePolicy :: InstanceResizePolicy
newInstanceResizePolicy =
  InstanceResizePolicy' :: Maybe [Text] -> Maybe [Text] -> Maybe Int -> InstanceResizePolicy
InstanceResizePolicy'
    { $sel:instancesToProtect:InstanceResizePolicy' :: Maybe [Text]
instancesToProtect =
        Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:instancesToTerminate:InstanceResizePolicy' :: Maybe [Text]
instancesToTerminate = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:instanceTerminationTimeout:InstanceResizePolicy' :: Maybe Int
instanceTerminationTimeout = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | Specific list of instances to be protected when shrinking an instance
-- group.
instanceResizePolicy_instancesToProtect :: Lens.Lens' InstanceResizePolicy (Prelude.Maybe [Prelude.Text])
instanceResizePolicy_instancesToProtect :: (Maybe [Text] -> f (Maybe [Text]))
-> InstanceResizePolicy -> f InstanceResizePolicy
instanceResizePolicy_instancesToProtect = (InstanceResizePolicy -> Maybe [Text])
-> (InstanceResizePolicy -> Maybe [Text] -> InstanceResizePolicy)
-> Lens
     InstanceResizePolicy
     InstanceResizePolicy
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceResizePolicy' {Maybe [Text]
instancesToProtect :: Maybe [Text]
$sel:instancesToProtect:InstanceResizePolicy' :: InstanceResizePolicy -> Maybe [Text]
instancesToProtect} -> Maybe [Text]
instancesToProtect) (\s :: InstanceResizePolicy
s@InstanceResizePolicy' {} Maybe [Text]
a -> InstanceResizePolicy
s {$sel:instancesToProtect:InstanceResizePolicy' :: Maybe [Text]
instancesToProtect = Maybe [Text]
a} :: InstanceResizePolicy) ((Maybe [Text] -> f (Maybe [Text]))
 -> InstanceResizePolicy -> f InstanceResizePolicy)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> InstanceResizePolicy
-> f InstanceResizePolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Specific list of instances to be terminated when shrinking an instance
-- group.
instanceResizePolicy_instancesToTerminate :: Lens.Lens' InstanceResizePolicy (Prelude.Maybe [Prelude.Text])
instanceResizePolicy_instancesToTerminate :: (Maybe [Text] -> f (Maybe [Text]))
-> InstanceResizePolicy -> f InstanceResizePolicy
instanceResizePolicy_instancesToTerminate = (InstanceResizePolicy -> Maybe [Text])
-> (InstanceResizePolicy -> Maybe [Text] -> InstanceResizePolicy)
-> Lens
     InstanceResizePolicy
     InstanceResizePolicy
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceResizePolicy' {Maybe [Text]
instancesToTerminate :: Maybe [Text]
$sel:instancesToTerminate:InstanceResizePolicy' :: InstanceResizePolicy -> Maybe [Text]
instancesToTerminate} -> Maybe [Text]
instancesToTerminate) (\s :: InstanceResizePolicy
s@InstanceResizePolicy' {} Maybe [Text]
a -> InstanceResizePolicy
s {$sel:instancesToTerminate:InstanceResizePolicy' :: Maybe [Text]
instancesToTerminate = Maybe [Text]
a} :: InstanceResizePolicy) ((Maybe [Text] -> f (Maybe [Text]))
 -> InstanceResizePolicy -> f InstanceResizePolicy)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> InstanceResizePolicy
-> f InstanceResizePolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Decommissioning timeout override for the specific list of instances to
-- be terminated.
instanceResizePolicy_instanceTerminationTimeout :: Lens.Lens' InstanceResizePolicy (Prelude.Maybe Prelude.Int)
instanceResizePolicy_instanceTerminationTimeout :: (Maybe Int -> f (Maybe Int))
-> InstanceResizePolicy -> f InstanceResizePolicy
instanceResizePolicy_instanceTerminationTimeout = (InstanceResizePolicy -> Maybe Int)
-> (InstanceResizePolicy -> Maybe Int -> InstanceResizePolicy)
-> Lens
     InstanceResizePolicy InstanceResizePolicy (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceResizePolicy' {Maybe Int
instanceTerminationTimeout :: Maybe Int
$sel:instanceTerminationTimeout:InstanceResizePolicy' :: InstanceResizePolicy -> Maybe Int
instanceTerminationTimeout} -> Maybe Int
instanceTerminationTimeout) (\s :: InstanceResizePolicy
s@InstanceResizePolicy' {} Maybe Int
a -> InstanceResizePolicy
s {$sel:instanceTerminationTimeout:InstanceResizePolicy' :: Maybe Int
instanceTerminationTimeout = Maybe Int
a} :: InstanceResizePolicy)

instance Core.FromJSON InstanceResizePolicy where
  parseJSON :: Value -> Parser InstanceResizePolicy
parseJSON =
    String
-> (Object -> Parser InstanceResizePolicy)
-> Value
-> Parser InstanceResizePolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"InstanceResizePolicy"
      ( \Object
x ->
          Maybe [Text] -> Maybe [Text] -> Maybe Int -> InstanceResizePolicy
InstanceResizePolicy'
            (Maybe [Text] -> Maybe [Text] -> Maybe Int -> InstanceResizePolicy)
-> Parser (Maybe [Text])
-> Parser (Maybe [Text] -> Maybe Int -> InstanceResizePolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"InstancesToProtect"
                            Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe [Text] -> Maybe Int -> InstanceResizePolicy)
-> Parser (Maybe [Text])
-> Parser (Maybe Int -> InstanceResizePolicy)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"InstancesToTerminate"
                            Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe Int -> InstanceResizePolicy)
-> Parser (Maybe Int) -> Parser InstanceResizePolicy
forall (f :: * -> *) a b. Applicative f => 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
"InstanceTerminationTimeout")
      )

instance Prelude.Hashable InstanceResizePolicy

instance Prelude.NFData InstanceResizePolicy

instance Core.ToJSON InstanceResizePolicy where
  toJSON :: InstanceResizePolicy -> Value
toJSON InstanceResizePolicy' {Maybe Int
Maybe [Text]
instanceTerminationTimeout :: Maybe Int
instancesToTerminate :: Maybe [Text]
instancesToProtect :: Maybe [Text]
$sel:instanceTerminationTimeout:InstanceResizePolicy' :: InstanceResizePolicy -> Maybe Int
$sel:instancesToTerminate:InstanceResizePolicy' :: InstanceResizePolicy -> Maybe [Text]
$sel:instancesToProtect:InstanceResizePolicy' :: InstanceResizePolicy -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"InstancesToProtect" 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]
instancesToProtect,
            (Text
"InstancesToTerminate" 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]
instancesToTerminate,
            (Text
"InstanceTerminationTimeout" 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
instanceTerminationTimeout
          ]
      )