{-# 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.AppMesh.Types.HealthCheckPolicy
-- 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.AppMesh.Types.HealthCheckPolicy where

import Amazonka.AppMesh.Types.PortProtocol
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

-- | An object that represents the health check policy for a virtual node\'s
-- listener.
--
-- /See:/ 'newHealthCheckPolicy' smart constructor.
data HealthCheckPolicy = HealthCheckPolicy'
  { -- | The destination path for the health check request. This value is only
    -- used if the specified protocol is HTTP or HTTP\/2. For any other
    -- protocol, this value is ignored.
    HealthCheckPolicy -> Maybe Text
path :: Prelude.Maybe Prelude.Text,
    -- | The destination port for the health check request. This port must match
    -- the port defined in the PortMapping for the listener.
    HealthCheckPolicy -> Maybe Natural
port :: Prelude.Maybe Prelude.Natural,
    -- | The number of consecutive successful health checks that must occur
    -- before declaring listener healthy.
    HealthCheckPolicy -> Natural
healthyThreshold :: Prelude.Natural,
    -- | The time period in milliseconds between each health check execution.
    HealthCheckPolicy -> Natural
intervalMillis :: Prelude.Natural,
    -- | The protocol for the health check request. If you specify @grpc@, then
    -- your service must conform to the
    -- <https://github.com/grpc/grpc/blob/master/doc/health-checking.md GRPC Health Checking Protocol>.
    HealthCheckPolicy -> PortProtocol
protocol :: PortProtocol,
    -- | The amount of time to wait when receiving a response from the health
    -- check, in milliseconds.
    HealthCheckPolicy -> Natural
timeoutMillis :: Prelude.Natural,
    -- | The number of consecutive failed health checks that must occur before
    -- declaring a virtual node unhealthy.
    HealthCheckPolicy -> Natural
unhealthyThreshold :: Prelude.Natural
  }
  deriving (HealthCheckPolicy -> HealthCheckPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HealthCheckPolicy -> HealthCheckPolicy -> Bool
$c/= :: HealthCheckPolicy -> HealthCheckPolicy -> Bool
== :: HealthCheckPolicy -> HealthCheckPolicy -> Bool
$c== :: HealthCheckPolicy -> HealthCheckPolicy -> Bool
Prelude.Eq, ReadPrec [HealthCheckPolicy]
ReadPrec HealthCheckPolicy
Int -> ReadS HealthCheckPolicy
ReadS [HealthCheckPolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HealthCheckPolicy]
$creadListPrec :: ReadPrec [HealthCheckPolicy]
readPrec :: ReadPrec HealthCheckPolicy
$creadPrec :: ReadPrec HealthCheckPolicy
readList :: ReadS [HealthCheckPolicy]
$creadList :: ReadS [HealthCheckPolicy]
readsPrec :: Int -> ReadS HealthCheckPolicy
$creadsPrec :: Int -> ReadS HealthCheckPolicy
Prelude.Read, Int -> HealthCheckPolicy -> ShowS
[HealthCheckPolicy] -> ShowS
HealthCheckPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HealthCheckPolicy] -> ShowS
$cshowList :: [HealthCheckPolicy] -> ShowS
show :: HealthCheckPolicy -> String
$cshow :: HealthCheckPolicy -> String
showsPrec :: Int -> HealthCheckPolicy -> ShowS
$cshowsPrec :: Int -> HealthCheckPolicy -> ShowS
Prelude.Show, forall x. Rep HealthCheckPolicy x -> HealthCheckPolicy
forall x. HealthCheckPolicy -> Rep HealthCheckPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HealthCheckPolicy x -> HealthCheckPolicy
$cfrom :: forall x. HealthCheckPolicy -> Rep HealthCheckPolicy x
Prelude.Generic)

-- |
-- Create a value of 'HealthCheckPolicy' 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:
--
-- 'path', 'healthCheckPolicy_path' - The destination path for the health check request. This value is only
-- used if the specified protocol is HTTP or HTTP\/2. For any other
-- protocol, this value is ignored.
--
-- 'port', 'healthCheckPolicy_port' - The destination port for the health check request. This port must match
-- the port defined in the PortMapping for the listener.
--
-- 'healthyThreshold', 'healthCheckPolicy_healthyThreshold' - The number of consecutive successful health checks that must occur
-- before declaring listener healthy.
--
-- 'intervalMillis', 'healthCheckPolicy_intervalMillis' - The time period in milliseconds between each health check execution.
--
-- 'protocol', 'healthCheckPolicy_protocol' - The protocol for the health check request. If you specify @grpc@, then
-- your service must conform to the
-- <https://github.com/grpc/grpc/blob/master/doc/health-checking.md GRPC Health Checking Protocol>.
--
-- 'timeoutMillis', 'healthCheckPolicy_timeoutMillis' - The amount of time to wait when receiving a response from the health
-- check, in milliseconds.
--
-- 'unhealthyThreshold', 'healthCheckPolicy_unhealthyThreshold' - The number of consecutive failed health checks that must occur before
-- declaring a virtual node unhealthy.
newHealthCheckPolicy ::
  -- | 'healthyThreshold'
  Prelude.Natural ->
  -- | 'intervalMillis'
  Prelude.Natural ->
  -- | 'protocol'
  PortProtocol ->
  -- | 'timeoutMillis'
  Prelude.Natural ->
  -- | 'unhealthyThreshold'
  Prelude.Natural ->
  HealthCheckPolicy
newHealthCheckPolicy :: Natural
-> Natural
-> PortProtocol
-> Natural
-> Natural
-> HealthCheckPolicy
newHealthCheckPolicy
  Natural
pHealthyThreshold_
  Natural
pIntervalMillis_
  PortProtocol
pProtocol_
  Natural
pTimeoutMillis_
  Natural
pUnhealthyThreshold_ =
    HealthCheckPolicy'
      { $sel:path:HealthCheckPolicy' :: Maybe Text
path = forall a. Maybe a
Prelude.Nothing,
        $sel:port:HealthCheckPolicy' :: Maybe Natural
port = forall a. Maybe a
Prelude.Nothing,
        $sel:healthyThreshold:HealthCheckPolicy' :: Natural
healthyThreshold = Natural
pHealthyThreshold_,
        $sel:intervalMillis:HealthCheckPolicy' :: Natural
intervalMillis = Natural
pIntervalMillis_,
        $sel:protocol:HealthCheckPolicy' :: PortProtocol
protocol = PortProtocol
pProtocol_,
        $sel:timeoutMillis:HealthCheckPolicy' :: Natural
timeoutMillis = Natural
pTimeoutMillis_,
        $sel:unhealthyThreshold:HealthCheckPolicy' :: Natural
unhealthyThreshold = Natural
pUnhealthyThreshold_
      }

-- | The destination path for the health check request. This value is only
-- used if the specified protocol is HTTP or HTTP\/2. For any other
-- protocol, this value is ignored.
healthCheckPolicy_path :: Lens.Lens' HealthCheckPolicy (Prelude.Maybe Prelude.Text)
healthCheckPolicy_path :: Lens' HealthCheckPolicy (Maybe Text)
healthCheckPolicy_path = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HealthCheckPolicy' {Maybe Text
path :: Maybe Text
$sel:path:HealthCheckPolicy' :: HealthCheckPolicy -> Maybe Text
path} -> Maybe Text
path) (\s :: HealthCheckPolicy
s@HealthCheckPolicy' {} Maybe Text
a -> HealthCheckPolicy
s {$sel:path:HealthCheckPolicy' :: Maybe Text
path = Maybe Text
a} :: HealthCheckPolicy)

-- | The destination port for the health check request. This port must match
-- the port defined in the PortMapping for the listener.
healthCheckPolicy_port :: Lens.Lens' HealthCheckPolicy (Prelude.Maybe Prelude.Natural)
healthCheckPolicy_port :: Lens' HealthCheckPolicy (Maybe Natural)
healthCheckPolicy_port = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HealthCheckPolicy' {Maybe Natural
port :: Maybe Natural
$sel:port:HealthCheckPolicy' :: HealthCheckPolicy -> Maybe Natural
port} -> Maybe Natural
port) (\s :: HealthCheckPolicy
s@HealthCheckPolicy' {} Maybe Natural
a -> HealthCheckPolicy
s {$sel:port:HealthCheckPolicy' :: Maybe Natural
port = Maybe Natural
a} :: HealthCheckPolicy)

