{-# 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.CodeDeploy.Types.MinimumHealthyHosts
-- 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.CodeDeploy.Types.MinimumHealthyHosts where

import Amazonka.CodeDeploy.Types.MinimumHealthyHostsType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about minimum healthy instance.
--
-- /See:/ 'newMinimumHealthyHosts' smart constructor.
data MinimumHealthyHosts = MinimumHealthyHosts'
  { -- | The minimum healthy instance value.
    MinimumHealthyHosts -> Maybe Int
value :: Prelude.Maybe Prelude.Int,
    -- | The minimum healthy instance type:
    --
    -- -   @HOST_COUNT@: The minimum number of healthy instances as an absolute
    --     value.
    --
    -- -   @FLEET_PERCENT@: The minimum number of healthy instances as a
    --     percentage of the total number of instances in the deployment.
    --
    -- In an example of nine instances, if a HOST_COUNT of six is specified,
    -- deploy to up to three instances at a time. The deployment is successful
    -- if six or more instances are deployed to successfully. Otherwise, the
    -- deployment fails. If a FLEET_PERCENT of 40 is specified, deploy to up to
    -- five instances at a time. The deployment is successful if four or more
    -- instances are deployed to successfully. Otherwise, the deployment fails.
    --
    -- In a call to the @GetDeploymentConfig@, CodeDeployDefault.OneAtATime
    -- returns a minimum healthy instance type of MOST_CONCURRENCY and a value
    -- of 1. This means a deployment to only one instance at a time. (You
    -- cannot set the type to MOST_CONCURRENCY, only to HOST_COUNT or
    -- FLEET_PERCENT.) In addition, with CodeDeployDefault.OneAtATime, AWS
    -- CodeDeploy attempts to ensure that all instances but one are kept in a
    -- healthy state during the deployment. Although this allows one instance
    -- at a time to be taken offline for a new deployment, it also means that
    -- if the deployment to the last instance fails, the overall deployment is
    -- still successful.
    --
    -- For more information, see
    -- <https://docs.aws.amazon.com/codedeploy/latest/userguide/instances-health.html AWS CodeDeploy Instance Health>
    -- in the /AWS CodeDeploy User Guide/.
    MinimumHealthyHosts -> Maybe MinimumHealthyHostsType
type' :: Prelude.Maybe MinimumHealthyHostsType
  }
  deriving (MinimumHealthyHosts -> MinimumHealthyHosts -> Bool
(MinimumHealthyHosts -> MinimumHealthyHosts -> Bool)
-> (MinimumHealthyHosts -> MinimumHealthyHosts -> Bool)
-> Eq MinimumHealthyHosts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MinimumHealthyHosts -> MinimumHealthyHosts -> Bool
$c/= :: MinimumHealthyHosts -> MinimumHealthyHosts -> Bool
== :: MinimumHealthyHosts -> MinimumHealthyHosts -> Bool
$c== :: MinimumHealthyHosts -> MinimumHealthyHosts -> Bool
Prelude.Eq, ReadPrec [MinimumHealthyHosts]
ReadPrec MinimumHealthyHosts
Int -> ReadS MinimumHealthyHosts
ReadS [MinimumHealthyHosts]
(Int -> ReadS MinimumHealthyHosts)
-> ReadS [MinimumHealthyHosts]
-> ReadPrec MinimumHealthyHosts
-> ReadPrec [MinimumHealthyHosts]
-> Read MinimumHealthyHosts
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MinimumHealthyHosts]
$creadListPrec :: ReadPrec [MinimumHealthyHosts]
readPrec :: ReadPrec MinimumHealthyHosts
$creadPrec :: ReadPrec MinimumHealthyHosts
readList :: ReadS [MinimumHealthyHosts]
$creadList :: ReadS [MinimumHealthyHosts]
readsPrec :: Int -> ReadS MinimumHealthyHosts
$creadsPrec :: Int -> ReadS MinimumHealthyHosts
Prelude.Read, Int -> MinimumHealthyHosts -> ShowS
[MinimumHealthyHosts] -> ShowS
MinimumHealthyHosts -> String
(Int -> MinimumHealthyHosts -> ShowS)
-> (MinimumHealthyHosts -> String)
-> ([MinimumHealthyHosts] -> ShowS)
-> Show MinimumHealthyHosts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MinimumHealthyHosts] -> ShowS
$cshowList :: [MinimumHealthyHosts] -> ShowS
show :: MinimumHealthyHosts -> String
$cshow :: MinimumHealthyHosts -> String
showsPrec :: Int -> MinimumHealthyHosts -> ShowS
$cshowsPrec :: Int -> MinimumHealthyHosts -> ShowS
Prelude.Show, (forall x. MinimumHealthyHosts -> Rep MinimumHealthyHosts x)
-> (forall x. Rep MinimumHealthyHosts x -> MinimumHealthyHosts)
-> Generic MinimumHealthyHosts
forall x. Rep MinimumHealthyHosts x -> MinimumHealthyHosts
forall x. MinimumHealthyHosts -> Rep MinimumHealthyHosts x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MinimumHealthyHosts x -> MinimumHealthyHosts
$cfrom :: forall x. MinimumHealthyHosts -> Rep MinimumHealthyHosts x
Prelude.Generic)

-- |
-- Create a value of 'MinimumHealthyHosts' 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:
--
-- 'value', 'minimumHealthyHosts_value' - The minimum healthy instance value.
--
-- 'type'', 'minimumHealthyHosts_type' - The minimum healthy instance type:
--
-- -   @HOST_COUNT@: The minimum number of healthy instances as an absolute
--     value.
--
-- -   @FLEET_PERCENT@: The minimum number of healthy instances as a
--     percentage of the total number of instances in the deployment.
--
-- In an example of nine instances, if a HOST_COUNT of six is specified,
-- deploy to up to three instances at a time. The deployment is successful
-- if six or more instances are deployed to successfully. Otherwise, the
-- deployment fails. If a FLEET_PERCENT of 40 is specified, deploy to up to
-- five instances at a time. The deployment is successful if four or more
-- instances are deployed to successfully. Otherwise, the deployment fails.
--
-- In a call to the @GetDeploymentConfig@, CodeDeployDefault.OneAtATime
-- returns a minimum healthy instance type of MOST_CONCURRENCY and a value
-- of 1. This means a deployment to only one instance at a time. (You
-- cannot set the type to MOST_CONCURRENCY, only to HOST_COUNT or
-- FLEET_PERCENT.) In addition, with CodeDeployDefault.OneAtATime, AWS
-- CodeDeploy attempts to ensure that all instances but one are kept in a
-- healthy state during the deployment. Although this allows one instance
-- at a time to be taken offline for a new deployment, it also means that
-- if the deployment to the last instance fails, the overall deployment is
-- still successful.
--
-- For more information, see
-- <https://docs.aws.amazon.com/codedeploy/latest/userguide/instances-health.html AWS CodeDeploy Instance Health>
-- in the /AWS CodeDeploy User Guide/.
newMinimumHealthyHosts ::
  MinimumHealthyHosts
newMinimumHealthyHosts :: MinimumHealthyHosts
newMinimumHealthyHosts =
  MinimumHealthyHosts' :: Maybe Int -> Maybe MinimumHealthyHostsType -> MinimumHealthyHosts
MinimumHealthyHosts'
    { $sel:value:MinimumHealthyHosts' :: Maybe Int
value = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:type':MinimumHealthyHosts' :: Maybe MinimumHealthyHostsType
type' = Maybe MinimumHealthyHostsType
forall a. Maybe a
Prelude.Nothing
    }

-- | The minimum healthy instance value.
minimumHealthyHosts_value :: Lens.Lens' MinimumHealthyHosts (Prelude.Maybe Prelude.Int)
minimumHealthyHosts_value :: (Maybe Int -> f (Maybe Int))
-> MinimumHealthyHosts -> f MinimumHealthyHosts
minimumHealthyHosts_value = (MinimumHealthyHosts -> Maybe Int)
-> (MinimumHealthyHosts -> Maybe Int -> MinimumHealthyHosts)
-> Lens
     MinimumHealthyHosts MinimumHealthyHosts (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MinimumHealthyHosts' {Maybe Int
value :: Maybe Int
$sel:value:MinimumHealthyHosts' :: MinimumHealthyHosts -> Maybe Int
value} -> Maybe Int
value) (\s :: MinimumHealthyHosts
s@MinimumHealthyHosts' {} Maybe Int
a -> MinimumHealthyHosts
s {$sel:value:MinimumHealthyHosts' :: Maybe Int
value = Maybe Int
a} :: MinimumHealthyHosts)

-- | The minimum healthy instance type:
--
-- -   @HOST_COUNT@: The minimum number of healthy instances as an absolute
--     value.
--
-- -   @FLEET_PERCENT@: The minimum number of healthy instances as a
--     percentage of the total number of instances in the deployment.
--
-- In an example of nine instances, if a HOST_COUNT of six is specified,
-- deploy to up to three instances at a time. The deployment is successful
-- if six or more instances are deployed to successfully. Otherwise, the
-- deployment fails. If a FLEET_PERCENT of 40 is specified, deploy to up to
-- five instances at a time. The deployment is successful if four or more
-- instances are deployed to successfully. Otherwise, the deployment fails.
--
-- In a call to the @GetDeploymentConfig@, CodeDeployDefault.OneAtATime
-- returns a minimum healthy instance type of MOST_CONCURRENCY and a value
-- of 1. This means a deployment to only one instance at a time. (You
-- cannot set the type to MOST_CONCURRENCY, only to HOST_COUNT or
-- FLEET_PERCENT.) In addition, with CodeDeployDefault.OneAtATime, AWS
-- CodeDeploy attempts to ensure that all instances but one are kept in a
-- healthy state during the deployment. Although this allows one instance
-- at a time to be taken offline for a new deployment, it also means that
-- if the deployment to the last instance fails, the overall deployment is
-- still successful.
--
-- For more information, see
-- <https://docs.aws.amazon.com/codedeploy/latest/userguide/instances-health.html AWS CodeDeploy Instance Health>
-- in the /AWS CodeDeploy User Guide/.
minimumHealthyHosts_type :: Lens.Lens' MinimumHealthyHosts (Prelude.Maybe MinimumHealthyHostsType)
minimumHealthyHosts_type :: (Maybe MinimumHealthyHostsType
 -> f (Maybe MinimumHealthyHostsType))
-> MinimumHealthyHosts -> f MinimumHealthyHosts
minimumHealthyHosts_type = (MinimumHealthyHosts -> Maybe MinimumHealthyHostsType)
-> (MinimumHealthyHosts
    -> Maybe MinimumHealthyHostsType -> MinimumHealthyHosts)
-> Lens
     MinimumHealthyHosts
     MinimumHealthyHosts
     (Maybe MinimumHealthyHostsType)
     (Maybe MinimumHealthyHostsType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MinimumHealthyHosts' {Maybe MinimumHealthyHostsType
type' :: Maybe MinimumHealthyHostsType
$sel:type':MinimumHealthyHosts' :: MinimumHealthyHosts -> Maybe MinimumHealthyHostsType
type'} -> Maybe MinimumHealthyHostsType
type') (\s :: MinimumHealthyHosts
s@MinimumHealthyHosts' {} Maybe MinimumHealthyHostsType
a -> MinimumHealthyHosts
s {$sel:type':MinimumHealthyHosts' :: Maybe MinimumHealthyHostsType
type' = Maybe MinimumHealthyHostsType
a} :: MinimumHealthyHosts)

instance Core.FromJSON MinimumHealthyHosts where
  parseJSON :: Value -> Parser MinimumHealthyHosts
parseJSON =
    String
-> (Object -> Parser MinimumHealthyHosts)
-> Value
-> Parser MinimumHealthyHosts
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MinimumHealthyHosts"
      ( \Object
x ->
          Maybe Int -> Maybe MinimumHealthyHostsType -> MinimumHealthyHosts
MinimumHealthyHosts'
            (Maybe Int -> Maybe MinimumHealthyHostsType -> MinimumHealthyHosts)
-> Parser (Maybe Int)
-> Parser (Maybe MinimumHealthyHostsType -> MinimumHealthyHosts)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"value") Parser (Maybe MinimumHealthyHostsType -> MinimumHealthyHosts)
-> Parser (Maybe MinimumHealthyHostsType)
-> Parser MinimumHealthyHosts
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe MinimumHealthyHostsType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"type")
      )

instance Prelude.Hashable MinimumHealthyHosts

instance Prelude.NFData MinimumHealthyHosts

instance Core.ToJSON MinimumHealthyHosts where
  toJSON :: MinimumHealthyHosts -> Value
toJSON MinimumHealthyHosts' {Maybe Int
Maybe MinimumHealthyHostsType
type' :: Maybe MinimumHealthyHostsType
value :: Maybe Int
$sel:type':MinimumHealthyHosts' :: MinimumHealthyHosts -> Maybe MinimumHealthyHostsType
$sel:value:MinimumHealthyHosts' :: MinimumHealthyHosts -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"value" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
value,
            (Text
"type" Text -> MinimumHealthyHostsType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (MinimumHealthyHostsType -> Pair)
-> Maybe MinimumHealthyHostsType -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe MinimumHealthyHostsType
type'
          ]
      )