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

import qualified Amazonka.Core as Core
import Amazonka.EMR.Types.InstanceRoleType
import Amazonka.EMR.Types.PlacementGroupStrategy
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Placement group configuration for an Amazon EMR cluster. The
-- configuration specifies the placement strategy that can be applied to
-- instance roles during cluster creation.
--
-- To use this configuration, consider attaching managed policy
-- AmazonElasticMapReducePlacementGroupPolicy to the EMR role.
--
-- /See:/ 'newPlacementGroupConfig' smart constructor.
data PlacementGroupConfig = PlacementGroupConfig'
  { -- | EC2 Placement Group strategy associated with instance role.
    --
    -- Starting with Amazon EMR version 5.23.0, the only supported placement
    -- strategy is @SPREAD@ for the @MASTER@ instance role.
    PlacementGroupConfig -> Maybe PlacementGroupStrategy
placementStrategy :: Prelude.Maybe PlacementGroupStrategy,
    -- | Role of the instance in the cluster.
    --
    -- Starting with Amazon EMR version 5.23.0, the only supported instance
    -- role is @MASTER@.
    PlacementGroupConfig -> InstanceRoleType
instanceRole :: InstanceRoleType
  }
  deriving (PlacementGroupConfig -> PlacementGroupConfig -> Bool
(PlacementGroupConfig -> PlacementGroupConfig -> Bool)
-> (PlacementGroupConfig -> PlacementGroupConfig -> Bool)
-> Eq PlacementGroupConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PlacementGroupConfig -> PlacementGroupConfig -> Bool
$c/= :: PlacementGroupConfig -> PlacementGroupConfig -> Bool
== :: PlacementGroupConfig -> PlacementGroupConfig -> Bool
$c== :: PlacementGroupConfig -> PlacementGroupConfig -> Bool
Prelude.Eq, ReadPrec [PlacementGroupConfig]
ReadPrec PlacementGroupConfig
Int -> ReadS PlacementGroupConfig
ReadS [PlacementGroupConfig]
(Int -> ReadS PlacementGroupConfig)
-> ReadS [PlacementGroupConfig]
-> ReadPrec PlacementGroupConfig
-> ReadPrec [PlacementGroupConfig]
-> Read PlacementGroupConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PlacementGroupConfig]
$creadListPrec :: ReadPrec [PlacementGroupConfig]
readPrec :: ReadPrec PlacementGroupConfig
$creadPrec :: ReadPrec PlacementGroupConfig
readList :: ReadS [PlacementGroupConfig]
$creadList :: ReadS [PlacementGroupConfig]
readsPrec :: Int -> ReadS PlacementGroupConfig
$creadsPrec :: Int -> ReadS PlacementGroupConfig
Prelude.Read, Int -> PlacementGroupConfig -> ShowS
[PlacementGroupConfig] -> ShowS
PlacementGroupConfig -> String
(Int -> PlacementGroupConfig -> ShowS)
-> (PlacementGroupConfig -> String)
-> ([PlacementGroupConfig] -> ShowS)
-> Show PlacementGroupConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PlacementGroupConfig] -> ShowS
$cshowList :: [PlacementGroupConfig] -> ShowS
show :: PlacementGroupConfig -> String
$cshow :: PlacementGroupConfig -> String
showsPrec :: Int -> PlacementGroupConfig -> ShowS
$cshowsPrec :: Int -> PlacementGroupConfig -> ShowS
Prelude.Show, (forall x. PlacementGroupConfig -> Rep PlacementGroupConfig x)
-> (forall x. Rep PlacementGroupConfig x -> PlacementGroupConfig)
-> Generic PlacementGroupConfig
forall x. Rep PlacementGroupConfig x -> PlacementGroupConfig
forall x. PlacementGroupConfig -> Rep PlacementGroupConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PlacementGroupConfig x -> PlacementGroupConfig
$cfrom :: forall x. PlacementGroupConfig -> Rep PlacementGroupConfig x
Prelude.Generic)

-- |
-- Create a value of 'PlacementGroupConfig' 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:
--
-- 'placementStrategy', 'placementGroupConfig_placementStrategy' - EC2 Placement Group strategy associated with instance role.
--
-- Starting with Amazon EMR version 5.23.0, the only supported placement
-- strategy is @SPREAD@ for the @MASTER@ instance role.
--
-- 'instanceRole', 'placementGroupConfig_instanceRole' - Role of the instance in the cluster.
--
-- Starting with Amazon EMR version 5.23.0, the only supported instance
-- role is @MASTER@.
newPlacementGroupConfig ::
  -- | 'instanceRole'
  InstanceRoleType ->
  PlacementGroupConfig
newPlacementGroupConfig :: InstanceRoleType -> PlacementGroupConfig
newPlacementGroupConfig InstanceRoleType
pInstanceRole_ =
  PlacementGroupConfig' :: Maybe PlacementGroupStrategy
