{-# 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.ELB.Types.InstanceState
-- 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.ELB.Types.InstanceState where

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

-- | Information about the state of an EC2 instance.
--
-- /See:/ 'newInstanceState' smart constructor.
data InstanceState = InstanceState'
  { -- | The ID of the instance.
    InstanceState -> Maybe Text
instanceId :: Prelude.Maybe Prelude.Text,
    -- | The current state of the instance.
    --
    -- Valid values: @InService@ | @OutOfService@ | @Unknown@
    InstanceState -> Maybe Text
state :: Prelude.Maybe Prelude.Text,
    -- | Information about the cause of @OutOfService@ instances. Specifically,
    -- whether the cause is Elastic Load Balancing or the instance.
    --
    -- Valid values: @ELB@ | @Instance@ | @N\/A@
    InstanceState -> Maybe Text
reasonCode :: Prelude.Maybe Prelude.Text,
    -- | A description of the instance state. This string can contain one or more
    -- of the following messages.
    --
    -- -   @N\/A@
    --
    -- -   @A transient error occurred. Please try again later.@
    --
    -- -   @Instance has failed at least the UnhealthyThreshold number of health checks consecutively.@
    --
    -- -   @Instance has not passed the configured HealthyThreshold number of health checks consecutively.@
    --
    -- -   @Instance registration is still in progress.@
    --
    -- -   @Instance is in the EC2 Availability Zone for which LoadBalancer is not configured to route traffic to.@
    --
    -- -   @Instance is not currently registered with the LoadBalancer.@
    --
    -- -   @Instance deregistration currently in progress.@
    --
    -- -   @Disable Availability Zone is currently in progress.@
    --
    -- -   @Instance is in pending state.@
    --
    -- -   @Instance is in stopped state.@
    --
    -- -   @Instance is in terminated state.@
    InstanceState -> Maybe Text
description :: Prelude.Maybe Prelude.Text
  }
  deriving (InstanceState -> InstanceState -> Bool
(InstanceState -> InstanceState -> Bool)
-> (InstanceState -> InstanceState -> Bool) -> Eq InstanceState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InstanceState -> InstanceState -> Bool
$c/= :: InstanceState -> InstanceState -> Bool
== :: InstanceState -> InstanceState -> Bool
$c== :: InstanceState -> InstanceState -> Bool
Prelude.Eq, ReadPrec [InstanceState]
ReadPrec InstanceState
Int -> ReadS InstanceState
ReadS [InstanceState]
(Int -> ReadS InstanceState)
-> ReadS [InstanceState]
-> ReadPrec InstanceState
-> ReadPrec [InstanceState]
-> Read InstanceState
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InstanceState]
$creadListPrec :: ReadPrec [InstanceState]
readPrec :: ReadPrec InstanceState
$creadPrec :: ReadPrec InstanceState
readList :: ReadS [InstanceState]
$creadList :: ReadS [InstanceState]
readsPrec :: Int -> ReadS InstanceState
$creadsPrec :: Int -> ReadS InstanceState
Prelude.Read, Int -> InstanceState -> ShowS
[InstanceState] -> ShowS
InstanceState -> String
(Int -> InstanceState -> ShowS)
-> (InstanceState -> String)
-> ([InstanceState] -> ShowS)
-> Show InstanceState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InstanceState] -> ShowS
$cshowList :: [InstanceState] -> ShowS
show :: InstanceState -> String
$cshow :: InstanceState -> String
showsPrec :: Int -> InstanceState -> ShowS
$cshowsPrec :: Int -> InstanceState -> ShowS
Prelude.Show, (forall x. InstanceState -> Rep InstanceState x)
-> (forall x. Rep InstanceState x -> InstanceState)
-> Generic InstanceState
forall x. Rep InstanceState x -> InstanceState
forall x. InstanceState -> Rep InstanceState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InstanceState x -> InstanceState
$cfrom :: forall x. InstanceState -> Rep InstanceState x
Prelude.Generic)

-- |
-- Create a value of 'InstanceState' 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:
--
-- 'instanceId', 'instanceState_instanceId' - The ID of the instance.
--
-- 'state', 'instanceState_state' - The current state of the instance.
--
-- Valid values: @InService@ | @OutOfService@ | @Unknown@
--
-- 'reasonCode', 'instanceState_reasonCode' - Information about the cause of @OutOfService@ instances. Specifically,
-- whether the cause is Elastic Load Balancing or the instance.
--
-- Valid values: @ELB@ | @Instance@ | @N\/A@
--
-- 'description', 'instanceState_description' - A description of the instance state. This string can contain one or more
-- of the following messages.
--
-- -   @N\/A@
--
-- -   @A transient error occurred. Please try again later.@
--
-- -   @Instance has failed at least the UnhealthyThreshold number of health checks consecutively.@
--
-- -   @Instance has not passed the configured HealthyThreshold number of health checks consecutively.@
--
-- -   @Instance registration is still in progress.@
--
-- -   @Instance is in the EC2 Availability Zone for which LoadBalancer is not configured to route traffic to.@
--
-- -   @Instance is not currently registered with the LoadBalancer.@
--
-- -   @Instance deregistration currently in progress.@
--
-- -   @Disable Availability Zone is currently in progress.@
--
-- -   @Instance is in pending state.@
--
-- -   @Instance is in stopped state.@
--
-- -   @Instance is in terminated state.@
newInstanceState ::
  InstanceState
newInstanceState :: InstanceState
newInstanceState =
  InstanceState' :: Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Text -> InstanceState
