{-# 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.Kinesis.MergeShards
-- 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)
--
-- Merges two adjacent shards in a Kinesis data stream and combines them
-- into a single shard to reduce the stream\'s capacity to ingest and
-- transport data. Two shards are considered adjacent if the union of the
-- hash key ranges for the two shards form a contiguous set with no gaps.
-- For example, if you have two shards, one with a hash key range of
-- 276...381 and the other with a hash key range of 382...454, then you
-- could merge these two shards into a single shard that would have a hash
-- key range of 276...454. After the merge, the single child shard receives
-- data for all hash key values covered by the two parent shards.
--
-- @MergeShards@ is called when there is a need to reduce the overall
-- capacity of a stream because of excess capacity that is not being used.
-- You must specify the shard to be merged and the adjacent shard for a
-- stream. For more information about merging shards, see
-- <https://docs.aws.amazon.com/kinesis/latest/dev/kinesis-using-sdk-java-resharding-merge.html Merge Two Shards>
-- in the /Amazon Kinesis Data Streams Developer Guide/.
--
-- If the stream is in the @ACTIVE@ state, you can call @MergeShards@. If a
-- stream is in the @CREATING@, @UPDATING@, or @DELETING@ state,
-- @MergeShards@ returns a @ResourceInUseException@. If the specified
-- stream does not exist, @MergeShards@ returns a
-- @ResourceNotFoundException@.
--
-- You can use DescribeStream to check the state of the stream, which is
-- returned in @StreamStatus@.
--
-- @MergeShards@ is an asynchronous operation. Upon receiving a
-- @MergeShards@ request, Amazon Kinesis Data Streams immediately returns a
-- response and sets the @StreamStatus@ to @UPDATING@. After the operation
-- is completed, Kinesis Data Streams sets the @StreamStatus@ to @ACTIVE@.
-- Read and write operations continue to work while the stream is in the
-- @UPDATING@ state.
--
-- You use DescribeStream to determine the shard IDs that are specified in
-- the @MergeShards@ request.
--
-- If you try to operate on too many streams in parallel using
-- CreateStream, DeleteStream, @MergeShards@, or SplitShard, you receive a
-- @LimitExceededException@.
--
-- @MergeShards@ has a limit of five transactions per second per account.
module Amazonka.Kinesis.MergeShards
  ( -- * Creating a Request
    MergeShards (..),
    newMergeShards,

    -- * Request Lenses
    mergeShards_streamName,
    mergeShards_shardToMerge,
    mergeShards_adjacentShardToMerge,

    -- * Destructuring the Response
    MergeShardsResponse (..),
    newMergeShardsResponse,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Kinesis.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

-- | Represents the input for @MergeShards@.
--
-- /See:/ 'newMergeShards' smart constructor.
data MergeShards = MergeShards'
  { -- | The name of the stream for the merge.
    MergeShards -> Text
streamName :: Prelude.Text,
    -- | The shard ID of the shard to combine with the adjacent shard for the
    -- merge.
    MergeShards -> Text
shardToMerge :: Prelude.Text,
    -- | The shard ID of the adjacent shard for the merge.
    MergeShards -> Text
adjacentShardToMerge :: Prelude.Text
  }
  deriving (MergeShards -> MergeShards -> Bool
(MergeShards -> MergeShards -> Bool)
-> (MergeShards -> MergeShards -> Bool) -> Eq MergeShards
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MergeShards -> MergeShards -> Bool
$c/= :: MergeShards -> MergeShards -> Bool
== :: MergeShards -> MergeShards -> Bool
$c== :: MergeShards -> MergeShards -> Bool
Prelude.Eq, ReadPrec [MergeShards]
ReadPrec MergeShards
Int -> ReadS MergeShards
ReadS [MergeShards]
(Int -> ReadS MergeShards)
-> ReadS [MergeShards]
-> ReadPrec MergeShards
-> ReadPrec [MergeShards]
-> Read MergeShards
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MergeShards]
$creadListPrec :: ReadPrec [MergeShards]
readPrec :: ReadPrec MergeShards
$creadPrec :: ReadPrec MergeShards
readList :: ReadS [MergeShards]
$creadList :: ReadS [MergeShards]
readsPrec :: Int -> ReadS MergeShards
$creadsPrec :: Int -> ReadS MergeShards
Prelude.Read, Int -> MergeShards -> ShowS
[MergeShards] -> ShowS
MergeShards -> String
(Int -> MergeShards -> ShowS)
-> (MergeShards -> String)
-> ([MergeShards] -> ShowS)
-> Show MergeShards
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MergeShards] -> ShowS
$cshowList :: [MergeShards] -> ShowS
show :: MergeShards -> String
$cshow :: MergeShards -> String
showsPrec :: Int -> MergeShards -> ShowS
$cshowsPrec :: Int -> MergeShards -> ShowS
Prelude.Show, (forall x. MergeShards -> Rep MergeShards x)
-> (forall x. Rep MergeShards x -> MergeShards)
-> Generic MergeShards
forall x. Rep MergeShards x -> MergeShards
forall x. MergeShards -> Rep MergeShards x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MergeShards x -> MergeShards
$cfrom :: forall x. MergeShards -> Rep MergeShards x
Prelude.Generic)

