{-# 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.GameLift.Types.RuntimeConfiguration
-- 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.GameLift.Types.RuntimeConfiguration where

import qualified Amazonka.Core as Core
import Amazonka.GameLift.Types.ServerProcess
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A collection of server process configurations that describe the set of
-- processes to run on each instance in a fleet. Server processes run
-- either an executable in a custom game build or a Realtime Servers
-- script. GameLift launches the configured processes, manages their life
-- cycle, and replaces them as needed. Each instance checks regularly for
-- an updated runtime configuration.
--
-- A GameLift instance is limited to 50 processes running concurrently. To
-- calculate the total number of processes in a runtime configuration, add
-- the values of the @ConcurrentExecutions@ parameter for each
-- ServerProcess. Learn more about
-- <https://docs.aws.amazon.com/gamelift/latest/developerguide/fleets-multiprocess.html Running Multiple Processes on a Fleet>.
--
-- __Related actions__
--
-- DescribeRuntimeConfiguration | UpdateRuntimeConfiguration
--
-- /See:/ 'newRuntimeConfiguration' smart constructor.
data RuntimeConfiguration = RuntimeConfiguration'
  { -- | The maximum amount of time (in seconds) allowed to launch a new game
    -- session and have it report ready to host players. During this time, the
    -- game session is in status @ACTIVATING@. If the game session does not
    -- become active before the timeout, it is ended and the game session
    -- status is changed to @TERMINATED@.
    RuntimeConfiguration -> Maybe Natural
gameSessionActivationTimeoutSeconds :: Prelude.Maybe Prelude.Natural,
    -- | A collection of server process configurations that identify what server
    -- processes to run on each instance in a fleet.
    RuntimeConfiguration -> Maybe (NonEmpty ServerProcess)
serverProcesses :: Prelude.Maybe (Prelude.NonEmpty ServerProcess),
    -- | The number of game sessions in status @ACTIVATING@ to allow on an
    -- instance. This setting limits the instance resources that can be used
    -- for new game activations at any one time.
    RuntimeConfiguration -> Maybe Natural
maxConcurrentGameSessionActivations :: Prelude.Maybe Prelude.Natural
  }
  deriving (RuntimeConfiguration -> RuntimeConfiguration -> Bool
(RuntimeConfiguration -> RuntimeConfiguration -> Bool)
-> (RuntimeConfiguration -> RuntimeConfiguration -> Bool)
-> Eq RuntimeConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RuntimeConfiguration -> RuntimeConfiguration -> Bool
$c/= :: RuntimeConfiguration -> RuntimeConfiguration -> Bool
== :: RuntimeConfiguration -> RuntimeConfiguration -> Bool
$c== :: RuntimeConfiguration -> RuntimeConfiguration -> Bool
Prelude.Eq, ReadPrec [RuntimeConfiguration]
ReadPrec RuntimeConfiguration
Int -> ReadS RuntimeConfiguration
ReadS [RuntimeConfiguration]
(Int -> ReadS RuntimeConfiguration)
-> ReadS [RuntimeConfiguration]
-> ReadPrec RuntimeConfiguration
-> ReadPrec [RuntimeConfiguration]
-> Read RuntimeConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RuntimeConfiguration]
$creadListPrec :: ReadPrec [RuntimeConfiguration]
readPrec :: ReadPrec RuntimeConfiguration
$creadPrec :: ReadPrec RuntimeConfiguration
readList :: ReadS [RuntimeConfiguration]
$creadList :: ReadS [RuntimeConfiguration]
readsPrec :: Int -> ReadS RuntimeConfiguration
$creadsPrec :: Int -> ReadS RuntimeConfiguration
Prelude.Read, Int -> RuntimeConfiguration -> ShowS
[RuntimeConfiguration] -> ShowS
RuntimeConfiguration -> String
(Int -> RuntimeConfiguration -> ShowS)
-> (RuntimeConfiguration -> String)
-> ([RuntimeConfiguration] -> ShowS)
-> Show RuntimeConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RuntimeConfiguration] -> ShowS
$cshowList :: [RuntimeConfiguration] -> ShowS
show :: RuntimeConfiguration -> String
$cshow :: RuntimeConfiguration -> String
showsPrec :: Int -> RuntimeConfiguration -> ShowS
$cshowsPrec :: Int -> RuntimeConfiguration -> ShowS
Prelude.Show, (forall x. RuntimeConfiguration -> Rep RuntimeConfiguration x)
-> (forall x. Rep RuntimeConfiguration x -> RuntimeConfiguration)
-> Generic RuntimeConfiguration
forall x. Rep RuntimeConfiguration x -> RuntimeConfiguration
forall x. RuntimeConfiguration -> Rep RuntimeConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RuntimeConfiguration x -> RuntimeConfiguration
$cfrom :: forall x. RuntimeConfiguration -> Rep RuntimeConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'RuntimeConfiguration' 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:
--
-- 'gameSessionActivationTimeoutSeconds', 'runtimeConfiguration_gameSessionActivationTimeoutSeconds' - The maximum amount of time (in seconds) allowed to launch a new game
-- session and have it report ready to host players. During this time, the
-- game session is in status @ACTIVATING@. If the game session does not
-- become active before the timeout, it is ended and the game session
-- status is changed to @TERMINATED@.
--
-- 'serverProcesses', 'runtimeConfiguration_serverProcesses' - A collection of server process configurations that identify what server
-- processes to run on each instance in a fleet.
--
-- 'maxConcurrentGameSessionActivations', 'runtimeConfiguration_maxConcurrentGameSessionActivations' - The number of game sessions in status @ACTIVATING@ to allow on an
-- instance. This setting limits the instance resources that can be used
-- for new game activations at any one time.
newRuntimeConfiguration ::
  RuntimeConfiguration
