{-# 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.ECS.Types.DeploymentCircuitBreaker
-- 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.ECS.Types.DeploymentCircuitBreaker where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The deployment circuit breaker can only be used for services using the
-- rolling update (@ECS@) deployment type that are not behind a Classic
-- Load Balancer.
--
-- The __deployment circuit breaker__ determines whether a service
-- deployment will fail if the service can\'t reach a steady state. If
-- enabled, a service deployment will transition to a failed state and stop
-- launching new tasks. You can also enable Amazon ECS to roll back your
-- service to the last completed deployment after a failure. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-type-ecs.html Rolling update>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- /See:/ 'newDeploymentCircuitBreaker' smart constructor.
data DeploymentCircuitBreaker = DeploymentCircuitBreaker'
  { -- | Whether to enable the deployment circuit breaker logic for the service.
    DeploymentCircuitBreaker -> Bool
enable :: Prelude.Bool,
    -- | Whether to enable Amazon ECS to roll back the service if a service
    -- deployment fails. If rollback is enabled, when a service deployment
    -- fails, the service is rolled back to the last deployment that completed
    -- successfully.
    DeploymentCircuitBreaker -> Bool
rollback :: Prelude.Bool
  }
  deriving (DeploymentCircuitBreaker -> DeploymentCircuitBreaker -> Bool
(DeploymentCircuitBreaker -> DeploymentCircuitBreaker -> Bool)
-> (DeploymentCircuitBreaker -> DeploymentCircuitBreaker -> Bool)
-> Eq DeploymentCircuitBreaker
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeploymentCircuitBreaker -> DeploymentCircuitBreaker -> Bool
$c/= :: DeploymentCircuitBreaker -> DeploymentCircuitBreaker -> Bool
== :: DeploymentCircuitBreaker -> DeploymentCircuitBreaker -> Bool
$c== :: DeploymentCircuitBreaker -> DeploymentCircuitBreaker -> Bool
Prelude.Eq, ReadPrec [DeploymentCircuitBreaker]
ReadPrec DeploymentCircuitBreaker
Int -> ReadS DeploymentCircuitBreaker
ReadS [DeploymentCircuitBreaker]
(Int -> ReadS DeploymentCircuitBreaker)
-> ReadS [DeploymentCircuitBreaker]
-> ReadPrec DeploymentCircuitBreaker
-> ReadPrec [DeploymentCircuitBreaker]
-> Read DeploymentCircuitBreaker
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeploymentCircuitBreaker]
$creadListPrec :: ReadPrec [DeploymentCircuitBreaker]
readPrec :: ReadPrec DeploymentCircuitBreaker
$creadPrec :: ReadPrec DeploymentCircuitBreaker
readList :: ReadS [DeploymentCircuitBreaker]
$creadList :: ReadS [DeploymentCircuitBreaker]
readsPrec :: Int -> ReadS DeploymentCircuitBreaker
$creadsPrec :: Int -> ReadS DeploymentCircuitBreaker
Prelude.Read, Int -> DeploymentCircuitBreaker -> ShowS
[DeploymentCircuitBreaker] -> ShowS
DeploymentCircuitBreaker -> String
(Int -> DeploymentCircuitBreaker -> ShowS)
-> (DeploymentCircuitBreaker -> String)
-> ([DeploymentCircuitBreaker] -> ShowS)
-> Show DeploymentCircuitBreaker
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeploymentCircuitBreaker] -> ShowS
$cshowList :: [DeploymentCircuitBreaker] -> ShowS
show :: DeploymentCircuitBreaker -> String
$cshow :: DeploymentCircuitBreaker -> String
showsPrec :: Int -> DeploymentCircuitBreaker -> ShowS
$cshowsPrec :: Int -> DeploymentCircuitBreaker -> ShowS
Prelude.Show, (forall x.
 DeploymentCircuitBreaker -> Rep DeploymentCircuitBreaker x)
-> (forall x.
    Rep DeploymentCircuitBreaker x -> DeploymentCircuitBreaker)
-> Generic DeploymentCircuitBreaker
forall x.
Rep DeploymentCircuitBreaker x -> DeploymentCircuitBreaker
forall x.
DeploymentCircuitBreaker -> Rep DeploymentCircuitBreaker x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DeploymentCircuitBreaker x -> DeploymentCircuitBreaker
$cfrom :: forall x.
DeploymentCircuitBreaker -> Rep DeploymentCircuitBreaker x
Prelude.Generic)

