{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.DAX.RebootNode
-- 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)
--
-- Reboots a single node of a DAX cluster. The reboot action takes place as
-- soon as possible. During the reboot, the node status is set to
-- REBOOTING.
--
-- @RebootNode@ restarts the DAX engine process and does not remove the
-- contents of the cache.
module Amazonka.DAX.RebootNode
  ( -- * Creating a Request
    RebootNode (..),
    newRebootNode,

    -- * Request Lenses
    rebootNode_clusterName,
    rebootNode_nodeId,

    -- * Destructuring the Response
    RebootNodeResponse (..),
    newRebootNodeResponse,

    -- * Response Lenses
    rebootNodeResponse_cluster,
    rebootNodeResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.DAX.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newRebootNode' smart constructor.
data RebootNode = RebootNode'
  { -- | The name of the DAX cluster containing the node to be rebooted.
    RebootNode -> Text
clusterName :: Prelude.Text,
    -- | The system-assigned ID of the node to be rebooted.
    RebootNode -> Text
nodeId :: Prelude.Text
  }
  deriving (RebootNode -> RebootNode -> Bool
(RebootNode -> RebootNode -> Bool)
-> (RebootNode -> RebootNode -> Bool) -> Eq RebootNode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RebootNode -> RebootNode -> Bool
$c/= :: RebootNode -> RebootNode -> Bool
== :: RebootNode -> RebootNode -> Bool
$c== :: RebootNode -> RebootNode -> Bool
Prelude.Eq, ReadPrec [RebootNode]
ReadPrec RebootNode
Int -> ReadS RebootNode
ReadS [RebootNode]
(Int -> ReadS RebootNode)
-> ReadS [RebootNode]
-> ReadPrec RebootNode
-> ReadPrec [RebootNode]
-> Read RebootNode
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RebootNode]
$creadListPrec :: ReadPrec [RebootNode]
readPrec :: ReadPrec RebootNode
$creadPrec :: ReadPrec RebootNode
readList :: ReadS [RebootNode]
$creadList :: ReadS [RebootNode]
readsPrec :: Int -> ReadS RebootNode
$creadsPrec :: Int -> ReadS RebootNode
Prelude.Read, Int -> RebootNode -> ShowS
[RebootNode] -> ShowS
RebootNode -> String
(Int -> RebootNode -> ShowS)
-> (RebootNode -> String)
-> ([RebootNode] -> ShowS)
-> Show RebootNode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RebootNode] -> ShowS
$cshowList :: [RebootNode] -> ShowS
show :: RebootNode -> String
$cshow :: RebootNode -> String
showsPrec :: Int -> RebootNode -> ShowS
$cshowsPrec :: Int -> RebootNode -> ShowS
Prelude.Show, (forall x. RebootNode -> Rep RebootNode x)
-> (forall x. Rep RebootNode x -> RebootNode) -> Generic RebootNode
forall x. Rep RebootNode x -> RebootNode
forall x. RebootNode -> Rep RebootNode x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RebootNode x -> RebootNode
$cfrom :: forall x. RebootNode -> Rep RebootNode x
Prelude.Generic)

-- |
-- Create a value of 'RebootNode' 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:
--
-- 'clusterName', 'rebootNode_clusterName' - The name of the DAX cluster containing the node to be rebooted.
--
-- 'nodeId', 'rebootNode_nodeId' - The system-assigned ID of the node to be rebooted.
newRebootNode ::
  -- | 'clusterName'
  Prelude.Text ->
  -- | 'nodeId'
  Prelude.Text ->
  RebootNode
newRebootNode :: Text -> Text -> RebootNode
newRebootNode Text
pClusterName_ Text
pNodeId_ =
  RebootNode' :: Text -> Text -> RebootNode
RebootNode'
    { $sel:clusterName:RebootNode' :: Text
clusterName = Text
pClusterName_,
      $sel:nodeId:RebootNode' :: Text
nodeId = Text
pNodeId_
    }

