{-# 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.DeploymentComponentUpdatePolicy
-- 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.DeploymentComponentUpdatePolicy where

import qualified Amazonka.Core as Core
import Amazonka.GreengrassV2.Types.DeploymentComponentUpdatePolicyAction
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information about a deployment\'s policy that defines when
-- components are safe to update.
--
-- Each component on a device can report whether or not it\'s ready to
-- update. After a component and its dependencies are ready, they can apply
-- the update in the deployment. You can configure whether or not the
-- deployment notifies components of an update and waits for a response.
-- You specify the amount of time each component has to respond to the
-- update notification.
--
-- /See:/ 'newDeploymentComponentUpdatePolicy' smart constructor.
data DeploymentComponentUpdatePolicy = DeploymentComponentUpdatePolicy'
  { -- | Whether or not to notify components and wait for components to become
    -- safe to update. Choose from the following options:
    --
    -- -   @NOTIFY_COMPONENTS@ – The deployment notifies each component before
    --     it stops and updates that component. Components can use the
    --     <https://docs.aws.amazon.com/greengrass/v2/developerguide/interprocess-communication.html#ipc-operation-subscribetocomponentupdates SubscribeToComponentUpdates>
    --     IPC operation to receive these notifications. Then, components can
    --     respond with the
    --     <https://docs.aws.amazon.com/greengrass/v2/developerguide/interprocess-communication.html#ipc-operation-defercomponentupdate DeferComponentUpdate>
    --     IPC operation. For more information, see
    --     <https://docs.aws.amazon.com/greengrass/v2/developerguide/create-deployments.html Create deployments>
    --     in the /IoT Greengrass V2 Developer Guide/.
    --
    -- -   @SKIP_NOTIFY_COMPONENTS@ – The deployment doesn\'t notify components
    --     or wait for them to be safe to update.
    --
    -- Default: @NOTIFY_COMPONENTS@
    DeploymentComponentUpdatePolicy
-> Maybe DeploymentComponentUpdatePolicyAction
action :: Prelude.Maybe DeploymentComponentUpdatePolicyAction,
    -- | The amount of time in seconds that each component on a device has to
    -- report that it\'s safe to update. If the component waits for longer than
    -- this timeout, then the deployment proceeds on the device.
    --
    -- Default: @60@
    DeploymentComponentUpdatePolicy -> Maybe Int
timeoutInSeconds :: Prelude.Maybe Prelude.Int
  }
  deriving (DeploymentComponentUpdatePolicy
-> DeploymentComponentUpdatePolicy -> Bool
(DeploymentComponentUpdatePolicy
 -> DeploymentComponentUpdatePolicy -> Bool)
-> (DeploymentComponentUpdatePolicy
    -> DeploymentComponentUpdatePolicy -> Bool)
-> Eq DeploymentComponentUpdatePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeploymentComponentUpdatePolicy
-> DeploymentComponentUpdatePolicy -> Bool
$c/= :: DeploymentComponentUpdatePolicy
-> DeploymentComponentUpdatePolicy -> Bool
== :: DeploymentComponentUpdatePolicy
-> DeploymentComponentUpdatePolicy -> Bool
$c== :: DeploymentComponentUpdatePolicy
-> DeploymentComponentUpdatePolicy -> Bool
Prelude.Eq, ReadPrec [DeploymentComponentUpdatePolicy]
ReadPrec DeploymentComponentUpdatePolicy
Int -> ReadS DeploymentComponentUpdatePolicy
ReadS [DeploymentComponentUpdatePolicy]
(Int -> ReadS DeploymentComponentUpdatePolicy)
-> ReadS [DeploymentComponentUpdatePolicy]
-> ReadPrec DeploymentComponentUpdatePolicy
-> ReadPrec [DeploymentComponentUpdatePolicy]
-> Read DeploymentComponentUpdatePolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeploymentComponentUpdatePolicy]
$creadListPrec :: ReadPrec [DeploymentComponentUpdatePolicy]
readPrec :: ReadPrec DeploymentComponentUpdatePolicy
$creadPrec :: ReadPrec DeploymentComponentUpdatePolicy
readList :: ReadS [DeploymentComponentUpdatePolicy]
$creadList :: ReadS [DeploymentComponentUpdatePolicy]
readsPrec :: Int -> ReadS DeploymentComponentUpdatePolicy
$creadsPrec :: Int -> ReadS DeploymentComponentUpdatePolicy
Prelude.Read, Int -> DeploymentComponentUpdatePolicy -> ShowS
[DeploymentComponentUpdatePolicy] -> ShowS
DeploymentComponentUpdatePolicy -> String
(Int -> DeploymentComponentUpdatePolicy -> ShowS)
-> (DeploymentComponentUpdatePolicy -> String)
-> ([DeploymentComponentUpdatePolicy] -> ShowS)
-> Show DeploymentComponentUpdatePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeploymentComponentUpdatePolicy] -> ShowS
$cshowList :: [DeploymentComponentUpdatePolicy] -> ShowS
show :: DeploymentComponentUpdatePolicy -> String
$cshow :: DeploymentComponentUpdatePolicy -> String
showsPrec :: Int -> DeploymentComponentUpdatePolicy -> ShowS
$cshowsPrec :: Int -> DeploymentComponentUpdatePolicy -> ShowS
Prelude.Show, (forall x.
 DeploymentComponentUpdatePolicy
 -> Rep DeploymentComponentUpdatePolicy x)
