{-# 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.ECS.Types.ResourceRequirement
-- 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.ECS.Types.ResourceRequirement where

import qualified Amazonka.Core as Core
import Amazonka.ECS.Types.ResourceType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The type and amount of a resource to assign to a container. The
-- supported resource types are GPUs and Elastic Inference accelerators.
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-gpu.html Working with GPUs on Amazon ECS>
-- or
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-inference.html Working with Amazon Elastic Inference on Amazon ECS>
-- in the /Amazon Elastic Container Service Developer Guide/
--
-- /See:/ 'newResourceRequirement' smart constructor.
data ResourceRequirement = ResourceRequirement'
  { -- | The value for the specified resource type.
    --
    -- If the @GPU@ type is used, the value is the number of physical @GPUs@
    -- the Amazon ECS container agent will reserve for the container. The
    -- number of GPUs reserved for all containers in a task should not exceed
    -- the number of available GPUs on the container instance the task is
    -- launched on.
    --
    -- If the @InferenceAccelerator@ type is used, the @value@ should match the
    -- @deviceName@ for an InferenceAccelerator specified in a task definition.
    ResourceRequirement -> Text
value :: Prelude.Text,
    -- | The type of resource to assign to a container. The supported values are
    -- @GPU@ or @InferenceAccelerator@.
    ResourceRequirement -> ResourceType
type' :: ResourceType
  }
  deriving (ResourceRequirement -> ResourceRequirement -> Bool
(ResourceRequirement -> ResourceRequirement -> Bool)
-> (ResourceRequirement -> ResourceRequirement -> Bool)
-> Eq ResourceRequirement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourceRequirement -> ResourceRequirement -> Bool
$c/= :: ResourceRequirement -> ResourceRequirement -> Bool
== :: ResourceRequirement -> ResourceRequirement -> Bool
$c== :: ResourceRequirement -> ResourceRequirement -> Bool
Prelude.Eq, ReadPrec [ResourceRequirement]
ReadPrec ResourceRequirement
Int -> ReadS ResourceRequirement
ReadS [ResourceRequirement]
(Int -> ReadS ResourceRequirement)
-> ReadS [ResourceRequirement]
-> ReadPrec ResourceRequirement
-> ReadPrec [ResourceRequirement]
-> Read ResourceRequirement
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourceRequirement]
$creadListPrec :: ReadPrec [ResourceRequirement]
readPrec :: ReadPrec ResourceRequirement
$creadPrec :: ReadPrec ResourceRequirement
readList :: ReadS [ResourceRequirement]
$creadList :: ReadS [ResourceRequirement]
readsPrec :: Int -> ReadS ResourceRequirement
$creadsPrec :: Int -> ReadS ResourceRequirement
Prelude.Read, Int -> ResourceRequirement -> ShowS
[ResourceRequirement] -> ShowS
ResourceRequirement -> String
(Int -> ResourceRequirement -> ShowS)
-> (ResourceRequirement -> String)
-> ([ResourceRequirement] -> ShowS)
-> Show ResourceRequirement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourceRequirement] -> ShowS
$cshowList :: [ResourceRequirement] -> ShowS
show :: ResourceRequirement -> String
$cshow :: ResourceRequirement -> String
showsPrec :: Int -> ResourceRequirement -> ShowS
$cshowsPrec :: Int -> ResourceRequirement -> ShowS
Prelude.Show, (forall x. ResourceRequirement -> Rep ResourceRequirement x)
-> (forall x. Rep ResourceRequirement x -> ResourceRequirement)
-> Generic ResourceRequirement
forall x. Rep ResourceRequirement x -> ResourceRequirement
forall x. ResourceRequirement -> Rep ResourceRequirement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourceRequirement x -> ResourceRequirement
$cfrom :: forall x. ResourceRequirement -> Rep ResourceRequirement x
Prelude.Generic)

