{-# 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.ECS.StopTask
-- 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 running task. Any tags associated with the task will be deleted.
--
-- When StopTask is called on a task, the equivalent of @docker stop@ is
-- issued to the containers running in the task. This results in a
-- @SIGTERM@ value and a default 30-second timeout, after which the
-- @SIGKILL@ value is sent and the containers are forcibly stopped. If the
-- container handles the @SIGTERM@ value gracefully and exits within 30
-- seconds from receiving it, no @SIGKILL@ value is sent.
--
-- The default 30-second timeout can be configured on the Amazon ECS
-- container agent with the @ECS_CONTAINER_STOP_TIMEOUT@ variable. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-config.html Amazon ECS Container Agent Configuration>
-- in the /Amazon Elastic Container Service Developer Guide/.
module Amazonka.ECS.StopTask
  ( -- * Creating a Request
    StopTask (..),
    newStopTask,

    -- * Request Lenses
    stopTask_cluster,
    stopTask_reason,
    stopTask_task,

    -- * Destructuring the Response
    StopTaskResponse (..),
    newStopTaskResponse,

    -- * Response Lenses
    stopTaskResponse_task,
    stopTaskResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.ECS.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newStopTask' smart constructor.
data StopTask = StopTask'
  { -- | The short name or full Amazon Resource Name (ARN) of the cluster that
    -- hosts the task to stop. If you do not specify a cluster, the default
    -- cluster is assumed.
    StopTask -> Maybe Text
cluster :: Prelude.Maybe Prelude.Text,
    -- | An optional message specified when a task is stopped. For example, if
    -- you are using a custom scheduler, you can use this parameter to specify
    -- the reason for stopping the task here, and the message appears in
    -- subsequent DescribeTasks API operations on this task. Up to 255
    -- characters are allowed in this message.
    StopTask -> Maybe Text
reason :: Prelude.Maybe Prelude.Text,
    -- | The task ID or full Amazon Resource Name (ARN) of the task to stop.
    StopTask -> Text
task :: Prelude.Text
  }
  deriving (StopTask -> StopTask -> Bool
(StopTask -> StopTask -> Bool)
-> (StopTask -> StopTask -> Bool) -> Eq StopTask
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopTask -> StopTask -> Bool
$c/= :: StopTask -> StopTask -> Bool
== :: StopTask -> StopTask -> Bool
$c== :: StopTask -> StopTask -> Bool
Prelude.Eq, ReadPrec [StopTask]
ReadPrec StopTask
Int -> ReadS StopTask
ReadS [StopTask]
(Int -> ReadS StopTask)
-> ReadS [StopTask]
-> ReadPrec StopTask
-> ReadPrec [StopTask]
-> Read StopTask
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopTask]
$creadListPrec :: ReadPrec [StopTask]
readPrec :: ReadPrec StopTask
$creadPrec :: ReadPrec StopTask
readList :: ReadS [StopTask]
$creadList :: ReadS [StopTask]
readsPrec :: Int -> ReadS StopTask
$creadsPrec :: Int -> ReadS StopTask
Prelude.Read, Int -> StopTask -> ShowS
[StopTask] -> ShowS
StopTask -> String
(Int -> StopTask -> ShowS)
-> (StopTask -> String) -> ([StopTask] -> ShowS) -> Show StopTask
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopTask] -> ShowS
$cshowList :: [StopTask] -> ShowS
show :: StopTask -> String
$cshow :: StopTask -> String
showsPrec :: Int -> StopTask -> ShowS
$cshowsPrec :: Int -> StopTask -> ShowS
Prelude.Show, (forall x. StopTask -> Rep StopTask x)
-> (forall x. Rep StopTask x -> StopTask) -> Generic StopTask
forall x. Rep StopTask x -> StopTask
forall x. StopTask -> Rep StopTask x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopTask x -> StopTask
$cfrom :: forall x. StopTask -> Rep StopTask x
Prelude.Generic)

-- |
-- Create a value of 'StopTask' 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:
--
-- 'cluster', 'stopTask_cluster' - The short name or full Amazon Resource Name (ARN) of the cluster that
-- hosts the task to stop. If you do not specify a cluster, the default
-- cluster is assumed.
--
-- 'reason', 'stopTask_reason' - An optional message specified when a task is stopped. For example, if
-- you are using a custom scheduler, you can use this parameter to specify
-- the reason for stopping the task here, and the message appears in
-- subsequent DescribeTasks API operations on this task. Up to 255
-- characters are allowed in this message.
--
-- 'task', 'stopTask_task' - The task ID or full Amazon Resource Name (ARN) of the task to stop.
newStopTask ::
  -- | 'task'
  Prelude.Text ->
  StopTask
newStopTask :: Text -> StopTask
newStopTask Text
pTask_ =
  StopTask' :: Maybe Text -> Maybe Text -> Text -> StopTask
StopTask'
    { $sel:cluster:StopTask' :: Maybe Text
cluster = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:reason:StopTask' :: Maybe Text
reason = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:task:StopTask' :: Text
task = Text
pTask_
    }

-- | The short name or full Amazon Resource Name (ARN) of the cluster that
-- hosts the task to stop. If you do not specify a cluster, the default
-- cluster is assumed.
stopTask_cluster :: Lens.Lens' StopTask (Prelude.Maybe Prelude.Text)
stopTask_cluster :: (Maybe Text -> f (Maybe Text)) -> StopTask -> f StopTask
stopTask_cluster = (StopTask -> Maybe Text)
-> (StopTask -> Maybe Text -> StopTask)
-> Lens StopTask StopTask (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopTask' {Maybe Text
cluster :: Maybe Text
$sel:cluster:StopTask' :: StopTask -> Maybe Text
cluster} -> Maybe Text
cluster) (\s :: StopTask
s@StopTask' {} Maybe Text
a -> StopTask
s {$sel:cluster:StopTask' :: Maybe Text
cluster = Maybe Text
a} :: StopTask)

-- | An optional message specified when a task is stopped. For example, if
-- you are using a custom scheduler, you can use this parameter to specify
-- the reason for stopping the task here, and the message appears in
-- subsequent DescribeTasks API operations on this task. Up to 255
-- characters are allowed in this message.
stopTask_reason :: Lens.Lens' StopTask (Prelude.Maybe Prelude.Text)
stopTask_reason :: (Maybe Text -> f (Maybe Text)) -> StopTask -> f StopTask
stopTask_reason = (StopTask -> Maybe Text)
-> (StopTask -> Maybe Text -> StopTask)
-> Lens StopTask StopTask (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopTask' {Maybe Text
reason :: Maybe Text
$sel:reason:StopTask' :: StopTask -> Maybe Text
reason} -> Maybe Text
reason) (\s :: StopTask
s@StopTask' {} Maybe Text
a -> StopTask
s {$sel:reason:StopTask' :: Maybe Text
reason = Maybe Text
a} :: StopTask)

-- | The task ID or full Amazon Resource Name (ARN) of the task to stop.
stopTask_task :: Lens.Lens' StopTask Prelude.Text
stopTask_task :: (Text -> f Text) -> StopTask -> f StopTask
stopTask_task = (StopTask -> Text)
-> (StopTask -> Text -> StopTask)
-> Lens StopTask StopTask Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopTask' {Text
task :: Text
$sel:task:StopTask' :: StopTask -> Text
task} -> Text
task) (\s :: StopTask
s@StopTask' {} Text
a -> StopTask
s {$sel:task:StopTask' :: Text
task = Text
a} :: StopTask)

instance Core.AWSRequest StopTask where
  type AWSResponse StopTask = StopTaskResponse
  request :: StopTask -> Request StopTask
request = Service -> StopTask -> Request StopTask
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StopTask
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopTask)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StopTask))
-> Logger
-> Service
-> Proxy StopTask
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopTask)))
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 Task -> Int -> StopTaskResponse
StopTaskResponse'
            (Maybe Task -> Int -> StopTaskResponse)
-> Either String (Maybe Task)
-> Either String (Int -> StopTaskResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Task)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"task")
            Either String (Int -> StopTaskResponse)
-> Either String Int -> Either String StopTaskResponse
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 StopTask

instance Prelude.NFData StopTask

instance Core.ToHeaders StopTask where
  toHeaders :: StopTask -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StopTask -> 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
"AmazonEC2ContainerServiceV20141113.StopTask" ::
                          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 StopTask where
  toJSON :: StopTask -> Value
toJSON StopTask' {Maybe Text
Text
task :: Text
reason :: Maybe Text
cluster :: Maybe Text
$sel:task:StopTask' :: StopTask -> Text
$sel:reason:StopTask' :: StopTask -> Maybe Text
$sel:cluster:StopTask' :: StopTask -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"cluster" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
cluster,
            (Text
"reason" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
reason,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"task" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
task)
          ]
      )

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

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

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

-- |
-- Create a value of 'StopTaskResponse' 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:
--
-- 'task', 'stopTaskResponse_task' - The task that was stopped.
--
-- 'httpStatus', 'stopTaskResponse_httpStatus' - The response's http status code.
newStopTaskResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopTaskResponse
newStopTaskResponse :: Int -> StopTaskResponse
newStopTaskResponse Int
pHttpStatus_ =
  StopTaskResponse' :: Maybe Task -> Int -> StopTaskResponse
StopTaskResponse'
    { $sel:task:StopTaskResponse' :: Maybe Task
task = Maybe Task
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StopTaskResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The task that was stopped.
stopTaskResponse_task :: Lens.Lens' StopTaskResponse (Prelude.Maybe Task)
stopTaskResponse_task :: (Maybe Task -> f (Maybe Task))
-> StopTaskResponse -> f StopTaskResponse
stopTaskResponse_task = (StopTaskResponse -> Maybe Task)
-> (StopTaskResponse -> Maybe Task -> StopTaskResponse)
-> Lens StopTaskResponse StopTaskResponse (Maybe Task) (Maybe Task)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopTaskResponse' {Maybe Task
task :: Maybe Task
$sel:task:StopTaskResponse' :: StopTaskResponse -> Maybe Task
task} -> Maybe Task
task) (\s :: StopTaskResponse
s@StopTaskResponse' {} Maybe Task
a -> StopTaskResponse
s {$sel:task:StopTaskResponse' :: Maybe Task
task = Maybe Task
a} :: StopTaskResponse)

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

instance Prelude.NFData StopTaskResponse