{-# 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.ElastiCache.Types.NodeGroup
-- 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.ElastiCache.Types.NodeGroup where

import qualified Amazonka.Core as Core
import Amazonka.ElastiCache.Types.Endpoint
import Amazonka.ElastiCache.Types.NodeGroupMember
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a collection of cache nodes in a replication group. One node
-- in the node group is the read\/write primary node. All the other nodes
-- are read-only Replica nodes.
--
-- /See:/ 'newNodeGroup' smart constructor.
data NodeGroup = NodeGroup'
  { -- | The current state of this replication group - @creating@, @available@,
    -- @modifying@, @deleting@.
    NodeGroup -> Maybe Text
status :: Prelude.Maybe Prelude.Text,
    -- | The endpoint of the primary node in this node group (shard).
    NodeGroup -> Maybe Endpoint
primaryEndpoint :: Prelude.Maybe Endpoint,
    -- | The keyspace for this node group (shard).
    NodeGroup -> Maybe Text
slots :: Prelude.Maybe Prelude.Text,
    -- | A list containing information about individual nodes within the node
    -- group (shard).
    NodeGroup -> Maybe [NodeGroupMember]
nodeGroupMembers :: Prelude.Maybe [NodeGroupMember],
    -- | The identifier for the node group (shard). A Redis (cluster mode
    -- disabled) replication group contains only 1 node group; therefore, the
    -- node group ID is 0001. A Redis (cluster mode enabled) replication group
    -- contains 1 to 90 node groups numbered 0001 to 0090. Optionally, the user
    -- can provide the id for a node group.
    NodeGroup -> Maybe Text
nodeGroupId :: Prelude.Maybe Prelude.Text,
    -- | The endpoint of the replica nodes in this node group (shard).
    NodeGroup -> Maybe Endpoint
readerEndpoint :: Prelude.Maybe Endpoint
  }
  deriving (NodeGroup -> NodeGroup -> Bool
(NodeGroup -> NodeGroup -> Bool)
-> (NodeGroup -> NodeGroup -> Bool) -> Eq NodeGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NodeGroup -> NodeGroup -> Bool
$c/= :: NodeGroup -> NodeGroup -> Bool
== :: NodeGroup -> NodeGroup -> Bool
$c== :: NodeGroup -> NodeGroup -> Bool
Prelude.Eq, ReadPrec [NodeGroup]
ReadPrec NodeGroup
Int -> ReadS NodeGroup
ReadS [NodeGroup]
(Int -> ReadS NodeGroup)
-> ReadS [NodeGroup]
-> ReadPrec NodeGroup
-> ReadPrec [NodeGroup]
-> Read NodeGroup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NodeGroup]
$creadListPrec :: ReadPrec [NodeGroup]
readPrec :: ReadPrec NodeGroup
$creadPrec :: ReadPrec NodeGroup
readList :: ReadS [NodeGroup]
$creadList :: ReadS [NodeGroup]
readsPrec :: Int -> ReadS NodeGroup
$creadsPrec :: Int -> ReadS NodeGroup
Prelude.Read, Int -> NodeGroup -> ShowS
[NodeGroup] -> ShowS
NodeGroup -> String
(Int -> NodeGroup -> ShowS)
-> (NodeGroup -> String)
-> ([NodeGroup] -> ShowS)
-> Show NodeGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NodeGroup] -> ShowS
$cshowList :: [NodeGroup] -> ShowS
show :: NodeGroup -> String
$cshow :: NodeGroup -> String
showsPrec :: Int -> NodeGroup -> ShowS
$cshowsPrec :: Int -> NodeGroup -> ShowS
Prelude.Show, (forall x. NodeGroup -> Rep NodeGroup x)
-> (forall x. Rep NodeGroup x -> NodeGroup) -> Generic NodeGroup
forall x. Rep NodeGroup x -> NodeGroup
forall x. NodeGroup -> Rep NodeGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NodeGroup x -> NodeGroup
$cfrom :: forall x. NodeGroup -> Rep NodeGroup x
Prelude.Generic)