-- | The number of consecutive successful health checks that must occur
-- before declaring listener healthy.
healthCheckPolicy_healthyThreshold :: Lens.Lens' HealthCheckPolicy Prelude.Natural
healthCheckPolicy_healthyThreshold :: Lens' HealthCheckPolicy Natural
healthCheckPolicy_healthyThreshold = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HealthCheckPolicy' {Natural
healthyThreshold :: Natural
$sel:healthyThreshold:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
healthyThreshold} -> Natural
healthyThreshold) (\s :: HealthCheckPolicy
s@HealthCheckPolicy' {} Natural
a -> HealthCheckPolicy
s {$sel:healthyThreshold:HealthCheckPolicy' :: Natural
healthyThreshold = Natural
a} :: HealthCheckPolicy)

-- | The time period in milliseconds between each health check execution.
healthCheckPolicy_intervalMillis :: Lens.Lens' HealthCheckPolicy Prelude.Natural
healthCheckPolicy_intervalMillis :: Lens' HealthCheckPolicy Natural
healthCheckPolicy_intervalMillis = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HealthCheckPolicy' {Natural
intervalMillis :: Natural
$sel:intervalMillis:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
intervalMillis} -> Natural
intervalMillis) (\s :: HealthCheckPolicy
s@HealthCheckPolicy' {} Natural
a -> HealthCheckPolicy
s {$sel:intervalMillis:HealthCheckPolicy' :: Natural
intervalMillis = Natural
a} :: HealthCheckPolicy)

-- | The protocol for the health check request. If you specify @grpc@, then
-- your service must conform to the
-- <https://github.com/grpc/grpc/blob/master/doc/health-checking.md GRPC Health Checking Protocol>.
healthCheckPolicy_protocol :: Lens.Lens' HealthCheckPolicy PortProtocol
healthCheckPolicy_protocol :: Lens' HealthCheckPolicy PortProtocol
healthCheckPolicy_protocol = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HealthCheckPolicy' {PortProtocol
protocol :: PortProtocol
$sel:protocol:HealthCheckPolicy' :: HealthCheckPolicy -> PortProtocol
protocol} -> PortProtocol
protocol) (\s :: HealthCheckPolicy
s@HealthCheckPolicy' {} PortProtocol
a -> HealthCheckPolicy
s {$sel:protocol:HealthCheckPolicy' :: PortProtocol
protocol = PortProtocol
a} :: HealthCheckPolicy)

-- | The amount of time to wait when receiving a response from the health
-- check, in milliseconds.
healthCheckPolicy_timeoutMillis :: Lens.Lens' HealthCheckPolicy Prelude.Natural
healthCheckPolicy_timeoutMillis :: Lens' HealthCheckPolicy Natural
healthCheckPolicy_timeoutMillis = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HealthCheckPolicy' {Natural
timeoutMillis :: Natural
$sel:timeoutMillis:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
timeoutMillis} -> Natural
timeoutMillis) (\s :: HealthCheckPolicy
s@HealthCheckPolicy' {} Natural
a -> HealthCheckPolicy
s {$sel:timeoutMillis:HealthCheckPolicy' :: Natural
timeoutMillis = Natural
a} :: HealthCheckPolicy)

-- | The number of consecutive failed health checks that must occur before
-- declaring a virtual node unhealthy.
healthCheckPolicy_unhealthyThreshold :: Lens.Lens' HealthCheckPolicy Prelude.Natural
healthCheckPolicy_unhealthyThreshold :: Lens' HealthCheckPolicy Natural
healthCheckPolicy_unhealthyThreshold = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HealthCheckPolicy' {Natural
unhealthyThreshold :: Natural
$sel:unhealthyThreshold:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
unhealthyThreshold} -> Natural
unhealthyThreshold) (\s :: HealthCheckPolicy
s@HealthCheckPolicy' {} Natural
a -> HealthCheckPolicy
s {$sel:unhealthyThreshold:HealthCheckPolicy' :: Natural
unhealthyThreshold = Natural
a} :: HealthCheckPolicy)