-> (forall x.
    Rep DeploymentComponentUpdatePolicy x
    -> DeploymentComponentUpdatePolicy)
-> Generic DeploymentComponentUpdatePolicy
forall x.
Rep DeploymentComponentUpdatePolicy x
-> DeploymentComponentUpdatePolicy
forall x.
DeploymentComponentUpdatePolicy
-> Rep DeploymentComponentUpdatePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DeploymentComponentUpdatePolicy x
-> DeploymentComponentUpdatePolicy
$cfrom :: forall x.
DeploymentComponentUpdatePolicy
-> Rep DeploymentComponentUpdatePolicy x
Prelude.Generic)

-- |
-- Create a value of 'DeploymentComponentUpdatePolicy' 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:
--
-- 'action', 'deploymentComponentUpdatePolicy_action' - Whether or not to notify components and wait for components to become
-- safe to update. Choose from the following options:
--
-- -   @NOTIFY_COMPONENTS@ – The deployment notifies each component before
--     it stops and updates that component. Components can use the
--     <https://docs.aws.amazon.com/greengrass/v2/developerguide/interprocess-communication.html#ipc-operation-subscribetocomponentupdates SubscribeToComponentUpdates>
--     IPC operation to receive these notifications. Then, components can
--     respond with the
--     <https://docs.aws.amazon.com/greengrass/v2/developerguide/interprocess-communication.html#ipc-operation-defercomponentupdate DeferComponentUpdate>
--     IPC operation. For more information, see
--     <https://docs.aws.amazon.com/greengrass/v2/developerguide/create-deployments.html Create deployments>
--     in the /IoT Greengrass V2 Developer Guide/.
--
-- -   @SKIP_NOTIFY_COMPONENTS@ – The deployment doesn\'t notify components
--     or wait for them to be safe to update.
--
-- Default: @NOTIFY_COMPONENTS@
--
-- 'timeoutInSeconds', 'deploymentComponentUpdatePolicy_timeoutInSeconds' - The amount of time in seconds that each component on a device has to
-- report that it\'s safe to update. If the component waits for longer than
-- this timeout, then the deployment proceeds on the device.
--
-- Default: @60@
newDeploymentComponentUpdatePolicy ::
  DeploymentComponentUpdatePolicy
newDeploymentComponentUpdatePolicy :: DeploymentComponentUpdatePolicy
newDeploymentComponentUpdatePolicy =
  DeploymentComponentUpdatePolicy' :: Maybe DeploymentComponentUpdatePolicyAction
-> Maybe Int -> DeploymentComponentUpdatePolicy
DeploymentComponentUpdatePolicy'
    { $sel:action:DeploymentComponentUpdatePolicy' :: Maybe DeploymentComponentUpdatePolicyAction
action =
        Maybe DeploymentComponentUpdatePolicyAction
forall a. Maybe a
Prelude.Nothing,
      $sel:timeoutInSeconds:DeploymentComponentUpdatePolicy' :: Maybe Int
timeoutInSeconds = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | Whether or not to notify components and wait for components to become
-- safe to update. Choose from the following options:
--
-- -   @NOTIFY_COMPONENTS@ – The deployment notifies each component before
--     it stops and updates that component. Components can use the
--     <https://docs.aws.amazon.com/greengrass/v2/developerguide/interprocess-communication.html#ipc-operation-subscribetocomponentupdates SubscribeToComponentUpdates>
--     IPC operation to receive these notifications. Then, components can
--     respond with the
--     <https://docs.aws.amazon.com/greengrass/v2/developerguide/interprocess-communication.html#ipc-operation-defercomponentupdate DeferComponentUpdate>
--     IPC operation. For more information, see
--     <https://docs.aws.amazon.com/greengrass/v2/developerguide/create-deployments.html Create deployments>
--     in the /IoT Greengrass V2 Developer Guide/.
--
-- -   @SKIP_NOTIFY_COMPONENTS@ – The deployment doesn\'t notify components
--     or wait for them to be safe to update.
--
-- Default: @NOTIFY_COMPONENTS@
deploymentComponentUpdatePolicy_action :: Lens.Lens' DeploymentComponentUpdatePolicy (Prelude.Maybe DeploymentComponentUpdatePolicyAction)
deploymentComponentUpdatePolicy_action :: (Maybe DeploymentComponentUpdatePolicyAction
 -> f (Maybe DeploymentComponentUpdatePolicyAction))
-> DeploymentComponentUpdatePolicy
-> f DeploymentComponentUpdatePolicy
deploymentComponentUpdatePolicy_action = (DeploymentComponentUpdatePolicy
 -> Maybe DeploymentComponentUpdatePolicyAction)
-> (DeploymentComponentUpdatePolicy
    -> Maybe DeploymentComponentUpdatePolicyAction
    -> DeploymentComponentUpdatePolicy)
-> Lens
     DeploymentComponentUpdatePolicy
     DeploymentComponentUpdatePolicy
     (Maybe DeploymentComponentUpdatePolicyAction)
     (Maybe DeploymentComponentUpdatePolicyAction)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentComponentUpdatePolicy' {Maybe DeploymentComponentUpdatePolicyAction
action :: Maybe DeploymentComponentUpdatePolicyAction
$sel:action:DeploymentComponentUpdatePolicy' :: DeploymentComponentUpdatePolicy
-> Maybe DeploymentComponentUpdatePolicyAction
action} -> Maybe DeploymentComponentUpdatePolicyAction
action) (\s :: DeploymentComponentUpdatePolicy
s@DeploymentComponentUpdatePolicy' {} Maybe DeploymentComponentUpdatePolicyAction
a -> DeploymentComponentUpdatePolicy
s {$sel:action:DeploymentComponentUpdatePolicy' :: Maybe DeploymentComponentUpdatePolicyAction
action = Maybe DeploymentComponentUpdatePolicyAction
a} :: DeploymentComponentUpdatePolicy)

