{-# 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.TrafficRoutingConfig
-- 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.TrafficRoutingConfig 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.CapacitySize
import Amazonka.SageMaker.Types.TrafficRoutingConfigType

-- | Defines the traffic routing strategy during an endpoint deployment to
-- shift traffic from the old fleet to the new fleet.
--
-- /See:/ 'newTrafficRoutingConfig' smart constructor.
data TrafficRoutingConfig = TrafficRoutingConfig'
  { -- | Batch size for the first step to turn on traffic on the new endpoint
    -- fleet. @Value@ must be less than or equal to 50% of the variant\'s total
    -- instance count.
    TrafficRoutingConfig -> Maybe CapacitySize
canarySize :: Prelude.Maybe CapacitySize,
    -- | Batch size for each step to turn on traffic on the new endpoint fleet.
    -- @Value@ must be 10-50% of the variant\'s total instance count.
    TrafficRoutingConfig -> Maybe CapacitySize
linearStepSize :: Prelude.Maybe CapacitySize,
    -- | Traffic routing strategy type.
    --
    -- -   @ALL_AT_ONCE@: Endpoint traffic shifts to the new fleet in a single
    --     step.
    --
    -- -   @CANARY@: Endpoint traffic shifts to the new fleet in two steps. The
    --     first step is the canary, which is a small portion of the traffic.
    --     The second step is the remainder of the traffic.
    --
    -- -   @LINEAR@: Endpoint traffic shifts to the new fleet in n steps of a
    --     configurable size.
    TrafficRoutingConfig -> TrafficRoutingConfigType
type' :: TrafficRoutingConfigType,
    -- | The waiting time (in seconds) between incremental steps to turn on
    -- traffic on the new endpoint fleet.
    TrafficRoutingConfig -> Natural
waitIntervalInSeconds :: Prelude.Natural
  }
  deriving (TrafficRoutingConfig -> TrafficRoutingConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TrafficRoutingConfig -> TrafficRoutingConfig -> Bool
$c/= :: TrafficRoutingConfig -> TrafficRoutingConfig -> Bool
== :: TrafficRoutingConfig -> TrafficRoutingConfig -> Bool
$c== :: TrafficRoutingConfig -> TrafficRoutingConfig -> Bool
Prelude.Eq, ReadPrec [TrafficRoutingConfig]
ReadPrec TrafficRoutingConfig
Int -> ReadS TrafficRoutingConfig
ReadS [TrafficRoutingConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TrafficRoutingConfig]
$creadListPrec :: ReadPrec [TrafficRoutingConfig]
readPrec :: ReadPrec TrafficRoutingConfig
$creadPrec :: ReadPrec TrafficRoutingConfig
readList :: ReadS [TrafficRoutingConfig]
$creadList :: ReadS [TrafficRoutingConfig]
readsPrec :: Int -> ReadS TrafficRoutingConfig
$creadsPrec :: Int -> ReadS TrafficRoutingConfig
Prelude.Read, Int -> TrafficRoutingConfig -> ShowS
[TrafficRoutingConfig] -> ShowS
TrafficRoutingConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TrafficRoutingConfig] -> ShowS
$cshowList :: [TrafficRoutingConfig] -> ShowS
show :: TrafficRoutingConfig -> String
$cshow :: TrafficRoutingConfig -> String
showsPrec :: Int -> TrafficRoutingConfig -> ShowS
$cshowsPrec :: Int -> TrafficRoutingConfig -> ShowS
Prelude.Show, forall x. Rep TrafficRoutingConfig x -> TrafficRoutingConfig
forall x. TrafficRoutingConfig -> Rep TrafficRoutingConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TrafficRoutingConfig x -> TrafficRoutingConfig
$cfrom :: forall x. TrafficRoutingConfig -> Rep TrafficRoutingConfig x
Prelude.Generic)

-- |
-- Create a value of 'TrafficRoutingConfig' 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:
--
-- 'canarySize', 'trafficRoutingConfig_canarySize' - Batch size for the first step to turn on traffic on the new endpoint
-- fleet. @Value@ must be less than or equal to 50% of the variant\'s total
-- instance count.
--
-- 'linearStepSize', 'trafficRoutingConfig_linearStepSize' - Batch size for each step to turn on traffic on the new endpoint fleet.
-- @Value@ must be 10-50% of the variant\'s total instance count.
--
-- 'type'', 'trafficRoutingConfig_type' - Traffic routing strategy type.
--
-- -   @ALL_AT_ONCE@: Endpoint traffic shifts to the new fleet in a single
--     step.
--
-- -   @CANARY@: Endpoint traffic shifts to the new fleet in two steps. The
--     first step is the canary, which is a small portion of the traffic.
--     The second step is the remainder of the traffic.
--
-- -   @LINEAR@: Endpoint traffic shifts to the new fleet in n steps of a
--     configurable size.
--
-- 'waitIntervalInSeconds', 'trafficRoutingConfig_waitIntervalInSeconds' - The waiting time (in seconds) between incremental steps to turn on
-- traffic on the new endpoint fleet.
newTrafficRoutingConfig ::
  -- | 'type''
  TrafficRoutingConfigType ->
  -- | 'waitIntervalInSeconds'
  Prelude.Natural ->
  TrafficRoutingConfig
