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

-- | One of the methods which provide a way for you to quickly identify when
-- a deployment has failed, and then to optionally roll back the failure to
-- the last working deployment.
--
-- When the alarms are generated, Amazon ECS sets the service deployment to
-- failed. Set the rollback parameter to have Amazon ECS to roll back your
-- service to the last completed deployment after a failure.
--
-- You can only use the @DeploymentAlarms@ method to detect failures when
-- the @DeploymentController@ is set to @ECS@ (rolling update).
--
-- 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:/ 'newDeploymentAlarms' smart constructor.
data DeploymentAlarms = DeploymentAlarms'
  { -- | One or more CloudWatch alarm names. Use a \",\" to separate the alarms.
    DeploymentAlarms -> [Text]
alarmNames :: [Prelude.Text],
    -- | Determines whether to use the CloudWatch alarm option in the service
    -- deployment process.
    DeploymentAlarms -> Bool
enable :: Prelude.Bool,
    -- | Determines whether to configure Amazon ECS to roll back the service if a
    -- service deployment fails. If rollback is used, when a service deployment
    -- fails, the service is rolled back to the last deployment that completed
    -- successfully.
    DeploymentAlarms -> Bool
rollback :: Prelude.Bool
  }
  deriving (DeploymentAlarms -> DeploymentAlarms -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeploymentAlarms -> DeploymentAlarms -> Bool
$c/= :: DeploymentAlarms -> DeploymentAlarms -> Bool
== :: DeploymentAlarms -> DeploymentAlarms -> Bool
$c== :: DeploymentAlarms -> DeploymentAlarms -> Bool
Prelude.Eq, ReadPrec [DeploymentAlarms]
ReadPrec DeploymentAlarms
Int -> ReadS DeploymentAlarms
ReadS [DeploymentAlarms]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeploymentAlarms]
$creadListPrec :: ReadPrec [DeploymentAlarms]
readPrec :: ReadPrec DeploymentAlarms
$creadPrec :: ReadPrec DeploymentAlarms
readList :: ReadS [DeploymentAlarms]
$creadList :: ReadS [DeploymentAlarms]
readsPrec :: Int -> ReadS DeploymentAlarms
$creadsPrec :: Int -> ReadS DeploymentAlarms
Prelude.Read, Int -> DeploymentAlarms -> ShowS
[DeploymentAlarms] -> ShowS
DeploymentAlarms -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeploymentAlarms] -> ShowS
$cshowList :: [DeploymentAlarms] -> ShowS
show :: DeploymentAlarms -> String
$cshow :: DeploymentAlarms -> String
showsPrec :: Int -> DeploymentAlarms -> ShowS
$cshowsPrec :: Int -> DeploymentAlarms -> ShowS
Prelude.Show, forall x. Rep DeploymentAlarms x -> DeploymentAlarms
forall x. DeploymentAlarms -> Rep DeploymentAlarms x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeploymentAlarms x -> DeploymentAlarms
$cfrom :: forall x. DeploymentAlarms -> Rep DeploymentAlarms x
Prelude.Generic)

-- |
-- Create a value of 'DeploymentAlarms' 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:
--
-- 'alarmNames', 'deploymentAlarms_alarmNames' - One or more CloudWatch alarm names. Use a \",\" to separate the alarms.
--
-- 'enable', 'deploymentAlarms_enable' - Determines whether to use the CloudWatch alarm option in the service
-- deployment process.
--
-- 'rollback', 'deploymentAlarms_rollback' - Determines whether to configure Amazon ECS to roll back the service if a
-- service deployment fails. If rollback is used, when a service deployment
-- fails, the service is rolled back to the last deployment that completed
-- successfully.
newDeploymentAlarms ::
  -- | 'enable'
  Prelude.Bool ->
  -- | 'rollback'
  Prelude.Bool ->
  DeploymentAlarms
newDeploymentAlarms :: Bool -> Bool -> DeploymentAlarms
newDeploymentAlarms Bool
pEnable_ Bool
pRollback_ =
  DeploymentAlarms'
    { $sel:alarmNames:DeploymentAlarms' :: [Text]
alarmNames = forall a. Monoid a => a
Prelude.mempty,
      $sel:enable:DeploymentAlarms' :: Bool
enable = Bool
pEnable_,
      $sel:rollback:DeploymentAlarms' :: Bool
rollback = Bool
pRollback_
    }

-- | One or more CloudWatch alarm names. Use a \",\" to separate the alarms.
deploymentAlarms_alarmNames :: Lens.Lens' DeploymentAlarms [Prelude.Text]
deploymentAlarms_alarmNames :: Lens' DeploymentAlarms [Text]
deploymentAlarms_alarmNames = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentAlarms' {[Text]
alarmNames :: [Text]
$sel:alarmNames:DeploymentAlarms' :: DeploymentAlarms -> [Text]
alarmNames} -> [Text]
alarmNames) (\s :: DeploymentAlarms
s@DeploymentAlarms' {} [Text]
a -> DeploymentAlarms
s {$sel:alarmNames:DeploymentAlarms' :: [Text]
alarmNames = [Text]
a} :: DeploymentAlarms) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Determines whether to use the CloudWatch alarm option in the service
-- deployment process.
deploymentAlarms_enable :: Lens.Lens' DeploymentAlarms Prelude.Bool
deploymentAlarms_enable :: Lens' DeploymentAlarms Bool
deploymentAlarms_enable = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentAlarms' {Bool
enable :: Bool
$sel:enable:DeploymentAlarms' :: DeploymentAlarms -> Bool
enable} -> Bool
enable) (\s :: DeploymentAlarms
s@DeploymentAlarms' {} Bool
a -> DeploymentAlarms
s {$sel:enable:DeploymentAlarms' :: Bool
enable = Bool
a} :: DeploymentAlarms)

-- | Determines whether to configure Amazon ECS to roll back the service if a
-- service deployment fails. If rollback is used, when a service deployment
-- fails, the service is rolled back to the last deployment that completed
-- successfully.
deploymentAlarms_rollback :: Lens.Lens' DeploymentAlarms Prelude.Bool
deploymentAlarms_rollback :: Lens' DeploymentAlarms Bool
deploymentAlarms_rollback = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentAlarms' {Bool
rollback :: Bool
$sel:rollback:DeploymentAlarms' :: DeploymentAlarms -> Bool
rollback} -> Bool
rollback) (\s :: DeploymentAlarms
s@DeploymentAlarms' {} Bool
a -> DeploymentAlarms
s {$sel:rollback:DeploymentAlarms' :: Bool
rollback = Bool
a} :: DeploymentAlarms)

instance Data.FromJSON DeploymentAlarms where
  parseJSON :: Value -> Parser DeploymentAlarms
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DeploymentAlarms"
      ( \Object
x ->
          [Text] -> Bool -> Bool -> DeploymentAlarms
DeploymentAlarms'
            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
"alarmNames" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"enable")
            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
"rollback")
      )

instance Prelude.Hashable DeploymentAlarms where
  hashWithSalt :: Int -> DeploymentAlarms -> Int
hashWithSalt Int
_salt DeploymentAlarms' {Bool
[Text]
rollback :: Bool
enable :: Bool
alarmNames :: [Text]
$sel:rollback:DeploymentAlarms' :: DeploymentAlarms -> Bool
$sel:enable:DeploymentAlarms' :: DeploymentAlarms -> Bool
$sel:alarmNames:DeploymentAlarms' :: DeploymentAlarms -> [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
alarmNames
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
enable
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Bool
rollback

instance Prelude.NFData DeploymentAlarms where
  rnf :: DeploymentAlarms -> ()
rnf DeploymentAlarms' {Bool
[Text]
rollback :: Bool
enable :: Bool
alarmNames :: [Text]
$sel:rollback:DeploymentAlarms' :: DeploymentAlarms -> Bool
$sel:enable:DeploymentAlarms' :: DeploymentAlarms -> Bool
$sel:alarmNames:DeploymentAlarms' :: DeploymentAlarms -> [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf [Text]
alarmNames
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Bool
enable
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Bool
rollback

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