{-# 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.Scheduler.Types.PlacementStrategy
-- 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.Scheduler.Types.PlacementStrategy where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.Scheduler.Types.PlacementStrategyType

-- | The task placement strategy for a task or service.
--
-- /See:/ 'newPlacementStrategy' smart constructor.
data PlacementStrategy = PlacementStrategy'
  { -- | The field to apply the placement strategy against. For the spread
    -- placement strategy, valid values are @instanceId@ (or @instanceId@,
    -- which has the same effect), or any platform or custom attribute that is
    -- applied to a container instance, such as
    -- @attribute:ecs.availability-zone@. For the binpack placement strategy,
    -- valid values are @cpu@ and @memory@. For the random placement strategy,
    -- this field is not used.
    PlacementStrategy -> Maybe Text
field :: Prelude.Maybe Prelude.Text,
    -- | The type of placement strategy. The random placement strategy randomly
    -- places tasks on available candidates. The spread placement strategy
    -- spreads placement across available candidates evenly based on the field
    -- parameter. The binpack strategy places tasks on available candidates
    -- that have the least available amount of the resource that is specified
    -- with the field parameter. For example, if you binpack on memory, a task
    -- is placed on the instance with the least amount of remaining memory (but
    -- still enough to run the task).
    PlacementStrategy -> Maybe PlacementStrategyType
type' :: Prelude.Maybe PlacementStrategyType
  }
  deriving (PlacementStrategy -> PlacementStrategy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PlacementStrategy -> PlacementStrategy -> Bool
$c/= :: PlacementStrategy -> PlacementStrategy -> Bool
== :: PlacementStrategy -> PlacementStrategy -> Bool
$c== :: PlacementStrategy -> PlacementStrategy -> Bool
Prelude.Eq, ReadPrec [PlacementStrategy]
ReadPrec PlacementStrategy
Int -> ReadS PlacementStrategy
ReadS [PlacementStrategy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PlacementStrategy]
$creadListPrec :: ReadPrec [PlacementStrategy]
readPrec :: ReadPrec PlacementStrategy
$creadPrec :: ReadPrec PlacementStrategy
readList :: ReadS [PlacementStrategy]
$creadList :: ReadS [PlacementStrategy]
readsPrec :: Int -> ReadS PlacementStrategy
$creadsPrec :: Int -> ReadS PlacementStrategy
Prelude.Read, Int -> PlacementStrategy -> ShowS
[PlacementStrategy] -> ShowS
PlacementStrategy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PlacementStrategy] -> ShowS
$cshowList :: [PlacementStrategy] -> ShowS
show :: PlacementStrategy -> String
$cshow :: PlacementStrategy -> String
showsPrec :: Int -> PlacementStrategy -> ShowS
$cshowsPrec :: Int -> PlacementStrategy -> ShowS
Prelude.Show, forall x. Rep PlacementStrategy x -> PlacementStrategy
forall x. PlacementStrategy -> Rep PlacementStrategy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PlacementStrategy x -> PlacementStrategy
$cfrom :: forall x. PlacementStrategy -> Rep PlacementStrategy x
Prelude.Generic)

-- |
-- Create a value of 'PlacementStrategy' 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:
--
-- 'field', 'placementStrategy_field' - The field to apply the placement strategy against. For the spread
-- placement strategy, valid values are @instanceId@ (or @instanceId@,
-- which has the same effect), or any platform or custom attribute that is
-- applied to a container instance, such as
-- @attribute:ecs.availability-zone@. For the binpack placement strategy,
-- valid values are @cpu@ and @memory@. For the random placement strategy,
-- this field is not used.
--
-- 'type'', 'placementStrategy_type' - The type of placement strategy. The random placement strategy randomly
-- places tasks on available candidates. The spread placement strategy
-- spreads placement across available candidates evenly based on the field
-- parameter. The binpack strategy places tasks on available candidates
-- that have the least available amount of the resource that is specified
-- with the field parameter. For example, if you binpack on memory, a task
-- is placed on the instance with the least amount of remaining memory (but
-- still enough to run the task).
newPlacementStrategy ::
  PlacementStrategy
