{-# 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.Batch.Types.Volume
-- 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.Batch.Types.Volume where

import Amazonka.Batch.Types.EFSVolumeConfiguration
import Amazonka.Batch.Types.Host
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A data volume used in a job\'s container properties.
--
-- /See:/ 'newVolume' smart constructor.
data Volume = Volume'
  { -- | The name of the volume. Up to 255 letters (uppercase and lowercase),
    -- numbers, hyphens, and underscores are allowed. This name is referenced
    -- in the @sourceVolume@ parameter of container definition @mountPoints@.
    Volume -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | This parameter is specified when you are using an Amazon Elastic File
    -- System file system for job storage. Jobs that are running on Fargate
    -- resources must specify a @platformVersion@ of at least @1.4.0@.
    Volume -> Maybe EFSVolumeConfiguration
efsVolumeConfiguration :: Prelude.Maybe EFSVolumeConfiguration,
    -- | The contents of the @host@ parameter determine whether your data volume
    -- persists on the host container instance and where it is stored. If the
    -- host parameter is empty, then the Docker daemon assigns a host path for
    -- your data volume. However, the data isn\'t guaranteed to persist after
    -- the containers associated with it stop running.
    --
    -- This parameter isn\'t applicable to jobs that are running on Fargate
    -- resources and shouldn\'t be provided.
    Volume -> Maybe Host
host :: Prelude.Maybe Host
  }
  deriving (Volume -> Volume -> Bool
(Volume -> Volume -> Bool)
-> (Volume -> Volume -> Bool) -> Eq Volume
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Volume -> Volume -> Bool
$c/= :: Volume -> Volume -> Bool
== :: Volume -> Volume -> Bool
$c== :: Volume -> Volume -> Bool
Prelude.Eq, ReadPrec [Volume]
ReadPrec Volume
Int -> ReadS Volume
ReadS [Volume]
(Int -> ReadS Volume)
-> ReadS [Volume]
-> ReadPrec Volume
-> ReadPrec [Volume]
-> Read Volume
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Volume]
$creadListPrec :: ReadPrec [Volume]
readPrec :: ReadPrec Volume
$creadPrec :: ReadPrec Volume
readList :: ReadS [Volume]
$creadList :: ReadS [Volume]
readsPrec :: Int -> ReadS Volume
$creadsPrec :: Int -> ReadS Volume
Prelude.Read, Int -> Volume -> ShowS
[Volume] -> ShowS
Volume -> String
(Int -> Volume -> ShowS)
-> (Volume -> String) -> ([Volume] -> ShowS) -> Show Volume
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Volume] -> ShowS
$cshowList :: [Volume] -> ShowS
show :: Volume -> String
$cshow :: Volume -> String
showsPrec :: Int -> Volume -> ShowS
$cshowsPrec :: Int -> Volume -> ShowS
Prelude.Show, (forall x. Volume -> Rep Volume x)
-> (forall x. Rep Volume x -> Volume) -> Generic Volume
forall x. Rep Volume x -> Volume
forall x. Volume -> Rep Volume x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Volume x -> Volume
$cfrom :: forall x. Volume -> Rep Volume x
Prelude.Generic)

-- |
-- Create a value of 'Volume' 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:
--
-- 'name', 'volume_name' - The name of the volume. Up to 255 letters (uppercase and lowercase),
-- numbers, hyphens, and underscores are allowed. This name is referenced
-- in the @sourceVolume@ parameter of container definition @mountPoints@.
--
-- 'efsVolumeConfiguration', 'volume_efsVolumeConfiguration' - This parameter is specified when you are using an Amazon Elastic File
-- System file system for job storage. Jobs that are running on Fargate
-- resources must specify a @platformVersion@ of at least @1.4.0@.
--
-- 'host', 'volume_host' - The contents of the @host@ parameter determine whether your data volume
-- persists on the host container instance and where it is stored. If the
-- host parameter is empty, then the Docker daemon assigns a host path for
-- your data volume. However, the data isn\'t guaranteed to persist after
-- the containers associated with it stop running.
--
-- This parameter isn\'t applicable to jobs that are running on Fargate
-- resources and shouldn\'t be provided.
newVolume ::
  Volume
newVolume :: Volume
newVolume =
  Volume' :: Maybe Text -> Maybe EFSVolumeConfiguration -> Maybe Host -> Volume
Volume'
    { $sel:name:Volume' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:efsVolumeConfiguration:Volume' :: Maybe EFSVolumeConfiguration
efsVolumeConfiguration = Maybe EFSVolumeConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:host:Volume' :: Maybe Host
host = Maybe Host
forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the volume. Up to 255 letters (uppercase and lowercase),
-- numbers, hyphens, and underscores are allowed. This name is referenced
-- in the @sourceVolume@ parameter of container definition @mountPoints@.
volume_name :: Lens.Lens' Volume (Prelude.Maybe Prelude.Text)
volume_name :: (Maybe Text -> f (Maybe Text)) -> Volume -> f Volume
volume_name = (Volume -> Maybe Text)
-> (Volume -> Maybe Text -> Volume)
-> Lens Volume Volume (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Volume' {Maybe Text
name :: Maybe Text
$sel:name:Volume' :: Volume -> Maybe Text
name} -> Maybe Text
name) (\s :: Volume
s@Volume' {} Maybe Text
a -> Volume
s {$sel:name:Volume' :: Maybe Text
name = Maybe Text
a} :: Volume)