-- |
-- Create a value of 'ResourceRequirement' 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:
--
-- 'value', 'resourceRequirement_value' - The value for the specified resource type.
--
-- If the @GPU@ type is used, the value is the number of physical @GPUs@
-- the Amazon ECS container agent will reserve for the container. The
-- number of GPUs reserved for all containers in a task should not exceed
-- the number of available GPUs on the container instance the task is
-- launched on.
--
-- If the @InferenceAccelerator@ type is used, the @value@ should match the
-- @deviceName@ for an InferenceAccelerator specified in a task definition.
--
-- 'type'', 'resourceRequirement_type' - The type of resource to assign to a container. The supported values are
-- @GPU@ or @InferenceAccelerator@.
newResourceRequirement ::
  -- | 'value'
  Prelude.Text ->
  -- | 'type''
  ResourceType ->
  ResourceRequirement
newResourceRequirement :: Text -> ResourceType -> ResourceRequirement
newResourceRequirement Text
pValue_ ResourceType
pType_ =
  ResourceRequirement' :: Text -> ResourceType -> ResourceRequirement
ResourceRequirement'
    { $sel:value:ResourceRequirement' :: Text
value = Text
pValue_,
      $sel:type':ResourceRequirement' :: ResourceType
type' = ResourceType
pType_
    }

-- | The value for the specified resource type.
--
-- If the @GPU@ type is used, the value is the number of physical @GPUs@
-- the Amazon ECS container agent will reserve for the container. The
-- number of GPUs reserved for all containers in a task should not exceed
-- the number of available GPUs on the container instance the task is
-- launched on.
--
-- If the @InferenceAccelerator@ type is used, the @value@ should match the
-- @deviceName@ for an InferenceAccelerator specified in a task definition.
resourceRequirement_value :: Lens.Lens' ResourceRequirement Prelude.Text
resourceRequirement_value :: (Text -> f Text) -> ResourceRequirement -> f ResourceRequirement
resourceRequirement_value = (ResourceRequirement -> Text)
-> (ResourceRequirement -> Text -> ResourceRequirement)
-> Lens ResourceRequirement ResourceRequirement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceRequirement' {Text
value :: Text
$sel:value:ResourceRequirement' :: ResourceRequirement -> Text
value} -> Text
value) (\s :: ResourceRequirement
s@ResourceRequirement' {} Text
a -> ResourceRequirement
s {$sel:value:ResourceRequirement' :: Text
value = Text
a} :: ResourceRequirement)

-- | The type of resource to assign to a container. The supported values are
-- @GPU@ or @InferenceAccelerator@.
resourceRequirement_type :: Lens.Lens' ResourceRequirement ResourceType
resourceRequirement_type :: (ResourceType -> f ResourceType)
-> ResourceRequirement -> f ResourceRequirement
resourceRequirement_type = (ResourceRequirement -> ResourceType)
-> (ResourceRequirement -> ResourceType -> ResourceRequirement)
-> Lens
     ResourceRequirement ResourceRequirement ResourceType ResourceType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceRequirement' {ResourceType
type' :: ResourceType
$sel:type':ResourceRequirement' :: ResourceRequirement -> ResourceType
type'} -> ResourceType
type') (\s :: ResourceRequirement
s@ResourceRequirement' {} ResourceType
a -> ResourceRequirement
s {$sel:type':ResourceRequirement' :: ResourceType
type' = ResourceType
a} :: ResourceRequirement)

instance Core.FromJSON ResourceRequirement where
  parseJSON :: Value -> Parser ResourceRequirement
parseJSON =
    String
-> (Object -> Parser ResourceRequirement)
-> Value
-> Parser ResourceRequirement
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ResourceRequirement"
      ( \Object
x ->
          Text -> ResourceType -> ResourceRequirement
ResourceRequirement'
            (Text -> ResourceType -> ResourceRequirement)
-> Parser Text -> Parser (ResourceType -> ResourceRequirement)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"value") Parser (ResourceType -> ResourceRequirement)
-> Parser ResourceType -> Parser ResourceRequirement
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ResourceType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"type")
      )

instance Prelude.Hashable ResourceRequirement

instance Prelude.NFData ResourceRequirement

instance Core.ToJSON ResourceRequirement where
  toJSON :: ResourceRequirement -> Value
toJSON ResourceRequirement' {Text
ResourceType
type' :: ResourceType
value :: Text
$sel:type':ResourceRequirement' :: ResourceRequirement -> ResourceType
$sel:value:ResourceRequirement' :: ResourceRequirement -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
value),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"type" Text -> ResourceType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ResourceType
type')
          ]
      )