-- |
-- Create a value of 'MergeShards' 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:
--
-- 'streamName', 'mergeShards_streamName' - The name of the stream for the merge.
--
-- 'shardToMerge', 'mergeShards_shardToMerge' - The shard ID of the shard to combine with the adjacent shard for the
-- merge.
--
-- 'adjacentShardToMerge', 'mergeShards_adjacentShardToMerge' - The shard ID of the adjacent shard for the merge.
newMergeShards ::
  -- | 'streamName'
  Prelude.Text ->
  -- | 'shardToMerge'
  Prelude.Text ->
  -- | 'adjacentShardToMerge'
  Prelude.Text ->
  MergeShards
newMergeShards :: Text -> Text -> Text -> MergeShards
newMergeShards
  Text
pStreamName_
  Text
pShardToMerge_
  Text
pAdjacentShardToMerge_ =
    MergeShards' :: Text -> Text -> Text -> MergeShards
MergeShards'
      { $sel:streamName:MergeShards' :: Text
streamName = Text
pStreamName_,
        $sel:shardToMerge:MergeShards' :: Text
shardToMerge = Text
pShardToMerge_,
        $sel:adjacentShardToMerge:MergeShards' :: Text
adjacentShardToMerge = Text
pAdjacentShardToMerge_
      }

-- | The name of the stream for the merge.
mergeShards_streamName :: Lens.Lens' MergeShards Prelude.Text
mergeShards_streamName :: (Text -> f Text) -> MergeShards -> f MergeShards
mergeShards_streamName = (MergeShards -> Text)
-> (MergeShards -> Text -> MergeShards)
-> Lens MergeShards MergeShards Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MergeShards' {Text
streamName :: Text
$sel:streamName:MergeShards' :: MergeShards -> Text
streamName} -> Text
streamName) (\s :: MergeShards
s@MergeShards' {} Text
a -> MergeShards
s {$sel:streamName:MergeShards' :: Text
streamName = Text
a} :: MergeShards)

-- | The shard ID of the shard to combine with the adjacent shard for the
-- merge.
mergeShards_shardToMerge :: Lens.Lens' MergeShards Prelude.Text
mergeShards_shardToMerge :: (Text -> f Text) -> MergeShards -> f MergeShards
mergeShards_shardToMerge = (MergeShards -> Text)
-> (MergeShards -> Text -> MergeShards)
-> Lens MergeShards MergeShards Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MergeShards' {Text
shardToMerge :: Text
$sel:shardToMerge:MergeShards' :: MergeShards -> Text
shardToMerge} -> Text
shardToMerge) (\s :: MergeShards
s@MergeShards' {} Text
a -> MergeShards
s {$sel:shardToMerge:MergeShards' :: Text
shardToMerge = Text
a} :: MergeShards)

-- | The shard ID of the adjacent shard for the merge.
mergeShards_adjacentShardToMerge :: Lens.Lens' MergeShards Prelude.Text
mergeShards_adjacentShardToMerge :: (Text -> f Text) -> MergeShards -> f MergeShards
mergeShards_adjacentShardToMerge = (MergeShards -> Text)
-> (MergeShards -> Text -> MergeShards)
-> Lens MergeShards MergeShards Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MergeShards' {Text
adjacentShardToMerge :: Text
$sel:adjacentShardToMerge:MergeShards' :: MergeShards -> Text
adjacentShardToMerge} -> Text
adjacentShardToMerge) (\s :: MergeShards
s@MergeShards' {} Text
a -> MergeShards
s {$sel:adjacentShardToMerge:MergeShards' :: Text
adjacentShardToMerge = Text
a} :: MergeShards)