-- | This parameter is specified when you are using an Amazon Elastic File
-- System file system for job storage. Jobs that are running on Fargate
-- resources must specify a @platformVersion@ of at least @1.4.0@.
volume_efsVolumeConfiguration :: Lens.Lens' Volume (Prelude.Maybe EFSVolumeConfiguration)
volume_efsVolumeConfiguration :: (Maybe EFSVolumeConfiguration -> f (Maybe EFSVolumeConfiguration))
-> Volume -> f Volume
volume_efsVolumeConfiguration = (Volume -> Maybe EFSVolumeConfiguration)
-> (Volume -> Maybe EFSVolumeConfiguration -> Volume)
-> Lens
     Volume
     Volume
     (Maybe EFSVolumeConfiguration)
     (Maybe EFSVolumeConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Volume' {Maybe EFSVolumeConfiguration
efsVolumeConfiguration :: Maybe EFSVolumeConfiguration
$sel:efsVolumeConfiguration:Volume' :: Volume -> Maybe EFSVolumeConfiguration
efsVolumeConfiguration} -> Maybe EFSVolumeConfiguration
efsVolumeConfiguration) (\s :: Volume
s@Volume' {} Maybe EFSVolumeConfiguration
a -> Volume
s {$sel:efsVolumeConfiguration:Volume' :: Maybe EFSVolumeConfiguration
efsVolumeConfiguration = Maybe EFSVolumeConfiguration
a} :: Volume)

-- | The contents of the @host@ parameter determine whether your data volume
-- persists on the host container instance and where it is stored. If the
-- host parameter is empty, then the Docker daemon assigns a host path for
-- your data volume. However, the data isn\'t guaranteed to persist after
-- the containers associated with it stop running.
--
-- This parameter isn\'t applicable to jobs that are running on Fargate
-- resources and shouldn\'t be provided.
volume_host :: Lens.Lens' Volume (Prelude.Maybe Host)
volume_host :: (Maybe Host -> f (Maybe Host)) -> Volume -> f Volume
volume_host = (Volume -> Maybe Host)
-> (Volume -> Maybe Host -> Volume)
-> Lens Volume Volume (Maybe Host) (Maybe Host)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Volume' {Maybe Host
host :: Maybe Host
$sel:host:Volume' :: Volume -> Maybe Host
host} -> Maybe Host
host) (\s :: Volume
s@Volume' {} Maybe Host
a -> Volume
s {$sel:host:Volume' :: Maybe Host
host = Maybe Host
a} :: Volume)

instance Core.FromJSON Volume where
  parseJSON :: Value -> Parser Volume
parseJSON =
    String -> (Object -> Parser Volume) -> Value -> Parser Volume
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Volume"
      ( \Object
x ->
          Maybe Text -> Maybe EFSVolumeConfiguration -> Maybe Host -> Volume
Volume'
            (Maybe Text
 -> Maybe EFSVolumeConfiguration -> Maybe Host -> Volume)
-> Parser (Maybe Text)
-> Parser (Maybe EFSVolumeConfiguration -> Maybe Host -> Volume)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"name")
            Parser (Maybe EFSVolumeConfiguration -> Maybe Host -> Volume)
-> Parser (Maybe EFSVolumeConfiguration)
-> Parser (Maybe Host -> Volume)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe EFSVolumeConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"efsVolumeConfiguration")
            Parser (Maybe Host -> Volume)
-> Parser (Maybe Host) -> Parser Volume
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Host)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"host")
      )

instance Prelude.Hashable Volume

instance Prelude.NFData Volume

instance Core.ToJSON Volume where
  toJSON :: Volume -> Value
toJSON Volume' {Maybe Text
Maybe EFSVolumeConfiguration
Maybe Host
host :: Maybe Host
efsVolumeConfiguration :: Maybe EFSVolumeConfiguration
name :: Maybe Text
$sel:host:Volume' :: Volume -> Maybe Host
$sel:efsVolumeConfiguration:Volume' :: Volume -> Maybe EFSVolumeConfiguration
$sel:name:Volume' :: Volume -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
name,
            (Text
"efsVolumeConfiguration" Text -> EFSVolumeConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (EFSVolumeConfiguration -> Pair)
-> Maybe EFSVolumeConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe EFSVolumeConfiguration
efsVolumeConfiguration,
            (Text
"host" Text -> Host -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Host -> Pair) -> Maybe Host -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Host
host
          ]
      )