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

import qualified Amazonka.Core as Core
import Amazonka.GreengrassV2.Types.DeploymentComponentUpdatePolicy
import Amazonka.GreengrassV2.Types.DeploymentConfigurationValidationPolicy
import Amazonka.GreengrassV2.Types.DeploymentFailureHandlingPolicy
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information about policies that define how a deployment updates
-- components and handles failure.
--
-- /See:/ 'newDeploymentPolicies' smart constructor.
data DeploymentPolicies = DeploymentPolicies'
  { -- | The failure handling policy for the configuration deployment. This
    -- policy defines what to do if the deployment fails.
    --
    -- Default: @ROLLBACK@
    DeploymentPolicies -> Maybe DeploymentFailureHandlingPolicy
failureHandlingPolicy :: Prelude.Maybe DeploymentFailureHandlingPolicy,
    -- | The configuration validation policy for the configuration deployment.
    -- This policy defines how long each component has to validate its
    -- configure updates.
    DeploymentPolicies -> Maybe DeploymentConfigurationValidationPolicy
configurationValidationPolicy :: Prelude.Maybe DeploymentConfigurationValidationPolicy,
    -- | The component update policy for the configuration deployment. This
    -- policy defines when it\'s safe to deploy the configuration to devices.
    DeploymentPolicies -> Maybe DeploymentComponentUpdatePolicy
componentUpdatePolicy :: Prelude.Maybe DeploymentComponentUpdatePolicy
  }
  deriving (DeploymentPolicies -> DeploymentPolicies -> Bool
(DeploymentPolicies -> DeploymentPolicies -> Bool)
-> (DeploymentPolicies -> DeploymentPolicies -> Bool)
-> Eq DeploymentPolicies
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeploymentPolicies -> DeploymentPolicies -> Bool
$c/= :: DeploymentPolicies -> DeploymentPolicies -> Bool
== :: DeploymentPolicies -> DeploymentPolicies -> Bool
$c== :: DeploymentPolicies -> DeploymentPolicies -> Bool
Prelude.Eq, ReadPrec [DeploymentPolicies]
ReadPrec DeploymentPolicies
Int -> ReadS DeploymentPolicies
ReadS [DeploymentPolicies]
(Int -> ReadS DeploymentPolicies)
-> ReadS [DeploymentPolicies]
-> ReadPrec DeploymentPolicies
-> ReadPrec [DeploymentPolicies]
-> Read DeploymentPolicies
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeploymentPolicies]
$creadListPrec :: ReadPrec [DeploymentPolicies]
readPrec :: ReadPrec DeploymentPolicies
$creadPrec :: ReadPrec DeploymentPolicies
readList :: ReadS [DeploymentPolicies]
$creadList :: ReadS [DeploymentPolicies]
readsPrec :: Int -> ReadS DeploymentPolicies
$creadsPrec :: Int -> ReadS DeploymentPolicies
Prelude.Read, Int -> DeploymentPolicies -> ShowS
[DeploymentPolicies] -> ShowS
DeploymentPolicies -> String
(Int -> DeploymentPolicies -> ShowS)
-> (DeploymentPolicies -> String)
-> ([DeploymentPolicies] -> ShowS)
-> Show DeploymentPolicies
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeploymentPolicies] -> ShowS
$cshowList :: [DeploymentPolicies] -> ShowS
show :: DeploymentPolicies -> String
$cshow :: DeploymentPolicies -> String
showsPrec :: Int -> DeploymentPolicies -> ShowS
$cshowsPrec :: Int -> DeploymentPolicies -> ShowS
Prelude.Show, (forall x. DeploymentPolicies -> Rep DeploymentPolicies x)
-> (forall x. Rep DeploymentPolicies x -> DeploymentPolicies)
-> Generic DeploymentPolicies
forall x. Rep DeploymentPolicies x -> DeploymentPolicies
forall x. DeploymentPolicies -> Rep DeploymentPolicies x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeploymentPolicies x -> DeploymentPolicies
$cfrom :: forall x. DeploymentPolicies -> Rep DeploymentPolicies x
Prelude.Generic)

-- |
-- Create a value of 'DeploymentPolicies' 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:
--
-- 'failureHandlingPolicy', 'deploymentPolicies_failureHandlingPolicy' - The failure handling policy for the configuration deployment. This
-- policy defines what to do if the deployment fails.
--
-- Default: @ROLLBACK@
--
-- 'configurationValidationPolicy', 'deploymentPolicies_configurationValidationPolicy' - The configuration validation policy for the configuration deployment.
-- This policy defines how long each component has to validate its
-- configure updates.
--
-- 'componentUpdatePolicy', 'deploymentPolicies_componentUpdatePolicy' - The component update policy for the configuration deployment. This
-- policy defines when it\'s safe to deploy the configuration to devices.
newDeploymentPolicies ::
  DeploymentPolicies
newDeploymentPolicies :: DeploymentPolicies
newDeploymentPolicies =
  DeploymentPolicies' :: Maybe DeploymentFailureHandlingPolicy
-> Maybe DeploymentConfigurationValidationPolicy
-> Maybe DeploymentComponentUpdatePolicy
-> DeploymentPolicies
DeploymentPolicies'
    { $sel:failureHandlingPolicy:DeploymentPolicies' :: Maybe DeploymentFailureHandlingPolicy
failureHandlingPolicy =
        Maybe DeploymentFailureHandlingPolicy
forall a. Maybe a
Prelude.Nothing,
      $sel:configurationValidationPolicy:DeploymentPolicies' :: Maybe DeploymentConfigurationValidationPolicy
configurationValidationPolicy = Maybe DeploymentConfigurationValidationPolicy
forall a. Maybe a
Prelude.Nothing,
      $sel:componentUpdatePolicy:DeploymentPolicies' :: Maybe DeploymentComponentUpdatePolicy
componentUpdatePolicy = Maybe DeploymentComponentUpdatePolicy
forall a. Maybe a
Prelude.Nothing
    }

-- | The failure handling policy for the configuration deployment. This
-- policy defines what to do if the deployment fails.
--
-- Default: @ROLLBACK@
deploymentPolicies_failureHandlingPolicy :: Lens.Lens' DeploymentPolicies (Prelude.Maybe DeploymentFailureHandlingPolicy)
deploymentPolicies_failureHandlingPolicy :: (Maybe DeploymentFailureHandlingPolicy
 -> f (Maybe DeploymentFailureHandlingPolicy))
-> DeploymentPolicies -> f DeploymentPolicies
deploymentPolicies_failureHandlingPolicy = (DeploymentPolicies -> Maybe DeploymentFailureHandlingPolicy)
-> (DeploymentPolicies
    -> Maybe DeploymentFailureHandlingPolicy -> DeploymentPolicies)
-> Lens
     DeploymentPolicies
     DeploymentPolicies
     (Maybe DeploymentFailureHandlingPolicy)
     (Maybe DeploymentFailureHandlingPolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentPolicies' {Maybe DeploymentFailureHandlingPolicy
failureHandlingPolicy :: Maybe DeploymentFailureHandlingPolicy
$sel:failureHandlingPolicy:DeploymentPolicies' :: DeploymentPolicies -> Maybe DeploymentFailureHandlingPolicy
failureHandlingPolicy} -> Maybe DeploymentFailureHandlingPolicy
failureHandlingPolicy) (\s :: DeploymentPolicies
s@DeploymentPolicies' {} Maybe DeploymentFailureHandlingPolicy
a -> DeploymentPolicies
s {$sel:failureHandlingPolicy:DeploymentPolicies' :: Maybe DeploymentFailureHandlingPolicy
failureHandlingPolicy = Maybe DeploymentFailureHandlingPolicy
a} :: DeploymentPolicies)

-- | The configuration validation policy for the configuration deployment.
-- This policy defines how long each component has to validate its
-- configure updates.
deploymentPolicies_configurationValidationPolicy :: Lens.Lens' DeploymentPolicies (Prelude.Maybe DeploymentConfigurationValidationPolicy)
deploymentPolicies_configurationValidationPolicy :: (Maybe DeploymentConfigurationValidationPolicy
 -> f (Maybe DeploymentConfigurationValidationPolicy))
-> DeploymentPolicies -> f DeploymentPolicies
deploymentPolicies_configurationValidationPolicy = (DeploymentPolicies
 -> Maybe DeploymentConfigurationValidationPolicy)
-> (DeploymentPolicies
    -> Maybe DeploymentConfigurationValidationPolicy
    -> DeploymentPolicies)
-> Lens
     DeploymentPolicies
     DeploymentPolicies
     (Maybe DeploymentConfigurationValidationPolicy)
     (Maybe DeploymentConfigurationValidationPolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentPolicies' {Maybe DeploymentConfigurationValidationPolicy
configurationValidationPolicy :: Maybe DeploymentConfigurationValidationPolicy
$sel:configurationValidationPolicy:DeploymentPolicies' :: DeploymentPolicies -> Maybe DeploymentConfigurationValidationPolicy
configurationValidationPolicy} -> Maybe DeploymentConfigurationValidationPolicy
configurationValidationPolicy) (\s :: DeploymentPolicies
s@DeploymentPolicies' {} Maybe DeploymentConfigurationValidationPolicy
a -> DeploymentPolicies
s {$sel:configurationValidationPolicy:DeploymentPolicies' :: Maybe DeploymentConfigurationValidationPolicy
configurationValidationPolicy = Maybe DeploymentConfigurationValidationPolicy
a} :: DeploymentPolicies)

-- | The component update policy for the configuration deployment. This
-- policy defines when it\'s safe to deploy the configuration to devices.
deploymentPolicies_componentUpdatePolicy :: Lens.Lens' DeploymentPolicies (Prelude.Maybe DeploymentComponentUpdatePolicy)
deploymentPolicies_componentUpdatePolicy :: (Maybe DeploymentComponentUpdatePolicy
 -> f (Maybe DeploymentComponentUpdatePolicy))
-> DeploymentPolicies -> f DeploymentPolicies
deploymentPolicies_componentUpdatePolicy = (DeploymentPolicies -> Maybe DeploymentComponentUpdatePolicy)
-> (DeploymentPolicies
    -> Maybe DeploymentComponentUpdatePolicy -> DeploymentPolicies)
-> Lens
     DeploymentPolicies
     DeploymentPolicies
     (Maybe DeploymentComponentUpdatePolicy)
     (Maybe DeploymentComponentUpdatePolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeploymentPolicies' {Maybe DeploymentComponentUpdatePolicy
componentUpdatePolicy :: Maybe DeploymentComponentUpdatePolicy
$sel:componentUpdatePolicy:DeploymentPolicies' :: DeploymentPolicies -> Maybe DeploymentComponentUpdatePolicy
componentUpdatePolicy} -> Maybe DeploymentComponentUpdatePolicy
componentUpdatePolicy) (\s :: DeploymentPolicies
s@DeploymentPolicies' {} Maybe DeploymentComponentUpdatePolicy
a -> DeploymentPolicies
s {$sel:componentUpdatePolicy:DeploymentPolicies' :: Maybe DeploymentComponentUpdatePolicy
componentUpdatePolicy = Maybe DeploymentComponentUpdatePolicy
a} :: DeploymentPolicies)

instance Core.FromJSON DeploymentPolicies where
  parseJSON :: Value -> Parser DeploymentPolicies
parseJSON =
    String
-> (Object -> Parser DeploymentPolicies)
-> Value
-> Parser DeploymentPolicies
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DeploymentPolicies"
      ( \Object
x ->
          Maybe DeploymentFailureHandlingPolicy
-> Maybe DeploymentConfigurationValidationPolicy
-> Maybe DeploymentComponentUpdatePolicy
-> DeploymentPolicies
DeploymentPolicies'
            (Maybe DeploymentFailureHandlingPolicy
 -> Maybe DeploymentConfigurationValidationPolicy
 -> Maybe DeploymentComponentUpdatePolicy
 -> DeploymentPolicies)
-> Parser (Maybe DeploymentFailureHandlingPolicy)
-> Parser
     (Maybe DeploymentConfigurationValidationPolicy
      -> Maybe DeploymentComponentUpdatePolicy -> DeploymentPolicies)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe DeploymentFailureHandlingPolicy)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"failureHandlingPolicy")
            Parser
  (Maybe DeploymentConfigurationValidationPolicy
   -> Maybe DeploymentComponentUpdatePolicy -> DeploymentPolicies)
-> Parser (Maybe DeploymentConfigurationValidationPolicy)
-> Parser
     (Maybe DeploymentComponentUpdatePolicy -> DeploymentPolicies)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object
-> Text -> Parser (Maybe DeploymentConfigurationValidationPolicy)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"configurationValidationPolicy")
            Parser
  (Maybe DeploymentComponentUpdatePolicy -> DeploymentPolicies)
-> Parser (Maybe DeploymentComponentUpdatePolicy)
-> Parser DeploymentPolicies
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe DeploymentComponentUpdatePolicy)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"componentUpdatePolicy")
      )

instance Prelude.Hashable DeploymentPolicies

instance Prelude.NFData DeploymentPolicies

instance Core.ToJSON DeploymentPolicies where
  toJSON :: DeploymentPolicies -> Value
toJSON DeploymentPolicies' {Maybe DeploymentComponentUpdatePolicy
Maybe DeploymentConfigurationValidationPolicy
Maybe DeploymentFailureHandlingPolicy
componentUpdatePolicy :: Maybe DeploymentComponentUpdatePolicy
configurationValidationPolicy :: Maybe DeploymentConfigurationValidationPolicy
failureHandlingPolicy :: Maybe DeploymentFailureHandlingPolicy
$sel:componentUpdatePolicy:DeploymentPolicies' :: DeploymentPolicies -> Maybe DeploymentComponentUpdatePolicy
$sel:configurationValidationPolicy:DeploymentPolicies' :: DeploymentPolicies -> Maybe DeploymentConfigurationValidationPolicy
$sel:failureHandlingPolicy:DeploymentPolicies' :: DeploymentPolicies -> Maybe DeploymentFailureHandlingPolicy
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"failureHandlingPolicy" Text -> DeploymentFailureHandlingPolicy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (DeploymentFailureHandlingPolicy -> Pair)
-> Maybe DeploymentFailureHandlingPolicy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DeploymentFailureHandlingPolicy
failureHandlingPolicy,
            (Text
"configurationValidationPolicy" Text -> DeploymentConfigurationValidationPolicy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (DeploymentConfigurationValidationPolicy -> Pair)
-> Maybe DeploymentConfigurationValidationPolicy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DeploymentConfigurationValidationPolicy
configurationValidationPolicy,
            (Text
"componentUpdatePolicy" Text -> DeploymentComponentUpdatePolicy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (DeploymentComponentUpdatePolicy -> Pair)
-> Maybe DeploymentComponentUpdatePolicy -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DeploymentComponentUpdatePolicy
componentUpdatePolicy
          ]
      )