{-# 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.SageMaker.Types.DeploymentConfig
-- 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.SageMaker.Types.DeploymentConfig 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
import Amazonka.SageMaker.Types.AutoRollbackConfig
import Amazonka.SageMaker.Types.BlueGreenUpdatePolicy

-- | The deployment configuration for an endpoint, which contains the desired
-- deployment strategy and rollback configurations.
--
-- /See:/ 'newDeploymentConfig' smart constructor.
data DeploymentConfig = DeploymentConfig'
  { -- | Automatic rollback configuration for handling endpoint deployment
    -- failures and recovery.
    DeploymentConfig -> Maybe AutoRollbackConfig
autoRollbackConfiguration :: Prelude.Maybe AutoRollbackConfig,
    -- | Update policy for a blue\/green deployment. If this update policy is
    -- specified, SageMaker creates a new fleet during the deployment while
    -- maintaining the old fleet. SageMaker flips traffic to the new fleet
    -- according to the specified traffic routing configuration. Only one
    -- update policy should be used in the deployment configuration. If no
    -- update policy is specified, SageMaker uses a blue\/green deployment
    -- strategy with all at once traffic shifting by default.
    DeploymentConfig -> BlueGreenUpdatePolicy
blueGreenUpdatePolicy :: BlueGreenUpdatePolicy
  }
  deriving (DeploymentConfig -> DeploymentConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeploymentConfig -> DeploymentConfig -> Bool
$c/= :: DeploymentConfig -> DeploymentConfig -> Bool
== :: DeploymentConfig -> DeploymentConfig -> Bool
$c== :: DeploymentConfig -> DeploymentConfig -> Bool
Prelude.Eq, ReadPrec [DeploymentConfig]
ReadPrec DeploymentConfig
Int -> ReadS DeploymentConfig
ReadS [DeploymentConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeploymentConfig]
$creadListPrec :: ReadPrec [DeploymentConfig]
readPrec :: ReadPrec DeploymentConfig
$creadPrec :: ReadPrec DeploymentConfig
readList :: ReadS [DeploymentConfig]
$creadList :: ReadS [DeploymentConfig]
readsPrec :: Int -> ReadS DeploymentConfig
$creadsPrec :: Int -> ReadS DeploymentConfig
Prelude.Read, Int -> DeploymentConfig -> ShowS
[DeploymentConfig] -> ShowS
DeploymentConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeploymentConfig] -> ShowS
$cshowList :: [DeploymentConfig] -> ShowS
show :: DeploymentConfig -> String
$cshow :: DeploymentConfig -> String
showsPrec :: Int -> DeploymentConfig -> ShowS
$cshowsPrec :: Int -> DeploymentConfig -> ShowS
Prelude.Show, forall x. Rep DeploymentConfig x -> DeploymentConfig
forall x. DeploymentConfig -> Rep DeploymentConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeploymentConfig x -> DeploymentConfig
$cfrom :: forall x. DeploymentConfig -> Rep DeploymentConfig x
Prelude.Generic)

-- |
-- Create a value of 'DeploymentConfig' 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:
--
-- 'autoRollbackConfiguration', 'deploymentConfig_autoRollbackConfiguration' - Automatic rollback configuration for handling endpoint deployment
-- failures and recovery.
--
-- 'blueGreenUpdatePolicy', 'deploymentConfig_blueGreenUpdatePolicy' - Update policy for a blue\/green deployment. If this update policy is
-- specified, SageMaker creates a new fleet during the deployment while
-- maintaining the old fleet. SageMaker flips traffic to the new fleet
-- according to the specified traffic routing configuration. Only one
-- update policy should be used in the deployment configuration. If no
-- update policy is specified, SageMaker uses a blue\/green deployment
-- strategy with all at once traffic shifting by default.
newDeploymentConfig ::
  -- | 'blueGreenUpdatePolicy'
  BlueGreenUpdatePolicy ->
  DeploymentConfig
newDeploymentConfig :: BlueGreenUpdatePolicy -> DeploymentConfig
newDeploymentConfig BlueGreenUpdatePolicy
pBlueGreenUpdatePolicy_ =
  DeploymentConfig'
    { $sel:autoRollbackConfiguration:DeploymentConfig' :: Maybe AutoRollbackConfig
autoRollbackConfiguration =
        forall a. Maybe a
Prelude.Nothing,
      $sel:blueGreenUpdatePolicy:DeploymentConfig' :: BlueGreenUpdatePolicy
blueGreenUpdatePolicy = BlueGreenUpdatePolicy
pBlueGreenUpdatePolicy_
    }

