{-# 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.Glue.BatchStopJobRun
-- 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 one or more job runs for a specified job definition.
module Amazonka.Glue.BatchStopJobRun
  ( -- * Creating a Request
    BatchStopJobRun (..),
    newBatchStopJobRun,

    -- * Request Lenses
    batchStopJobRun_jobName,
    batchStopJobRun_jobRunIds,

    -- * Destructuring the Response
    BatchStopJobRunResponse (..),
    newBatchStopJobRunResponse,

    -- * Response Lenses
    batchStopJobRunResponse_errors,
    batchStopJobRunResponse_successfulSubmissions,
    batchStopJobRunResponse_httpStatus,
  )
where

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

-- | /See:/ 'newBatchStopJobRun' smart constructor.
data BatchStopJobRun = BatchStopJobRun'
  { -- | The name of the job definition for which to stop job runs.
    BatchStopJobRun -> Text
jobName :: Prelude.Text,
    -- | A list of the @JobRunIds@ that should be stopped for that job
    -- definition.
    BatchStopJobRun -> NonEmpty Text
jobRunIds :: Prelude.NonEmpty Prelude.Text
  }
  deriving (BatchStopJobRun -> BatchStopJobRun -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchStopJobRun -> BatchStopJobRun -> Bool
$c/= :: BatchStopJobRun -> BatchStopJobRun -> Bool
== :: BatchStopJobRun -> BatchStopJobRun -> Bool
$c== :: BatchStopJobRun -> BatchStopJobRun -> Bool
Prelude.Eq, ReadPrec [BatchStopJobRun]
ReadPrec BatchStopJobRun
Int -> ReadS BatchStopJobRun
ReadS [BatchStopJobRun]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchStopJobRun]
$creadListPrec :: ReadPrec [BatchStopJobRun]
readPrec :: ReadPrec BatchStopJobRun
$creadPrec :: ReadPrec BatchStopJobRun
readList :: ReadS [BatchStopJobRun]
$creadList :: ReadS [BatchStopJobRun]
readsPrec :: Int -> ReadS BatchStopJobRun
$creadsPrec :: Int -> ReadS BatchStopJobRun
Prelude.Read, Int -> BatchStopJobRun -> ShowS
[BatchStopJobRun] -> ShowS
BatchStopJobRun -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchStopJobRun] -> ShowS
$cshowList :: [BatchStopJobRun] -> ShowS
show :: BatchStopJobRun -> String
$cshow :: BatchStopJobRun -> String
showsPrec :: Int -> BatchStopJobRun -> ShowS
$cshowsPrec :: Int -> BatchStopJobRun -> ShowS
Prelude.Show, forall x. Rep BatchStopJobRun x -> BatchStopJobRun
forall x. BatchStopJobRun -> Rep BatchStopJobRun x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchStopJobRun x -> BatchStopJobRun
$cfrom :: forall x. BatchStopJobRun -> Rep BatchStopJobRun x
Prelude.Generic)

-- |
-- Create a value of 'BatchStopJobRun' 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:
--
-- 'jobName', 'batchStopJobRun_jobName' - The name of the job definition for which to stop job runs.
--
-- 'jobRunIds', 'batchStopJobRun_jobRunIds' - A list of the @JobRunIds@ that should be stopped for that job
-- definition.
newBatchStopJobRun ::
  -- | 'jobName'
  Prelude.Text ->
  -- | 'jobRunIds'
  Prelude.NonEmpty Prelude.Text ->
  BatchStopJobRun
newBatchStopJobRun :: Text -> NonEmpty Text -> BatchStopJobRun
newBatchStopJobRun Text
pJobName_ NonEmpty Text
pJobRunIds_ =
  BatchStopJobRun'
    { $sel:jobName:BatchStopJobRun' :: Text
jobName = Text
pJobName_,
      $sel:jobRunIds:BatchStopJobRun' :: NonEmpty Text
jobRunIds = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pJobRunIds_
    }

-- | The name of the job definition for which to stop job runs.
batchStopJobRun_jobName :: Lens.Lens' BatchStopJobRun Prelude.Text
batchStopJobRun_jobName :: Lens' BatchStopJobRun Text
batchStopJobRun_jobName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchStopJobRun' {Text
jobName :: Text
$sel:jobName:BatchStopJobRun' :: BatchStopJobRun -> Text
jobName} -> Text
jobName) (\s :: BatchStopJobRun
s@BatchStopJobRun' {} Text
a -> BatchStopJobRun
s {$sel:jobName:BatchStopJobRun' :: Text
jobName = Text
a} :: BatchStopJobRun)

