{-# 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.StopTrainingJob
-- 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 training job. To stop a job, Amazon SageMaker sends the
-- algorithm the @SIGTERM@ signal, which delays job termination for 120
-- seconds. Algorithms might use this 120-second window to save the model
-- artifacts, so the results of the training is not lost.
--
-- When it receives a @StopTrainingJob@ request, Amazon SageMaker changes
-- the status of the job to @Stopping@. After Amazon SageMaker stops the
-- job, it sets the status to @Stopped@.
module Amazonka.SageMaker.StopTrainingJob
  ( -- * Creating a Request
    StopTrainingJob (..),
    newStopTrainingJob,

    -- * Request Lenses
    stopTrainingJob_trainingJobName,

    -- * Destructuring the Response
    StopTrainingJobResponse (..),
    newStopTrainingJobResponse,
  )
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:/ 'newStopTrainingJob' smart constructor.
data StopTrainingJob = StopTrainingJob'
  { -- | The name of the training job to stop.
    StopTrainingJob -> Text
trainingJobName :: Prelude.Text
  }
  deriving (StopTrainingJob -> StopTrainingJob -> Bool
(StopTrainingJob -> StopTrainingJob -> Bool)
-> (StopTrainingJob -> StopTrainingJob -> Bool)
-> Eq StopTrainingJob
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopTrainingJob -> StopTrainingJob -> Bool
$c/= :: StopTrainingJob -> StopTrainingJob -> Bool
== :: StopTrainingJob -> StopTrainingJob -> Bool
$c== :: StopTrainingJob -> StopTrainingJob -> Bool
Prelude.Eq, ReadPrec [StopTrainingJob]
ReadPrec StopTrainingJob
Int -> ReadS StopTrainingJob
ReadS [StopTrainingJob]
(Int -> ReadS StopTrainingJob)
-> ReadS [StopTrainingJob]
-> ReadPrec StopTrainingJob
-> ReadPrec [StopTrainingJob]
-> Read StopTrainingJob
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopTrainingJob]
$creadListPrec :: ReadPrec [StopTrainingJob]
readPrec :: ReadPrec StopTrainingJob
$creadPrec :: ReadPrec StopTrainingJob
readList :: ReadS [StopTrainingJob]
$creadList :: ReadS [StopTrainingJob]
readsPrec :: Int -> ReadS StopTrainingJob
$creadsPrec :: Int -> ReadS StopTrainingJob
Prelude.Read, Int -> StopTrainingJob -> ShowS
[StopTrainingJob] -> ShowS
StopTrainingJob -> String
(Int -> StopTrainingJob -> ShowS)
-> (StopTrainingJob -> String)
-> ([StopTrainingJob] -> ShowS)
-> Show StopTrainingJob
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopTrainingJob] -> ShowS
$cshowList :: [StopTrainingJob] -> ShowS
show :: StopTrainingJob -> String
$cshow :: StopTrainingJob -> String
showsPrec :: Int -> StopTrainingJob -> ShowS
$cshowsPrec :: Int -> StopTrainingJob -> ShowS
Prelude.Show, (forall x. StopTrainingJob -> Rep StopTrainingJob x)
-> (forall x. Rep StopTrainingJob x -> StopTrainingJob)
-> Generic StopTrainingJob
forall x. Rep StopTrainingJob x -> StopTrainingJob
forall x. StopTrainingJob -> Rep StopTrainingJob x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopTrainingJob x -> StopTrainingJob
$cfrom :: forall x. StopTrainingJob -> Rep StopTrainingJob x
Prelude.Generic)

-- |
-- Create a value of 'StopTrainingJob' 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:
--
-- 'trainingJobName', 'stopTrainingJob_trainingJobName' - The name of the training job to stop.
newStopTrainingJob ::
  -- | 'trainingJobName'
  Prelude.Text ->
  StopTrainingJob
newStopTrainingJob :: Text -> StopTrainingJob
newStopTrainingJob Text
pTrainingJobName_ =
  StopTrainingJob' :: Text -> StopTrainingJob
StopTrainingJob'
    { $sel:trainingJobName:StopTrainingJob' :: Text
trainingJobName =
        Text
pTrainingJobName_
    }

-- | The name of the training job to stop.
stopTrainingJob_trainingJobName :: Lens.Lens' StopTrainingJob Prelude.Text
stopTrainingJob_trainingJobName :: (Text -> f Text) -> StopTrainingJob -> f StopTrainingJob
stopTrainingJob_trainingJobName = (StopTrainingJob -> Text)
-> (StopTrainingJob -> Text -> StopTrainingJob)
-> Lens StopTrainingJob StopTrainingJob Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopTrainingJob' {Text
trainingJobName :: Text
$sel:trainingJobName:StopTrainingJob' :: StopTrainingJob -> Text
trainingJobName} -> Text
trainingJobName) (\s :: StopTrainingJob
s@StopTrainingJob' {} Text
a -> StopTrainingJob
s {$sel:trainingJobName:StopTrainingJob' :: Text
trainingJobName = Text
a} :: StopTrainingJob)

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

instance Prelude.Hashable StopTrainingJob

instance Prelude.NFData StopTrainingJob

instance Core.ToHeaders StopTrainingJob where
  toHeaders :: StopTrainingJob -> [Header]
toHeaders =
    [Header] -> StopTrainingJob -> [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
"SageMaker.StopTrainingJob" :: 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 StopTrainingJob where
  toJSON :: StopTrainingJob -> Value
toJSON StopTrainingJob' {Text
trainingJobName :: Text
$sel:trainingJobName:StopTrainingJob' :: StopTrainingJob -> 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
"TrainingJobName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
trainingJobName)
          ]
      )

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

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

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

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

instance Prelude.NFData StopTrainingJobResponse