-- |
-- Create a value of 'NodeGroup' 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:
--
-- 'status', 'nodeGroup_status' - The current state of this replication group - @creating@, @available@,
-- @modifying@, @deleting@.
--
-- 'primaryEndpoint', 'nodeGroup_primaryEndpoint' - The endpoint of the primary node in this node group (shard).
--
-- 'slots', 'nodeGroup_slots' - The keyspace for this node group (shard).
--
-- 'nodeGroupMembers', 'nodeGroup_nodeGroupMembers' - A list containing information about individual nodes within the node
-- group (shard).
--
-- 'nodeGroupId', 'nodeGroup_nodeGroupId' - The identifier for the node group (shard). A Redis (cluster mode
-- disabled) replication group contains only 1 node group; therefore, the
-- node group ID is 0001. A Redis (cluster mode enabled) replication group
-- contains 1 to 90 node groups numbered 0001 to 0090. Optionally, the user
-- can provide the id for a node group.
--
-- 'readerEndpoint', 'nodeGroup_readerEndpoint' - The endpoint of the replica nodes in this node group (shard).
newNodeGroup ::
  NodeGroup
newNodeGroup :: NodeGroup
newNodeGroup =
  NodeGroup' :: Maybe Text
-> Maybe Endpoint
-> Maybe Text
-> Maybe [NodeGroupMember]
-> Maybe Text
-> Maybe Endpoint
-> NodeGroup
NodeGroup'
    { $sel:status:NodeGroup' :: Maybe Text
status = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:primaryEndpoint:NodeGroup' :: Maybe Endpoint
primaryEndpoint = Maybe Endpoint
forall a. Maybe a
Prelude.Nothing,
      $sel:slots:NodeGroup' :: Maybe Text
slots = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:nodeGroupMembers:NodeGroup' :: Maybe [NodeGroupMember]
nodeGroupMembers = Maybe [NodeGroupMember]
forall a. Maybe a
Prelude.Nothing,
      $sel:nodeGroupId:NodeGroup' :: Maybe Text
nodeGroupId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:readerEndpoint:NodeGroup' :: Maybe Endpoint
readerEndpoint = Maybe Endpoint
forall a. Maybe a
Prelude.Nothing
    }

-- | The current state of this replication group - @creating@, @available@,
-- @modifying@, @deleting@.
nodeGroup_status :: Lens.Lens' NodeGroup (Prelude.Maybe Prelude.Text)
nodeGroup_status :: (Maybe Text -> f (Maybe Text)) -> NodeGroup -> f NodeGroup
nodeGroup_status = (NodeGroup -> Maybe Text)
-> (NodeGroup -> Maybe Text -> NodeGroup)
-> Lens NodeGroup NodeGroup (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NodeGroup' {Maybe Text
status :: Maybe Text
$sel:status:NodeGroup' :: NodeGroup -> Maybe Text
status} -> Maybe Text
status) (\s :: NodeGroup
s@NodeGroup' {} Maybe Text
a -> NodeGroup
s {$sel:status:NodeGroup' :: Maybe Text
status = Maybe Text
a} :: NodeGroup)

-- | The endpoint of the primary node in this node group (shard).
nodeGroup_primaryEndpoint :: Lens.Lens' NodeGroup (Prelude.Maybe Endpoint)
nodeGroup_primaryEndpoint :: (Maybe Endpoint -> f (Maybe Endpoint)) -> NodeGroup -> f NodeGroup
nodeGroup_primaryEndpoint = (NodeGroup -> Maybe Endpoint)
-> (NodeGroup -> Maybe Endpoint -> NodeGroup)
-> Lens NodeGroup NodeGroup (Maybe Endpoint) (Maybe Endpoint)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NodeGroup' {Maybe Endpoint
primaryEndpoint :: Maybe Endpoint
$sel:primaryEndpoint:NodeGroup' :: NodeGroup -> Maybe Endpoint
primaryEndpoint} -> Maybe Endpoint
primaryEndpoint) (\s :: NodeGroup
s@NodeGroup' {} Maybe Endpoint
a -> NodeGroup
s {$sel:primaryEndpoint:NodeGroup' :: Maybe Endpoint
primaryEndpoint = Maybe Endpoint
a} :: NodeGroup)

-- | The keyspace for this node group (shard).
nodeGroup_slots :: Lens.Lens' NodeGroup (Prelude.Maybe Prelude.Text)
nodeGroup_slots :: (Maybe Text -> f (Maybe Text)) -> NodeGroup -> f NodeGroup
nodeGroup_slots = (NodeGroup -> Maybe Text)
-> (NodeGroup -> Maybe Text -> NodeGroup)
-> Lens NodeGroup NodeGroup (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NodeGroup' {Maybe Text
slots :: Maybe Text
$sel:slots:NodeGroup' :: NodeGroup -> Maybe Text
slots} -> Maybe Text
slots) (\s :: NodeGroup
s@NodeGroup' {} Maybe Text
a -> NodeGroup
s {$sel:slots:NodeGroup' :: Maybe Text
slots = Maybe Text
a} :: NodeGroup)

-- | A list containing information about individual nodes within the node
-- group (shard).
nodeGroup_nodeGroupMembers :: Lens.Lens' NodeGroup (Prelude.Maybe [NodeGroupMember])
nodeGroup_nodeGroupMembers :: (Maybe [NodeGroupMember] -> f (Maybe [NodeGroupMember]))
-> NodeGroup -> f NodeGroup
nodeGroup_nodeGroupMembers = (NodeGroup -> Maybe [NodeGroupMember])
-> (NodeGroup -> Maybe [NodeGroupMember] -> NodeGroup)
-> Lens
     NodeGroup
     NodeGroup
     (Maybe [NodeGroupMember])
     (Maybe [NodeGroupMember])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NodeGroup' {Maybe [NodeGroupMember]
nodeGroupMembers :: Maybe [NodeGroupMember]
$sel:nodeGroupMembers:NodeGroup' :: NodeGroup -> Maybe [NodeGroupMember]
nodeGroupMembers} -> Maybe [NodeGroupMember]
nodeGroupMembers) (\s :: NodeGroup
s@NodeGroup' {} Maybe [NodeGroupMember]
a -> NodeGroup
s {$sel:nodeGroupMembers:NodeGroup' :: Maybe [NodeGroupMember]
nodeGroupMembers = Maybe [NodeGroupMember]
a} :: NodeGroup) ((Maybe [NodeGroupMember] -> f (Maybe [NodeGroupMember]))
 -> NodeGroup -> f NodeGroup)
-> ((Maybe [NodeGroupMember] -> f (Maybe [NodeGroupMember]))
    -> Maybe [NodeGroupMember] -> f (Maybe [NodeGroupMember]))
-> (Maybe [NodeGroupMember] -> f (Maybe [NodeGroupMember]))
-> NodeGroup
-> f NodeGroup
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [NodeGroupMember]
  [NodeGroupMember]
  [NodeGroupMember]
  [NodeGroupMember]
-> Iso
     (Maybe [NodeGroupMember])
     (Maybe [NodeGroupMember])
     (Maybe [NodeGroupMember])
     (Maybe [NodeGroupMember])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [NodeGroupMember]
  [NodeGroupMember]
  [NodeGroupMember]
  [NodeGroupMember]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The identifier for the node group (shard). A Redis (cluster mode
-- disabled) replication group contains only 1 node group; therefore, the
-- node group ID is 0001. A Redis (cluster mode enabled) replication group
-- contains 1 to 90 node groups numbered 0001 to 0090. Optionally, the user
-- can provide the id for a node group.
nodeGroup_nodeGroupId :: Lens.Lens' NodeGroup (Prelude.Maybe Prelude.Text)
nodeGroup_nodeGroupId :: (Maybe Text -> f (Maybe Text)) -> NodeGroup -> f NodeGroup
nodeGroup_nodeGroupId = (NodeGroup -> Maybe Text)
-> (NodeGroup -> Maybe Text -> NodeGroup)
-> Lens NodeGroup NodeGroup (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NodeGroup' {Maybe Text
nodeGroupId :: Maybe Text
$sel:nodeGroupId:NodeGroup' :: NodeGroup -> Maybe Text
nodeGroupId} -> Maybe Text
nodeGroupId) (\s :: NodeGroup
s@NodeGroup' {} Maybe Text
a -> NodeGroup
s {$sel:nodeGroupId:NodeGroup' :: Maybe Text
nodeGroupId = Maybe Text
a} :: NodeGroup)