newRuntimeConfiguration :: RuntimeConfiguration
newRuntimeConfiguration =
  RuntimeConfiguration' :: Maybe Natural
-> Maybe (NonEmpty ServerProcess)
-> Maybe Natural
-> RuntimeConfiguration
RuntimeConfiguration'
    { $sel:gameSessionActivationTimeoutSeconds:RuntimeConfiguration' :: Maybe Natural
gameSessionActivationTimeoutSeconds =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:serverProcesses:RuntimeConfiguration' :: Maybe (NonEmpty ServerProcess)
serverProcesses = Maybe (NonEmpty ServerProcess)
forall a. Maybe a
Prelude.Nothing,
      $sel:maxConcurrentGameSessionActivations:RuntimeConfiguration' :: Maybe Natural
maxConcurrentGameSessionActivations =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum amount of time (in seconds) allowed to launch a new game
-- session and have it report ready to host players. During this time, the
-- game session is in status @ACTIVATING@. If the game session does not
-- become active before the timeout, it is ended and the game session
-- status is changed to @TERMINATED@.
runtimeConfiguration_gameSessionActivationTimeoutSeconds :: Lens.Lens' RuntimeConfiguration (Prelude.Maybe Prelude.Natural)
runtimeConfiguration_gameSessionActivationTimeoutSeconds :: (Maybe Natural -> f (Maybe Natural))
-> RuntimeConfiguration -> f RuntimeConfiguration
runtimeConfiguration_gameSessionActivationTimeoutSeconds = (RuntimeConfiguration -> Maybe Natural)
-> (RuntimeConfiguration -> Maybe Natural -> RuntimeConfiguration)
-> Lens
     RuntimeConfiguration
     RuntimeConfiguration
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuntimeConfiguration' {Maybe Natural
gameSessionActivationTimeoutSeconds :: Maybe Natural
$sel:gameSessionActivationTimeoutSeconds:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe Natural
gameSessionActivationTimeoutSeconds} -> Maybe Natural
gameSessionActivationTimeoutSeconds) (\s :: RuntimeConfiguration
s@RuntimeConfiguration' {} Maybe Natural
a -> RuntimeConfiguration
s {$sel:gameSessionActivationTimeoutSeconds:RuntimeConfiguration' :: Maybe Natural
gameSessionActivationTimeoutSeconds = Maybe Natural
a} :: RuntimeConfiguration)

-- | A collection of server process configurations that identify what server
-- processes to run on each instance in a fleet.
runtimeConfiguration_serverProcesses :: Lens.Lens' RuntimeConfiguration (Prelude.Maybe (Prelude.NonEmpty ServerProcess))
runtimeConfiguration_serverProcesses :: (Maybe (NonEmpty ServerProcess)
 -> f (Maybe (NonEmpty ServerProcess)))
-> RuntimeConfiguration -> f RuntimeConfiguration
runtimeConfiguration_serverProcesses = (RuntimeConfiguration -> Maybe (NonEmpty ServerProcess))
-> (RuntimeConfiguration
    -> Maybe (NonEmpty ServerProcess) -> RuntimeConfiguration)
-> Lens
     RuntimeConfiguration
     RuntimeConfiguration
     (Maybe (NonEmpty ServerProcess))
     (Maybe (NonEmpty ServerProcess))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuntimeConfiguration' {Maybe (NonEmpty ServerProcess)
serverProcesses :: Maybe (NonEmpty ServerProcess)
$sel:serverProcesses:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe (NonEmpty ServerProcess)
serverProcesses} -> Maybe (NonEmpty ServerProcess)
serverProcesses) (\s :: RuntimeConfiguration
s@RuntimeConfiguration' {} Maybe (NonEmpty ServerProcess)
a -> RuntimeConfiguration
s {$sel:serverProcesses:RuntimeConfiguration' :: Maybe (NonEmpty ServerProcess)
serverProcesses = Maybe (NonEmpty ServerProcess)
a} :: RuntimeConfiguration) ((Maybe (NonEmpty ServerProcess)
  -> f (Maybe (NonEmpty ServerProcess)))
 -> RuntimeConfiguration -> f RuntimeConfiguration)