-- | A list of the @JobRunIds@ that should be stopped for that job
-- definition.
batchStopJobRun_jobRunIds :: Lens.Lens' BatchStopJobRun (Prelude.NonEmpty Prelude.Text)
batchStopJobRun_jobRunIds :: Lens' BatchStopJobRun (NonEmpty Text)
batchStopJobRun_jobRunIds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchStopJobRun' {NonEmpty Text
jobRunIds :: NonEmpty Text
$sel:jobRunIds:BatchStopJobRun' :: BatchStopJobRun -> NonEmpty Text
jobRunIds} -> NonEmpty Text
jobRunIds) (\s :: BatchStopJobRun
s@BatchStopJobRun' {} NonEmpty Text
a -> BatchStopJobRun
s {$sel:jobRunIds:BatchStopJobRun' :: NonEmpty Text
jobRunIds = NonEmpty Text
a} :: BatchStopJobRun) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest BatchStopJobRun where
  type
    AWSResponse BatchStopJobRun =
      BatchStopJobRunResponse
  request :: (Service -> Service) -> BatchStopJobRun -> Request BatchStopJobRun
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 BatchStopJobRun
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BatchStopJobRun)))
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 [BatchStopJobRunError]
-> Maybe [BatchStopJobRunSuccessfulSubmission]
-> Int
-> BatchStopJobRunResponse
BatchStopJobRunResponse'
            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
"Errors" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"SuccessfulSubmissions"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                        )
            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 BatchStopJobRun where
  hashWithSalt :: Int -> BatchStopJobRun -> Int
hashWithSalt Int
_salt BatchStopJobRun' {NonEmpty Text
Text
jobRunIds :: NonEmpty Text
jobName :: Text
$sel:jobRunIds:BatchStopJobRun' :: BatchStopJobRun -> NonEmpty Text
$sel:jobName:BatchStopJobRun' :: BatchStopJobRun -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
jobName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
jobRunIds

instance Prelude.NFData BatchStopJobRun where
  rnf :: BatchStopJobRun -> ()
rnf BatchStopJobRun' {NonEmpty Text
Text
jobRunIds :: NonEmpty Text
jobName :: Text
$sel:jobRunIds:BatchStopJobRun' :: BatchStopJobRun -> NonEmpty Text
$sel:jobName:BatchStopJobRun' :: BatchStopJobRun -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
jobName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
jobRunIds

instance Data.ToHeaders BatchStopJobRun where
  toHeaders :: BatchStopJobRun -> 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
"AWSGlue.BatchStopJobRun" :: 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 BatchStopJobRun where
  toJSON :: BatchStopJobRun -> Value
toJSON BatchStopJobRun' {NonEmpty Text
Text
jobRunIds :: NonEmpty Text
jobName :: Text
$sel:jobRunIds:BatchStopJobRun' :: BatchStopJobRun -> NonEmpty Text
$sel:jobName:BatchStopJobRun' :: BatchStopJobRun -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"JobName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
jobName),
            forall a. a -> Maybe a
Prelude.Just (Key
"JobRunIds" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
jobRunIds)
          ]
      )

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

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