-- | The name of the DAX cluster containing the node to be rebooted.
rebootNode_clusterName :: Lens.Lens' RebootNode Prelude.Text
rebootNode_clusterName :: (Text -> f Text) -> RebootNode -> f RebootNode
rebootNode_clusterName = (RebootNode -> Text)
-> (RebootNode -> Text -> RebootNode)
-> Lens RebootNode RebootNode Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RebootNode' {Text
clusterName :: Text
$sel:clusterName:RebootNode' :: RebootNode -> Text
clusterName} -> Text
clusterName) (\s :: RebootNode
s@RebootNode' {} Text
a -> RebootNode
s {$sel:clusterName:RebootNode' :: Text
clusterName = Text
a} :: RebootNode)

-- | The system-assigned ID of the node to be rebooted.
rebootNode_nodeId :: Lens.Lens' RebootNode Prelude.Text
rebootNode_nodeId :: (Text -> f Text) -> RebootNode -> f RebootNode
rebootNode_nodeId = (RebootNode -> Text)
-> (RebootNode -> Text -> RebootNode)
-> Lens RebootNode RebootNode Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RebootNode' {Text
nodeId :: Text
$sel:nodeId:RebootNode' :: RebootNode -> Text
nodeId} -> Text
nodeId) (\s :: RebootNode
s@RebootNode' {} Text
a -> RebootNode
s {$sel:nodeId:RebootNode' :: Text
nodeId = Text
a} :: RebootNode)

instance Core.AWSRequest RebootNode where
  type AWSResponse RebootNode = RebootNodeResponse
  request :: RebootNode -> Request RebootNode
request = Service -> RebootNode -> Request RebootNode
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy RebootNode
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RebootNode)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse RebootNode))
-> Logger
-> Service
-> Proxy RebootNode
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RebootNode)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Cluster -> Int -> RebootNodeResponse
RebootNodeResponse'
            (Maybe Cluster -> Int -> RebootNodeResponse)
-> Either String (Maybe Cluster)
-> Either String (Int -> RebootNodeResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Cluster)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Cluster")
            Either String (Int -> RebootNodeResponse)
-> Either String Int -> Either String RebootNodeResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable RebootNode

instance Prelude.NFData RebootNode

instance Core.ToHeaders RebootNode where
  toHeaders :: RebootNode -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RebootNode -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"AmazonDAXV3.RebootNode" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON RebootNode where
  toJSON :: RebootNode -> Value
toJSON RebootNode' {Text
nodeId :: Text
clusterName :: Text
$sel:nodeId:RebootNode' :: RebootNode -> Text
$sel:clusterName:RebootNode' :: RebootNode -> Text
..} =
    [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
"ClusterName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clusterName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"NodeId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
nodeId)
          ]
      )

instance Core.ToPath RebootNode where
  toPath :: RebootNode -> ByteString
toPath = ByteString -> RebootNode -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery RebootNode where
  toQuery :: RebootNode -> QueryString
toQuery = QueryString -> RebootNode -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newRebootNodeResponse' smart constructor.
data RebootNodeResponse = RebootNodeResponse'
  { -- | A description of the DAX cluster after a node has been rebooted.
    RebootNodeResponse -> Maybe Cluster
cluster :: Prelude.Maybe Cluster,
    -- | The response's http status code.
    RebootNodeResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (RebootNodeResponse -> RebootNodeResponse -> Bool
(RebootNodeResponse -> RebootNodeResponse -> Bool)
-> (RebootNodeResponse -> RebootNodeResponse -> Bool)
-> Eq RebootNodeResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RebootNodeResponse -> RebootNodeResponse -> Bool
$c/= :: RebootNodeResponse -> RebootNodeResponse -> Bool
== :: RebootNodeResponse -> RebootNodeResponse -> Bool
$c== :: RebootNodeResponse -> RebootNodeResponse -> Bool
Prelude.Eq, ReadPrec [RebootNodeResponse]
ReadPrec RebootNodeResponse
Int -> ReadS RebootNodeResponse
ReadS [RebootNodeResponse]
(Int -> ReadS RebootNodeResponse)
-> ReadS [RebootNodeResponse]
-> ReadPrec RebootNodeResponse
-> ReadPrec [RebootNodeResponse]
-> Read RebootNodeResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RebootNodeResponse]
$creadListPrec :: ReadPrec [RebootNodeResponse]
readPrec :: ReadPrec RebootNodeResponse
$creadPrec :: ReadPrec RebootNodeResponse
readList :: ReadS [RebootNodeResponse]
$creadList :: ReadS [RebootNodeResponse]
readsPrec :: Int -> ReadS RebootNodeResponse
$creadsPrec :: Int -> ReadS RebootNodeResponse
Prelude.Read, Int -> RebootNodeResponse -> ShowS
[RebootNodeResponse] -> ShowS
RebootNodeResponse -> String
(Int -> RebootNodeResponse -> ShowS)
-> (RebootNodeResponse -> String)
-> ([RebootNodeResponse] -> ShowS)
-> Show RebootNodeResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RebootNodeResponse] -> ShowS
$cshowList :: [RebootNodeResponse] -> ShowS
show :: RebootNodeResponse -> String
$cshow :: RebootNodeResponse -> String
showsPrec :: Int -> RebootNodeResponse -> ShowS
$cshowsPrec :: Int -> RebootNodeResponse -> ShowS
Prelude.Show, (forall x. RebootNodeResponse -> Rep RebootNodeResponse x)
-> (forall x. Rep RebootNodeResponse x -> RebootNodeResponse)
-> Generic RebootNodeResponse
forall x. Rep RebootNodeResponse x -> RebootNodeResponse
forall x. RebootNodeResponse -> Rep RebootNodeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RebootNodeResponse x -> RebootNodeResponse
$cfrom :: forall x. RebootNodeResponse -> Rep RebootNodeResponse x
Prelude.Generic)

