{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | Information about minimum healthy instance.
--
-- /See:/ 'newMinimumHealthyHosts' smart constructor.
data MinimumHealthyHosts = 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,
    -- 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 CodeDeploy Instance Health>
    -- in the /CodeDeploy User Guide/.
    MinimumHealthyHosts -> Maybe MinimumHealthyHostsType
type' :: Prelude.Maybe MinimumHealthyHostsType,
    -- | The minimum healthy instance value.
    MinimumHealthyHosts -> Maybe Int
value :: Prelude.Maybe Prelude.Int
  }
  deriving (MinimumHealthyHosts -> MinimumHealthyHosts -> Bool
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]
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
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. 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:
--
-- '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,
-- 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 CodeDeploy Instance Health>
-- in the /CodeDeploy User Guide/.
--
-- 'value', 'minimumHealthyHosts_value' - The minimum healthy instance value.
newMinimumHealthyHosts ::
  MinimumHealthyHosts
newMinimumHealthyHosts :: MinimumHealthyHosts
newMinimumHealthyHosts =
  MinimumHealthyHosts'
    { $sel:type':MinimumHealthyHosts' :: Maybe MinimumHealthyHostsType
type' = forall a. Maybe a
Prelude.Nothing,
      $sel:value:MinimumHealthyHosts' :: Maybe Int
value = forall a. Maybe a
Prelude.Nothing
    }

-- | 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,
-- 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 CodeDeploy Instance Health>
-- in the /CodeDeploy User Guide/.
minimumHealthyHosts_type :: Lens.Lens' MinimumHealthyHosts (Prelude.Maybe MinimumHealthyHostsType)
minimumHealthyHosts_type :: Lens' MinimumHealthyHosts (Maybe MinimumHealthyHostsType)
minimumHealthyHosts_type = 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)

-- | The minimum healthy instance value.
minimumHealthyHosts_value :: Lens.Lens' MinimumHealthyHosts (Prelude.Maybe Prelude.Int)
minimumHealthyHosts_value :: Lens' MinimumHealthyHosts (Maybe Int)
minimumHealthyHosts_value = 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)

instance Data.FromJSON MinimumHealthyHosts where
  parseJSON :: Value -> Parser MinimumHealthyHosts
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MinimumHealthyHosts"
      ( \Object
x ->
          Maybe MinimumHealthyHostsType -> Maybe Int -> MinimumHealthyHosts
MinimumHealthyHosts'
            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
"type")
            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
"value")
      )

instance Prelude.Hashable MinimumHealthyHosts where
  hashWithSalt :: Int -> MinimumHealthyHosts -> Int
hashWithSalt Int
_salt MinimumHealthyHosts' {Maybe Int
Maybe MinimumHealthyHostsType
value :: Maybe Int
type' :: Maybe MinimumHealthyHostsType
$sel:value:MinimumHealthyHosts' :: MinimumHealthyHosts -> Maybe Int
$sel:type':MinimumHealthyHosts' :: MinimumHealthyHosts -> Maybe MinimumHealthyHostsType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe MinimumHealthyHostsType
type'
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
value

instance Prelude.NFData MinimumHealthyHosts where
  rnf :: MinimumHealthyHosts -> ()
rnf MinimumHealthyHosts' {Maybe Int
Maybe MinimumHealthyHostsType
value :: Maybe Int
type' :: Maybe MinimumHealthyHostsType
$sel:value:MinimumHealthyHosts' :: MinimumHealthyHosts -> Maybe Int
$sel:type':MinimumHealthyHosts' :: MinimumHealthyHosts -> Maybe MinimumHealthyHostsType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe MinimumHealthyHostsType
type' seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
value

instance Data.ToJSON MinimumHealthyHosts where
  toJSON :: MinimumHealthyHosts -> Value
toJSON MinimumHealthyHosts' {Maybe Int
Maybe MinimumHealthyHostsType
value :: Maybe Int
type' :: Maybe MinimumHealthyHostsType
$sel:value:MinimumHealthyHosts' :: MinimumHealthyHosts -> Maybe Int
$sel:type':MinimumHealthyHosts' :: MinimumHealthyHosts -> Maybe MinimumHealthyHostsType
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"type" 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 MinimumHealthyHostsType
type',
            (Key
"value" 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 Int
value
          ]
      )