{-# 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.Batch.TerminateJob
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Terminates a job in a job queue. Jobs that are in the @STARTING@ or
-- @RUNNING@ state are terminated, which causes them to transition to
-- @FAILED@. Jobs that have not progressed to the @STARTING@ state are
-- cancelled.
module Amazonka.Batch.TerminateJob
  ( -- * Creating a Request
    TerminateJob (..),
    newTerminateJob,

    -- * Request Lenses
    terminateJob_jobId,
    terminateJob_reason,

    -- * Destructuring the Response
    TerminateJobResponse (..),
    newTerminateJobResponse,

    -- * Response Lenses
    terminateJobResponse_httpStatus,
  )
where

import Amazonka.Batch.Types
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

-- | Contains the parameters for @TerminateJob@.
--
-- /See:/ 'newTerminateJob' smart constructor.
data TerminateJob = TerminateJob'
  { -- | The Batch job ID of the job to terminate.
    TerminateJob -> Text
jobId :: Prelude.Text,
    -- | A message to attach to the job that explains the reason for canceling
    -- it. This message is returned by future DescribeJobs operations on the
    -- job. This message is also recorded in the Batch activity logs.
    TerminateJob -> Text
reason :: Prelude.Text
  }
  deriving (TerminateJob -> TerminateJob -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TerminateJob -> TerminateJob -> Bool
$c/= :: TerminateJob -> TerminateJob -> Bool
== :: TerminateJob -> TerminateJob -> Bool
$c== :: TerminateJob -> TerminateJob -> Bool
Prelude.Eq, ReadPrec [TerminateJob]
ReadPrec TerminateJob
Int -> ReadS TerminateJob
ReadS [TerminateJob]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TerminateJob]
$creadListPrec :: ReadPrec [TerminateJob]
readPrec :: ReadPrec TerminateJob
$creadPrec :: ReadPrec TerminateJob
readList :: ReadS [TerminateJob]
$creadList :: ReadS [TerminateJob]
readsPrec :: Int -> ReadS TerminateJob
$creadsPrec :: Int -> ReadS TerminateJob
Prelude.Read, Int -> TerminateJob -> ShowS
[TerminateJob] -> ShowS
TerminateJob -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TerminateJob] -> ShowS
$cshowList :: [TerminateJob] -> ShowS
show :: TerminateJob -> String
$cshow :: TerminateJob -> String
showsPrec :: Int -> TerminateJob -> ShowS
$cshowsPrec :: Int -> TerminateJob -> ShowS
Prelude.Show, forall x. Rep TerminateJob x -> TerminateJob
forall x. TerminateJob -> Rep TerminateJob x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TerminateJob x -> TerminateJob
$cfrom :: forall x. TerminateJob -> Rep TerminateJob x
Prelude.Generic)

-- |
-- Create a value of 'TerminateJob' 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:
--
-- 'jobId', 'terminateJob_jobId' - The Batch job ID of the job to terminate.
--
-- 'reason', 'terminateJob_reason' - A message to attach to the job that explains the reason for canceling
-- it. This message is returned by future DescribeJobs operations on the
-- job. This message is also recorded in the Batch activity logs.
newTerminateJob ::
  -- | 'jobId'
  Prelude.Text ->
  -- | 'reason'
  Prelude.Text ->
  TerminateJob
newTerminateJob :: Text -> Text -> TerminateJob
newTerminateJob Text
pJobId_ Text
pReason_ =
  TerminateJob' {$sel:jobId:TerminateJob' :: Text
jobId = Text
pJobId_, $sel:reason:TerminateJob' :: Text
reason = Text
pReason_}

-- | The Batch job ID of the job to terminate.
terminateJob_jobId :: Lens.Lens' TerminateJob Prelude.Text
terminateJob_jobId :: Lens' TerminateJob Text
terminateJob_jobId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TerminateJob' {Text
jobId :: Text
$sel:jobId:TerminateJob' :: TerminateJob -> Text
jobId} -> Text
jobId) (\s :: TerminateJob
s@TerminateJob' {} Text
a -> TerminateJob
s {$sel:jobId:TerminateJob' :: Text
jobId = Text
a} :: TerminateJob)

-- | A message to attach to the job that explains the reason for canceling
-- it. This message is returned by future DescribeJobs operations on the
-- job. This message is also recorded in the Batch activity logs.
terminateJob_reason :: Lens.Lens' TerminateJob Prelude.Text
terminateJob_reason :: Lens' TerminateJob Text
terminateJob_reason = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TerminateJob' {Text
reason :: Text
$sel:reason:TerminateJob' :: TerminateJob -> Text
reason} -> Text
reason) (\s :: TerminateJob
s@TerminateJob' {} Text
a -> TerminateJob
s {$sel:reason:TerminateJob' :: Text
reason = Text
a} :: TerminateJob)

instance Core.AWSRequest TerminateJob where
  type AWSResponse TerminateJob = TerminateJobResponse
  request :: (Service -> Service) -> TerminateJob -> Request TerminateJob
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 TerminateJob
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse TerminateJob)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> TerminateJobResponse
TerminateJobResponse'
            forall (f :: * -> *) a b. Functor 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 TerminateJob where
  hashWithSalt :: Int -> TerminateJob -> Int
hashWithSalt Int
_salt TerminateJob' {Text
reason :: Text
jobId :: Text
$sel:reason:TerminateJob' :: TerminateJob -> Text
$sel:jobId:TerminateJob' :: TerminateJob -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
jobId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
reason

instance Prelude.NFData TerminateJob where
  rnf :: TerminateJob -> ()
rnf TerminateJob' {Text
reason :: Text
jobId :: Text
$sel:reason:TerminateJob' :: TerminateJob -> Text
$sel:jobId:TerminateJob' :: TerminateJob -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
jobId seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
reason

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

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

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

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

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

-- |
-- Create a value of 'TerminateJobResponse' 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:
--
-- 'httpStatus', 'terminateJobResponse_httpStatus' - The response's http status code.
newTerminateJobResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  TerminateJobResponse
newTerminateJobResponse :: Int -> TerminateJobResponse
newTerminateJobResponse Int
pHttpStatus_ =
  TerminateJobResponse' {$sel:httpStatus:TerminateJobResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData TerminateJobResponse where
  rnf :: TerminateJobResponse -> ()
rnf TerminateJobResponse' {Int
httpStatus :: Int
$sel:httpStatus:TerminateJobResponse' :: TerminateJobResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus