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

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

-- | The @ulimit@ settings to pass to the container.
--
-- Amazon ECS tasks hosted on Fargate use the default resource limit values
-- set by the operating system with the exception of the @nofile@ resource
-- limit parameter which Fargate overrides. The @nofile@ resource limit
-- sets a restriction on the number of open files that a container can use.
-- The default @nofile@ soft limit is @1024@ and hard limit is @4096@.
--
-- /See:/ 'newUlimit' smart constructor.
data Ulimit = Ulimit'
  { -- | The @type@ of the @ulimit@.
    Ulimit -> UlimitName
name :: UlimitName,
    -- | The soft limit for the ulimit type.
    Ulimit -> Int
softLimit :: Prelude.Int,
    -- | The hard limit for the ulimit type.
    Ulimit -> Int
hardLimit :: Prelude.Int
  }
  deriving (Ulimit -> Ulimit -> Bool
(Ulimit -> Ulimit -> Bool)
-> (Ulimit -> Ulimit -> Bool) -> Eq Ulimit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ulimit -> Ulimit -> Bool
$c/= :: Ulimit -> Ulimit -> Bool
== :: Ulimit -> Ulimit -> Bool
$c== :: Ulimit -> Ulimit -> Bool
Prelude.Eq, ReadPrec [Ulimit]
ReadPrec Ulimit
Int -> ReadS Ulimit
ReadS [Ulimit]
(Int -> ReadS Ulimit)
-> ReadS [Ulimit]
-> ReadPrec Ulimit
-> ReadPrec [Ulimit]
-> Read Ulimit
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Ulimit]
$creadListPrec :: ReadPrec [Ulimit]
readPrec :: ReadPrec Ulimit
$creadPrec :: ReadPrec Ulimit
readList :: ReadS [Ulimit]
$creadList :: ReadS [Ulimit]
readsPrec :: Int -> ReadS Ulimit
$creadsPrec :: Int -> ReadS Ulimit
Prelude.Read, Int -> Ulimit -> ShowS
[Ulimit] -> ShowS
Ulimit -> String
(Int -> Ulimit -> ShowS)
-> (Ulimit -> String) -> ([Ulimit] -> ShowS) -> Show Ulimit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ulimit] -> ShowS
$cshowList :: [Ulimit] -> ShowS
show :: Ulimit -> String
$cshow :: Ulimit -> String
showsPrec :: Int -> Ulimit -> ShowS
$cshowsPrec :: Int -> Ulimit -> ShowS
Prelude.Show, (forall x. Ulimit -> Rep Ulimit x)
-> (forall x. Rep Ulimit x -> Ulimit) -> Generic Ulimit
forall x. Rep Ulimit x -> Ulimit
forall x. Ulimit -> Rep Ulimit x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Ulimit x -> Ulimit
$cfrom :: forall x. Ulimit -> Rep Ulimit x
Prelude.Generic)

-- |
-- Create a value of 'Ulimit' 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:
--
-- 'name', 'ulimit_name' - The @type@ of the @ulimit@.
--
-- 'softLimit', 'ulimit_softLimit' - The soft limit for the ulimit type.
--
-- 'hardLimit', 'ulimit_hardLimit' - The hard limit for the ulimit type.
newUlimit ::
  -- | 'name'
  UlimitName ->
  -- | 'softLimit'
  Prelude.Int ->
  -- | 'hardLimit'
  Prelude.Int ->
  Ulimit
newUlimit :: UlimitName -> Int -> Int -> Ulimit
newUlimit UlimitName
pName_ Int
pSoftLimit_ Int
pHardLimit_ =
  Ulimit' :: UlimitName -> Int -> Int -> Ulimit
Ulimit'
    { $sel:name:Ulimit' :: UlimitName
name = UlimitName
pName_,
      $sel:softLimit:Ulimit' :: Int
softLimit = Int
pSoftLimit_,
      $sel:hardLimit:Ulimit' :: Int
hardLimit = Int
pHardLimit_
    }

-- | The @type@ of the @ulimit@.
ulimit_name :: Lens.Lens' Ulimit UlimitName
ulimit_name :: (UlimitName -> f UlimitName) -> Ulimit -> f Ulimit
ulimit_name = (Ulimit -> UlimitName)
-> (Ulimit -> UlimitName -> Ulimit)
-> Lens Ulimit Ulimit UlimitName UlimitName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Ulimit' {UlimitName
name :: UlimitName
$sel:name:Ulimit' :: Ulimit -> UlimitName
name} -> UlimitName
name) (\s :: Ulimit
s@Ulimit' {} UlimitName
a -> Ulimit
s {$sel:name:Ulimit' :: UlimitName
name = UlimitName
a} :: Ulimit)

-- | The soft limit for the ulimit type.
ulimit_softLimit :: Lens.Lens' Ulimit Prelude.Int
ulimit_softLimit :: (Int -> f Int) -> Ulimit -> f Ulimit
ulimit_softLimit = (Ulimit -> Int)
-> (Ulimit -> Int -> Ulimit) -> Lens Ulimit Ulimit Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Ulimit' {Int
softLimit :: Int
$sel:softLimit:Ulimit' :: Ulimit -> Int
softLimit} -> Int
softLimit) (\s :: Ulimit
s@Ulimit' {} Int
a -> Ulimit
s {$sel:softLimit:Ulimit' :: Int
softLimit = Int
a} :: Ulimit)

-- | The hard limit for the ulimit type.
ulimit_hardLimit :: Lens.Lens' Ulimit Prelude.Int
ulimit_hardLimit :: (Int -> f Int) -> Ulimit -> f Ulimit
ulimit_hardLimit = (Ulimit -> Int)
-> (Ulimit -> Int -> Ulimit) -> Lens Ulimit Ulimit Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Ulimit' {Int
hardLimit :: Int
$sel:hardLimit:Ulimit' :: Ulimit -> Int
hardLimit} -> Int
hardLimit) (\s :: Ulimit
s@Ulimit' {} Int
a -> Ulimit
s {$sel:hardLimit:Ulimit' :: Int
hardLimit = Int
a} :: Ulimit)

instance Core.FromJSON Ulimit where
  parseJSON :: Value -> Parser Ulimit
parseJSON =
    String -> (Object -> Parser Ulimit) -> Value -> Parser Ulimit
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Ulimit"
      ( \Object
x ->
          UlimitName -> Int -> Int -> Ulimit
Ulimit'
            (UlimitName -> Int -> Int -> Ulimit)
-> Parser UlimitName -> Parser (Int -> Int -> Ulimit)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser UlimitName
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"name")
            Parser (Int -> Int -> Ulimit)
-> Parser Int -> Parser (Int -> Ulimit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"softLimit")
            Parser (Int -> Ulimit) -> Parser Int -> Parser Ulimit
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"hardLimit")
      )

instance Prelude.Hashable Ulimit

instance Prelude.NFData Ulimit

instance Core.ToJSON Ulimit where
  toJSON :: Ulimit -> Value
toJSON Ulimit' {Int
UlimitName
hardLimit :: Int
softLimit :: Int
name :: UlimitName
$sel:hardLimit:Ulimit' :: Ulimit -> Int
$sel:softLimit:Ulimit' :: Ulimit -> Int
$sel:name:Ulimit' :: Ulimit -> UlimitName
..} =
    [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
"name" Text -> UlimitName -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= UlimitName
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"softLimit" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
softLimit),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"hardLimit" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
hardLimit)
          ]
      )