-- | Automatic rollback configuration for handling endpoint deployment
-- failures and recovery.
deploymentConfig_autoRollbackConfiguration :: Lens.Lens' DeploymentConfig (Prelude.Maybe AutoRollbackConfig)
deploymentConfig_autoRollbackConfiguration :: Lens' DeploymentConfig (Maybe AutoRollbackConfig)
deploymentConfig_autoRollbackConfiguration = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentConfig' {Maybe AutoRollbackConfig
autoRollbackConfiguration :: Maybe AutoRollbackConfig
$sel:autoRollbackConfiguration:DeploymentConfig' :: DeploymentConfig -> Maybe AutoRollbackConfig
autoRollbackConfiguration} -> Maybe AutoRollbackConfig
autoRollbackConfiguration) (\s :: DeploymentConfig
s@DeploymentConfig' {} Maybe AutoRollbackConfig
a -> DeploymentConfig
s {$sel:autoRollbackConfiguration:DeploymentConfig' :: Maybe AutoRollbackConfig
autoRollbackConfiguration = Maybe AutoRollbackConfig
a} :: DeploymentConfig)

-- | Update policy for a blue\/green deployment. If this update policy is
-- specified, SageMaker creates a new fleet during the deployment while
-- maintaining the old fleet. SageMaker flips traffic to the new fleet
-- according to the specified traffic routing configuration. Only one
-- update policy should be used in the deployment configuration. If no
-- update policy is specified, SageMaker uses a blue\/green deployment
-- strategy with all at once traffic shifting by default.
deploymentConfig_blueGreenUpdatePolicy :: Lens.Lens' DeploymentConfig BlueGreenUpdatePolicy
deploymentConfig_blueGreenUpdatePolicy :: Lens' DeploymentConfig BlueGreenUpdatePolicy
deploymentConfig_blueGreenUpdatePolicy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentConfig' {BlueGreenUpdatePolicy
blueGreenUpdatePolicy :: BlueGreenUpdatePolicy
$sel:blueGreenUpdatePolicy:DeploymentConfig' :: DeploymentConfig -> BlueGreenUpdatePolicy
blueGreenUpdatePolicy} -> BlueGreenUpdatePolicy
blueGreenUpdatePolicy) (\s :: DeploymentConfig
s@DeploymentConfig' {} BlueGreenUpdatePolicy
a -> DeploymentConfig
s {$sel:blueGreenUpdatePolicy:DeploymentConfig' :: BlueGreenUpdatePolicy
blueGreenUpdatePolicy = BlueGreenUpdatePolicy
a} :: DeploymentConfig)

instance Data.FromJSON DeploymentConfig where
  parseJSON :: Value -> Parser DeploymentConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DeploymentConfig"
      ( \Object
x ->
          Maybe AutoRollbackConfig
-> BlueGreenUpdatePolicy -> DeploymentConfig
DeploymentConfig'
            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
"AutoRollbackConfiguration")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"BlueGreenUpdatePolicy")
      )

instance Prelude.Hashable DeploymentConfig where
  hashWithSalt :: Int -> DeploymentConfig -> Int
hashWithSalt Int
_salt DeploymentConfig' {Maybe AutoRollbackConfig
BlueGreenUpdatePolicy
blueGreenUpdatePolicy :: BlueGreenUpdatePolicy
autoRollbackConfiguration :: Maybe AutoRollbackConfig
$sel:blueGreenUpdatePolicy:DeploymentConfig' :: DeploymentConfig -> BlueGreenUpdatePolicy
$sel:autoRollbackConfiguration:DeploymentConfig' :: DeploymentConfig -> Maybe AutoRollbackConfig
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AutoRollbackConfig
autoRollbackConfiguration
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` BlueGreenUpdatePolicy
blueGreenUpdatePolicy

instance Prelude.NFData DeploymentConfig where
  rnf :: DeploymentConfig -> ()
rnf DeploymentConfig' {Maybe AutoRollbackConfig
BlueGreenUpdatePolicy
blueGreenUpdatePolicy :: BlueGreenUpdatePolicy
autoRollbackConfiguration :: Maybe AutoRollbackConfig
$sel:blueGreenUpdatePolicy:DeploymentConfig' :: DeploymentConfig -> BlueGreenUpdatePolicy
$sel:autoRollbackConfiguration:DeploymentConfig' :: DeploymentConfig -> Maybe AutoRollbackConfig
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe AutoRollbackConfig
autoRollbackConfiguration
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf BlueGreenUpdatePolicy
blueGreenUpdatePolicy

instance Data.ToJSON DeploymentConfig where
  toJSON :: DeploymentConfig -> Value
toJSON DeploymentConfig' {Maybe AutoRollbackConfig
BlueGreenUpdatePolicy
blueGreenUpdatePolicy :: BlueGreenUpdatePolicy
autoRollbackConfiguration :: Maybe AutoRollbackConfig
$sel:blueGreenUpdatePolicy:DeploymentConfig' :: DeploymentConfig -> BlueGreenUpdatePolicy
$sel:autoRollbackConfiguration:DeploymentConfig' :: DeploymentConfig -> Maybe AutoRollbackConfig
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"AutoRollbackConfiguration" 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 AutoRollbackConfig
autoRollbackConfiguration,
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"BlueGreenUpdatePolicy"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= BlueGreenUpdatePolicy
blueGreenUpdatePolicy
              )
          ]
      )