newTrafficRoutingConfig :: TrafficRoutingConfigType -> Natural -> TrafficRoutingConfig
newTrafficRoutingConfig
  TrafficRoutingConfigType
pType_
  Natural
pWaitIntervalInSeconds_ =
    TrafficRoutingConfig'
      { $sel:canarySize:TrafficRoutingConfig' :: Maybe CapacitySize
canarySize = forall a. Maybe a
Prelude.Nothing,
        $sel:linearStepSize:TrafficRoutingConfig' :: Maybe CapacitySize
linearStepSize = forall a. Maybe a
Prelude.Nothing,
        $sel:type':TrafficRoutingConfig' :: TrafficRoutingConfigType
type' = TrafficRoutingConfigType
pType_,
        $sel:waitIntervalInSeconds:TrafficRoutingConfig' :: Natural
waitIntervalInSeconds = Natural
pWaitIntervalInSeconds_
      }

-- | Batch size for the first step to turn on traffic on the new endpoint
-- fleet. @Value@ must be less than or equal to 50% of the variant\'s total
-- instance count.
trafficRoutingConfig_canarySize :: Lens.Lens' TrafficRoutingConfig (Prelude.Maybe CapacitySize)
trafficRoutingConfig_canarySize :: Lens' TrafficRoutingConfig (Maybe CapacitySize)
trafficRoutingConfig_canarySize = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrafficRoutingConfig' {Maybe CapacitySize
canarySize :: Maybe CapacitySize
$sel:canarySize:TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe CapacitySize
canarySize} -> Maybe CapacitySize
canarySize) (\s :: TrafficRoutingConfig
s@TrafficRoutingConfig' {} Maybe CapacitySize
a -> TrafficRoutingConfig
s {$sel:canarySize:TrafficRoutingConfig' :: Maybe CapacitySize
canarySize = Maybe CapacitySize
a} :: TrafficRoutingConfig)

-- | Batch size for each step to turn on traffic on the new endpoint fleet.
-- @Value@ must be 10-50% of the variant\'s total instance count.
trafficRoutingConfig_linearStepSize :: Lens.Lens' TrafficRoutingConfig (Prelude.Maybe CapacitySize)
trafficRoutingConfig_linearStepSize :: Lens' TrafficRoutingConfig (Maybe CapacitySize)
trafficRoutingConfig_linearStepSize = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrafficRoutingConfig' {Maybe CapacitySize
linearStepSize :: Maybe CapacitySize
$sel:linearStepSize:TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe CapacitySize
linearStepSize} -> Maybe CapacitySize
linearStepSize) (\s :: TrafficRoutingConfig
s@TrafficRoutingConfig' {} Maybe CapacitySize
a -> TrafficRoutingConfig
s {$sel:linearStepSize:TrafficRoutingConfig' :: Maybe CapacitySize
linearStepSize = Maybe CapacitySize
a} :: TrafficRoutingConfig)

-- | Traffic routing strategy type.
--
-- -   @ALL_AT_ONCE@: Endpoint traffic shifts to the new fleet in a single
--     step.
--
-- -   @CANARY@: Endpoint traffic shifts to the new fleet in two steps. The
--     first step is the canary, which is a small portion of the traffic.
--     The second step is the remainder of the traffic.
--
-- -   @LINEAR@: Endpoint traffic shifts to the new fleet in n steps of a
--     configurable size.
trafficRoutingConfig_type :: Lens.Lens' TrafficRoutingConfig TrafficRoutingConfigType
trafficRoutingConfig_type :: Lens' TrafficRoutingConfig TrafficRoutingConfigType
trafficRoutingConfig_type = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrafficRoutingConfig' {TrafficRoutingConfigType
type' :: TrafficRoutingConfigType
$sel:type':TrafficRoutingConfig' :: TrafficRoutingConfig -> TrafficRoutingConfigType
type'} -> TrafficRoutingConfigType
type') (\s :: TrafficRoutingConfig
s@TrafficRoutingConfig' {} TrafficRoutingConfigType
a -> TrafficRoutingConfig
s {$sel:type':TrafficRoutingConfig' :: TrafficRoutingConfigType
type' = TrafficRoutingConfigType
a} :: TrafficRoutingConfig)