-- | /See:/ 'newBatchStopJobRunResponse' smart constructor.
data BatchStopJobRunResponse = BatchStopJobRunResponse'
  { -- | A list of the errors that were encountered in trying to stop @JobRuns@,
    -- including the @JobRunId@ for which each error was encountered and
    -- details about the error.
    BatchStopJobRunResponse -> Maybe [BatchStopJobRunError]
errors :: Prelude.Maybe [BatchStopJobRunError],
    -- | A list of the JobRuns that were successfully submitted for stopping.
    BatchStopJobRunResponse
-> Maybe [BatchStopJobRunSuccessfulSubmission]
successfulSubmissions :: Prelude.Maybe [BatchStopJobRunSuccessfulSubmission],
    -- | The response's http status code.
    BatchStopJobRunResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BatchStopJobRunResponse -> BatchStopJobRunResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchStopJobRunResponse -> BatchStopJobRunResponse -> Bool
$c/= :: BatchStopJobRunResponse -> BatchStopJobRunResponse -> Bool
== :: BatchStopJobRunResponse -> BatchStopJobRunResponse -> Bool
$c== :: BatchStopJobRunResponse -> BatchStopJobRunResponse -> Bool
Prelude.Eq, ReadPrec [BatchStopJobRunResponse]
ReadPrec BatchStopJobRunResponse
Int -> ReadS BatchStopJobRunResponse
ReadS [BatchStopJobRunResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchStopJobRunResponse]
$creadListPrec :: ReadPrec [BatchStopJobRunResponse]
readPrec :: ReadPrec BatchStopJobRunResponse
$creadPrec :: ReadPrec BatchStopJobRunResponse
readList :: ReadS [BatchStopJobRunResponse]
$creadList :: ReadS [BatchStopJobRunResponse]
readsPrec :: Int -> ReadS BatchStopJobRunResponse
$creadsPrec :: Int -> ReadS BatchStopJobRunResponse
Prelude.Read, Int -> BatchStopJobRunResponse -> ShowS
[BatchStopJobRunResponse] -> ShowS
BatchStopJobRunResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchStopJobRunResponse] -> ShowS
$cshowList :: [BatchStopJobRunResponse] -> ShowS
show :: BatchStopJobRunResponse -> String
$cshow :: BatchStopJobRunResponse -> String
showsPrec :: Int -> BatchStopJobRunResponse -> ShowS
$cshowsPrec :: Int -> BatchStopJobRunResponse -> ShowS
Prelude.Show, forall x. Rep BatchStopJobRunResponse x -> BatchStopJobRunResponse
forall x. BatchStopJobRunResponse -> Rep BatchStopJobRunResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchStopJobRunResponse x -> BatchStopJobRunResponse
$cfrom :: forall x. BatchStopJobRunResponse -> Rep BatchStopJobRunResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchStopJobRunResponse' 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:
--
-- 'errors', 'batchStopJobRunResponse_errors' - A list of the errors that were encountered in trying to stop @JobRuns@,
-- including the @JobRunId@ for which each error was encountered and
-- details about the error.
--
-- 'successfulSubmissions', 'batchStopJobRunResponse_successfulSubmissions' - A list of the JobRuns that were successfully submitted for stopping.
--
-- 'httpStatus', 'batchStopJobRunResponse_httpStatus' - The response's http status code.
newBatchStopJobRunResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchStopJobRunResponse
newBatchStopJobRunResponse :: Int -> BatchStopJobRunResponse
newBatchStopJobRunResponse Int
pHttpStatus_ =
  BatchStopJobRunResponse'
    { $sel:errors:BatchStopJobRunResponse' :: Maybe [BatchStopJobRunError]
errors = forall a. Maybe a
Prelude.Nothing,
      $sel:successfulSubmissions:BatchStopJobRunResponse' :: Maybe [BatchStopJobRunSuccessfulSubmission]
successfulSubmissions = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BatchStopJobRunResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of the errors that were encountered in trying to stop @JobRuns@,
-- including the @JobRunId@ for which each error was encountered and
-- details about the error.
batchStopJobRunResponse_errors :: Lens.Lens' BatchStopJobRunResponse (Prelude.Maybe [BatchStopJobRunError])
batchStopJobRunResponse_errors :: Lens' BatchStopJobRunResponse (Maybe [BatchStopJobRunError])
batchStopJobRunResponse_errors = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchStopJobRunResponse' {Maybe [BatchStopJobRunError]
errors :: Maybe [BatchStopJobRunError]
$sel:errors:BatchStopJobRunResponse' :: BatchStopJobRunResponse -> Maybe [BatchStopJobRunError]
errors} -> Maybe [BatchStopJobRunError]
errors) (\s :: BatchStopJobRunResponse
s@BatchStopJobRunResponse' {} Maybe [BatchStopJobRunError]
a -> BatchStopJobRunResponse
s {$sel:errors:BatchStopJobRunResponse' :: Maybe [BatchStopJobRunError]
errors = Maybe [BatchStopJobRunError]
a} :: BatchStopJobRunResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A list of the JobRuns that were successfully submitted for stopping.
batchStopJobRunResponse_successfulSubmissions :: Lens.Lens' BatchStopJobRunResponse (Prelude.Maybe [BatchStopJobRunSuccessfulSubmission])
batchStopJobRunResponse_successfulSubmissions :: Lens'
  BatchStopJobRunResponse
  (Maybe [BatchStopJobRunSuccessfulSubmission])
batchStopJobRunResponse_successfulSubmissions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchStopJobRunResponse' {Maybe [BatchStopJobRunSuccessfulSubmission]
successfulSubmissions :: Maybe [BatchStopJobRunSuccessfulSubmission]
$sel:successfulSubmissions:BatchStopJobRunResponse' :: BatchStopJobRunResponse
-> Maybe [BatchStopJobRunSuccessfulSubmission]
successfulSubmissions} -> Maybe [BatchStopJobRunSuccessfulSubmission]
successfulSubmissions) (\s :: BatchStopJobRunResponse
s@BatchStopJobRunResponse' {} Maybe [BatchStopJobRunSuccessfulSubmission]
a -> BatchStopJobRunResponse
s {$sel:successfulSubmissions:BatchStopJobRunResponse' :: Maybe [BatchStopJobRunSuccessfulSubmission]
successfulSubmissions = Maybe [BatchStopJobRunSuccessfulSubmission]
a} :: BatchStopJobRunResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData BatchStopJobRunResponse where
  rnf :: BatchStopJobRunResponse -> ()
rnf BatchStopJobRunResponse' {Int
Maybe [BatchStopJobRunSuccessfulSubmission]
Maybe [BatchStopJobRunError]
httpStatus :: Int
successfulSubmissions :: Maybe [BatchStopJobRunSuccessfulSubmission]
errors :: Maybe [BatchStopJobRunError]
$sel:httpStatus:BatchStopJobRunResponse' :: BatchStopJobRunResponse -> Int
$sel:successfulSubmissions:BatchStopJobRunResponse' :: BatchStopJobRunResponse
-> Maybe [BatchStopJobRunSuccessfulSubmission]
$sel:errors:BatchStopJobRunResponse' :: BatchStopJobRunResponse -> Maybe [BatchStopJobRunError]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [BatchStopJobRunError]
errors
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [BatchStopJobRunSuccessfulSubmission]
successfulSubmissions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus