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

import Amazonka.Batch.Types.NodeRangeProperty
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object representing the node properties of a multi-node parallel job.
--
-- /See:/ 'newNodeProperties' smart constructor.
data NodeProperties = NodeProperties'
  { -- | The number of nodes associated with a multi-node parallel job.
    NodeProperties -> Int
numNodes :: Prelude.Int,
    -- | Specifies the node index for the main node of a multi-node parallel job.
    -- This node index value must be fewer than the number of nodes.
    NodeProperties -> Int
mainNode :: Prelude.Int,
    -- | A list of node ranges and their properties associated with a multi-node
    -- parallel job.
    NodeProperties -> [NodeRangeProperty]
nodeRangeProperties :: [NodeRangeProperty]
  }
  deriving (NodeProperties -> NodeProperties -> Bool
(NodeProperties -> NodeProperties -> Bool)
-> (NodeProperties -> NodeProperties -> Bool) -> Eq NodeProperties
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NodeProperties -> NodeProperties -> Bool
$c/= :: NodeProperties -> NodeProperties -> Bool
== :: NodeProperties -> NodeProperties -> Bool
$c== :: NodeProperties -> NodeProperties -> Bool
Prelude.Eq, ReadPrec [NodeProperties]
ReadPrec NodeProperties
Int -> ReadS NodeProperties
ReadS [NodeProperties]
(Int -> ReadS NodeProperties)
-> ReadS [NodeProperties]
-> ReadPrec NodeProperties
-> ReadPrec [NodeProperties]
-> Read NodeProperties
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NodeProperties]
$creadListPrec :: ReadPrec [NodeProperties]
readPrec :: ReadPrec NodeProperties
$creadPrec :: ReadPrec NodeProperties
readList :: ReadS [NodeProperties]
$creadList :: ReadS [NodeProperties]
readsPrec :: Int -> ReadS NodeProperties
$creadsPrec :: Int -> ReadS NodeProperties
Prelude.Read, Int -> NodeProperties -> ShowS
[NodeProperties] -> ShowS
NodeProperties -> String
(Int -> NodeProperties -> ShowS)
-> (NodeProperties -> String)
-> ([NodeProperties] -> ShowS)
-> Show NodeProperties
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NodeProperties] -> ShowS
$cshowList :: [NodeProperties] -> ShowS
show :: NodeProperties -> String
$cshow :: NodeProperties -> String
showsPrec :: Int -> NodeProperties -> ShowS
$cshowsPrec :: Int -> NodeProperties -> ShowS
Prelude.Show, (forall x. NodeProperties -> Rep NodeProperties x)
-> (forall x. Rep NodeProperties x -> NodeProperties)
-> Generic NodeProperties
forall x. Rep NodeProperties x -> NodeProperties
forall x. NodeProperties -> Rep NodeProperties x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NodeProperties x -> NodeProperties
$cfrom :: forall x. NodeProperties -> Rep NodeProperties x
Prelude.Generic)

-- |
-- Create a value of 'NodeProperties' 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:
--
-- 'numNodes', 'nodeProperties_numNodes' - The number of nodes associated with a multi-node parallel job.
--
-- 'mainNode', 'nodeProperties_mainNode' - Specifies the node index for the main node of a multi-node parallel job.
-- This node index value must be fewer than the number of nodes.
--
-- 'nodeRangeProperties', 'nodeProperties_nodeRangeProperties' - A list of node ranges and their properties associated with a multi-node
-- parallel job.
newNodeProperties ::
  -- | 'numNodes'
  Prelude.Int ->
  -- | 'mainNode'
  Prelude.Int ->
  NodeProperties
newNodeProperties :: Int -> Int -> NodeProperties
newNodeProperties Int
pNumNodes_ Int
pMainNode_ =
  NodeProperties' :: Int -> Int -> [NodeRangeProperty] -> NodeProperties
NodeProperties'
    { $sel:numNodes:NodeProperties' :: Int
numNodes = Int
pNumNodes_,
      $sel:mainNode:NodeProperties' :: Int
mainNode = Int
pMainNode_,
      $sel:nodeRangeProperties:NodeProperties' :: [NodeRangeProperty]
nodeRangeProperties = [NodeRangeProperty]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The number of nodes associated with a multi-node parallel job.
nodeProperties_numNodes :: Lens.Lens' NodeProperties Prelude.Int
nodeProperties_numNodes :: (Int -> f Int) -> NodeProperties -> f NodeProperties
nodeProperties_numNodes = (NodeProperties -> Int)
-> (NodeProperties -> Int -> NodeProperties)
-> Lens NodeProperties NodeProperties Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NodeProperties' {Int
numNodes :: Int
$sel:numNodes:NodeProperties' :: NodeProperties -> Int
numNodes} -> Int
numNodes) (\s :: NodeProperties
s@NodeProperties' {} Int
a -> NodeProperties
s {$sel:numNodes:NodeProperties' :: Int
numNodes = Int
a} :: NodeProperties)

