{-# 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.SageMaker.StopPipelineExecution
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Stops a pipeline execution.
--
-- __Callback Step__
--
-- A pipeline execution won\'t stop while a callback step is running. When
-- you call @StopPipelineExecution@ on a pipeline execution with a running
-- callback step, SageMaker Pipelines sends an additional Amazon SQS
-- message to the specified SQS queue. The body of the SQS message contains
-- a \"Status\" field which is set to \"Stopping\".
--
-- You should add logic to your Amazon SQS message consumer to take any
-- needed action (for example, resource cleanup) upon receipt of the
-- message followed by a call to @SendPipelineExecutionStepSuccess@ or
-- @SendPipelineExecutionStepFailure@.
--
-- Only when SageMaker Pipelines receives one of these calls will it stop
-- the pipeline execution.
--
-- __Lambda Step__
--
-- A pipeline execution can\'t be stopped while a lambda step is running
-- because the Lambda function invoked by the lambda step can\'t be
-- stopped. If you attempt to stop the execution while the Lambda function
-- is running, the pipeline waits for the Lambda function to finish or
-- until the timeout is hit, whichever occurs first, and then stops. If the
-- Lambda function finishes, the pipeline execution status is @Stopped@. If
-- the timeout is hit the pipeline execution status is @Failed@.
module Amazonka.SageMaker.StopPipelineExecution
  ( -- * Creating a Request
    StopPipelineExecution (..),
    newStopPipelineExecution,

    -- * Request Lenses
    stopPipelineExecution_pipelineExecutionArn,
    stopPipelineExecution_clientRequestToken,

    -- * Destructuring the Response
    StopPipelineExecutionResponse (..),
    newStopPipelineExecutionResponse,

    -- * Response Lenses
    stopPipelineExecutionResponse_pipelineExecutionArn,
    stopPipelineExecutionResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SageMaker.Types

-- | /See:/ 'newStopPipelineExecution' smart constructor.
data StopPipelineExecution = StopPipelineExecution'
  { -- | The Amazon Resource Name (ARN) of the pipeline execution.
    StopPipelineExecution -> Text
pipelineExecutionArn :: Prelude.Text,
    -- | A unique, case-sensitive identifier that you provide to ensure the
    -- idempotency of the operation. An idempotent operation completes no more
    -- than once.
    StopPipelineExecution -> Text
clientRequestToken :: Prelude.Text
  }
  deriving (StopPipelineExecution -> StopPipelineExecution -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopPipelineExecution -> StopPipelineExecution -> Bool
$c/= :: StopPipelineExecution -> StopPipelineExecution -> Bool
== :: StopPipelineExecution -> StopPipelineExecution -> Bool
$c== :: StopPipelineExecution -> StopPipelineExecution -> Bool
Prelude.Eq, ReadPrec [StopPipelineExecution]
ReadPrec StopPipelineExecution
Int -> ReadS StopPipelineExecution
ReadS [StopPipelineExecution]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopPipelineExecution]
$creadListPrec :: ReadPrec [StopPipelineExecution]
readPrec :: ReadPrec StopPipelineExecution
$creadPrec :: ReadPrec StopPipelineExecution
readList :: ReadS [StopPipelineExecution]
$creadList :: ReadS [StopPipelineExecution]
readsPrec :: Int -> ReadS StopPipelineExecution
$creadsPrec :: Int -> ReadS StopPipelineExecution
Prelude.Read, Int -> StopPipelineExecution -> ShowS
[StopPipelineExecution] -> ShowS
StopPipelineExecution -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopPipelineExecution] -> ShowS
$cshowList :: [StopPipelineExecution] -> ShowS
show :: StopPipelineExecution -> String
$cshow :: StopPipelineExecution -> String
showsPrec :: Int -> StopPipelineExecution -> ShowS
$cshowsPrec :: Int -> StopPipelineExecution -> ShowS
Prelude.Show, forall x. Rep StopPipelineExecution x -> StopPipelineExecution
forall x. StopPipelineExecution -> Rep StopPipelineExecution x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopPipelineExecution x -> StopPipelineExecution
$cfrom :: forall x. StopPipelineExecution -> Rep StopPipelineExecution x
Prelude.Generic)

-- |
-- Create a value of 'StopPipelineExecution' 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:
--
-- 'pipelineExecutionArn', 'stopPipelineExecution_pipelineExecutionArn' - The Amazon Resource Name (ARN) of the pipeline execution.
--
-- 'clientRequestToken', 'stopPipelineExecution_clientRequestToken' - A unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the operation. An idempotent operation completes no more
-- than once.
newStopPipelineExecution ::
  -- | 'pipelineExecutionArn'
  Prelude.Text ->
  -- | 'clientRequestToken'
  Prelude.Text ->
  StopPipelineExecution
newStopPipelineExecution :: Text -> Text -> StopPipelineExecution
newStopPipelineExecution
  Text
pPipelineExecutionArn_
  Text
pClientRequestToken_ =
    StopPipelineExecution'
      { $sel:pipelineExecutionArn:StopPipelineExecution' :: Text
pipelineExecutionArn =
          Text
pPipelineExecutionArn_,
        $sel:clientRequestToken:StopPipelineExecution' :: Text
clientRequestToken = Text
pClientRequestToken_
      }

-- | The Amazon Resource Name (ARN) of the pipeline execution.
stopPipelineExecution_pipelineExecutionArn :: Lens.Lens' StopPipelineExecution Prelude.Text
stopPipelineExecution_pipelineExecutionArn :: Lens' StopPipelineExecution Text
stopPipelineExecution_pipelineExecutionArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopPipelineExecution' {Text
pipelineExecutionArn :: Text
$sel:pipelineExecutionArn:StopPipelineExecution' :: StopPipelineExecution -> Text
pipelineExecutionArn} -> Text
pipelineExecutionArn) (\s :: StopPipelineExecution
s@StopPipelineExecution' {} Text
a -> StopPipelineExecution
s {$sel:pipelineExecutionArn:StopPipelineExecution' :: Text
pipelineExecutionArn = Text
a} :: StopPipelineExecution)

-- | A unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the operation. An idempotent operation completes no more
-- than once.
stopPipelineExecution_clientRequestToken :: Lens.Lens' StopPipelineExecution Prelude.Text
stopPipelineExecution_clientRequestToken :: Lens' StopPipelineExecution Text
stopPipelineExecution_clientRequestToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopPipelineExecution' {Text
clientRequestToken :: Text
$sel:clientRequestToken:StopPipelineExecution' :: StopPipelineExecution -> Text
clientRequestToken} -> Text
clientRequestToken) (\s :: StopPipelineExecution
s@StopPipelineExecution' {} Text
a -> StopPipelineExecution
s {$sel:clientRequestToken:StopPipelineExecution' :: Text
clientRequestToken = Text
a} :: StopPipelineExecution)

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

instance Prelude.Hashable StopPipelineExecution where
  hashWithSalt :: Int -> StopPipelineExecution -> Int
hashWithSalt Int
_salt StopPipelineExecution' {Text
clientRequestToken :: Text
pipelineExecutionArn :: Text
$sel:clientRequestToken:StopPipelineExecution' :: StopPipelineExecution -> Text
$sel:pipelineExecutionArn:StopPipelineExecution' :: StopPipelineExecution -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
pipelineExecutionArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
clientRequestToken

instance Prelude.NFData StopPipelineExecution where
  rnf :: StopPipelineExecution -> ()
rnf StopPipelineExecution' {Text
clientRequestToken :: Text
pipelineExecutionArn :: Text
$sel:clientRequestToken:StopPipelineExecution' :: StopPipelineExecution -> Text
$sel:pipelineExecutionArn:StopPipelineExecution' :: StopPipelineExecution -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
pipelineExecutionArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
clientRequestToken

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

instance Data.ToJSON StopPipelineExecution where
  toJSON :: StopPipelineExecution -> Value
toJSON StopPipelineExecution' {Text
clientRequestToken :: Text
pipelineExecutionArn :: Text
$sel:clientRequestToken:StopPipelineExecution' :: StopPipelineExecution -> Text
$sel:pipelineExecutionArn:StopPipelineExecution' :: StopPipelineExecution -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              ( Key
"PipelineExecutionArn"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
pipelineExecutionArn
              ),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ClientRequestToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
clientRequestToken)
          ]
      )

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

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

