{-# 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.GreengrassV2.Types.SystemResourceLimits
-- 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.GreengrassV2.Types.SystemResourceLimits 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

-- | Contains information about system resource limits that the IoT
-- Greengrass Core software applies to a component\'s processes. For more
-- information, see
-- <https://docs.aws.amazon.com/greengrass/v2/developerguide/configure-greengrass-core-v2.html#configure-component-system-resource-limits Configure system resource limits for components>.
--
-- /See:/ 'newSystemResourceLimits' smart constructor.
data SystemResourceLimits = SystemResourceLimits'
  { -- | The maximum amount of CPU time that a component\'s processes can use on
    -- the core device. A core device\'s total CPU time is equivalent to the
    -- device\'s number of CPU cores. For example, on a core device with 4 CPU
    -- cores, you can set this value to @2@ to limit the component\'s processes
    -- to 50 percent usage of each CPU core. On a device with 1 CPU core, you
    -- can set this value to @0.25@ to limit the component\'s processes to 25
    -- percent usage of the CPU. If you set this value to a number greater than
    -- the number of CPU cores, the IoT Greengrass Core software doesn\'t limit
    -- the component\'s CPU usage.
    SystemResourceLimits -> Maybe Double
cpus :: Prelude.Maybe Prelude.Double,
    -- | The maximum amount of RAM, expressed in kilobytes, that a component\'s
    -- processes can use on the core device.
    SystemResourceLimits -> Maybe Natural
memory :: Prelude.Maybe Prelude.Natural
  }
  deriving (SystemResourceLimits -> SystemResourceLimits -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SystemResourceLimits -> SystemResourceLimits -> Bool
$c/= :: SystemResourceLimits -> SystemResourceLimits -> Bool
== :: SystemResourceLimits -> SystemResourceLimits -> Bool
$c== :: SystemResourceLimits -> SystemResourceLimits -> Bool
Prelude.Eq, ReadPrec [SystemResourceLimits]
ReadPrec SystemResourceLimits
Int -> ReadS SystemResourceLimits
ReadS [SystemResourceLimits]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SystemResourceLimits]
$creadListPrec :: ReadPrec [SystemResourceLimits]
readPrec :: ReadPrec SystemResourceLimits
$creadPrec :: ReadPrec SystemResourceLimits
readList :: ReadS [SystemResourceLimits]
$creadList :: ReadS [SystemResourceLimits]
readsPrec :: Int -> ReadS SystemResourceLimits
$creadsPrec :: Int -> ReadS SystemResourceLimits
Prelude.Read, Int -> SystemResourceLimits -> ShowS
[SystemResourceLimits] -> ShowS
SystemResourceLimits -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SystemResourceLimits] -> ShowS
$cshowList :: [SystemResourceLimits] -> ShowS
show :: SystemResourceLimits -> String
$cshow :: SystemResourceLimits -> String
showsPrec :: Int -> SystemResourceLimits -> ShowS
$cshowsPrec :: Int -> SystemResourceLimits -> ShowS
Prelude.Show, forall x. Rep SystemResourceLimits x -> SystemResourceLimits
forall x. SystemResourceLimits -> Rep SystemResourceLimits x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SystemResourceLimits x -> SystemResourceLimits
$cfrom :: forall x. SystemResourceLimits -> Rep SystemResourceLimits x
Prelude.Generic)

-- |
-- Create a value of 'SystemResourceLimits' 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:
--
-- 'cpus', 'systemResourceLimits_cpus' - The maximum amount of CPU time that a component\'s processes can use on
-- the core device. A core device\'s total CPU time is equivalent to the
-- device\'s number of CPU cores. For example, on a core device with 4 CPU
-- cores, you can set this value to @2@ to limit the component\'s processes
-- to 50 percent usage of each CPU core. On a device with 1 CPU core, you
-- can set this value to @0.25@ to limit the component\'s processes to 25
-- percent usage of the CPU. If you set this value to a number greater than
-- the number of CPU cores, the IoT Greengrass Core software doesn\'t limit
-- the component\'s CPU usage.
--
-- 'memory', 'systemResourceLimits_memory' - The maximum amount of RAM, expressed in kilobytes, that a component\'s
-- processes can use on the core device.
newSystemResourceLimits ::
  SystemResourceLimits