newPlacementStrategy :: PlacementStrategy
newPlacementStrategy =
  PlacementStrategy'
    { $sel:field:PlacementStrategy' :: Maybe Text
field = forall a. Maybe a
Prelude.Nothing,
      $sel:type':PlacementStrategy' :: Maybe PlacementStrategyType
type' = forall a. Maybe a
Prelude.Nothing
    }

-- | The field to apply the placement strategy against. For the spread
-- placement strategy, valid values are @instanceId@ (or @instanceId@,
-- which has the same effect), or any platform or custom attribute that is
-- applied to a container instance, such as
-- @attribute:ecs.availability-zone@. For the binpack placement strategy,
-- valid values are @cpu@ and @memory@. For the random placement strategy,
-- this field is not used.
placementStrategy_field :: Lens.Lens' PlacementStrategy (Prelude.Maybe Prelude.Text)
placementStrategy_field :: Lens' PlacementStrategy (Maybe Text)
placementStrategy_field = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PlacementStrategy' {Maybe Text
field :: Maybe Text
$sel:field:PlacementStrategy' :: PlacementStrategy -> Maybe Text
field} -> Maybe Text
field) (\s :: PlacementStrategy
s@PlacementStrategy' {} Maybe Text
a -> PlacementStrategy
s {$sel:field:PlacementStrategy' :: Maybe Text
field = Maybe Text
a} :: PlacementStrategy)

-- | The type of placement strategy. The random placement strategy randomly
-- places tasks on available candidates. The spread placement strategy
-- spreads placement across available candidates evenly based on the field
-- parameter. The binpack strategy places tasks on available candidates
-- that have the least available amount of the resource that is specified
-- with the field parameter. For example, if you binpack on memory, a task
-- is placed on the instance with the least amount of remaining memory (but
-- still enough to run the task).
placementStrategy_type :: Lens.Lens' PlacementStrategy (Prelude.Maybe PlacementStrategyType)
placementStrategy_type :: Lens' PlacementStrategy (Maybe PlacementStrategyType)
placementStrategy_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PlacementStrategy' {Maybe PlacementStrategyType
type' :: Maybe PlacementStrategyType
$sel:type':PlacementStrategy' :: PlacementStrategy -> Maybe PlacementStrategyType
type'} -> Maybe PlacementStrategyType
type') (\s :: PlacementStrategy
s@PlacementStrategy' {} Maybe PlacementStrategyType
a -> PlacementStrategy
s {$sel:type':PlacementStrategy' :: Maybe PlacementStrategyType
type' = Maybe PlacementStrategyType
a} :: PlacementStrategy)

instance Data.FromJSON PlacementStrategy where
  parseJSON :: Value -> Parser PlacementStrategy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PlacementStrategy"
      ( \Object
x ->
          Maybe Text -> Maybe PlacementStrategyType -> PlacementStrategy
PlacementStrategy'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"field")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"type")
      )

instance Prelude.Hashable PlacementStrategy where
  hashWithSalt :: Int -> PlacementStrategy -> Int
hashWithSalt Int
_salt PlacementStrategy' {Maybe Text
Maybe PlacementStrategyType
type' :: Maybe PlacementStrategyType
field :: Maybe Text
$sel:type':PlacementStrategy' :: PlacementStrategy -> Maybe PlacementStrategyType
$sel:field:PlacementStrategy' :: PlacementStrategy -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
field
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe PlacementStrategyType
type'

instance Prelude.NFData PlacementStrategy where
  rnf :: PlacementStrategy -> ()
rnf PlacementStrategy' {Maybe Text
Maybe PlacementStrategyType
type' :: Maybe PlacementStrategyType
field :: Maybe Text
$sel:type':PlacementStrategy' :: PlacementStrategy -> Maybe PlacementStrategyType
$sel:field:PlacementStrategy' :: PlacementStrategy -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
field seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe PlacementStrategyType
type'

instance Data.ToJSON PlacementStrategy where
  toJSON :: PlacementStrategy -> Value
toJSON PlacementStrategy' {Maybe Text
Maybe PlacementStrategyType
type' :: Maybe PlacementStrategyType
field :: Maybe Text
$sel:type':PlacementStrategy' :: PlacementStrategy -> Maybe PlacementStrategyType
$sel:field:PlacementStrategy' :: PlacementStrategy -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"field" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
field,
            (Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PlacementStrategyType
type'
          ]
      )