{-# 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.GreengrassV2.Types.IoTJobAbortCriteria
-- 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.GreengrassV2.Types.IoTJobAbortCriteria where

import qualified Amazonka.Core as Core
import Amazonka.GreengrassV2.Types.IoTJobAbortAction
import Amazonka.GreengrassV2.Types.IoTJobExecutionFailureType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains criteria that define when and how to cancel a job.
--
-- The deployment stops if the following conditions are true:
--
-- 1.  The number of things that receive the deployment exceeds the
--     @minNumberOfExecutedThings@.
--
-- 2.  The percentage of failures with type @failureType@ exceeds the
--     @thresholdPercentage@.
--
-- /See:/ 'newIoTJobAbortCriteria' smart constructor.
data IoTJobAbortCriteria = IoTJobAbortCriteria'
  { -- | The type of job deployment failure that can cancel a job.
    IoTJobAbortCriteria -> IoTJobExecutionFailureType
failureType :: IoTJobExecutionFailureType,
    -- | The action to perform when the criteria are met.
    IoTJobAbortCriteria -> IoTJobAbortAction
action :: IoTJobAbortAction,
    -- | The minimum percentage of @failureType@ failures that occur before the
    -- job can cancel.
    --
    -- This parameter supports up to two digits after the decimal (for example,
    -- you can specify @10.9@ or @10.99@, but not @10.999@).
    IoTJobAbortCriteria -> Double
thresholdPercentage :: Prelude.Double,
    -- | The minimum number of things that receive the configuration before the
    -- job can cancel.
    IoTJobAbortCriteria -> Natural
minNumberOfExecutedThings :: Prelude.Natural
  }
  deriving (IoTJobAbortCriteria -> IoTJobAbortCriteria -> Bool
(IoTJobAbortCriteria -> IoTJobAbortCriteria -> Bool)
-> (IoTJobAbortCriteria -> IoTJobAbortCriteria -> Bool)
-> Eq IoTJobAbortCriteria
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IoTJobAbortCriteria -> IoTJobAbortCriteria -> Bool
$c/= :: IoTJobAbortCriteria -> IoTJobAbortCriteria -> Bool
== :: IoTJobAbortCriteria -> IoTJobAbortCriteria -> Bool
$c== :: IoTJobAbortCriteria -> IoTJobAbortCriteria -> Bool
Prelude.Eq, ReadPrec [IoTJobAbortCriteria]
ReadPrec IoTJobAbortCriteria
Int -> ReadS IoTJobAbortCriteria
ReadS [IoTJobAbortCriteria]
(Int -> ReadS IoTJobAbortCriteria)
-> ReadS [IoTJobAbortCriteria]
-> ReadPrec IoTJobAbortCriteria
-> ReadPrec [IoTJobAbortCriteria]
-> Read IoTJobAbortCriteria
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IoTJobAbortCriteria]
$creadListPrec :: ReadPrec [IoTJobAbortCriteria]
readPrec :: ReadPrec IoTJobAbortCriteria
$creadPrec :: ReadPrec IoTJobAbortCriteria
readList :: ReadS [IoTJobAbortCriteria]
$creadList :: ReadS [IoTJobAbortCriteria]
readsPrec :: Int -> ReadS IoTJobAbortCriteria
$creadsPrec :: Int -> ReadS IoTJobAbortCriteria
Prelude.Read, Int -> IoTJobAbortCriteria -> ShowS
[IoTJobAbortCriteria] -> ShowS
IoTJobAbortCriteria -> String
(Int -> IoTJobAbortCriteria -> ShowS)
-> (IoTJobAbortCriteria -> String)
-> ([IoTJobAbortCriteria] -> ShowS)
-> Show IoTJobAbortCriteria
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IoTJobAbortCriteria] -> ShowS
$cshowList :: [IoTJobAbortCriteria] -> ShowS
show :: IoTJobAbortCriteria -> String
$cshow :: IoTJobAbortCriteria -> String
showsPrec :: Int -> IoTJobAbortCriteria -> ShowS
$cshowsPrec :: Int -> IoTJobAbortCriteria -> ShowS
Prelude.Show, (forall x. IoTJobAbortCriteria -> Rep IoTJobAbortCriteria x)
-> (forall x. Rep IoTJobAbortCriteria x -> IoTJobAbortCriteria)
-> Generic IoTJobAbortCriteria
forall x. Rep IoTJobAbortCriteria x -> IoTJobAbortCriteria
forall x. IoTJobAbortCriteria -> Rep IoTJobAbortCriteria x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IoTJobAbortCriteria x -> IoTJobAbortCriteria
$cfrom :: forall x. IoTJobAbortCriteria -> Rep IoTJobAbortCriteria x
Prelude.Generic)