InstanceState'
    { $sel:instanceId:InstanceState' :: Maybe Text
instanceId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:state:InstanceState' :: Maybe Text
state = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:reasonCode:InstanceState' :: Maybe Text
reasonCode = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:description:InstanceState' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The ID of the instance.
instanceState_instanceId :: Lens.Lens' InstanceState (Prelude.Maybe Prelude.Text)
instanceState_instanceId :: (Maybe Text -> f (Maybe Text)) -> InstanceState -> f InstanceState
instanceState_instanceId = (InstanceState -> Maybe Text)
-> (InstanceState -> Maybe Text -> InstanceState)
-> Lens InstanceState InstanceState (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceState' {Maybe Text
instanceId :: Maybe Text
$sel:instanceId:InstanceState' :: InstanceState -> Maybe Text
instanceId} -> Maybe Text
instanceId) (\s :: InstanceState
s@InstanceState' {} Maybe Text
a -> InstanceState
s {$sel:instanceId:InstanceState' :: Maybe Text
instanceId = Maybe Text
a} :: InstanceState)

-- | The current state of the instance.
--
-- Valid values: @InService@ | @OutOfService@ | @Unknown@
instanceState_state :: Lens.Lens' InstanceState (Prelude.Maybe Prelude.Text)
instanceState_state :: (Maybe Text -> f (Maybe Text)) -> InstanceState -> f InstanceState
instanceState_state = (InstanceState -> Maybe Text)
-> (InstanceState -> Maybe Text -> InstanceState)
-> Lens InstanceState InstanceState (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceState' {Maybe Text
state :: Maybe Text
$sel:state:InstanceState' :: InstanceState -> Maybe Text
state} -> Maybe Text
state) (\s :: InstanceState
s@InstanceState' {} Maybe Text
a -> InstanceState
s {$sel:state:InstanceState' :: Maybe Text
state = Maybe Text
a} :: InstanceState)

-- | Information about the cause of @OutOfService@ instances. Specifically,
-- whether the cause is Elastic Load Balancing or the instance.
--
-- Valid values: @ELB@ | @Instance@ | @N\/A@
instanceState_reasonCode :: Lens.Lens' InstanceState (Prelude.Maybe Prelude.Text)
instanceState_reasonCode :: (Maybe Text -> f (Maybe Text)) -> InstanceState -> f InstanceState
instanceState_reasonCode = (InstanceState -> Maybe Text)
-> (InstanceState -> Maybe Text -> InstanceState)
-> Lens InstanceState InstanceState (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceState' {Maybe Text
reasonCode :: Maybe Text
$sel:reasonCode:InstanceState' :: InstanceState -> Maybe Text
reasonCode} -> Maybe Text
reasonCode) (\s :: InstanceState
s@InstanceState' {} Maybe Text
a -> InstanceState
s {$sel:reasonCode:InstanceState' :: Maybe Text
reasonCode = Maybe Text
a} :: InstanceState)

-- | A description of the instance state. This string can contain one or more
-- of the following messages.
--
-- -   @N\/A@
--
-- -   @A transient error occurred. Please try again later.@
--
-- -   @Instance has failed at least the UnhealthyThreshold number of health checks consecutively.@
--
-- -   @Instance has not passed the configured HealthyThreshold number of health checks consecutively.@
--
-- -   @Instance registration is still in progress.@
--
-- -   @Instance is in the EC2 Availability Zone for which LoadBalancer is not configured to route traffic to.@
--
-- -   @Instance is not currently registered with the LoadBalancer.@
--
-- -   @Instance deregistration currently in progress.@
--
-- -   @Disable Availability Zone is currently in progress.@
--
-- -   @Instance is in pending state.@
--
-- -   @Instance is in stopped state.@
--
-- -   @Instance is in terminated state.@
instanceState_description :: Lens.Lens' InstanceState (Prelude.Maybe Prelude.Text)
instanceState_description :: (Maybe Text -> f (Maybe Text)) -> InstanceState -> f InstanceState
instanceState_description = (InstanceState -> Maybe Text)
-> (InstanceState -> Maybe Text -> InstanceState)
-> Lens InstanceState InstanceState (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceState' {Maybe Text
description :: Maybe Text
$sel:description:InstanceState' :: InstanceState -> Maybe Text
description} -> Maybe Text
description) (\s :: InstanceState
s@InstanceState' {} Maybe Text
a -> InstanceState
s {$sel:description:InstanceState' :: Maybe Text
description = Maybe Text
a} :: InstanceState)

instance Core.FromXML InstanceState where
  parseXML :: [Node] -> Either String InstanceState
parseXML [Node]
x =
    Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Text -> InstanceState
InstanceState'
      (Maybe Text
 -> Maybe Text -> Maybe Text -> Maybe Text -> InstanceState)
-> Either String (Maybe Text)
-> Either
     String (Maybe Text -> Maybe Text -> Maybe Text -> InstanceState)
forall (f :: * -> *) a b. Functor 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
"InstanceId")
      Either
  String (Maybe Text -> Maybe Text -> Maybe Text -> InstanceState)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Maybe Text -> InstanceState)
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
"State")
      Either String (Maybe Text -> Maybe Text -> InstanceState)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> InstanceState)
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
"ReasonCode")
      Either String (Maybe Text -> InstanceState)
-> Either String (Maybe Text) -> Either String InstanceState
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 InstanceState

instance Prelude.NFData InstanceState