newSystemResourceLimits :: SystemResourceLimits
newSystemResourceLimits =
  SystemResourceLimits'
    { $sel:cpus:SystemResourceLimits' :: Maybe Double
cpus = forall a. Maybe a
Prelude.Nothing,
      $sel:memory:SystemResourceLimits' :: Maybe Natural
memory = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum amount of CPU time that a component\'s processes can use on
-- the core device. A core device\'s total CPU time is equivalent to the
-- device\'s number of CPU cores. For example, on a core device with 4 CPU
-- cores, you can set this value to @2@ to limit the component\'s processes
-- to 50 percent usage of each CPU core. On a device with 1 CPU core, you
-- can set this value to @0.25@ to limit the component\'s processes to 25
-- percent usage of the CPU. If you set this value to a number greater than
-- the number of CPU cores, the IoT Greengrass Core software doesn\'t limit
-- the component\'s CPU usage.
systemResourceLimits_cpus :: Lens.Lens' SystemResourceLimits (Prelude.Maybe Prelude.Double)
systemResourceLimits_cpus :: Lens' SystemResourceLimits (Maybe Double)
systemResourceLimits_cpus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SystemResourceLimits' {Maybe Double
cpus :: Maybe Double
$sel:cpus:SystemResourceLimits' :: SystemResourceLimits -> Maybe Double
cpus} -> Maybe Double
cpus) (\s :: SystemResourceLimits
s@SystemResourceLimits' {} Maybe Double
a -> SystemResourceLimits
s {$sel:cpus:SystemResourceLimits' :: Maybe Double
cpus = Maybe Double
a} :: SystemResourceLimits)

-- | The maximum amount of RAM, expressed in kilobytes, that a component\'s
-- processes can use on the core device.
systemResourceLimits_memory :: Lens.Lens' SystemResourceLimits (Prelude.Maybe Prelude.Natural)
systemResourceLimits_memory :: Lens' SystemResourceLimits (Maybe Natural)
systemResourceLimits_memory = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SystemResourceLimits' {Maybe Natural
memory :: Maybe Natural
$sel:memory:SystemResourceLimits' :: SystemResourceLimits -> Maybe Natural
memory} -> Maybe Natural
memory) (\s :: SystemResourceLimits
s@SystemResourceLimits' {} Maybe Natural
a -> SystemResourceLimits
s {$sel:memory:SystemResourceLimits' :: Maybe Natural
memory = Maybe Natural
a} :: SystemResourceLimits)

instance Data.FromJSON SystemResourceLimits where
  parseJSON :: Value -> Parser SystemResourceLimits
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SystemResourceLimits"
      ( \Object
x ->
          Maybe Double -> Maybe Natural -> SystemResourceLimits
SystemResourceLimits'
            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
"cpus")
            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
"memory")
      )

instance Prelude.Hashable SystemResourceLimits where
  hashWithSalt :: Int -> SystemResourceLimits -> Int
hashWithSalt Int
_salt SystemResourceLimits' {Maybe Double
Maybe Natural
memory :: Maybe Natural
cpus :: Maybe Double
$sel:memory:SystemResourceLimits' :: SystemResourceLimits -> Maybe Natural
$sel:cpus:SystemResourceLimits' :: SystemResourceLimits -> Maybe Double
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
cpus
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
memory

instance Prelude.NFData SystemResourceLimits where
  rnf :: SystemResourceLimits -> ()
rnf SystemResourceLimits' {Maybe Double
Maybe Natural
memory :: Maybe Natural
cpus :: Maybe Double
$sel:memory:SystemResourceLimits' :: SystemResourceLimits -> Maybe Natural
$sel:cpus:SystemResourceLimits' :: SystemResourceLimits -> Maybe Double
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
cpus seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
memory

instance Data.ToJSON SystemResourceLimits where
  toJSON :: SystemResourceLimits -> Value
toJSON SystemResourceLimits' {Maybe Double
Maybe Natural
memory :: Maybe Natural
cpus :: Maybe Double
$sel:memory:SystemResourceLimits' :: SystemResourceLimits -> Maybe Natural
$sel:cpus:SystemResourceLimits' :: SystemResourceLimits -> Maybe Double
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"cpus" 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 Double
cpus,
            (Key
"memory" 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 Natural
memory
          ]
      )