-- |
-- Create a value of 'IoTJobAbortCriteria' 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:
--
-- 'failureType', 'ioTJobAbortCriteria_failureType' - The type of job deployment failure that can cancel a job.
--
-- 'action', 'ioTJobAbortCriteria_action' - The action to perform when the criteria are met.
--
-- 'thresholdPercentage', 'ioTJobAbortCriteria_thresholdPercentage' - The minimum percentage of @failureType@ failures that occur before the
-- job can cancel.
--
-- This parameter supports up to two digits after the decimal (for example,
-- you can specify @10.9@ or @10.99@, but not @10.999@).
--
-- 'minNumberOfExecutedThings', 'ioTJobAbortCriteria_minNumberOfExecutedThings' - The minimum number of things that receive the configuration before the
-- job can cancel.
newIoTJobAbortCriteria ::
  -- | 'failureType'
  IoTJobExecutionFailureType ->
  -- | 'action'
  IoTJobAbortAction ->
  -- | 'thresholdPercentage'
  Prelude.Double ->
  -- | 'minNumberOfExecutedThings'
  Prelude.Natural ->
  IoTJobAbortCriteria
newIoTJobAbortCriteria :: IoTJobExecutionFailureType
-> IoTJobAbortAction -> Double -> Natural -> IoTJobAbortCriteria
newIoTJobAbortCriteria
  IoTJobExecutionFailureType
pFailureType_
  IoTJobAbortAction
pAction_
  Double
pThresholdPercentage_
  Natural
pMinNumberOfExecutedThings_ =
    IoTJobAbortCriteria' :: IoTJobExecutionFailureType
-> IoTJobAbortAction -> Double -> Natural -> IoTJobAbortCriteria
IoTJobAbortCriteria'
      { $sel:failureType:IoTJobAbortCriteria' :: IoTJobExecutionFailureType
failureType = IoTJobExecutionFailureType
pFailureType_,
        $sel:action:IoTJobAbortCriteria' :: IoTJobAbortAction
action = IoTJobAbortAction
pAction_,
        $sel:thresholdPercentage:IoTJobAbortCriteria' :: Double
thresholdPercentage = Double
pThresholdPercentage_,
        $sel:minNumberOfExecutedThings:IoTJobAbortCriteria' :: Natural
minNumberOfExecutedThings =
          Natural
pMinNumberOfExecutedThings_
      }

-- | The type of job deployment failure that can cancel a job.
ioTJobAbortCriteria_failureType :: Lens.Lens' IoTJobAbortCriteria IoTJobExecutionFailureType
ioTJobAbortCriteria_failureType :: (IoTJobExecutionFailureType -> f IoTJobExecutionFailureType)
-> IoTJobAbortCriteria -> f IoTJobAbortCriteria
ioTJobAbortCriteria_failureType = (IoTJobAbortCriteria -> IoTJobExecutionFailureType)
-> (IoTJobAbortCriteria
    -> IoTJobExecutionFailureType -> IoTJobAbortCriteria)
-> Lens
     IoTJobAbortCriteria
     IoTJobAbortCriteria
     IoTJobExecutionFailureType
     IoTJobExecutionFailureType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IoTJobAbortCriteria' {IoTJobExecutionFailureType
failureType :: IoTJobExecutionFailureType
$sel:failureType:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> IoTJobExecutionFailureType
failureType} -> IoTJobExecutionFailureType
failureType) (\s :: IoTJobAbortCriteria
s@IoTJobAbortCriteria' {} IoTJobExecutionFailureType
a -> IoTJobAbortCriteria
s {$sel:failureType:IoTJobAbortCriteria' :: IoTJobExecutionFailureType
failureType = IoTJobExecutionFailureType
a} :: IoTJobAbortCriteria)

-- | The action to perform when the criteria are met.
ioTJobAbortCriteria_action :: Lens.Lens' IoTJobAbortCriteria IoTJobAbortAction
ioTJobAbortCriteria_action :: (IoTJobAbortAction -> f IoTJobAbortAction)
-> IoTJobAbortCriteria -> f IoTJobAbortCriteria
ioTJobAbortCriteria_action = (IoTJobAbortCriteria -> IoTJobAbortAction)
-> (IoTJobAbortCriteria
    -> IoTJobAbortAction -> IoTJobAbortCriteria)
-> Lens
     IoTJobAbortCriteria
     IoTJobAbortCriteria
     IoTJobAbortAction
     IoTJobAbortAction
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IoTJobAbortCriteria' {IoTJobAbortAction
action :: IoTJobAbortAction
$sel:action:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> IoTJobAbortAction
action} -> IoTJobAbortAction
action) (\s :: IoTJobAbortCriteria
s@IoTJobAbortCriteria' {} IoTJobAbortAction
a -> IoTJobAbortCriteria
s {$sel:action:IoTJobAbortCriteria' :: IoTJobAbortAction
action = IoTJobAbortAction
a} :: IoTJobAbortCriteria)