-> InstanceRoleType -> PlacementGroupConfig
PlacementGroupConfig'
    { $sel:placementStrategy:PlacementGroupConfig' :: Maybe PlacementGroupStrategy
placementStrategy =
        Maybe PlacementGroupStrategy
forall a. Maybe a
Prelude.Nothing,
      $sel:instanceRole:PlacementGroupConfig' :: InstanceRoleType
instanceRole = InstanceRoleType
pInstanceRole_
    }

-- | EC2 Placement Group strategy associated with instance role.
--
-- Starting with Amazon EMR version 5.23.0, the only supported placement
-- strategy is @SPREAD@ for the @MASTER@ instance role.
placementGroupConfig_placementStrategy :: Lens.Lens' PlacementGroupConfig (Prelude.Maybe PlacementGroupStrategy)
placementGroupConfig_placementStrategy :: (Maybe PlacementGroupStrategy -> f (Maybe PlacementGroupStrategy))
-> PlacementGroupConfig -> f PlacementGroupConfig
placementGroupConfig_placementStrategy = (PlacementGroupConfig -> Maybe PlacementGroupStrategy)
-> (PlacementGroupConfig
    -> Maybe PlacementGroupStrategy -> PlacementGroupConfig)
-> Lens
     PlacementGroupConfig
     PlacementGroupConfig
     (Maybe PlacementGroupStrategy)
     (Maybe PlacementGroupStrategy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PlacementGroupConfig' {Maybe PlacementGroupStrategy
placementStrategy :: Maybe PlacementGroupStrategy
$sel:placementStrategy:PlacementGroupConfig' :: PlacementGroupConfig -> Maybe PlacementGroupStrategy
placementStrategy} -> Maybe PlacementGroupStrategy
placementStrategy) (\s :: PlacementGroupConfig
s@PlacementGroupConfig' {} Maybe PlacementGroupStrategy
a -> PlacementGroupConfig
s {$sel:placementStrategy:PlacementGroupConfig' :: Maybe PlacementGroupStrategy
placementStrategy = Maybe PlacementGroupStrategy
a} :: PlacementGroupConfig)

-- | Role of the instance in the cluster.
--
-- Starting with Amazon EMR version 5.23.0, the only supported instance
-- role is @MASTER@.
placementGroupConfig_instanceRole :: Lens.Lens' PlacementGroupConfig InstanceRoleType
placementGroupConfig_instanceRole :: (InstanceRoleType -> f InstanceRoleType)
-> PlacementGroupConfig -> f PlacementGroupConfig
placementGroupConfig_instanceRole = (PlacementGroupConfig -> InstanceRoleType)
-> (PlacementGroupConfig
    -> InstanceRoleType -> PlacementGroupConfig)
-> Lens
     PlacementGroupConfig
     PlacementGroupConfig
     InstanceRoleType
     InstanceRoleType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PlacementGroupConfig' {InstanceRoleType
instanceRole :: InstanceRoleType
$sel:instanceRole:PlacementGroupConfig' :: PlacementGroupConfig -> InstanceRoleType
instanceRole} -> InstanceRoleType
instanceRole) (\s :: PlacementGroupConfig
s@PlacementGroupConfig' {} InstanceRoleType
a -> PlacementGroupConfig
s {$sel:instanceRole:PlacementGroupConfig' :: InstanceRoleType
instanceRole = InstanceRoleType
a} :: PlacementGroupConfig)

instance Core.FromJSON PlacementGroupConfig where
  parseJSON :: Value -> Parser PlacementGroupConfig
parseJSON =
    String
-> (Object -> Parser PlacementGroupConfig)
-> Value
-> Parser PlacementGroupConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PlacementGroupConfig"
      ( \Object
x ->
          Maybe PlacementGroupStrategy
-> InstanceRoleType -> PlacementGroupConfig
PlacementGroupConfig'
            (Maybe PlacementGroupStrategy
 -> InstanceRoleType -> PlacementGroupConfig)
-> Parser (Maybe PlacementGroupStrategy)
-> Parser (InstanceRoleType -> PlacementGroupConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe PlacementGroupStrategy)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PlacementStrategy")
            Parser (InstanceRoleType -> PlacementGroupConfig)
-> Parser InstanceRoleType -> Parser PlacementGroupConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser InstanceRoleType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"InstanceRole")
      )

instance Prelude.Hashable PlacementGroupConfig

instance Prelude.NFData PlacementGroupConfig

instance Core.ToJSON PlacementGroupConfig where
  toJSON :: PlacementGroupConfig -> Value
toJSON PlacementGroupConfig' {Maybe PlacementGroupStrategy
InstanceRoleType
instanceRole :: InstanceRoleType
placementStrategy :: Maybe PlacementGroupStrategy
$sel:instanceRole:PlacementGroupConfig' :: PlacementGroupConfig -> InstanceRoleType
$sel:placementStrategy:PlacementGroupConfig' :: PlacementGroupConfig -> Maybe PlacementGroupStrategy
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"PlacementStrategy" Text -> PlacementGroupStrategy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (PlacementGroupStrategy -> Pair)
-> Maybe PlacementGroupStrategy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PlacementGroupStrategy
placementStrategy,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"InstanceRole" Text -> InstanceRoleType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= InstanceRoleType
instanceRole)
          ]
      )