instance Data.FromJSON HealthCheckPolicy where
  parseJSON :: Value -> Parser HealthCheckPolicy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"HealthCheckPolicy"
      ( \Object
x ->
          Maybe Text
-> Maybe Natural
-> Natural
-> Natural
-> PortProtocol
-> Natural
-> Natural
-> HealthCheckPolicy
HealthCheckPolicy'
            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
"path")
            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
"port")
            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
"healthyThreshold")
            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
"intervalMillis")
            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
"protocol")
            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
"timeoutMillis")
            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
"unhealthyThreshold")
      )

instance Prelude.Hashable HealthCheckPolicy where
  hashWithSalt :: Int -> HealthCheckPolicy -> Int
hashWithSalt Int
_salt HealthCheckPolicy' {Natural
Maybe Natural
Maybe Text
PortProtocol
unhealthyThreshold :: Natural
timeoutMillis :: Natural
protocol :: PortProtocol
intervalMillis :: Natural
healthyThreshold :: Natural
port :: Maybe Natural
path :: Maybe Text
$sel:unhealthyThreshold:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
$sel:timeoutMillis:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
$sel:protocol:HealthCheckPolicy' :: HealthCheckPolicy -> PortProtocol
$sel:intervalMillis:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
$sel:healthyThreshold:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
$sel:port:HealthCheckPolicy' :: HealthCheckPolicy -> Maybe Natural
$sel:path:HealthCheckPolicy' :: HealthCheckPolicy -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
path
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
port
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
healthyThreshold
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
intervalMillis
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` PortProtocol
protocol
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
timeoutMillis
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
unhealthyThreshold

instance Prelude.NFData HealthCheckPolicy where
  rnf :: HealthCheckPolicy -> ()
rnf HealthCheckPolicy' {Natural
Maybe Natural
Maybe Text
PortProtocol
unhealthyThreshold :: Natural
timeoutMillis :: Natural
protocol :: PortProtocol
intervalMillis :: Natural
healthyThreshold :: Natural
port :: Maybe Natural
path :: Maybe Text
$sel:unhealthyThreshold:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
$sel:timeoutMillis:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
$sel:protocol:HealthCheckPolicy' :: HealthCheckPolicy -> PortProtocol
$sel:intervalMillis:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
$sel:healthyThreshold:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
$sel:port:HealthCheckPolicy' :: HealthCheckPolicy -> Maybe Natural
$sel:path:HealthCheckPolicy' :: HealthCheckPolicy -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
path
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
port
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
healthyThreshold
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
intervalMillis
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf PortProtocol
protocol
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
timeoutMillis
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
unhealthyThreshold

instance Data.ToJSON HealthCheckPolicy where
  toJSON :: HealthCheckPolicy -> Value
toJSON HealthCheckPolicy' {Natural
Maybe Natural
Maybe Text
PortProtocol
unhealthyThreshold :: Natural
timeoutMillis :: Natural
protocol :: PortProtocol
intervalMillis :: Natural
healthyThreshold :: Natural
port :: Maybe Natural
path :: Maybe Text
$sel:unhealthyThreshold:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
$sel:timeoutMillis:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
$sel:protocol:HealthCheckPolicy' :: HealthCheckPolicy -> PortProtocol
$sel:intervalMillis:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
$sel:healthyThreshold:HealthCheckPolicy' :: HealthCheckPolicy -> Natural
$sel:port:HealthCheckPolicy' :: HealthCheckPolicy -> Maybe Natural
$sel:path:HealthCheckPolicy' :: HealthCheckPolicy -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"path" 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 Text
path,
            (Key
"port" 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 Natural
port,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"healthyThreshold" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
healthyThreshold),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"intervalMillis" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
intervalMillis),
            forall a. a -> Maybe a
Prelude.Just (Key
"protocol" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= PortProtocol
protocol),
            forall a. a -> Maybe a
Prelude.Just (Key
"timeoutMillis" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
timeoutMillis),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"unhealthyThreshold" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
unhealthyThreshold)
          ]
      )