-- | The minimum percentage of @failureType@ failures that occur before the
-- job can cancel.
--
-- This parameter supports up to two digits after the decimal (for example,
-- you can specify @10.9@ or @10.99@, but not @10.999@).
ioTJobAbortCriteria_thresholdPercentage :: Lens.Lens' IoTJobAbortCriteria Prelude.Double
ioTJobAbortCriteria_thresholdPercentage :: (Double -> f Double)
-> IoTJobAbortCriteria -> f IoTJobAbortCriteria
ioTJobAbortCriteria_thresholdPercentage = (IoTJobAbortCriteria -> Double)
-> (IoTJobAbortCriteria -> Double -> IoTJobAbortCriteria)
-> Lens IoTJobAbortCriteria IoTJobAbortCriteria Double Double
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IoTJobAbortCriteria' {Double
thresholdPercentage :: Double
$sel:thresholdPercentage:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> Double
thresholdPercentage} -> Double
thresholdPercentage) (\s :: IoTJobAbortCriteria
s@IoTJobAbortCriteria' {} Double
a -> IoTJobAbortCriteria
s {$sel:thresholdPercentage:IoTJobAbortCriteria' :: Double
thresholdPercentage = Double
a} :: IoTJobAbortCriteria)

-- | The minimum number of things that receive the configuration before the
-- job can cancel.
ioTJobAbortCriteria_minNumberOfExecutedThings :: Lens.Lens' IoTJobAbortCriteria Prelude.Natural
ioTJobAbortCriteria_minNumberOfExecutedThings :: (Natural -> f Natural)
-> IoTJobAbortCriteria -> f IoTJobAbortCriteria
ioTJobAbortCriteria_minNumberOfExecutedThings = (IoTJobAbortCriteria -> Natural)
-> (IoTJobAbortCriteria -> Natural -> IoTJobAbortCriteria)
-> Lens IoTJobAbortCriteria IoTJobAbortCriteria Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IoTJobAbortCriteria' {Natural
minNumberOfExecutedThings :: Natural
$sel:minNumberOfExecutedThings:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> Natural
minNumberOfExecutedThings} -> Natural
minNumberOfExecutedThings) (\s :: IoTJobAbortCriteria
s@IoTJobAbortCriteria' {} Natural
a -> IoTJobAbortCriteria
s {$sel:minNumberOfExecutedThings:IoTJobAbortCriteria' :: Natural
minNumberOfExecutedThings = Natural
a} :: IoTJobAbortCriteria)

instance Core.FromJSON IoTJobAbortCriteria where
  parseJSON :: Value -> Parser IoTJobAbortCriteria
parseJSON =
    String
-> (Object -> Parser IoTJobAbortCriteria)
-> Value
-> Parser IoTJobAbortCriteria
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"IoTJobAbortCriteria"
      ( \Object
x ->
          IoTJobExecutionFailureType
-> IoTJobAbortAction -> Double -> Natural -> IoTJobAbortCriteria
IoTJobAbortCriteria'
            (IoTJobExecutionFailureType
 -> IoTJobAbortAction -> Double -> Natural -> IoTJobAbortCriteria)
-> Parser IoTJobExecutionFailureType
-> Parser
     (IoTJobAbortAction -> Double -> Natural -> IoTJobAbortCriteria)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser IoTJobExecutionFailureType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"failureType")
            Parser
  (IoTJobAbortAction -> Double -> Natural -> IoTJobAbortCriteria)
-> Parser IoTJobAbortAction
-> Parser (Double -> Natural -> IoTJobAbortCriteria)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser IoTJobAbortAction
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"action")
            Parser (Double -> Natural -> IoTJobAbortCriteria)
-> Parser Double -> Parser (Natural -> IoTJobAbortCriteria)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Double
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"thresholdPercentage")
            Parser (Natural -> IoTJobAbortCriteria)
-> Parser Natural -> Parser IoTJobAbortCriteria
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"minNumberOfExecutedThings")
      )

instance Prelude.Hashable IoTJobAbortCriteria

instance Prelude.NFData IoTJobAbortCriteria

instance Core.ToJSON IoTJobAbortCriteria where
  toJSON :: IoTJobAbortCriteria -> Value
toJSON IoTJobAbortCriteria' {Double
Natural
IoTJobAbortAction
IoTJobExecutionFailureType
minNumberOfExecutedThings :: Natural
thresholdPercentage :: Double
action :: IoTJobAbortAction
failureType :: IoTJobExecutionFailureType
$sel:minNumberOfExecutedThings:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> Natural
$sel:thresholdPercentage:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> Double
$sel:action:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> IoTJobAbortAction
$sel:failureType:IoTJobAbortCriteria' :: IoTJobAbortCriteria -> IoTJobExecutionFailureType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"failureType" Text -> IoTJobExecutionFailureType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= IoTJobExecutionFailureType
failureType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"action" Text -> IoTJobAbortAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= IoTJobAbortAction
action),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"thresholdPercentage" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Double
thresholdPercentage),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"minNumberOfExecutedThings"
                  Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
minNumberOfExecutedThings
              )
          ]
      )