-- | The endpoint of the replica nodes in this node group (shard).
nodeGroup_readerEndpoint :: Lens.Lens' NodeGroup (Prelude.Maybe Endpoint)
nodeGroup_readerEndpoint :: (Maybe Endpoint -> f (Maybe Endpoint)) -> NodeGroup -> f NodeGroup
nodeGroup_readerEndpoint = (NodeGroup -> Maybe Endpoint)
-> (NodeGroup -> Maybe Endpoint -> NodeGroup)
-> Lens NodeGroup NodeGroup (Maybe Endpoint) (Maybe Endpoint)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NodeGroup' {Maybe Endpoint
readerEndpoint :: Maybe Endpoint
$sel:readerEndpoint:NodeGroup' :: NodeGroup -> Maybe Endpoint
readerEndpoint} -> Maybe Endpoint
readerEndpoint) (\s :: NodeGroup
s@NodeGroup' {} Maybe Endpoint
a -> NodeGroup
s {$sel:readerEndpoint:NodeGroup' :: Maybe Endpoint
readerEndpoint = Maybe Endpoint
a} :: NodeGroup)

instance Core.FromXML NodeGroup where
  parseXML :: [Node] -> Either String NodeGroup
parseXML [Node]
x =
    Maybe Text
-> Maybe Endpoint
-> Maybe Text
-> Maybe [NodeGroupMember]
-> Maybe Text
-> Maybe Endpoint
-> NodeGroup
NodeGroup'
      (Maybe Text
 -> Maybe Endpoint
 -> Maybe Text
 -> Maybe [NodeGroupMember]
 -> Maybe Text
 -> Maybe Endpoint
 -> NodeGroup)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Endpoint
      -> Maybe Text
      -> Maybe [NodeGroupMember]
      -> Maybe Text
      -> Maybe Endpoint
      -> NodeGroup)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Status")
      Either
  String
  (Maybe Endpoint
   -> Maybe Text
   -> Maybe [NodeGroupMember]
   -> Maybe Text
   -> Maybe Endpoint
   -> NodeGroup)
-> Either String (Maybe Endpoint)
-> Either
     String
     (Maybe Text
      -> Maybe [NodeGroupMember]
      -> Maybe Text
      -> Maybe Endpoint
      -> NodeGroup)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Endpoint)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"PrimaryEndpoint")
      Either
  String
  (Maybe Text
   -> Maybe [NodeGroupMember]
   -> Maybe Text
   -> Maybe Endpoint
   -> NodeGroup)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe [NodeGroupMember]
      -> Maybe Text -> Maybe Endpoint -> NodeGroup)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Slots")
      Either
  String
  (Maybe [NodeGroupMember]
   -> Maybe Text -> Maybe Endpoint -> NodeGroup)
-> Either String (Maybe [NodeGroupMember])
-> Either String (Maybe Text -> Maybe Endpoint -> NodeGroup)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"NodeGroupMembers"
                      Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [NodeGroupMember]))
-> Either String (Maybe [NodeGroupMember])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [NodeGroupMember])
-> [Node] -> Either String (Maybe [NodeGroupMember])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [NodeGroupMember]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"NodeGroupMember")
                  )
      Either String (Maybe Text -> Maybe Endpoint -> NodeGroup)
-> Either String (Maybe Text)
-> Either String (Maybe Endpoint -> NodeGroup)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"NodeGroupId")
      Either String (Maybe Endpoint -> NodeGroup)
-> Either String (Maybe Endpoint) -> Either String NodeGroup
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Endpoint)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"ReaderEndpoint")

instance Prelude.Hashable NodeGroup

instance Prelude.NFData NodeGroup