{-# 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-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)
--
-- 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.Lens as Lens
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
(StopPipelineExecution -> StopPipelineExecution -> Bool)
-> (StopPipelineExecution -> StopPipelineExecution -> Bool)
-> Eq StopPipelineExecution
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]
(Int -> ReadS StopPipelineExecution)
-> ReadS [StopPipelineExecution]
-> ReadPrec StopPipelineExecution
-> ReadPrec [StopPipelineExecution]
-> Read 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
(Int -> StopPipelineExecution -> ShowS)
-> (StopPipelineExecution -> String)
-> ([StopPipelineExecution] -> ShowS)
-> Show StopPipelineExecution
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. StopPipelineExecution -> Rep StopPipelineExecution x)
-> (forall x. Rep StopPipelineExecution x -> StopPipelineExecution)
-> Generic StopPipelineExecution
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' :: Text -> Text -> StopPipelineExecution
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 :: (Text -> f Text)
-> StopPipelineExecution -> f StopPipelineExecution
stopPipelineExecution_pipelineExecutionArn = (StopPipelineExecution -> Text)
-> (StopPipelineExecution -> Text -> StopPipelineExecution)
-> Lens StopPipelineExecution StopPipelineExecution Text Text
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 :: (Text -> f Text)
-> StopPipelineExecution -> f StopPipelineExecution
stopPipelineExecution_clientRequestToken = (StopPipelineExecution -> Text)
-> (StopPipelineExecution -> Text -> StopPipelineExecution)
-> Lens StopPipelineExecution StopPipelineExecution Text Text
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 :: StopPipelineExecution -> Request StopPipelineExecution
request = Service -> StopPipelineExecution -> Request StopPipelineExecution
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StopPipelineExecution
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StopPipelineExecution)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StopPipelineExecution))
-> Logger
-> Service
-> Proxy StopPipelineExecution
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StopPipelineExecution)))
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 Text -> Int -> StopPipelineExecutionResponse
StopPipelineExecutionResponse'
            (Maybe Text -> Int -> StopPipelineExecutionResponse)
-> Either String (Maybe Text)
-> Either String (Int -> StopPipelineExecutionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"PipelineExecutionArn")
            Either String (Int -> StopPipelineExecutionResponse)
-> Either String Int -> Either String StopPipelineExecutionResponse
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 StopPipelineExecution

instance Prelude.NFData StopPipelineExecution

instance Core.ToHeaders StopPipelineExecution where
  toHeaders :: StopPipelineExecution -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StopPipelineExecution -> 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
"SageMaker.StopPipelineExecution" ::
                          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 StopPipelineExecution where
  toJSON :: StopPipelineExecution -> Value
toJSON StopPipelineExecution' {Text
clientRequestToken :: Text
pipelineExecutionArn :: Text
$sel:clientRequestToken:StopPipelineExecution' :: StopPipelineExecution -> Text
$sel:pipelineExecutionArn:StopPipelineExecution' :: StopPipelineExecution -> 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
"PipelineExecutionArn"
                  Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
pipelineExecutionArn
              ),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ClientRequestToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clientRequestToken)
          ]
      )

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

instance Core.ToQuery StopPipelineExecution where
  toQuery :: StopPipelineExecution -> QueryString
toQuery = QueryString -> StopPipelineExecution -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(StopPipelineExecutionResponse
 -> StopPipelineExecutionResponse -> Bool)
-> (StopPipelineExecutionResponse
    -> StopPipelineExecutionResponse -> Bool)
-> Eq StopPipelineExecutionResponse
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]
(Int -> ReadS StopPipelineExecutionResponse)
-> ReadS [StopPipelineExecutionResponse]
-> ReadPrec StopPipelineExecutionResponse
-> ReadPrec [StopPipelineExecutionResponse]
-> Read 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
(Int -> StopPipelineExecutionResponse -> ShowS)
-> (StopPipelineExecutionResponse -> String)
-> ([StopPipelineExecutionResponse] -> ShowS)
-> Show StopPipelineExecutionResponse
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.
 StopPipelineExecutionResponse
 -> Rep StopPipelineExecutionResponse x)
-> (forall x.
    Rep StopPipelineExecutionResponse x
    -> StopPipelineExecutionResponse)
-> Generic StopPipelineExecutionResponse
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' :: Maybe Text -> Int -> StopPipelineExecutionResponse
StopPipelineExecutionResponse'
    { $sel:pipelineExecutionArn:StopPipelineExecutionResponse' :: Maybe Text
pipelineExecutionArn =
        Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> StopPipelineExecutionResponse -> f StopPipelineExecutionResponse
stopPipelineExecutionResponse_pipelineExecutionArn = (StopPipelineExecutionResponse -> Maybe Text)
-> (StopPipelineExecutionResponse
    -> Maybe Text -> StopPipelineExecutionResponse)
-> Lens
     StopPipelineExecutionResponse
     StopPipelineExecutionResponse
     (Maybe Text)
     (Maybe Text)
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 :: (Int -> f Int)
-> StopPipelineExecutionResponse -> f StopPipelineExecutionResponse
stopPipelineExecutionResponse_httpStatus = (StopPipelineExecutionResponse -> Int)
-> (StopPipelineExecutionResponse
    -> Int -> StopPipelineExecutionResponse)
-> Lens
     StopPipelineExecutionResponse StopPipelineExecutionResponse Int Int
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