-- | /See:/ 'newStopPipelineExecutionResponse' smart constructor.
data StopPipelineExecutionResponse = StopPipelineExecutionResponse'
  { -- | The Amazon Resource Name (ARN) of the pipeline execution.
    StopPipelineExecutionResponse -> Maybe Text
pipelineExecutionArn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    StopPipelineExecutionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StopPipelineExecutionResponse
-> StopPipelineExecutionResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopPipelineExecutionResponse
-> StopPipelineExecutionResponse -> Bool
$c/= :: StopPipelineExecutionResponse
-> StopPipelineExecutionResponse -> Bool
== :: StopPipelineExecutionResponse
-> StopPipelineExecutionResponse -> Bool
$c== :: StopPipelineExecutionResponse
-> StopPipelineExecutionResponse -> Bool
Prelude.Eq, ReadPrec [StopPipelineExecutionResponse]
ReadPrec StopPipelineExecutionResponse
Int -> ReadS StopPipelineExecutionResponse
ReadS [StopPipelineExecutionResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopPipelineExecutionResponse]
$creadListPrec :: ReadPrec [StopPipelineExecutionResponse]
readPrec :: ReadPrec StopPipelineExecutionResponse
$creadPrec :: ReadPrec StopPipelineExecutionResponse
readList :: ReadS [StopPipelineExecutionResponse]
$creadList :: ReadS [StopPipelineExecutionResponse]
readsPrec :: Int -> ReadS StopPipelineExecutionResponse
$creadsPrec :: Int -> ReadS StopPipelineExecutionResponse
Prelude.Read, Int -> StopPipelineExecutionResponse -> ShowS
[StopPipelineExecutionResponse] -> ShowS
StopPipelineExecutionResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopPipelineExecutionResponse] -> ShowS
$cshowList :: [StopPipelineExecutionResponse] -> ShowS
show :: StopPipelineExecutionResponse -> String
$cshow :: StopPipelineExecutionResponse -> String
showsPrec :: Int -> StopPipelineExecutionResponse -> ShowS
$cshowsPrec :: Int -> StopPipelineExecutionResponse -> ShowS
Prelude.Show, forall x.
Rep StopPipelineExecutionResponse x
-> StopPipelineExecutionResponse
forall x.
StopPipelineExecutionResponse
-> Rep StopPipelineExecutionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StopPipelineExecutionResponse x
-> StopPipelineExecutionResponse
$cfrom :: forall x.
StopPipelineExecutionResponse
-> Rep StopPipelineExecutionResponse x
Prelude.Generic)

-- |
-- Create a value of 'StopPipelineExecutionResponse' 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:
--
-- 'pipelineExecutionArn', 'stopPipelineExecutionResponse_pipelineExecutionArn' - The Amazon Resource Name (ARN) of the pipeline execution.
--
-- 'httpStatus', 'stopPipelineExecutionResponse_httpStatus' - The response's http status code.
newStopPipelineExecutionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopPipelineExecutionResponse
newStopPipelineExecutionResponse :: Int -> StopPipelineExecutionResponse
newStopPipelineExecutionResponse Int
pHttpStatus_ =
  StopPipelineExecutionResponse'
    { $sel:pipelineExecutionArn:StopPipelineExecutionResponse' :: Maybe Text
pipelineExecutionArn =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StopPipelineExecutionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Resource Name (ARN) of the pipeline execution.
stopPipelineExecutionResponse_pipelineExecutionArn :: Lens.Lens' StopPipelineExecutionResponse (Prelude.Maybe Prelude.Text)
stopPipelineExecutionResponse_pipelineExecutionArn :: Lens' StopPipelineExecutionResponse (Maybe Text)
stopPipelineExecutionResponse_pipelineExecutionArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopPipelineExecutionResponse' {Maybe Text
pipelineExecutionArn :: Maybe Text
$sel:pipelineExecutionArn:StopPipelineExecutionResponse' :: StopPipelineExecutionResponse -> Maybe Text
pipelineExecutionArn} -> Maybe Text
pipelineExecutionArn) (\s :: StopPipelineExecutionResponse
s@StopPipelineExecutionResponse' {} Maybe Text
a -> StopPipelineExecutionResponse
s {$sel:pipelineExecutionArn:StopPipelineExecutionResponse' :: Maybe Text
pipelineExecutionArn = Maybe Text
a} :: StopPipelineExecutionResponse)

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

instance Prelude.NFData StopPipelineExecutionResponse where
  rnf :: StopPipelineExecutionResponse -> ()
rnf StopPipelineExecutionResponse' {Int
Maybe Text
httpStatus :: Int
pipelineExecutionArn :: Maybe Text
$sel:httpStatus:StopPipelineExecutionResponse' :: StopPipelineExecutionResponse -> Int
$sel:pipelineExecutionArn:StopPipelineExecutionResponse' :: StopPipelineExecutionResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
pipelineExecutionArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus