{-# 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.ELBV2.Types.TargetHealth
-- 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.ELBV2.Types.TargetHealth where

import qualified Amazonka.Core as Core
import Amazonka.ELBV2.Types.TargetHealthReasonEnum
import Amazonka.ELBV2.Types.TargetHealthStateEnum
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about the current health of a target.
--
-- /See:/ 'newTargetHealth' smart constructor.
data TargetHealth = TargetHealth'
  { -- | The state of the target.
    TargetHealth -> Maybe TargetHealthStateEnum
state :: Prelude.Maybe TargetHealthStateEnum,
    -- | The reason code.
    --
    -- If the target state is @healthy@, a reason code is not provided.
    --
    -- If the target state is @initial@, the reason code can be one of the
    -- following values:
    --
    -- -   @Elb.RegistrationInProgress@ - The target is in the process of being
    --     registered with the load balancer.
    --
    -- -   @Elb.InitialHealthChecking@ - The load balancer is still sending the
    --     target the minimum number of health checks required to determine its
    --     health status.
    --
    -- If the target state is @unhealthy@, the reason code can be one of the
    -- following values:
    --
    -- -   @Target.ResponseCodeMismatch@ - The health checks did not return an
    --     expected HTTP code. Applies only to Application Load Balancers and
    --     Gateway Load Balancers.
    --
    -- -   @Target.Timeout@ - The health check requests timed out. Applies only
    --     to Application Load Balancers and Gateway Load Balancers.
    --
    -- -   @Target.FailedHealthChecks@ - The load balancer received an error
    --     while establishing a connection to the target or the target response
    --     was malformed.
    --
    -- -   @Elb.InternalError@ - The health checks failed due to an internal
    --     error. Applies only to Application Load Balancers.
    --
    -- If the target state is @unused@, the reason code can be one of the
    -- following values:
    --
    -- -   @Target.NotRegistered@ - The target is not registered with the
    --     target group.
    --
    -- -   @Target.NotInUse@ - The target group is not used by any load
    --     balancer or the target is in an Availability Zone that is not
    --     enabled for its load balancer.
    --
    -- -   @Target.InvalidState@ - The target is in the stopped or terminated
    --     state.
    --
    -- -   @Target.IpUnusable@ - The target IP address is reserved for use by a
    --     load balancer.
    --
    -- If the target state is @draining@, the reason code can be the following
    -- value:
    --
    -- -   @Target.DeregistrationInProgress@ - The target is in the process of
    --     being deregistered and the deregistration delay period has not
    --     expired.
    --
    -- If the target state is @unavailable@, the reason code can be the
    -- following value:
    --
    -- -   @Target.HealthCheckDisabled@ - Health checks are disabled for the
    --     target group. Applies only to Application Load Balancers.
    --
    -- -   @Elb.InternalError@ - Target health is unavailable due to an
    --     internal error. Applies only to Network Load Balancers.
    TargetHealth -> Maybe TargetHealthReasonEnum
reason :: Prelude.Maybe TargetHealthReasonEnum,
    -- | A description of the target health that provides additional details. If
    -- the state is @healthy@, a description is not provided.
    TargetHealth -> Maybe Text
description :: Prelude.Maybe Prelude.Text
  }
  deriving (TargetHealth -> TargetHealth -> Bool
(TargetHealth -> TargetHealth -> Bool)
-> (TargetHealth -> TargetHealth -> Bool) -> Eq TargetHealth
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TargetHealth -> TargetHealth -> Bool
$c/= :: TargetHealth -> TargetHealth -> Bool
== :: TargetHealth -> TargetHealth -> Bool
$c== :: TargetHealth -> TargetHealth -> Bool
Prelude.Eq, ReadPrec [TargetHealth]
ReadPrec TargetHealth
Int -> ReadS TargetHealth
ReadS [TargetHealth]
(Int -> ReadS TargetHealth)
-> ReadS [TargetHealth]
-> ReadPrec TargetHealth
-> ReadPrec [TargetHealth]
-> Read TargetHealth
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TargetHealth]
$creadListPrec :: ReadPrec [TargetHealth]
readPrec :: ReadPrec TargetHealth
$creadPrec :: ReadPrec TargetHealth
readList :: ReadS [TargetHealth]
$creadList :: ReadS [TargetHealth]
readsPrec :: Int -> ReadS TargetHealth
$creadsPrec :: Int -> ReadS TargetHealth
Prelude.Read, Int -> TargetHealth -> ShowS
[TargetHealth] -> ShowS
TargetHealth -> String
(Int -> TargetHealth -> ShowS)
-> (TargetHealth -> String)
-> ([TargetHealth] -> ShowS)
-> Show TargetHealth
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TargetHealth] -> ShowS
$cshowList :: [TargetHealth] -> ShowS
show :: TargetHealth -> String
$cshow :: TargetHealth -> String
showsPrec :: Int -> TargetHealth -> ShowS
$cshowsPrec :: Int -> TargetHealth -> ShowS
Prelude.Show, (forall x. TargetHealth -> Rep TargetHealth x)
-> (forall x. Rep TargetHealth x -> TargetHealth)
-> Generic TargetHealth
forall x. Rep TargetHealth x -> TargetHealth
forall x. TargetHealth -> Rep TargetHealth x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TargetHealth x -> TargetHealth
$cfrom :: forall x. TargetHealth -> Rep TargetHealth x
Prelude.Generic)

-- |
-- Create a value of 'TargetHealth' 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:
--
-- 'state', 'targetHealth_state' - The state of the target.
--
-- 'reason', 'targetHealth_reason' - The reason code.
--
-- If the target state is @healthy@, a reason code is not provided.
--
-- If the target state is @initial@, the reason code can be one of the
-- following values:
--
-- -   @Elb.RegistrationInProgress@ - The target is in the process of being
--     registered with the load balancer.
--
-- -   @Elb.InitialHealthChecking@ - The load balancer is still sending the
--     target the minimum number of health checks required to determine its
--     health status.
--
-- If the target state is @unhealthy@, the reason code can be one of the
-- following values:
--
-- -   @Target.ResponseCodeMismatch@ - The health checks did not return an
--     expected HTTP code. Applies only to Application Load Balancers and
--     Gateway Load Balancers.
--
-- -   @Target.Timeout@ - The health check requests timed out. Applies only
--     to Application Load Balancers and Gateway Load Balancers.
--
-- -   @Target.FailedHealthChecks@ - The load balancer received an error
--     while establishing a connection to the target or the target response
--     was malformed.
--
-- -   @Elb.InternalError@ - The health checks failed due to an internal
--     error. Applies only to Application Load Balancers.
--
-- If the target state is @unused@, the reason code can be one of the
-- following values:
--
-- -   @Target.NotRegistered@ - The target is not registered with the
--     target group.
--
-- -   @Target.NotInUse@ - The target group is not used by any load
--     balancer or the target is in an Availability Zone that is not
--     enabled for its load balancer.
--
-- -   @Target.InvalidState@ - The target is in the stopped or terminated
--     state.
--
-- -   @Target.IpUnusable@ - The target IP address is reserved for use by a
--     load balancer.
--
-- If the target state is @draining@, the reason code can be the following
-- value:
--
-- -   @Target.DeregistrationInProgress@ - The target is in the process of
--     being deregistered and the deregistration delay period has not
--     expired.
--
-- If the target state is @unavailable@, the reason code can be the
-- following value:
--
-- -   @Target.HealthCheckDisabled@ - Health checks are disabled for the
--     target group. Applies only to Application Load Balancers.
--
-- -   @Elb.InternalError@ - Target health is unavailable due to an
--     internal error. Applies only to Network Load Balancers.
--
-- 'description', 'targetHealth_description' - A description of the target health that provides additional details. If
-- the state is @healthy@, a description is not provided.
newTargetHealth ::
  TargetHealth
newTargetHealth :: TargetHealth
newTargetHealth =
  TargetHealth' :: Maybe TargetHealthStateEnum
-> Maybe TargetHealthReasonEnum -> Maybe Text -> TargetHealth
TargetHealth'
    { $sel:state:TargetHealth' :: Maybe TargetHealthStateEnum
state = Maybe TargetHealthStateEnum
forall a. Maybe a
Prelude.Nothing,
      $sel:reason:TargetHealth' :: Maybe TargetHealthReasonEnum
reason = Maybe TargetHealthReasonEnum
forall a. Maybe a
Prelude.Nothing,
      $sel:description:TargetHealth' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The state of the target.
targetHealth_state :: Lens.Lens' TargetHealth (Prelude.Maybe TargetHealthStateEnum)
targetHealth_state :: (Maybe TargetHealthStateEnum -> f (Maybe TargetHealthStateEnum))
-> TargetHealth -> f TargetHealth
targetHealth_state = (TargetHealth -> Maybe TargetHealthStateEnum)
-> (TargetHealth -> Maybe TargetHealthStateEnum -> TargetHealth)
-> Lens
     TargetHealth
     TargetHealth
     (Maybe TargetHealthStateEnum)
     (Maybe TargetHealthStateEnum)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetHealth' {Maybe TargetHealthStateEnum
state :: Maybe TargetHealthStateEnum
$sel:state:TargetHealth' :: TargetHealth -> Maybe TargetHealthStateEnum
state} -> Maybe TargetHealthStateEnum
state) (\s :: TargetHealth
s@TargetHealth' {} Maybe TargetHealthStateEnum
a -> TargetHealth
s {$sel:state:TargetHealth' :: Maybe TargetHealthStateEnum
state = Maybe TargetHealthStateEnum
a} :: TargetHealth)