-> ((Maybe (NonEmpty ServerProcess)
     -> f (Maybe (NonEmpty ServerProcess)))
    -> Maybe (NonEmpty ServerProcess)
    -> f (Maybe (NonEmpty ServerProcess)))
-> (Maybe (NonEmpty ServerProcess)
    -> f (Maybe (NonEmpty ServerProcess)))
-> RuntimeConfiguration
-> f RuntimeConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty ServerProcess)
  (NonEmpty ServerProcess)
  (NonEmpty ServerProcess)
  (NonEmpty ServerProcess)
-> Iso
     (Maybe (NonEmpty ServerProcess))
     (Maybe (NonEmpty ServerProcess))
     (Maybe (NonEmpty ServerProcess))
     (Maybe (NonEmpty ServerProcess))
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 AnIso
  (NonEmpty ServerProcess)
  (NonEmpty ServerProcess)
  (NonEmpty ServerProcess)
  (NonEmpty ServerProcess)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The number of game sessions in status @ACTIVATING@ to allow on an
-- instance. This setting limits the instance resources that can be used
-- for new game activations at any one time.
runtimeConfiguration_maxConcurrentGameSessionActivations :: Lens.Lens' RuntimeConfiguration (Prelude.Maybe Prelude.Natural)
runtimeConfiguration_maxConcurrentGameSessionActivations :: (Maybe Natural -> f (Maybe Natural))
-> RuntimeConfiguration -> f RuntimeConfiguration
runtimeConfiguration_maxConcurrentGameSessionActivations = (RuntimeConfiguration -> Maybe Natural)
-> (RuntimeConfiguration -> Maybe Natural -> RuntimeConfiguration)
-> Lens
     RuntimeConfiguration
     RuntimeConfiguration
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuntimeConfiguration' {Maybe Natural
maxConcurrentGameSessionActivations :: Maybe Natural
$sel:maxConcurrentGameSessionActivations:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe Natural
maxConcurrentGameSessionActivations} -> Maybe Natural
maxConcurrentGameSessionActivations) (\s :: RuntimeConfiguration
s@RuntimeConfiguration' {} Maybe Natural
a -> RuntimeConfiguration
s {$sel:maxConcurrentGameSessionActivations:RuntimeConfiguration' :: Maybe Natural
maxConcurrentGameSessionActivations = Maybe Natural
a} :: RuntimeConfiguration)

instance Core.FromJSON RuntimeConfiguration where
  parseJSON :: Value -> Parser RuntimeConfiguration
parseJSON =
    String
-> (Object -> Parser RuntimeConfiguration)
-> Value
-> Parser RuntimeConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RuntimeConfiguration"
      ( \Object
x ->
          Maybe Natural
-> Maybe (NonEmpty ServerProcess)
-> Maybe Natural
-> RuntimeConfiguration
RuntimeConfiguration'
            (Maybe Natural
 -> Maybe (NonEmpty ServerProcess)
 -> Maybe Natural
 -> RuntimeConfiguration)
-> Parser (Maybe Natural)
-> Parser
     (Maybe (NonEmpty ServerProcess)
      -> Maybe Natural -> RuntimeConfiguration)
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
"GameSessionActivationTimeoutSeconds")
            Parser
  (Maybe (NonEmpty ServerProcess)
   -> Maybe Natural -> RuntimeConfiguration)
-> Parser (Maybe (NonEmpty ServerProcess))
-> Parser (Maybe Natural -> RuntimeConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (NonEmpty ServerProcess))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ServerProcesses")
            Parser (Maybe Natural -> RuntimeConfiguration)
-> Parser (Maybe Natural) -> Parser RuntimeConfiguration
forall (f :: * -> *) a b. Applicative f => 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
"MaxConcurrentGameSessionActivations")
      )

instance Prelude.Hashable RuntimeConfiguration

instance Prelude.NFData RuntimeConfiguration

instance Core.ToJSON RuntimeConfiguration where
  toJSON :: RuntimeConfiguration -> Value
toJSON RuntimeConfiguration' {Maybe Natural
Maybe (NonEmpty ServerProcess)
maxConcurrentGameSessionActivations :: Maybe Natural
serverProcesses :: Maybe (NonEmpty ServerProcess)
gameSessionActivationTimeoutSeconds :: Maybe Natural
$sel:maxConcurrentGameSessionActivations:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe Natural
$sel:serverProcesses:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe (NonEmpty ServerProcess)
$sel:gameSessionActivationTimeoutSeconds:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"GameSessionActivationTimeoutSeconds" 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
gameSessionActivationTimeoutSeconds,
            (Text
"ServerProcesses" Text -> NonEmpty ServerProcess -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NonEmpty ServerProcess -> Pair)
-> Maybe (NonEmpty ServerProcess) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty ServerProcess)
serverProcesses,
            (Text
"MaxConcurrentGameSessionActivations" 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
maxConcurrentGameSessionActivations
          ]
      )