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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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 RAM, expressed in kilobytes, that a component\'s
    -- processes can use on the core device.
    SystemResourceLimits -> Maybe Natural
memory :: Prelude.Maybe Prelude.Natural,
    -- | 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
  }
  deriving (SystemResourceLimits -> SystemResourceLimits -> Bool
(SystemResourceLimits -> SystemResourceLimits -> Bool)
-> (SystemResourceLimits -> SystemResourceLimits -> Bool)
-> Eq SystemResourceLimits
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]
(Int -> ReadS SystemResourceLimits)
-> ReadS [SystemResourceLimits]
-> ReadPrec SystemResourceLimits
-> ReadPrec [SystemResourceLimits]
-> Read 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
(Int -> SystemResourceLimits -> ShowS)
-> (SystemResourceLimits -> String)
-> ([SystemResourceLimits] -> ShowS)
-> Show SystemResourceLimits
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. SystemResourceLimits -> Rep SystemResourceLimits x)
-> (forall x. Rep SystemResourceLimits x -> SystemResourceLimits)
-> Generic SystemResourceLimits
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:
--
-- 'memory', 'systemResourceLimits_memory' - The maximum amount of RAM, expressed in kilobytes, that a component\'s
-- processes can use on the core device.
--
-- '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.
newSystemResourceLimits ::
  SystemResourceLimits
newSystemResourceLimits :: SystemResourceLimits
newSystemResourceLimits =
  SystemResourceLimits' :: Maybe Natural -> Maybe Double -> SystemResourceLimits
SystemResourceLimits'
    { $sel:memory:SystemResourceLimits' :: Maybe Natural
memory = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:cpus:SystemResourceLimits' :: Maybe Double
cpus = Maybe Double
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe Natural -> f (Maybe Natural))
-> SystemResourceLimits -> f SystemResourceLimits
systemResourceLimits_memory = (SystemResourceLimits -> Maybe Natural)
-> (SystemResourceLimits -> Maybe Natural -> SystemResourceLimits)
-> Lens
     SystemResourceLimits
     SystemResourceLimits
     (Maybe Natural)
     (Maybe Natural)
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)

-- | 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 :: (Maybe Double -> f (Maybe Double))
-> SystemResourceLimits -> f SystemResourceLimits
systemResourceLimits_cpus = (SystemResourceLimits -> Maybe Double)
-> (SystemResourceLimits -> Maybe Double -> SystemResourceLimits)
-> Lens
     SystemResourceLimits
     SystemResourceLimits
     (Maybe Double)
     (Maybe Double)
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)

instance Core.FromJSON SystemResourceLimits where
  parseJSON :: Value -> Parser SystemResourceLimits
parseJSON =
    String
-> (Object -> Parser SystemResourceLimits)
-> Value
-> Parser SystemResourceLimits
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SystemResourceLimits"
      ( \Object
x ->
          Maybe Natural -> Maybe Double -> SystemResourceLimits
SystemResourceLimits'
            (Maybe Natural -> Maybe Double -> SystemResourceLimits)
-> Parser (Maybe Natural)
-> Parser (Maybe Double -> SystemResourceLimits)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"memory")
            Parser (Maybe Double -> SystemResourceLimits)
-> Parser (Maybe Double) -> Parser SystemResourceLimits
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"cpus")
      )

instance Prelude.Hashable SystemResourceLimits

instance Prelude.NFData SystemResourceLimits

instance Core.ToJSON SystemResourceLimits where
  toJSON :: SystemResourceLimits -> Value
toJSON SystemResourceLimits' {Maybe Double
Maybe Natural
cpus :: Maybe Double
memory :: Maybe Natural
$sel:cpus:SystemResourceLimits' :: SystemResourceLimits -> Maybe Double
$sel:memory:SystemResourceLimits' :: SystemResourceLimits -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"memory" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
memory,
            (Text
"cpus" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
cpus
          ]
      )