{-# 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.Batch.Types.FairsharePolicy
-- 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.Batch.Types.FairsharePolicy where

import Amazonka.Batch.Types.ShareAttributes
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

-- | The fair share policy for a scheduling policy.
--
-- /See:/ 'newFairsharePolicy' smart constructor.
data FairsharePolicy = FairsharePolicy'
  { -- | A value used to reserve some of the available maximum vCPU for fair
    -- share identifiers that aren\'t already used.
    --
    -- The reserved ratio is
    -- @(@/@computeReservation@/@\/100)^@/@ActiveFairShares@/@ @ where
    -- @ @/@ActiveFairShares@/@ @ is the number of active fair share
    -- identifiers.
    --
    -- For example, a @computeReservation@ value of 50 indicates that
    -- Batchreserves 50% of the maximum available vCPU if there\'s only one
    -- fair share identifier. It reserves 25% if there are two fair share
    -- identifiers. It reserves 12.5% if there are three fair share
    -- identifiers. A @computeReservation@ value of 25 indicates that Batch
    -- should reserve 25% of the maximum available vCPU if there\'s only one
    -- fair share identifier, 6.25% if there are two fair share identifiers,
    -- and 1.56% if there are three fair share identifiers.
    --
    -- The minimum value is 0 and the maximum value is 99.
    FairsharePolicy -> Maybe Int
computeReservation :: Prelude.Maybe Prelude.Int,
    -- | The amount of time (in seconds) to use to calculate a fair share
    -- percentage for each fair share identifier in use. A value of zero (0)
    -- indicates that only current usage is measured. The decay allows for more
    -- recently run jobs to have more weight than jobs that ran earlier. The
    -- maximum supported value is 604800 (1 week).
    FairsharePolicy -> Maybe Int
shareDecaySeconds :: Prelude.Maybe Prelude.Int,
    -- | An array of @SharedIdentifier@ objects that contain the weights for the
    -- fair share identifiers for the fair share policy. Fair share identifiers
    -- that aren\'t included have a default weight of @1.0@.
    FairsharePolicy -> Maybe [ShareAttributes]
shareDistribution :: Prelude.Maybe [ShareAttributes]
  }
  deriving (FairsharePolicy -> FairsharePolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FairsharePolicy -> FairsharePolicy -> Bool
$c/= :: FairsharePolicy -> FairsharePolicy -> Bool
== :: FairsharePolicy -> FairsharePolicy -> Bool
$c== :: FairsharePolicy -> FairsharePolicy -> Bool
Prelude.Eq, ReadPrec [FairsharePolicy]
ReadPrec FairsharePolicy
Int -> ReadS FairsharePolicy
ReadS [FairsharePolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FairsharePolicy]
$creadListPrec :: ReadPrec [FairsharePolicy]
readPrec :: ReadPrec FairsharePolicy
$creadPrec :: ReadPrec FairsharePolicy
readList :: ReadS [FairsharePolicy]
$creadList :: ReadS [FairsharePolicy]
readsPrec :: Int -> ReadS FairsharePolicy
$creadsPrec :: Int -> ReadS FairsharePolicy
Prelude.Read, Int -> FairsharePolicy -> ShowS
[FairsharePolicy] -> ShowS
FairsharePolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FairsharePolicy] -> ShowS
$cshowList :: [FairsharePolicy] -> ShowS
show :: FairsharePolicy -> String
$cshow :: FairsharePolicy -> String
showsPrec :: Int -> FairsharePolicy -> ShowS
$cshowsPrec :: Int -> FairsharePolicy -> ShowS
Prelude.Show, forall x. Rep FairsharePolicy x -> FairsharePolicy
forall x. FairsharePolicy -> Rep FairsharePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FairsharePolicy x -> FairsharePolicy
$cfrom :: forall x. FairsharePolicy -> Rep FairsharePolicy x
Prelude.Generic)