-- |
-- Create a value of 'RebootNodeResponse' 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:
--
-- 'cluster', 'rebootNodeResponse_cluster' - A description of the DAX cluster after a node has been rebooted.
--
-- 'httpStatus', 'rebootNodeResponse_httpStatus' - The response's http status code.
newRebootNodeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RebootNodeResponse
newRebootNodeResponse :: Int -> RebootNodeResponse
newRebootNodeResponse Int
pHttpStatus_ =
  RebootNodeResponse' :: Maybe Cluster -> Int -> RebootNodeResponse
RebootNodeResponse'
    { $sel:cluster:RebootNodeResponse' :: Maybe Cluster
cluster = Maybe Cluster
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:RebootNodeResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A description of the DAX cluster after a node has been rebooted.
rebootNodeResponse_cluster :: Lens.Lens' RebootNodeResponse (Prelude.Maybe Cluster)
rebootNodeResponse_cluster :: (Maybe Cluster -> f (Maybe Cluster))
-> RebootNodeResponse -> f RebootNodeResponse
rebootNodeResponse_cluster = (RebootNodeResponse -> Maybe Cluster)
-> (RebootNodeResponse -> Maybe Cluster -> RebootNodeResponse)
-> Lens
     RebootNodeResponse
     RebootNodeResponse
     (Maybe Cluster)
     (Maybe Cluster)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RebootNodeResponse' {Maybe Cluster
cluster :: Maybe Cluster
$sel:cluster:RebootNodeResponse' :: RebootNodeResponse -> Maybe Cluster
cluster} -> Maybe Cluster
cluster) (\s :: RebootNodeResponse
s@RebootNodeResponse' {} Maybe Cluster
a -> RebootNodeResponse
s {$sel:cluster:RebootNodeResponse' :: Maybe Cluster
cluster = Maybe Cluster
a} :: RebootNodeResponse)

-- | The response's http status code.
rebootNodeResponse_httpStatus :: Lens.Lens' RebootNodeResponse Prelude.Int
rebootNodeResponse_httpStatus :: (Int -> f Int) -> RebootNodeResponse -> f RebootNodeResponse
rebootNodeResponse_httpStatus = (RebootNodeResponse -> Int)
-> (RebootNodeResponse -> Int -> RebootNodeResponse)
-> Lens RebootNodeResponse RebootNodeResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RebootNodeResponse' {Int
httpStatus :: Int
$sel:httpStatus:RebootNodeResponse' :: RebootNodeResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: RebootNodeResponse
s@RebootNodeResponse' {} Int
a -> RebootNodeResponse
s {$sel:httpStatus:RebootNodeResponse' :: Int
httpStatus = Int
a} :: RebootNodeResponse)

instance Prelude.NFData RebootNodeResponse