-- | Specifies the node index for the main node of a multi-node parallel job.
-- This node index value must be fewer than the number of nodes.
nodeProperties_mainNode :: Lens.Lens' NodeProperties Prelude.Int
nodeProperties_mainNode :: (Int -> f Int) -> NodeProperties -> f NodeProperties
nodeProperties_mainNode = (NodeProperties -> Int)
-> (NodeProperties -> Int -> NodeProperties)
-> Lens NodeProperties NodeProperties Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NodeProperties' {Int
mainNode :: Int
$sel:mainNode:NodeProperties' :: NodeProperties -> Int
mainNode} -> Int
mainNode) (\s :: NodeProperties
s@NodeProperties' {} Int
a -> NodeProperties
s {$sel:mainNode:NodeProperties' :: Int
mainNode = Int
a} :: NodeProperties)

-- | A list of node ranges and their properties associated with a multi-node
-- parallel job.
nodeProperties_nodeRangeProperties :: Lens.Lens' NodeProperties [NodeRangeProperty]
nodeProperties_nodeRangeProperties :: ([NodeRangeProperty] -> f [NodeRangeProperty])
-> NodeProperties -> f NodeProperties
nodeProperties_nodeRangeProperties = (NodeProperties -> [NodeRangeProperty])
-> (NodeProperties -> [NodeRangeProperty] -> NodeProperties)
-> Lens
     NodeProperties
     NodeProperties
     [NodeRangeProperty]
     [NodeRangeProperty]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NodeProperties' {[NodeRangeProperty]
nodeRangeProperties :: [NodeRangeProperty]
$sel:nodeRangeProperties:NodeProperties' :: NodeProperties -> [NodeRangeProperty]
nodeRangeProperties} -> [NodeRangeProperty]
nodeRangeProperties) (\s :: NodeProperties
s@NodeProperties' {} [NodeRangeProperty]
a -> NodeProperties
s {$sel:nodeRangeProperties:NodeProperties' :: [NodeRangeProperty]
nodeRangeProperties = [NodeRangeProperty]
a} :: NodeProperties) (([NodeRangeProperty] -> f [NodeRangeProperty])
 -> NodeProperties -> f NodeProperties)
-> (([NodeRangeProperty] -> f [NodeRangeProperty])
    -> [NodeRangeProperty] -> f [NodeRangeProperty])
-> ([NodeRangeProperty] -> f [NodeRangeProperty])
-> NodeProperties
-> f NodeProperties
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([NodeRangeProperty] -> f [NodeRangeProperty])
-> [NodeRangeProperty] -> f [NodeRangeProperty]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON NodeProperties where
  parseJSON :: Value -> Parser NodeProperties
parseJSON =
    String
-> (Object -> Parser NodeProperties)
-> Value
-> Parser NodeProperties
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"NodeProperties"
      ( \Object
x ->
          Int -> Int -> [NodeRangeProperty] -> NodeProperties
NodeProperties'
            (Int -> Int -> [NodeRangeProperty] -> NodeProperties)
-> Parser Int
-> Parser (Int -> [NodeRangeProperty] -> NodeProperties)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"numNodes")
            Parser (Int -> [NodeRangeProperty] -> NodeProperties)
-> Parser Int -> Parser ([NodeRangeProperty] -> NodeProperties)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"mainNode")
            Parser ([NodeRangeProperty] -> NodeProperties)
-> Parser [NodeRangeProperty] -> Parser NodeProperties
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe [NodeRangeProperty])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"nodeRangeProperties"
                            Parser (Maybe [NodeRangeProperty])
-> [NodeRangeProperty] -> Parser [NodeRangeProperty]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [NodeRangeProperty]
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable NodeProperties

instance Prelude.NFData NodeProperties

instance Core.ToJSON NodeProperties where
  toJSON :: NodeProperties -> Value
toJSON NodeProperties' {Int
[NodeRangeProperty]
nodeRangeProperties :: [NodeRangeProperty]
mainNode :: Int
numNodes :: Int
$sel:nodeRangeProperties:NodeProperties' :: NodeProperties -> [NodeRangeProperty]
$sel:mainNode:NodeProperties' :: NodeProperties -> Int
$sel:numNodes:NodeProperties' :: NodeProperties -> Int
..} =
    [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
"numNodes" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
numNodes),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"mainNode" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
mainNode),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"nodeRangeProperties" Text -> [NodeRangeProperty] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [NodeRangeProperty]
nodeRangeProperties)
          ]
      )