-- | The waiting time (in seconds) between incremental steps to turn on
-- traffic on the new endpoint fleet.
trafficRoutingConfig_waitIntervalInSeconds :: Lens.Lens' TrafficRoutingConfig Prelude.Natural
trafficRoutingConfig_waitIntervalInSeconds :: Lens' TrafficRoutingConfig Natural
trafficRoutingConfig_waitIntervalInSeconds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TrafficRoutingConfig' {Natural
waitIntervalInSeconds :: Natural
$sel:waitIntervalInSeconds:TrafficRoutingConfig' :: TrafficRoutingConfig -> Natural
waitIntervalInSeconds} -> Natural
waitIntervalInSeconds) (\s :: TrafficRoutingConfig
s@TrafficRoutingConfig' {} Natural
a -> TrafficRoutingConfig
s {$sel:waitIntervalInSeconds:TrafficRoutingConfig' :: Natural
waitIntervalInSeconds = Natural
a} :: TrafficRoutingConfig)

instance Data.FromJSON TrafficRoutingConfig where
  parseJSON :: Value -> Parser TrafficRoutingConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TrafficRoutingConfig"
      ( \Object
x ->
          Maybe CapacitySize
-> Maybe CapacitySize
-> TrafficRoutingConfigType
-> Natural
-> TrafficRoutingConfig
TrafficRoutingConfig'
            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
"CanarySize")
            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
"LinearStepSize")
            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
"Type")
            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
"WaitIntervalInSeconds")
      )

instance Prelude.Hashable TrafficRoutingConfig where
  hashWithSalt :: Int -> TrafficRoutingConfig -> Int
hashWithSalt Int
_salt TrafficRoutingConfig' {Natural
Maybe CapacitySize
TrafficRoutingConfigType
waitIntervalInSeconds :: Natural
type' :: TrafficRoutingConfigType
linearStepSize :: Maybe CapacitySize
canarySize :: Maybe CapacitySize
$sel:waitIntervalInSeconds:TrafficRoutingConfig' :: TrafficRoutingConfig -> Natural
$sel:type':TrafficRoutingConfig' :: TrafficRoutingConfig -> TrafficRoutingConfigType
$sel:linearStepSize:TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe CapacitySize
$sel:canarySize:TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe CapacitySize
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CapacitySize
canarySize
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CapacitySize
linearStepSize
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` TrafficRoutingConfigType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
waitIntervalInSeconds

instance Prelude.NFData TrafficRoutingConfig where
  rnf :: TrafficRoutingConfig -> ()
rnf TrafficRoutingConfig' {Natural
Maybe CapacitySize
TrafficRoutingConfigType
waitIntervalInSeconds :: Natural
type' :: TrafficRoutingConfigType
linearStepSize :: Maybe CapacitySize
canarySize :: Maybe CapacitySize
$sel:waitIntervalInSeconds:TrafficRoutingConfig' :: TrafficRoutingConfig -> Natural
$sel:type':TrafficRoutingConfig' :: TrafficRoutingConfig -> TrafficRoutingConfigType
$sel:linearStepSize:TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe CapacitySize
$sel:canarySize:TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe CapacitySize
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe CapacitySize
canarySize
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe CapacitySize
linearStepSize
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf TrafficRoutingConfigType
type'
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
waitIntervalInSeconds

instance Data.ToJSON TrafficRoutingConfig where
  toJSON :: TrafficRoutingConfig -> Value
toJSON TrafficRoutingConfig' {Natural
Maybe CapacitySize
TrafficRoutingConfigType
waitIntervalInSeconds :: Natural
type' :: TrafficRoutingConfigType
linearStepSize :: Maybe CapacitySize
canarySize :: Maybe CapacitySize
$sel:waitIntervalInSeconds:TrafficRoutingConfig' :: TrafficRoutingConfig -> Natural
$sel:type':TrafficRoutingConfig' :: TrafficRoutingConfig -> TrafficRoutingConfigType
$sel:linearStepSize:TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe CapacitySize
$sel:canarySize:TrafficRoutingConfig' :: TrafficRoutingConfig -> Maybe CapacitySize
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CanarySize" 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 CapacitySize
canarySize,
            (Key
"LinearStepSize" 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 CapacitySize
linearStepSize,
            forall a. a -> Maybe a
Prelude.Just (Key
"Type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= TrafficRoutingConfigType
type'),
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"WaitIntervalInSeconds"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
waitIntervalInSeconds
              )
          ]
      )