instance Core.AWSRequest MergeShards where
  type AWSResponse MergeShards = MergeShardsResponse
  request :: MergeShards -> Request MergeShards
request = Service -> MergeShards -> Request MergeShards
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy MergeShards
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse MergeShards)))
response = AWSResponse MergeShards
-> Logger
-> Service
-> Proxy MergeShards
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse MergeShards)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse MergeShards
MergeShardsResponse
MergeShardsResponse'

instance Prelude.Hashable MergeShards

instance Prelude.NFData MergeShards

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

instance Core.ToJSON MergeShards where
  toJSON :: MergeShards -> Value
toJSON MergeShards' {Text
adjacentShardToMerge :: Text
shardToMerge :: Text
streamName :: Text
$sel:adjacentShardToMerge:MergeShards' :: MergeShards -> Text
$sel:shardToMerge:MergeShards' :: MergeShards -> Text
$sel:streamName:MergeShards' :: MergeShards -> 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
"StreamName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
streamName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ShardToMerge" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
shardToMerge),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"AdjacentShardToMerge"
                  Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
adjacentShardToMerge
              )
          ]
      )

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

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

-- | /See:/ 'newMergeShardsResponse' smart constructor.
data MergeShardsResponse = MergeShardsResponse'
  {
  }
  deriving (MergeShardsResponse -> MergeShardsResponse -> Bool
(MergeShardsResponse -> MergeShardsResponse -> Bool)
-> (MergeShardsResponse -> MergeShardsResponse -> Bool)
-> Eq MergeShardsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MergeShardsResponse -> MergeShardsResponse -> Bool
$c/= :: MergeShardsResponse -> MergeShardsResponse -> Bool
== :: MergeShardsResponse -> MergeShardsResponse -> Bool
$c== :: MergeShardsResponse -> MergeShardsResponse -> Bool
Prelude.Eq, ReadPrec [MergeShardsResponse]
ReadPrec MergeShardsResponse
Int -> ReadS MergeShardsResponse
ReadS [MergeShardsResponse]
(Int -> ReadS MergeShardsResponse)
-> ReadS [MergeShardsResponse]
-> ReadPrec MergeShardsResponse
-> ReadPrec [MergeShardsResponse]
-> Read MergeShardsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MergeShardsResponse]
$creadListPrec :: ReadPrec [MergeShardsResponse]
readPrec :: ReadPrec MergeShardsResponse
$creadPrec :: ReadPrec MergeShardsResponse
readList :: ReadS [MergeShardsResponse]
$creadList :: ReadS [MergeShardsResponse]
readsPrec :: Int -> ReadS MergeShardsResponse
$creadsPrec :: Int -> ReadS MergeShardsResponse
Prelude.Read, Int -> MergeShardsResponse -> ShowS
[MergeShardsResponse] -> ShowS
MergeShardsResponse -> String
(Int -> MergeShardsResponse -> ShowS)
-> (MergeShardsResponse -> String)
-> ([MergeShardsResponse] -> ShowS)
-> Show MergeShardsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MergeShardsResponse] -> ShowS
$cshowList :: [MergeShardsResponse] -> ShowS
show :: MergeShardsResponse -> String
$cshow :: MergeShardsResponse -> String
showsPrec :: Int -> MergeShardsResponse -> ShowS
$cshowsPrec :: Int -> MergeShardsResponse -> ShowS
Prelude.Show, (forall x. MergeShardsResponse -> Rep MergeShardsResponse x)
-> (forall x. Rep MergeShardsResponse x -> MergeShardsResponse)
-> Generic MergeShardsResponse
forall x. Rep MergeShardsResponse x -> MergeShardsResponse
forall x. MergeShardsResponse -> Rep MergeShardsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MergeShardsResponse x -> MergeShardsResponse
$cfrom :: forall x. MergeShardsResponse -> Rep MergeShardsResponse x
Prelude.Generic)

-- |
-- Create a value of 'MergeShardsResponse' 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.
newMergeShardsResponse ::
  MergeShardsResponse
newMergeShardsResponse :: MergeShardsResponse
newMergeShardsResponse = MergeShardsResponse
MergeShardsResponse'

instance Prelude.NFData MergeShardsResponse