-- |
-- Create a value of 'DeploymentCircuitBreaker' 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:
--
-- 'enable', 'deploymentCircuitBreaker_enable' - Whether to enable the deployment circuit breaker logic for the service.
--
-- 'rollback', 'deploymentCircuitBreaker_rollback' - Whether to enable Amazon ECS to roll back the service if a service
-- deployment fails. If rollback is enabled, when a service deployment
-- fails, the service is rolled back to the last deployment that completed
-- successfully.
newDeploymentCircuitBreaker ::
  -- | 'enable'
  Prelude.Bool ->
  -- | 'rollback'
  Prelude.Bool ->
  DeploymentCircuitBreaker
newDeploymentCircuitBreaker :: Bool -> Bool -> DeploymentCircuitBreaker
newDeploymentCircuitBreaker Bool
pEnable_ Bool
pRollback_ =
  DeploymentCircuitBreaker' :: Bool -> Bool -> DeploymentCircuitBreaker
DeploymentCircuitBreaker'
    { $sel:enable:DeploymentCircuitBreaker' :: Bool
enable = Bool
pEnable_,
      $sel:rollback:DeploymentCircuitBreaker' :: Bool
rollback = Bool
pRollback_
    }

-- | Whether to enable the deployment circuit breaker logic for the service.
deploymentCircuitBreaker_enable :: Lens.Lens' DeploymentCircuitBreaker Prelude.Bool
deploymentCircuitBreaker_enable :: (Bool -> f Bool)
-> DeploymentCircuitBreaker -> f DeploymentCircuitBreaker
deploymentCircuitBreaker_enable = (DeploymentCircuitBreaker -> Bool)
-> (DeploymentCircuitBreaker -> Bool -> DeploymentCircuitBreaker)
-> Lens DeploymentCircuitBreaker DeploymentCircuitBreaker Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentCircuitBreaker' {Bool
enable :: Bool
$sel:enable:DeploymentCircuitBreaker' :: DeploymentCircuitBreaker -> Bool
enable} -> Bool
enable) (\s :: DeploymentCircuitBreaker
s@DeploymentCircuitBreaker' {} Bool
a -> DeploymentCircuitBreaker
s {$sel:enable:DeploymentCircuitBreaker' :: Bool
enable = Bool
a} :: DeploymentCircuitBreaker)

-- | Whether to enable Amazon ECS to roll back the service if a service
-- deployment fails. If rollback is enabled, when a service deployment
-- fails, the service is rolled back to the last deployment that completed
-- successfully.
deploymentCircuitBreaker_rollback :: Lens.Lens' DeploymentCircuitBreaker Prelude.Bool
deploymentCircuitBreaker_rollback :: (Bool -> f Bool)
-> DeploymentCircuitBreaker -> f DeploymentCircuitBreaker
deploymentCircuitBreaker_rollback = (DeploymentCircuitBreaker -> Bool)
-> (DeploymentCircuitBreaker -> Bool -> DeploymentCircuitBreaker)
-> Lens DeploymentCircuitBreaker DeploymentCircuitBreaker Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentCircuitBreaker' {Bool
rollback :: Bool
$sel:rollback:DeploymentCircuitBreaker' :: DeploymentCircuitBreaker -> Bool
rollback} -> Bool
rollback) (\s :: DeploymentCircuitBreaker
s@DeploymentCircuitBreaker' {} Bool
a -> DeploymentCircuitBreaker
s {$sel:rollback:DeploymentCircuitBreaker' :: Bool
rollback = Bool
a} :: DeploymentCircuitBreaker)

instance Core.FromJSON DeploymentCircuitBreaker where
  parseJSON :: Value -> Parser DeploymentCircuitBreaker
parseJSON =
    String
-> (Object -> Parser DeploymentCircuitBreaker)
-> Value
-> Parser DeploymentCircuitBreaker
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DeploymentCircuitBreaker"
      ( \Object
x ->
          Bool -> Bool -> DeploymentCircuitBreaker
DeploymentCircuitBreaker'
            (Bool -> Bool -> DeploymentCircuitBreaker)
-> Parser Bool -> Parser (Bool -> DeploymentCircuitBreaker)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"enable")
            Parser (Bool -> DeploymentCircuitBreaker)
-> Parser Bool -> Parser DeploymentCircuitBreaker
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"rollback")
      )

instance Prelude.Hashable DeploymentCircuitBreaker

instance Prelude.NFData DeploymentCircuitBreaker

instance Core.ToJSON DeploymentCircuitBreaker where
  toJSON :: DeploymentCircuitBreaker -> Value
toJSON DeploymentCircuitBreaker' {Bool
rollback :: Bool
enable :: Bool
$sel:rollback:DeploymentCircuitBreaker' :: DeploymentCircuitBreaker -> Bool
$sel:enable:DeploymentCircuitBreaker' :: DeploymentCircuitBreaker -> Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"enable" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Bool
enable),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"rollback" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Bool
rollback)
          ]
      )