-- | The reason code.
--
-- If the target state is @healthy@, a reason code is not provided.
--
-- If the target state is @initial@, the reason code can be one of the
-- following values:
--
-- -   @Elb.RegistrationInProgress@ - The target is in the process of being
--     registered with the load balancer.
--
-- -   @Elb.InitialHealthChecking@ - The load balancer is still sending the
--     target the minimum number of health checks required to determine its
--     health status.
--
-- If the target state is @unhealthy@, the reason code can be one of the
-- following values:
--
-- -   @Target.ResponseCodeMismatch@ - The health checks did not return an
--     expected HTTP code. Applies only to Application Load Balancers and
--     Gateway Load Balancers.
--
-- -   @Target.Timeout@ - The health check requests timed out. Applies only
--     to Application Load Balancers and Gateway Load Balancers.
--
-- -   @Target.FailedHealthChecks@ - The load balancer received an error
--     while establishing a connection to the target or the target response
--     was malformed.
--
-- -   @Elb.InternalError@ - The health checks failed due to an internal
--     error. Applies only to Application Load Balancers.
--
-- If the target state is @unused@, the reason code can be one of the
-- following values:
--
-- -   @Target.NotRegistered@ - The target is not registered with the
--     target group.
--
-- -   @Target.NotInUse@ - The target group is not used by any load
--     balancer or the target is in an Availability Zone that is not
--     enabled for its load balancer.
--
-- -   @Target.InvalidState@ - The target is in the stopped or terminated
--     state.
--
-- -   @Target.IpUnusable@ - The target IP address is reserved for use by a
--     load balancer.
--
-- If the target state is @draining@, the reason code can be the following
-- value:
--
-- -   @Target.DeregistrationInProgress@ - The target is in the process of
--     being deregistered and the deregistration delay period has not
--     expired.
--
-- If the target state is @unavailable@, the reason code can be the
-- following value:
--
-- -   @Target.HealthCheckDisabled@ - Health checks are disabled for the
--     target group. Applies only to Application Load Balancers.
--
-- -   @Elb.InternalError@ - Target health is unavailable due to an
--     internal error. Applies only to Network Load Balancers.
targetHealth_reason :: Lens.Lens' TargetHealth (Prelude.Maybe TargetHealthReasonEnum)
targetHealth_reason :: (Maybe TargetHealthReasonEnum -> f (Maybe TargetHealthReasonEnum))
-> TargetHealth -> f TargetHealth
targetHealth_reason = (TargetHealth -> Maybe TargetHealthReasonEnum)
-> (TargetHealth -> Maybe TargetHealthReasonEnum -> TargetHealth)
-> Lens
     TargetHealth
     TargetHealth
     (Maybe TargetHealthReasonEnum)
     (Maybe TargetHealthReasonEnum)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetHealth' {Maybe TargetHealthReasonEnum
reason :: Maybe TargetHealthReasonEnum
$sel:reason:TargetHealth' :: TargetHealth -> Maybe TargetHealthReasonEnum
reason} -> Maybe TargetHealthReasonEnum
reason) (\s :: TargetHealth
s@TargetHealth' {} Maybe TargetHealthReasonEnum
a -> TargetHealth
s {$sel:reason:TargetHealth' :: Maybe TargetHealthReasonEnum
reason = Maybe TargetHealthReasonEnum
a} :: TargetHealth)

-- | A description of the target health that provides additional details. If
-- the state is @healthy@, a description is not provided.
targetHealth_description :: Lens.Lens' TargetHealth (Prelude.Maybe Prelude.Text)
targetHealth_description :: (Maybe Text -> f (Maybe Text)) -> TargetHealth -> f TargetHealth
targetHealth_description = (TargetHealth -> Maybe Text)
-> (TargetHealth -> Maybe Text -> TargetHealth)
-> Lens TargetHealth TargetHealth (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetHealth' {Maybe Text
description :: Maybe Text
$sel:description:TargetHealth' :: TargetHealth -> Maybe Text
description} -> Maybe Text
description) (\s :: TargetHealth
s@TargetHealth' {} Maybe Text
a -> TargetHealth
s {$sel:description:TargetHealth' :: Maybe Text
description = Maybe Text
a} :: TargetHealth)

instance Core.FromXML TargetHealth where
  parseXML :: [Node] -> Either String TargetHealth
parseXML [Node]
x =
    Maybe TargetHealthStateEnum
-> Maybe TargetHealthReasonEnum -> Maybe Text -> TargetHealth
TargetHealth'
      (Maybe TargetHealthStateEnum
 -> Maybe TargetHealthReasonEnum -> Maybe Text -> TargetHealth)
-> Either String (Maybe TargetHealthStateEnum)
-> Either
     String (Maybe TargetHealthReasonEnum -> Maybe Text -> TargetHealth)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe TargetHealthStateEnum)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"State")
      Either
  String (Maybe TargetHealthReasonEnum -> Maybe Text -> TargetHealth)
-> Either String (Maybe TargetHealthReasonEnum)
-> Either String (Maybe Text -> TargetHealth)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe TargetHealthReasonEnum)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Reason")
      Either String (Maybe Text -> TargetHealth)
-> Either String (Maybe Text) -> Either String TargetHealth
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Description")

instance Prelude.Hashable TargetHealth

instance Prelude.NFData TargetHealth