-- |
-- Create a value of 'FairsharePolicy' 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:
--
-- 'computeReservation', 'fairsharePolicy_computeReservation' - A value used to reserve some of the available maximum vCPU for fair
-- share identifiers that aren\'t already used.
--
-- The reserved ratio is
-- @(@/@computeReservation@/@\/100)^@/@ActiveFairShares@/@ @ where
-- @ @/@ActiveFairShares@/@ @ is the number of active fair share
-- identifiers.
--
-- For example, a @computeReservation@ value of 50 indicates that
-- Batchreserves 50% of the maximum available vCPU if there\'s only one
-- fair share identifier. It reserves 25% if there are two fair share
-- identifiers. It reserves 12.5% if there are three fair share
-- identifiers. A @computeReservation@ value of 25 indicates that Batch
-- should reserve 25% of the maximum available vCPU if there\'s only one
-- fair share identifier, 6.25% if there are two fair share identifiers,
-- and 1.56% if there are three fair share identifiers.
--
-- The minimum value is 0 and the maximum value is 99.
--
-- 'shareDecaySeconds', 'fairsharePolicy_shareDecaySeconds' - The amount of time (in seconds) to use to calculate a fair share
-- percentage for each fair share identifier in use. A value of zero (0)
-- indicates that only current usage is measured. The decay allows for more
-- recently run jobs to have more weight than jobs that ran earlier. The
-- maximum supported value is 604800 (1 week).
--
-- 'shareDistribution', 'fairsharePolicy_shareDistribution' - An array of @SharedIdentifier@ objects that contain the weights for the
-- fair share identifiers for the fair share policy. Fair share identifiers
-- that aren\'t included have a default weight of @1.0@.
newFairsharePolicy ::
  FairsharePolicy
newFairsharePolicy :: FairsharePolicy
newFairsharePolicy =
  FairsharePolicy'
    { $sel:computeReservation:FairsharePolicy' :: Maybe Int
computeReservation =
        forall a. Maybe a
Prelude.Nothing,
      $sel:shareDecaySeconds:FairsharePolicy' :: Maybe Int
shareDecaySeconds = forall a. Maybe a
Prelude.Nothing,
      $sel:shareDistribution:FairsharePolicy' :: Maybe [ShareAttributes]
shareDistribution = forall a. Maybe a
Prelude.Nothing
    }

-- | A value used to reserve some of the available maximum vCPU for fair
-- share identifiers that aren\'t already used.
--
-- The reserved ratio is
-- @(@/@computeReservation@/@\/100)^@/@ActiveFairShares@/@ @ where
-- @ @/@ActiveFairShares@/@ @ is the number of active fair share
-- identifiers.
--
-- For example, a @computeReservation@ value of 50 indicates that
-- Batchreserves 50% of the maximum available vCPU if there\'s only one
-- fair share identifier. It reserves 25% if there are two fair share
-- identifiers. It reserves 12.5% if there are three fair share
-- identifiers. A @computeReservation@ value of 25 indicates that Batch
-- should reserve 25% of the maximum available vCPU if there\'s only one
-- fair share identifier, 6.25% if there are two fair share identifiers,
-- and 1.56% if there are three fair share identifiers.
--
-- The minimum value is 0 and the maximum value is 99.
fairsharePolicy_computeReservation :: Lens.Lens' FairsharePolicy (Prelude.Maybe Prelude.Int)
fairsharePolicy_computeReservation :: Lens' FairsharePolicy (Maybe Int)
fairsharePolicy_computeReservation = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FairsharePolicy' {Maybe Int
computeReservation :: Maybe Int
$sel:computeReservation:FairsharePolicy' :: FairsharePolicy -> Maybe Int
computeReservation} -> Maybe Int
computeReservation) (\s :: FairsharePolicy
s@FairsharePolicy' {} Maybe Int
a -> FairsharePolicy
s {$sel:computeReservation:FairsharePolicy' :: Maybe Int
computeReservation = Maybe Int
a} :: FairsharePolicy)

-- | The amount of time (in seconds) to use to calculate a fair share
-- percentage for each fair share identifier in use. A value of zero (0)
-- indicates that only current usage is measured. The decay allows for more
-- recently run jobs to have more weight than jobs that ran earlier. The
-- maximum supported value is 604800 (1 week).
fairsharePolicy_shareDecaySeconds :: Lens.Lens' FairsharePolicy (Prelude.Maybe Prelude.Int)
fairsharePolicy_shareDecaySeconds :: Lens' FairsharePolicy (Maybe Int)
fairsharePolicy_shareDecaySeconds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FairsharePolicy' {Maybe Int
shareDecaySeconds :: Maybe Int
$sel:shareDecaySeconds:FairsharePolicy' :: FairsharePolicy -> Maybe Int
shareDecaySeconds} -> Maybe Int
shareDecaySeconds) (\s :: FairsharePolicy
s@FairsharePolicy' {} Maybe Int
a -> FairsharePolicy
s {$sel:shareDecaySeconds:FairsharePolicy' :: Maybe Int
shareDecaySeconds = Maybe Int
a} :: FairsharePolicy)

-- | An array of @SharedIdentifier@ objects that contain the weights for the
-- fair share identifiers for the fair share policy. Fair share identifiers
-- that aren\'t included have a default weight of @1.0@.
fairsharePolicy_shareDistribution :: Lens.Lens' FairsharePolicy (Prelude.Maybe [ShareAttributes])
fairsharePolicy_shareDistribution :: Lens' FairsharePolicy (Maybe [ShareAttributes])
fairsharePolicy_shareDistribution = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FairsharePolicy' {Maybe [ShareAttributes]
shareDistribution :: Maybe [ShareAttributes]
$sel:shareDistribution:FairsharePolicy' :: FairsharePolicy -> Maybe [ShareAttributes]
shareDistribution} -> Maybe [ShareAttributes]
shareDistribution) (\s :: FairsharePolicy
s@FairsharePolicy' {} Maybe [ShareAttributes]
a -> FairsharePolicy
s {$sel:shareDistribution:FairsharePolicy' :: Maybe [ShareAttributes]
shareDistribution = Maybe [ShareAttributes]
a} :: FairsharePolicy) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON FairsharePolicy where
  parseJSON :: Value -> Parser FairsharePolicy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"FairsharePolicy"
      ( \Object
x ->
          Maybe Int
-> Maybe Int -> Maybe [ShareAttributes] -> FairsharePolicy
FairsharePolicy'
            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
"computeReservation")
            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
"shareDecaySeconds")
            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
"shareDistribution"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable FairsharePolicy where
  hashWithSalt :: Int -> FairsharePolicy -> Int
hashWithSalt Int
_salt FairsharePolicy' {Maybe Int
Maybe [ShareAttributes]
shareDistribution :: Maybe [ShareAttributes]
shareDecaySeconds :: Maybe Int
computeReservation :: Maybe Int
$sel:shareDistribution:FairsharePolicy' :: FairsharePolicy -> Maybe [ShareAttributes]
$sel:shareDecaySeconds:FairsharePolicy' :: FairsharePolicy -> Maybe Int
$sel:computeReservation:FairsharePolicy' :: FairsharePolicy -> Maybe Int
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
computeReservation
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
shareDecaySeconds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [ShareAttributes]
shareDistribution

instance Prelude.NFData FairsharePolicy where
  rnf :: FairsharePolicy -> ()
rnf FairsharePolicy' {Maybe Int
Maybe [ShareAttributes]
shareDistribution :: Maybe [ShareAttributes]
shareDecaySeconds :: Maybe Int
computeReservation :: Maybe Int
$sel:shareDistribution:FairsharePolicy' :: FairsharePolicy -> Maybe [ShareAttributes]
$sel:shareDecaySeconds:FairsharePolicy' :: FairsharePolicy -> Maybe Int
$sel:computeReservation:FairsharePolicy' :: FairsharePolicy -> Maybe Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
computeReservation
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
shareDecaySeconds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [ShareAttributes]
shareDistribution

instance Data.ToJSON FairsharePolicy where
  toJSON :: FairsharePolicy -> Value
toJSON FairsharePolicy' {Maybe Int
Maybe [ShareAttributes]
shareDistribution :: Maybe [ShareAttributes]
shareDecaySeconds :: Maybe Int
computeReservation :: Maybe Int
$sel:shareDistribution:FairsharePolicy' :: FairsharePolicy -> Maybe [ShareAttributes]
$sel:shareDecaySeconds:FairsharePolicy' :: FairsharePolicy -> Maybe Int
$sel:computeReservation:FairsharePolicy' :: FairsharePolicy -> Maybe Int
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"computeReservation" 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 Int
computeReservation,
            (Key
"shareDecaySeconds" 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 Int
shareDecaySeconds,
            (Key
"shareDistribution" 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 [ShareAttributes]
shareDistribution
          ]
      )