-- | The amount of time in seconds that each component on a device has to
-- report that it\'s safe to update. If the component waits for longer than
-- this timeout, then the deployment proceeds on the device.
--
-- Default: @60@
deploymentComponentUpdatePolicy_timeoutInSeconds :: Lens.Lens' DeploymentComponentUpdatePolicy (Prelude.Maybe Prelude.Int)
deploymentComponentUpdatePolicy_timeoutInSeconds :: (Maybe Int -> f (Maybe Int))
-> DeploymentComponentUpdatePolicy
-> f DeploymentComponentUpdatePolicy
deploymentComponentUpdatePolicy_timeoutInSeconds = (DeploymentComponentUpdatePolicy -> Maybe Int)
-> (DeploymentComponentUpdatePolicy
    -> Maybe Int -> DeploymentComponentUpdatePolicy)
-> Lens
     DeploymentComponentUpdatePolicy
     DeploymentComponentUpdatePolicy
     (Maybe Int)
     (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentComponentUpdatePolicy' {Maybe Int
timeoutInSeconds :: Maybe Int
$sel:timeoutInSeconds:DeploymentComponentUpdatePolicy' :: DeploymentComponentUpdatePolicy -> Maybe Int
timeoutInSeconds} -> Maybe Int
timeoutInSeconds) (\s :: DeploymentComponentUpdatePolicy
s@DeploymentComponentUpdatePolicy' {} Maybe Int
a -> DeploymentComponentUpdatePolicy
s {$sel:timeoutInSeconds:DeploymentComponentUpdatePolicy' :: Maybe Int
timeoutInSeconds = Maybe Int
a} :: DeploymentComponentUpdatePolicy)

instance
  Core.FromJSON
    DeploymentComponentUpdatePolicy
  where
  parseJSON :: Value -> Parser DeploymentComponentUpdatePolicy
parseJSON =
    String
-> (Object -> Parser DeploymentComponentUpdatePolicy)
-> Value
-> Parser DeploymentComponentUpdatePolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DeploymentComponentUpdatePolicy"
      ( \Object
x ->
          Maybe DeploymentComponentUpdatePolicyAction
-> Maybe Int -> DeploymentComponentUpdatePolicy
DeploymentComponentUpdatePolicy'
            (Maybe DeploymentComponentUpdatePolicyAction
 -> Maybe Int -> DeploymentComponentUpdatePolicy)
-> Parser (Maybe DeploymentComponentUpdatePolicyAction)
-> Parser (Maybe Int -> DeploymentComponentUpdatePolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object
-> Text -> Parser (Maybe DeploymentComponentUpdatePolicyAction)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"action")
            Parser (Maybe Int -> DeploymentComponentUpdatePolicy)
-> Parser (Maybe Int) -> Parser DeploymentComponentUpdatePolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"timeoutInSeconds")
      )

instance
  Prelude.Hashable
    DeploymentComponentUpdatePolicy

instance
  Prelude.NFData
    DeploymentComponentUpdatePolicy

instance Core.ToJSON DeploymentComponentUpdatePolicy where
  toJSON :: DeploymentComponentUpdatePolicy -> Value
toJSON DeploymentComponentUpdatePolicy' {Maybe Int
Maybe DeploymentComponentUpdatePolicyAction
timeoutInSeconds :: Maybe Int
action :: Maybe DeploymentComponentUpdatePolicyAction
$sel:timeoutInSeconds:DeploymentComponentUpdatePolicy' :: DeploymentComponentUpdatePolicy -> Maybe Int
$sel:action:DeploymentComponentUpdatePolicy' :: DeploymentComponentUpdatePolicy
-> Maybe DeploymentComponentUpdatePolicyAction
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"action" Text -> DeploymentComponentUpdatePolicyAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (DeploymentComponentUpdatePolicyAction -> Pair)
-> Maybe DeploymentComponentUpdatePolicyAction -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DeploymentComponentUpdatePolicyAction
action,
            (Text
"timeoutInSeconds" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
timeoutInSeconds
          ]
      )